Skip to content

Commit

Permalink
QuickJS: using helper to declare Symbol.toStringTag properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
xeioex committed Feb 25, 2025
1 parent d145e03 commit 18d3170
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 147 deletions.
10 changes: 2 additions & 8 deletions external/njs_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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),
Expand Down
34 changes: 4 additions & 30 deletions external/qjs_fs_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down
13 changes: 2 additions & 11 deletions external/qjs_webcrypto_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -4000,13 +3998,6 @@ qjs_webcrypto_sign(JSContext *cx, JSValueConst this_val, int argc,
}


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)
{
Expand Down
27 changes: 3 additions & 24 deletions nginx/ngx_http_js_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 3 additions & 11 deletions nginx/ngx_js_shared_dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
{
Expand Down
27 changes: 4 additions & 23 deletions nginx/ngx_stream_js_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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),
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 18d3170

Please sign in to comment.