Anonymous User
September 03, 2024 09:00PM
details: https://github.com/nginx/njs/commit/65f1e8555e226f0072d69fd673d000639f6428db
branches: master
commit: 65f1e8555e226f0072d69fd673d000639f6428db
user: Dmitry Volyntsev <xeioex@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[];

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] QuickJS: added wrappers for strings creation.

Anonymous User 106 September 03, 2024 09:00PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 199
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready