mirror of
https://github.com/bellard/quickjs.git
synced 2025-11-15 18:22:15 +03:00
Improve error handling in Promise.withResolvers (bnoordhuis)
This commit is contained in:
25
quickjs.c
25
quickjs.c
@@ -51667,17 +51667,30 @@ static JSValue js_promise_withResolvers(JSContext *ctx,
|
||||
if (JS_IsException(result_promise))
|
||||
return result_promise;
|
||||
obj = JS_NewObject(ctx);
|
||||
if (JS_IsException(obj)) {
|
||||
if (JS_IsException(obj))
|
||||
goto exception;
|
||||
if (JS_DefinePropertyValue(ctx, obj, JS_ATOM_promise, result_promise,
|
||||
JS_PROP_C_W_E) < 0) {
|
||||
goto exception;
|
||||
}
|
||||
result_promise = JS_UNDEFINED;
|
||||
if (JS_DefinePropertyValue(ctx, obj, JS_ATOM_resolve, resolving_funcs[0],
|
||||
JS_PROP_C_W_E) < 0) {
|
||||
goto exception;
|
||||
}
|
||||
resolving_funcs[0] = JS_UNDEFINED;
|
||||
if (JS_DefinePropertyValue(ctx, obj, JS_ATOM_reject, resolving_funcs[1],
|
||||
JS_PROP_C_W_E) < 0) {
|
||||
goto exception;
|
||||
}
|
||||
return obj;
|
||||
exception:
|
||||
JS_FreeValue(ctx, resolving_funcs[0]);
|
||||
JS_FreeValue(ctx, resolving_funcs[1]);
|
||||
JS_FreeValue(ctx, result_promise);
|
||||
JS_FreeValue(ctx, obj);
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
JS_DefinePropertyValue(ctx, obj, JS_ATOM_promise, result_promise, JS_PROP_C_W_E);
|
||||
JS_DefinePropertyValue(ctx, obj, JS_ATOM_resolve, resolving_funcs[0], JS_PROP_C_W_E);
|
||||
JS_DefinePropertyValue(ctx, obj, JS_ATOM_reject, resolving_funcs[1], JS_PROP_C_W_E);
|
||||
return obj;
|
||||
}
|
||||
|
||||
static JSValue js_promise_try(JSContext *ctx, JSValueConst this_val,
|
||||
int argc, JSValueConst *argv)
|
||||
|
||||
Reference in New Issue
Block a user