From 93d1ab715b6efeab9679ce995ca369331d24fd88 Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Fri, 13 Sep 2024 17:20:41 -0700 Subject: [PATCH] Add `JS_SetPropertyFunctionList2()` --- quickjs.c | 19 +++++++++++++++++++ quickjs.h | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/quickjs.c b/quickjs.c index 642ae34..9c72fd3 100644 --- a/quickjs.c +++ b/quickjs.c @@ -36998,6 +36998,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) { diff --git a/quickjs.h b/quickjs.h index edc7b47..5fd65da 100644 --- a/quickjs.h +++ b/quickjs.h @@ -1060,6 +1060,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 */