Skip to content

Commit 3e7605f

Browse files
committed
feat: improve error report
1 parent 11b7592 commit 3e7605f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

quickjs.c

+25
Original file line numberDiff line numberDiff line change
@@ -8887,6 +8887,31 @@ static int JS_SetPropertyInternal2(JSContext *ctx, JSValue obj, JSAtom prop,
88878887
pr = add_property(ctx, p, prop, JS_PROP_C_W_E);
88888888
if (!pr)
88898889
goto fail;
8890+
8891+
// try give function name in every possible way
8892+
if (JS_IsFunction(ctx, val)) {
8893+
JSObject *vf = JS_VALUE_GET_OBJ(val);
8894+
if (vf->class_id == JS_CLASS_BYTECODE_FUNCTION &&
8895+
vf->u.func.var_refs == NULL) {
8896+
JSValue name_val = JS_GetProperty(ctx, val, JS_ATOM_name);
8897+
8898+
if (JS_IsString(name_val)) {
8899+
const char *name = JS_ToCString(ctx, name_val);
8900+
if (name != NULL) {
8901+
if (strcmp(name, "") == 0) {
8902+
JSValue js_value = JS_AtomToValue(ctx, prop);
8903+
JS_DefinePropertyValue(ctx, val, JS_ATOM_name, js_value, JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE);
8904+
JS_FreeValue(ctx, js_value);
8905+
}
8906+
8907+
JS_FreeCString(ctx, name);
8908+
}
8909+
8910+
}
8911+
JS_FreeValue(ctx, name_val);
8912+
}
8913+
}
8914+
88908915
pr->u.value = val;
88918916
return true;
88928917
}

0 commit comments

Comments
 (0)