details: https://github.com/nginx/njs/commit/18d31701cef4af1925f6702e591ca77761541b7e branches: master commit: 18d31701cef4af1925f6702e591ca77761541b7e user: Dmitry Volyntsev <xei...@nginx.com> date: Wed, 5 Feb 2025 16:47:03 -0800 description: QuickJS: using helper to declare Symbol.toStringTag properties.
--- external/njs_shell.c | 10 ++------- external/qjs_fs_module.c | 34 ++++-------------------------- external/qjs_webcrypto_module.c | 13 ++---------- nginx/ngx_http_js_module.c | 27 +++--------------------- nginx/ngx_js_shared_dict.c | 14 +++---------- nginx/ngx_stream_js_module.c | 27 ++++-------------------- src/qjs.c | 46 ++++++----------------------------------- 7 files changed, 24 insertions(+), 147 deletions(-) diff --git a/external/njs_shell.c b/external/njs_shell.c index 015c930f..1228b374 100644 --- a/external/njs_shell.c +++ b/external/njs_shell.c @@ -1901,13 +1901,6 @@ njs_qjs_clear_timeout(JSContext *ctx, JSValueConst this_val, int argc, } -static JSValue -njs_qjs_console_to_string_tag(JSContext *ctx, JSValueConst this_val) -{ - return JS_NewString(ctx, "Console"); -} - - static JSValue njs_qjs_process_getter(JSContext *ctx, JSValueConst this_val) { @@ -2487,7 +2480,8 @@ static const JSCFunctionListEntry njs_qjs_global_proto[] = { static const JSCFunctionListEntry njs_qjs_console_proto[] = { - JS_CGETSET_DEF("[Symbol.toStringTag]", njs_qjs_console_to_string_tag, NULL), + JS_PROP_STRING_DEF("[Symbol.toStringTag]", "Console", + JS_PROP_CONFIGURABLE), JS_CFUNC_MAGIC_DEF("error", 0, njs_qjs_console_log, NJS_LOG_ERROR), JS_CFUNC_MAGIC_DEF("info", 0, njs_qjs_console_log, NJS_LOG_INFO), JS_CFUNC_MAGIC_DEF("log", 0, njs_qjs_console_log, NJS_LOG_INFO), diff --git a/external/qjs_fs_module.c b/external/qjs_fs_module.c index 2adeef20..9d1f7687 100644 --- a/external/qjs_fs_module.c +++ b/external/qjs_fs_module.c @@ -167,7 +167,6 @@ static JSValue qjs_fs_write_file(JSContext *cx, JSValueConst this_val, int argc, static JSValue qjs_fs_unlink(JSContext *cx, JSValueConst this_val, int argc, JSValueConst *argv, int calltype); -static JSValue qjs_fs_stats_to_string_tag(JSContext *cx, JSValueConst this_val); static JSValue qjs_fs_stats_test(JSContext *cx, JSValueConst this_val, int argc, JSValueConst *argv, int testtype); static int qjs_fs_stats_get_own_property(JSContext *cx, @@ -176,15 +175,11 @@ static int qjs_fs_stats_get_own_property_names(JSContext *cx, JSPropertyEnum **ptab, uint32_t *plen, JSValueConst obj); static void qjs_fs_stats_finalizer(JSRuntime *rt, JSValue val); -static JSValue qjs_fs_dirent_to_string_tag(JSContext *cx, - JSValueConst this_val); static JSValue qjs_fs_dirent_ctor(JSContext *cx, JSValueConst new_target, int argc, JSValueConst *argv); static JSValue qjs_fs_dirent_test(JSContext *cx, JSValueConst this_val, int argc, JSValueConst *argv, int testtype); -static JSValue qjs_fs_filehandle_to_string_tag(JSContext *cx, - JSValueConst this_val); static JSValue qjs_fs_filehandle_fd(JSContext *cx, JSValueConst this_val); static JSValue qjs_fs_filehandle_value_of(JSContext *cx, JSValueConst this_val, int argc, JSValueConst *argv); @@ -222,7 +217,7 @@ static qjs_fs_entry_t qjs_flags_table[] = { static const JSCFunctionListEntry qjs_fs_stats_proto[] = { - JS_CGETSET_DEF("[Symbol.toStringTag]", qjs_fs_stats_to_string_tag, NULL), + JS_PROP_STRING_DEF("[Symbol.toStringTag]", "Stats", JS_PROP_CONFIGURABLE), JS_CFUNC_MAGIC_DEF("isBlockDevice", 0, qjs_fs_stats_test, DT_BLK), JS_CFUNC_MAGIC_DEF("isCharacterDevice", 0, qjs_fs_stats_test, DT_CHR), JS_CFUNC_MAGIC_DEF("isDirectory", 0, qjs_fs_stats_test, DT_DIR), @@ -234,7 +229,7 @@ static const JSCFunctionListEntry qjs_fs_stats_proto[] = { static const JSCFunctionListEntry qjs_fs_dirent_proto[] = { - JS_CGETSET_DEF("[Symbol.toStringTag]", qjs_fs_dirent_to_string_tag, NULL), + JS_PROP_STRING_DEF("[Symbol.toStringTag]", "Dirent", JS_PROP_CONFIGURABLE), JS_CFUNC_MAGIC_DEF("isBlockDevice", 0, qjs_fs_dirent_test, DT_BLK), JS_CFUNC_MAGIC_DEF("isCharacterDevice", 0, qjs_fs_dirent_test, DT_CHR), JS_CFUNC_MAGIC_DEF("isDirectory", 0, qjs_fs_dirent_test, DT_DIR), @@ -247,8 +242,8 @@ static const JSCFunctionListEntry qjs_fs_dirent_proto[] = { static const JSCFunctionListEntry qjs_fs_filehandle_proto[] = { - JS_CGETSET_DEF("[Symbol.toStringTag]", qjs_fs_filehandle_to_string_tag, - NULL), + JS_PROP_STRING_DEF("[Symbol.toStringTag]", "FileHandle", + JS_PROP_CONFIGURABLE), JS_CFUNC_MAGIC_DEF("close", 0, qjs_fs_close, QJS_FS_PROMISE), JS_CGETSET_DEF("fd", qjs_fs_filehandle_fd, NULL), JS_CFUNC_MAGIC_DEF("stat", 4, qjs_fs_stat, @@ -2341,13 +2336,6 @@ qjs_fs_unlink(JSContext *cx, JSValueConst this_val, int argc, } -static JSValue -qjs_fs_stats_to_string_tag(JSContext *cx, JSValueConst this_val) -{ - return JS_NewString(cx, "Stats"); -} - - static JSValue qjs_fs_stats_test(JSContext *cx, JSValueConst this_val, int argc, JSValueConst *argv, int testtype) @@ -2629,13 +2617,6 @@ qjs_fs_stats_finalizer(JSRuntime *rt, JSValue val) } -static JSValue -qjs_fs_dirent_to_string_tag(JSContext *cx, JSValueConst this_val) -{ - return JS_NewString(cx, "Dirent"); -} - - static JSValue qjs_fs_dirent_test(JSContext *cx, JSValueConst this_val, int argc, JSValueConst *argv, int testtype) @@ -2666,13 +2647,6 @@ qjs_fs_dirent_test(JSContext *cx, JSValueConst this_val, int argc, } -static JSValue -qjs_fs_filehandle_to_string_tag(JSContext *cx, JSValueConst this_val) -{ - return JS_NewString(cx, "FileHandle"); -} - - static JSValue qjs_fs_filehandle_fd(JSContext *cx, JSValueConst thisval) { diff --git a/external/qjs_webcrypto_module.c b/external/qjs_webcrypto_module.c index 560b2dd7..730feb6e 100644 --- a/external/qjs_webcrypto_module.c +++ b/external/qjs_webcrypto_module.c @@ -128,8 +128,6 @@ static JSValue qjs_webcrypto_import_key(JSContext *cx, JSValueConst this_val, static JSValue qjs_webcrypto_sign(JSContext *cx, JSValueConst this_val, int argc, JSValueConst *argv, int verify); -static JSValue qjs_webcrypto_key_to_string_tag(JSContext *cx, - JSValueConst this_val); static JSValue qjs_webcrypto_key_algorithm(JSContext *cx, JSValueConst this_val); static JSValue qjs_webcrypto_key_extractable(JSContext *cx, @@ -444,8 +442,8 @@ static const JSCFunctionListEntry qjs_webcrypto_subtle[] = { static const JSCFunctionListEntry qjs_webcrypto_key_proto[] = { - JS_CGETSET_DEF("[Symbol.toStringTag]", qjs_webcrypto_key_to_string_tag, - NULL), + JS_PROP_STRING_DEF("[Symbol.toStringTag]", "CryptoKey", + JS_PROP_CONFIGURABLE), JS_CGETSET_DEF("algorithm", qjs_webcrypto_key_algorithm, NULL), JS_CGETSET_DEF("extractable", qjs_webcrypto_key_extractable, NULL), JS_CGETSET_DEF("type", qjs_webcrypto_key_type, NULL), @@ -4000,13 +3998,6 @@ fail: } -static JSValue -qjs_webcrypto_key_to_string_tag(JSContext *cx, JSValueConst this_val) -{ - return JS_NewString(cx, "CryptoKey"); -} - - static JSValue qjs_webcrypto_key_algorithm(JSContext *cx, JSValueConst this_val) { diff --git a/nginx/ngx_http_js_module.c b/nginx/ngx_http_js_module.c index cdc668c5..71fd92ba 100644 --- a/nginx/ngx_http_js_module.c +++ b/nginx/ngx_http_js_module.c @@ -276,8 +276,6 @@ static njs_int_t ngx_http_js_server(njs_vm_t *vm, ngx_http_request_t *r, njs_value_t *retval); #if (NJS_HAVE_QUICKJS) -static JSValue ngx_http_qjs_ext_to_string_tag(JSContext *cx, - JSValueConst this_val); static JSValue ngx_http_qjs_ext_args(JSContext *cx, JSValueConst this_val); static JSValue ngx_http_qjs_ext_done(JSContext *cx, JSValueConst this_val, int argc, JSValueConst *argv); @@ -294,8 +292,6 @@ static JSValue ngx_http_qjs_ext_internal_redirect(JSContext *cx, JSValueConst this_val, int argc, JSValueConst *argv); static JSValue ngx_http_qjs_ext_log(JSContext *cx, JSValueConst this_val, int argc, JSValueConst *argv, int level); -static JSValue ngx_http_qjs_ext_periodic_to_string_tag(JSContext *cx, - JSValueConst this_val); static JSValue ngx_http_qjs_ext_periodic_variables(JSContext *cx, JSValueConst this_val, int type); static JSValue ngx_http_qjs_ext_parent(JSContext *cx, JSValueConst this_val); @@ -1035,8 +1031,7 @@ static ngx_http_js_entry_t ngx_http_methods[] = { #if (NJS_HAVE_QUICKJS) static const JSCFunctionListEntry ngx_http_qjs_ext_request[] = { - JS_CGETSET_DEF("[Symbol.toStringTag]", ngx_http_qjs_ext_to_string_tag, - NULL), + JS_PROP_STRING_DEF("[Symbol.toStringTag]", "Request", JS_PROP_CONFIGURABLE), JS_CGETSET_DEF("args", ngx_http_qjs_ext_args, NULL), JS_CFUNC_DEF("done", 0, ngx_http_qjs_ext_done), JS_CFUNC_MAGIC_DEF("error", 1, ngx_http_qjs_ext_log, NGX_LOG_ERR), @@ -1081,8 +1076,8 @@ static const JSCFunctionListEntry ngx_http_qjs_ext_request[] = { static const JSCFunctionListEntry ngx_http_qjs_ext_periodic[] = { - JS_CGETSET_DEF("[Symbol.toStringTag]", - ngx_http_qjs_ext_periodic_to_string_tag, NULL), + JS_PROP_STRING_DEF("[Symbol.toStringTag]", "PeriodicSession", + JS_PROP_CONFIGURABLE), JS_CGETSET_MAGIC_DEF("rawVariables", ngx_http_qjs_ext_periodic_variables, NULL, NGX_JS_BUFFER), JS_CGETSET_MAGIC_DEF("variables", ngx_http_qjs_ext_periodic_variables, @@ -4825,14 +4820,6 @@ ngx_http_qjs_query_string_decode(njs_chb_t *chain, const u_char *start, } -static JSValue -ngx_http_qjs_ext_to_string_tag(JSContext *cx, - JSValueConst this_val) -{ - return JS_NewString(cx, "Request"); -} - - static JSValue ngx_http_qjs_ext_args(JSContext *cx, JSValueConst this_val) { @@ -5181,14 +5168,6 @@ ngx_http_qjs_ext_log(JSContext *cx, JSValueConst this_val, int argc, } -static JSValue -ngx_http_qjs_ext_periodic_to_string_tag(JSContext *cx, - JSValueConst this_val) -{ - return JS_NewString(cx, "PeriodicSession"); -} - - static JSValue ngx_http_qjs_ext_periodic_variables(JSContext *cx, JSValueConst this_val, int type) diff --git a/nginx/ngx_js_shared_dict.c b/nginx/ngx_js_shared_dict.c index 06f940e0..6ae12d84 100644 --- a/nginx/ngx_js_shared_dict.c +++ b/nginx/ngx_js_shared_dict.c @@ -146,9 +146,7 @@ static JSValue ngx_qjs_ext_shared_dict_set(JSContext *cx, JSValueConst this_val, int argc, JSValueConst *argv, int flags); static JSValue ngx_qjs_ext_shared_dict_size(JSContext *cx, JSValueConst this_val, int argc, JSValueConst *argv); -static JSValue ngx_qjs_ext_shared_dict_tag(JSContext *cx, - JSValueConst this_val); -static JSValue ngx_qjs_ext_shared_dict_type(JSContext *cx, + static JSValue ngx_qjs_ext_shared_dict_type(JSContext *cx, JSValueConst this_val); static JSValue ngx_qjs_dict_copy_value_locked(JSContext *cx, @@ -425,7 +423,8 @@ static const JSCFunctionListEntry ngx_qjs_ext_ngx[] = { }; static const JSCFunctionListEntry ngx_qjs_ext_shared_dict[] = { - JS_CGETSET_DEF("[Symbol.toStringTag]", ngx_qjs_ext_shared_dict_tag, NULL), + JS_PROP_STRING_DEF("[Symbol.toStringTag]", "SharedDict", + JS_PROP_CONFIGURABLE), JS_CFUNC_MAGIC_DEF("add", 3, ngx_qjs_ext_shared_dict_set, NGX_JS_DICT_FLAG_MUST_NOT_EXIST), JS_CGETSET_DEF("capacity", ngx_qjs_ext_shared_dict_capacity, NULL), @@ -2604,13 +2603,6 @@ ngx_qjs_ext_shared_dict_size(JSContext *cx, JSValueConst this_val, } -static JSValue -ngx_qjs_ext_shared_dict_tag(JSContext *cx, JSValueConst this_val) -{ - return JS_NewString(cx, "SharedDict"); -} - - static JSValue ngx_qjs_ext_shared_dict_type(JSContext *cx, JSValueConst this_val) { diff --git a/nginx/ngx_stream_js_module.c b/nginx/ngx_stream_js_module.c index db00b922..7e93b237 100644 --- a/nginx/ngx_stream_js_module.c +++ b/nginx/ngx_stream_js_module.c @@ -145,8 +145,6 @@ static njs_int_t ngx_stream_js_periodic_variables(njs_vm_t *vm, #if (NJS_HAVE_QUICKJS) -static JSValue ngx_stream_qjs_ext_to_string_tag(JSContext *cx, - JSValueConst this_val); static JSValue ngx_stream_qjs_ext_done(JSContext *cx, JSValueConst this_val, int argc, JSValueConst *argv, int magic); static JSValue ngx_stream_qjs_ext_log(JSContext *cx, JSValueConst this_val, @@ -155,8 +153,6 @@ static JSValue ngx_stream_qjs_ext_on(JSContext *cx, JSValueConst this_val, int argc, JSValueConst *argv); static JSValue ngx_stream_qjs_ext_off(JSContext *cx, JSValueConst this_val, int argc, JSValueConst *argv); -static JSValue ngx_stream_qjs_ext_periodic_to_string_tag(JSContext *cx, - JSValueConst this_val); static JSValue ngx_stream_qjs_ext_periodic_variables(JSContext *cx, JSValueConst this_val, int type); static JSValue ngx_stream_qjs_ext_remote_address(JSContext *cx, @@ -762,8 +758,8 @@ njs_module_t *njs_stream_js_addon_modules[] = { #if (NJS_HAVE_QUICKJS) static const JSCFunctionListEntry ngx_stream_qjs_ext_session[] = { - JS_CGETSET_DEF("[Symbol.toStringTag]", ngx_stream_qjs_ext_to_string_tag, - NULL), + JS_PROP_STRING_DEF("[Symbol.toStringTag]", "Stream Session", + JS_PROP_CONFIGURABLE), JS_CFUNC_MAGIC_DEF("allow", 1, ngx_stream_qjs_ext_done, NGX_OK), JS_CFUNC_MAGIC_DEF("decline", 1, ngx_stream_qjs_ext_done, -NGX_DECLINED), JS_CFUNC_MAGIC_DEF("deny", 1, ngx_stream_qjs_ext_done, -NGX_DONE), @@ -790,8 +786,8 @@ static const JSCFunctionListEntry ngx_stream_qjs_ext_session[] = { static const JSCFunctionListEntry ngx_stream_qjs_ext_periodic[] = { - JS_CGETSET_DEF("[Symbol.toStringTag]", - ngx_stream_qjs_ext_periodic_to_string_tag, NULL), + JS_PROP_STRING_DEF("[Symbol.toStringTag]", "PeriodicSession", + JS_PROP_CONFIGURABLE), JS_CGETSET_MAGIC_DEF("rawVariables", ngx_stream_qjs_ext_periodic_variables, NULL, NGX_JS_BUFFER), JS_CGETSET_MAGIC_DEF("variables", ngx_stream_qjs_ext_periodic_variables, @@ -1998,13 +1994,6 @@ ngx_engine_njs_clone(ngx_js_ctx_t *ctx, ngx_js_loc_conf_t *cf, #if (NJS_HAVE_QUICKJS) -static JSValue -ngx_stream_qjs_ext_to_string_tag(JSContext *cx, JSValueConst this_val) -{ - return JS_NewString(cx, "Stream Session"); -} - - static JSValue ngx_stream_qjs_ext_done(JSContext *cx, JSValueConst this_val, int argc, JSValueConst *argv, int magic) @@ -2222,14 +2211,6 @@ ngx_stream_qjs_ext_off(JSContext *cx, JSValueConst this_val, int argc, } -static JSValue -ngx_stream_qjs_ext_periodic_to_string_tag(JSContext *cx, - JSValueConst this_val) -{ - return JS_NewString(cx, "PeriodicSession"); -} - - static JSValue ngx_stream_qjs_ext_periodic_variables(JSContext *cx, JSValueConst this_val, int type) diff --git a/src/qjs.c b/src/qjs.c index 56c6a3ba..ed9a6178 100644 --- a/src/qjs.c +++ b/src/qjs.c @@ -43,8 +43,6 @@ extern char **environ; static JSValue qjs_njs_getter(JSContext *ctx, JSValueConst this_val); -static JSValue qjs_njs_to_string_tag(JSContext *ctx, JSValueConst this_val); -static JSValue qjs_process_to_string_tag(JSContext *ctx, JSValueConst this_val); static JSValue qjs_process_env(JSContext *ctx, JSValueConst this_val); static JSValue qjs_process_kill(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv); @@ -52,8 +50,6 @@ static JSValue qjs_process_pid(JSContext *ctx, JSValueConst this_val); static JSValue qjs_process_ppid(JSContext *ctx, JSValueConst this_val); static int qjs_add_intrinsic_text_decoder(JSContext *cx, JSValueConst global); -static JSValue qjs_text_decoder_to_string_tag(JSContext *ctx, - JSValueConst this_val); static JSValue qjs_text_decoder_decode(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv); static JSValue qjs_text_decoder_encoding(JSContext *ctx, JSValueConst this_val); @@ -63,8 +59,6 @@ static JSValue qjs_text_decoder_ignore_bom(JSContext *ctx, static void qjs_text_decoder_finalizer(JSRuntime *rt, JSValue val); static int qjs_add_intrinsic_text_encoder(JSContext *cx, JSValueConst global); -static JSValue qjs_text_encoder_to_string_tag(JSContext *ctx, - JSValueConst this_val); static JSValue qjs_text_encoder_encode(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv); static JSValue qjs_text_encoder_encode_into(JSContext *ctx, @@ -110,8 +104,8 @@ static const JSCFunctionListEntry qjs_global_proto[] = { }; static const JSCFunctionListEntry qjs_text_decoder_proto[] = { - JS_CGETSET_DEF("[Symbol.toStringTag]", qjs_text_decoder_to_string_tag, - NULL), + JS_PROP_STRING_DEF("[Symbol.toStringTag]", "TextDecoder", + JS_PROP_CONFIGURABLE), JS_CFUNC_DEF("decode", 1, qjs_text_decoder_decode), JS_CGETSET_DEF("encoding", qjs_text_decoder_encoding, NULL), JS_CGETSET_DEF("fatal", qjs_text_decoder_fatal, NULL), @@ -119,15 +113,15 @@ static const JSCFunctionListEntry qjs_text_decoder_proto[] = { }; static const JSCFunctionListEntry qjs_text_encoder_proto[] = { - JS_CGETSET_DEF("[Symbol.toStringTag]", qjs_text_encoder_to_string_tag, - NULL), + JS_PROP_STRING_DEF("[Symbol.toStringTag]", "TextEncoder", + JS_PROP_CONFIGURABLE), JS_CFUNC_DEF("encode", 1, qjs_text_encoder_encode), JS_CFUNC_DEF("encodeInto", 1, qjs_text_encoder_encode_into), JS_CGETSET_DEF("encoding", qjs_text_encoder_encoding, NULL), }; static const JSCFunctionListEntry qjs_njs_proto[] = { - JS_CGETSET_DEF("[Symbol.toStringTag]", qjs_njs_to_string_tag, NULL), + JS_PROP_STRING_DEF("[Symbol.toStringTag]", "njs", JS_PROP_CONFIGURABLE), JS_PROP_STRING_DEF("version", NJS_VERSION, JS_PROP_C_W_E), JS_PROP_INT32_DEF("version_number", NJS_VERSION_NUMBER, JS_PROP_C_W_E), @@ -135,7 +129,7 @@ static const JSCFunctionListEntry qjs_njs_proto[] = { }; static const JSCFunctionListEntry qjs_process_proto[] = { - JS_CGETSET_DEF("[Symbol.toStringTag]", qjs_process_to_string_tag, NULL), + JS_PROP_STRING_DEF("[Symbol.toStringTag]", "process", JS_PROP_CONFIGURABLE), JS_CGETSET_DEF("env", qjs_process_env, NULL), JS_CFUNC_DEF("kill", 2, qjs_process_kill), JS_CGETSET_DEF("pid", qjs_process_pid, NULL), @@ -246,20 +240,6 @@ qjs_njs_getter(JSContext *ctx, JSValueConst this_val) } -static JSValue -qjs_njs_to_string_tag(JSContext *ctx, JSValueConst this_val) -{ - return JS_NewString(ctx, "njs"); -} - - -static JSValue -qjs_process_to_string_tag(JSContext *ctx, JSValueConst this_val) -{ - return JS_NewString(ctx, "process"); -} - - static JSValue qjs_process_env(JSContext *ctx, JSValueConst this_val) { @@ -583,13 +563,6 @@ qjs_add_intrinsic_text_decoder(JSContext *cx, JSValueConst global) } -static JSValue -qjs_text_decoder_to_string_tag(JSContext *ctx, JSValueConst this_val) -{ - return JS_NewString(ctx, "TextDecoder"); -} - - static JSValue qjs_text_decoder_decode(JSContext *cx, JSValueConst this_val, int argc, JSValueConst *argv) @@ -762,13 +735,6 @@ qjs_add_intrinsic_text_encoder(JSContext *cx, JSValueConst global) } -static JSValue -qjs_text_encoder_to_string_tag(JSContext *ctx, JSValueConst this_val) -{ - return JS_NewString(ctx, "TextEncoder"); -} - - static JSValue qjs_text_encoder_encoding(JSContext *ctx, JSValueConst this_val) { _______________________________________________ nginx-devel mailing list nginx-devel@nginx.org https://mailman.nginx.org/mailman/listinfo/nginx-devel