[njs] QuickJS: added wrappers for strings creation.
noreply at nginx.com
noreply at nginx.com
Wed Sep 4 00:59:02 UTC 2024
details: https://github.com/nginx/njs/commit/65f1e8555e226f0072d69fd673d000639f6428db
branches: master
commit: 65f1e8555e226f0072d69fd673d000639f6428db
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Fri, 16 Aug 2024 23:29:48 -0700
description:
QuickJS: added wrappers for strings creation.
---
src/qjs.c | 20 ++++++++++++++++++++
src/qjs.h | 11 +++++++++++
2 files changed, 31 insertions(+)
diff --git a/src/qjs.c b/src/qjs.c
index b8c53486..71aeab64 100644
--- 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;
+}
diff --git a/src/qjs.h b/src/qjs.h
index 531940ea..516fea96 100644
--- 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[];
More information about the nginx-devel
mailing list