Skip to content

Commit 2335bb6

Browse files
committed
feat: improve error report
1 parent 7000a65 commit 2335bb6

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

quickjs.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8882,6 +8882,31 @@ static int JS_SetPropertyInternal2(JSContext *ctx, JSValue obj, JSAtom prop,
88828882
pr = add_property(ctx, p, prop, JS_PROP_C_W_E);
88838883
if (!pr)
88848884
goto fail;
8885+
8886+
// try give function name in every possible way
8887+
if (JS_IsFunction(ctx, val)) {
8888+
JSObject *vf = JS_VALUE_GET_OBJ(val);
8889+
if (vf->class_id == JS_CLASS_BYTECODE_FUNCTION &&
8890+
vf->u.func.var_refs == NULL) {
8891+
JSValue name_val = JS_GetProperty(ctx, val, JS_ATOM_name);
8892+
8893+
if (JS_IsString(name_val)) {
8894+
const char *name = JS_ToCString(ctx, name_val);
8895+
if (name != NULL) {
8896+
if (strcmp(name, "") == 0) {
8897+
JSValue js_value = JS_AtomToValue(ctx, prop);
8898+
JS_DefinePropertyValue(ctx, val, JS_ATOM_name, js_value, JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE);
8899+
JS_FreeValue(ctx, js_value);
8900+
}
8901+
8902+
JS_FreeCString(ctx, name);
8903+
}
8904+
8905+
}
8906+
JS_FreeValue(ctx, name_val);
8907+
}
8908+
}
8909+
88858910
pr->u.value = val;
88868911
return true;
88878912
}

0 commit comments

Comments
 (0)