From 2335bb6b90708de650e997b8448fdf98f86984fa Mon Sep 17 00:00:00 2001 From: Jiawen Geng Date: Tue, 21 Jan 2025 10:21:57 +0000 Subject: [PATCH 1/7] feat: improve error report --- quickjs.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/quickjs.c b/quickjs.c index eff3ae05d..d217c67ef 100644 --- a/quickjs.c +++ b/quickjs.c @@ -8882,6 +8882,31 @@ static int JS_SetPropertyInternal2(JSContext *ctx, JSValue obj, JSAtom prop, pr = add_property(ctx, p, prop, JS_PROP_C_W_E); if (!pr) goto fail; + + // try give function name in every possible way + if (JS_IsFunction(ctx, val)) { + JSObject *vf = JS_VALUE_GET_OBJ(val); + if (vf->class_id == JS_CLASS_BYTECODE_FUNCTION && + vf->u.func.var_refs == NULL) { + JSValue name_val = JS_GetProperty(ctx, val, JS_ATOM_name); + + if (JS_IsString(name_val)) { + const char *name = JS_ToCString(ctx, name_val); + if (name != NULL) { + if (strcmp(name, "") == 0) { + JSValue js_value = JS_AtomToValue(ctx, prop); + JS_DefinePropertyValue(ctx, val, JS_ATOM_name, js_value, JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE); + JS_FreeValue(ctx, js_value); + } + + JS_FreeCString(ctx, name); + } + + } + JS_FreeValue(ctx, name_val); + } + } + pr->u.value = val; return true; } From 6ea0420154d7b2abc3c8bb656fde74669af17d30 Mon Sep 17 00:00:00 2001 From: Jiawen Geng Date: Wed, 22 Jan 2025 01:51:06 +0000 Subject: [PATCH 2/7] fixup: use get_func_name --- quickjs.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/quickjs.c b/quickjs.c index d217c67ef..94c904634 100644 --- a/quickjs.c +++ b/quickjs.c @@ -8888,22 +8888,14 @@ static int JS_SetPropertyInternal2(JSContext *ctx, JSValue obj, JSAtom prop, JSObject *vf = JS_VALUE_GET_OBJ(val); if (vf->class_id == JS_CLASS_BYTECODE_FUNCTION && vf->u.func.var_refs == NULL) { - JSValue name_val = JS_GetProperty(ctx, val, JS_ATOM_name); - - if (JS_IsString(name_val)) { - const char *name = JS_ToCString(ctx, name_val); - if (name != NULL) { - if (strcmp(name, "") == 0) { - JSValue js_value = JS_AtomToValue(ctx, prop); - JS_DefinePropertyValue(ctx, val, JS_ATOM_name, js_value, JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE); - JS_FreeValue(ctx, js_value); - } - - JS_FreeCString(ctx, name); - } - + const char* name = get_func_name(ctx, val); + if (strcmp(name, "") == 0) { + JSValue js_value = JS_AtomToValue(ctx, prop); + JS_DefinePropertyValue(ctx, val, JS_ATOM_name, js_value, JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE); + JS_FreeValue(ctx, js_value); } - JS_FreeValue(ctx, name_val); + + JS_FreeCString(ctx, name); } } From 393c331a41630173de580b2b57352a6f2c0970e3 Mon Sep 17 00:00:00 2001 From: Jiawen Geng Date: Wed, 22 Jan 2025 01:53:18 +0000 Subject: [PATCH 3/7] fixup: enable for closure too --- quickjs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/quickjs.c b/quickjs.c index 94c904634..aecdb1b7a 100644 --- a/quickjs.c +++ b/quickjs.c @@ -8886,8 +8886,7 @@ static int JS_SetPropertyInternal2(JSContext *ctx, JSValue obj, JSAtom prop, // try give function name in every possible way if (JS_IsFunction(ctx, val)) { JSObject *vf = JS_VALUE_GET_OBJ(val); - if (vf->class_id == JS_CLASS_BYTECODE_FUNCTION && - vf->u.func.var_refs == NULL) { + if (vf->class_id == JS_CLASS_BYTECODE_FUNCTION) { const char* name = get_func_name(ctx, val); if (strcmp(name, "") == 0) { JSValue js_value = JS_AtomToValue(ctx, prop); From 5397d3d1e1ae4385fa83066a9fa518df0b9e904e Mon Sep 17 00:00:00 2001 From: Jiawen Geng Date: Sun, 9 Feb 2025 06:00:12 +0000 Subject: [PATCH 4/7] fix: ASAN --- quickjs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/quickjs.c b/quickjs.c index aecdb1b7a..b8042e5a4 100644 --- a/quickjs.c +++ b/quickjs.c @@ -8887,7 +8887,8 @@ static int JS_SetPropertyInternal2(JSContext *ctx, JSValue obj, JSAtom prop, if (JS_IsFunction(ctx, val)) { JSObject *vf = JS_VALUE_GET_OBJ(val); if (vf->class_id == JS_CLASS_BYTECODE_FUNCTION) { - const char* name = get_func_name(ctx, val); + const char *name = get_func_name(ctx, val); + if(name != NULL) { if (strcmp(name, "") == 0) { JSValue js_value = JS_AtomToValue(ctx, prop); JS_DefinePropertyValue(ctx, val, JS_ATOM_name, js_value, JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE); @@ -8895,6 +8896,7 @@ static int JS_SetPropertyInternal2(JSContext *ctx, JSValue obj, JSAtom prop, } JS_FreeCString(ctx, name); + } } } From 83d7b2da61dce96dd7bab1f87fbff8db8b2aed13 Mon Sep 17 00:00:00 2001 From: Jiawen Geng Date: Sun, 9 Feb 2025 06:05:30 +0000 Subject: [PATCH 5/7] fix: try CI --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5fc58bc8a..7302a0a9a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,8 +11,6 @@ on: - '!examples/**' - '.github/workflows/ci.yml' push: - branches: - - master paths: - '**' - '!.gitignore' From f38e9598c6685cb18413efe0bcdb6ebea87c12f2 Mon Sep 17 00:00:00 2001 From: Jiawen Geng Date: Fri, 21 Feb 2025 06:37:31 +0000 Subject: [PATCH 6/7] ASAN fix --- quickjs.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/quickjs.c b/quickjs.c index b8042e5a4..f616cf700 100644 --- a/quickjs.c +++ b/quickjs.c @@ -8888,12 +8888,9 @@ static int JS_SetPropertyInternal2(JSContext *ctx, JSValue obj, JSAtom prop, JSObject *vf = JS_VALUE_GET_OBJ(val); if (vf->class_id == JS_CLASS_BYTECODE_FUNCTION) { const char *name = get_func_name(ctx, val); - if(name != NULL) { - if (strcmp(name, "") == 0) { - JSValue js_value = JS_AtomToValue(ctx, prop); - JS_DefinePropertyValue(ctx, val, JS_ATOM_name, js_value, JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE); - JS_FreeValue(ctx, js_value); - } + if(name && *name == '\0') { + JSValue js_value = JS_AtomToValue(ctx, prop); + JS_DefinePropertyValue(ctx, val, JS_ATOM_name, js_value, JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE); JS_FreeCString(ctx, name); } From fb615ac45e6431bbdf9ef76a47f3165cbbb6e33d Mon Sep 17 00:00:00 2001 From: Jiawen Geng Date: Fri, 21 Feb 2025 07:28:38 +0000 Subject: [PATCH 7/7] remove writable --- quickjs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quickjs.c b/quickjs.c index f616cf700..624a56334 100644 --- a/quickjs.c +++ b/quickjs.c @@ -8890,7 +8890,7 @@ static int JS_SetPropertyInternal2(JSContext *ctx, JSValue obj, JSAtom prop, const char *name = get_func_name(ctx, val); if(name && *name == '\0') { JSValue js_value = JS_AtomToValue(ctx, prop); - JS_DefinePropertyValue(ctx, val, JS_ATOM_name, js_value, JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE); + JS_DefinePropertyValue(ctx, val, JS_ATOM_name, js_value, JS_PROP_CONFIGURABLE); JS_FreeCString(ctx, name); }