Skip to content

Commit 752a3ca

Browse files
committed
Fix error handling in JS_InstantiateFunctionListItem()
1 parent 93d1ab7 commit 752a3ca

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

quickjs.c

+19-6
Original file line numberDiff line numberDiff line change
@@ -36892,6 +36892,7 @@ static JSValue JS_InstantiateFunctionListItem2(JSContext *ctx, JSObject *p,
3689236892
return val;
3689336893
}
3689436894

36895+
/* return -1 if exception, 0 if OK */
3689536896
static int JS_InstantiateFunctionListItem(JSContext *ctx, JSValueConst obj,
3689636897
JSAtom atom,
3689736898
const JSCFunctionListEntry *e)
@@ -36934,8 +36935,9 @@ static int JS_InstantiateFunctionListItem(JSContext *ctx, JSValueConst obj,
3693436935
/* Function.prototype[Symbol.hasInstance] is not writable nor configurable */
3693536936
prop_flags = 0;
3693636937
}
36937-
JS_DefineAutoInitProperty(ctx, obj, atom, JS_AUTOINIT_ID_PROP,
36938-
(void *)e, prop_flags);
36938+
if (JS_DefineAutoInitProperty(ctx, obj, atom, JS_AUTOINIT_ID_PROP,
36939+
(void *)e, prop_flags) < 0)
36940+
return -1;
3693936941
return 0;
3694036942
case JS_DEF_CGETSET: /* XXX: use autoinit again ? */
3694136943
case JS_DEF_CGETSET_MAGIC:
@@ -36949,15 +36951,22 @@ static int JS_InstantiateFunctionListItem(JSContext *ctx, JSValueConst obj,
3694936951
getter = JS_NewCFunction2(ctx, e->u.getset.get.generic,
3695036952
buf, 0, e->def_type == JS_DEF_CGETSET_MAGIC ? JS_CFUNC_getter_magic : JS_CFUNC_getter,
3695136953
e->magic);
36954+
if (JS_IsException(getter))
36955+
return -1;
3695236956
}
3695336957
setter = JS_UNDEFINED;
3695436958
if (e->u.getset.set.generic) {
3695536959
snprintf(buf, sizeof(buf), "set %s", e->name);
3695636960
setter = JS_NewCFunction2(ctx, e->u.getset.set.generic,
3695736961
buf, 1, e->def_type == JS_DEF_CGETSET_MAGIC ? JS_CFUNC_setter_magic : JS_CFUNC_setter,
3695836962
e->magic);
36963+
if (JS_IsException(setter)) {
36964+
JS_FreeValue(ctx, getter);
36965+
return -1;
36966+
}
3695936967
}
36960-
JS_DefinePropertyGetSet(ctx, obj, atom, getter, setter, prop_flags);
36968+
if (JS_DefinePropertyGetSet(ctx, obj, atom, getter, setter, prop_flags) < 0)
36969+
return -1;
3696136970
return 0;
3696236971
}
3696336972
break;
@@ -36975,13 +36984,17 @@ static int JS_InstantiateFunctionListItem(JSContext *ctx, JSValueConst obj,
3697536984
break;
3697636985
case JS_DEF_PROP_STRING:
3697736986
case JS_DEF_OBJECT:
36978-
JS_DefineAutoInitProperty(ctx, obj, atom, JS_AUTOINIT_ID_PROP,
36979-
(void *)e, prop_flags);
36987+
if (JS_DefineAutoInitProperty(ctx, obj, atom, JS_AUTOINIT_ID_PROP,
36988+
(void *)e, prop_flags) < 0)
36989+
return -1;
3698036990
return 0;
3698136991
default:
3698236992
abort();
3698336993
}
36984-
JS_DefinePropertyValue(ctx, obj, atom, val, prop_flags);
36994+
if (JS_DefinePropertyValue(ctx, obj, atom, val, prop_flags) < 0) {
36995+
JS_FreeValue(ctx, val);
36996+
return -1;
36997+
}
3698536998
return 0;
3698636999
}
3698737000

0 commit comments

Comments
 (0)