@@ -49216,6 +49216,34 @@ static JSValue js_promise_withResolvers(JSContext *ctx,
49216
49216
return obj;
49217
49217
}
49218
49218
49219
+ static JSValue js_promise_try(JSContext *ctx, JSValue this_val,
49220
+ int argc, JSValue *argv)
49221
+ {
49222
+ JSValue result_promise, resolving_funcs[2], ret, ret2;
49223
+ BOOL is_reject = 0;
49224
+
49225
+ if (!JS_IsObject(this_val))
49226
+ return JS_ThrowTypeErrorNotAnObject(ctx);
49227
+ result_promise = js_new_promise_capability(ctx, resolving_funcs, this_val);
49228
+ if (JS_IsException(result_promise))
49229
+ return result_promise;
49230
+ ret = JS_Call(ctx, argv[0], JS_UNDEFINED, argc - 1, argv + 1);
49231
+ if (JS_IsException(ret)) {
49232
+ is_reject = 1;
49233
+ ret = JS_GetException(ctx);
49234
+ }
49235
+ ret2 = JS_Call(ctx, resolving_funcs[is_reject], JS_UNDEFINED, 1, &ret);
49236
+ JS_FreeValue(ctx, resolving_funcs[0]);
49237
+ JS_FreeValue(ctx, resolving_funcs[1]);
49238
+ JS_FreeValue(ctx, ret);
49239
+ if (JS_IsException(ret2)) {
49240
+ JS_FreeValue(ctx, result_promise);
49241
+ return ret2;
49242
+ }
49243
+ JS_FreeValue(ctx, ret2);
49244
+ return result_promise;
49245
+ }
49246
+
49219
49247
static __exception int remainingElementsCount_add(JSContext *ctx,
49220
49248
JSValueConst resolve_element_env,
49221
49249
int addend)
@@ -49703,6 +49731,7 @@ static const JSCFunctionListEntry js_promise_funcs[] = {
49703
49731
JS_CFUNC_MAGIC_DEF("all", 1, js_promise_all, PROMISE_MAGIC_all ),
49704
49732
JS_CFUNC_MAGIC_DEF("allSettled", 1, js_promise_all, PROMISE_MAGIC_allSettled ),
49705
49733
JS_CFUNC_MAGIC_DEF("any", 1, js_promise_all, PROMISE_MAGIC_any ),
49734
+ JS_CFUNC_DEF("try", 1, js_promise_try ),
49706
49735
JS_CFUNC_DEF("race", 1, js_promise_race ),
49707
49736
JS_CFUNC_DEF("withResolvers", 0, js_promise_withResolvers ),
49708
49737
JS_CGETSET_DEF("[Symbol.species]", js_get_this, NULL),
0 commit comments