]> git.kaiwu.me - njs.git/commitdiff
QuickJS: added wrappers for strings creation.
authorDmitry Volyntsev <xeioex@nginx.com>
Sat, 17 Aug 2024 06:29:48 +0000 (23:29 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Wed, 4 Sep 2024 00:58:54 +0000 (17:58 -0700)
src/qjs.c
src/qjs.h

index b8c534861535bc62e30040a2d5ffba8c2e93819f..71aeab64cc7a91f0cadd86709c0043abad38fa6f 100644 (file)
--- a/src/qjs.c
+++ b/src/qjs.c
@@ -227,3 +227,23 @@ qjs_typed_array_data(JSContext *ctx, JSValueConst value, njs_str_t *data)
 
     return JS_UNDEFINED;
 }
+
+
+JSValue
+qjs_string_create_chb(JSContext *cx, njs_chb_t *chain)
+{
+    JSValue    val;
+    njs_int_t  ret;
+    njs_str_t  str;
+
+    ret = njs_chb_join(chain, &str);
+    if (ret != NJS_OK) {
+        return JS_ThrowInternalError(cx, "failed to create string");
+    }
+
+    val = JS_NewStringLen(cx, (const char *) str.start, str.length);
+
+    chain->free(cx, str.start);
+
+    return val;
+}
index 531940ea9f725fcb2f2e79d8f4c6ee98c5687ad8..516fea9691a6abef6f396e88d6ca300704c8d564 100644 (file)
--- a/src/qjs.h
+++ b/src/qjs.h
@@ -77,6 +77,17 @@ void qjs_bytes_free(JSContext *ctx, qjs_bytes_t *data);
 JSValue qjs_typed_array_data(JSContext *ctx, JSValueConst value,
     njs_str_t *data);
 
+#define qjs_string_create(ctx, data, len)                                   \
+    JS_NewStringLen(ctx, (const char *) (data), len)
+JSValue qjs_string_create_chb(JSContext *cx, njs_chb_t *chain);
+
+
+static inline JS_BOOL JS_IsNullOrUndefined(JSValueConst v)
+{
+    return JS_VALUE_GET_TAG(v) == JS_TAG_NULL
+           || JS_VALUE_GET_TAG(v) == JS_TAG_UNDEFINED;
+}
+
 
 extern qjs_module_t              *qjs_modules[];