Merge 752a3cac22e29416faa496a6e8320188d75b8c00 into f10ef299a6ab4c36c4162cc5840f128f74ec197c

This commit is contained in:
Dmitry Volyntsev 2025-05-22 15:40:47 +02:00 committed by GitHub
commit 359adf0ba4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 6 deletions

View File

@ -37874,6 +37874,7 @@ static JSValue JS_InstantiateFunctionListItem2(JSContext *ctx, JSObject *p,
return val;
}
/* return -1 if exception, 0 if OK */
static int JS_InstantiateFunctionListItem(JSContext *ctx, JSValueConst obj,
JSAtom atom,
const JSCFunctionListEntry *e)
@ -37916,8 +37917,9 @@ static int JS_InstantiateFunctionListItem(JSContext *ctx, JSValueConst obj,
/* Function.prototype[Symbol.hasInstance] is not writable nor configurable */
prop_flags = 0;
}
JS_DefineAutoInitProperty(ctx, obj, atom, JS_AUTOINIT_ID_PROP,
(void *)e, prop_flags);
if (JS_DefineAutoInitProperty(ctx, obj, atom, JS_AUTOINIT_ID_PROP,
(void *)e, prop_flags) < 0)
return -1;
return 0;
case JS_DEF_CGETSET: /* XXX: use autoinit again ? */
case JS_DEF_CGETSET_MAGIC:
@ -37931,6 +37933,8 @@ static int JS_InstantiateFunctionListItem(JSContext *ctx, JSValueConst obj,
getter = JS_NewCFunction2(ctx, e->u.getset.get.generic,
buf, 0, e->def_type == JS_DEF_CGETSET_MAGIC ? JS_CFUNC_getter_magic : JS_CFUNC_getter,
e->magic);
if (JS_IsException(getter))
return -1;
}
setter = JS_UNDEFINED;
if (e->u.getset.set.generic) {
@ -37938,8 +37942,13 @@ static int JS_InstantiateFunctionListItem(JSContext *ctx, JSValueConst obj,
setter = JS_NewCFunction2(ctx, e->u.getset.set.generic,
buf, 1, e->def_type == JS_DEF_CGETSET_MAGIC ? JS_CFUNC_setter_magic : JS_CFUNC_setter,
e->magic);
if (JS_IsException(setter)) {
JS_FreeValue(ctx, getter);
return -1;
}
JS_DefinePropertyGetSet(ctx, obj, atom, getter, setter, prop_flags);
}
if (JS_DefinePropertyGetSet(ctx, obj, atom, getter, setter, prop_flags) < 0)
return -1;
return 0;
}
break;
@ -37957,13 +37966,17 @@ static int JS_InstantiateFunctionListItem(JSContext *ctx, JSValueConst obj,
break;
case JS_DEF_PROP_STRING:
case JS_DEF_OBJECT:
JS_DefineAutoInitProperty(ctx, obj, atom, JS_AUTOINIT_ID_PROP,
(void *)e, prop_flags);
if (JS_DefineAutoInitProperty(ctx, obj, atom, JS_AUTOINIT_ID_PROP,
(void *)e, prop_flags) < 0)
return -1;
return 0;
default:
abort();
}
JS_DefinePropertyValue(ctx, obj, atom, val, prop_flags);
if (JS_DefinePropertyValue(ctx, obj, atom, val, prop_flags) < 0) {
JS_FreeValue(ctx, val);
return -1;
}
return 0;
}
@ -37980,6 +37993,25 @@ void JS_SetPropertyFunctionList(JSContext *ctx, JSValueConst obj,
}
}
int JS_SetPropertyFunctionList2(JSContext *ctx, JSValueConst obj,
const JSCFunctionListEntry *tab, int len)
{
int i;
for (i = 0; i < len; i++) {
const JSCFunctionListEntry *e = &tab[i];
JSAtom atom = find_atom(ctx, e->name);
if (atom == JS_ATOM_NULL)
return -1;
if (JS_InstantiateFunctionListItem(ctx, obj, atom, e) < 0) {
JS_FreeAtom(ctx, atom);
return -1;
}
JS_FreeAtom(ctx, atom);
}
return 0;
}
int JS_AddModuleExportList(JSContext *ctx, JSModuleDef *m,
const JSCFunctionListEntry *tab, int len)
{

View File

@ -1116,6 +1116,10 @@ typedef struct JSCFunctionListEntry {
void JS_SetPropertyFunctionList(JSContext *ctx, JSValueConst obj,
const JSCFunctionListEntry *tab,
int len);
/* same as JS_SetPropertyFunctionList() returns -1 if exception, 0 if OK */
int JS_SetPropertyFunctionList2(JSContext *ctx, JSValueConst obj,
const JSCFunctionListEntry *tab,
int len);
/* C module definition */