Skip to content

Commit

Permalink
Fix error handling in JS_InstantiateFunctionListItem()
Browse files Browse the repository at this point in the history
  • Loading branch information
xeioex committed Sep 14, 2024
1 parent 93d1ab7 commit 752a3ca
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -36892,6 +36892,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)
Expand Down Expand Up @@ -36934,8 +36935,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:
Expand All @@ -36949,15 +36951,22 @@ 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) {
snprintf(buf, sizeof(buf), "set %s", e->name);
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;
Expand All @@ -36975,13 +36984,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;
}

Expand Down

0 comments on commit 752a3ca

Please sign in to comment.