@@ -50210,6 +50210,32 @@ static JSValue promise_reaction_job(JSContext *ctx, int argc,
50210
50210
return res2;
50211
50211
}
50212
50212
50213
+ static JSValue promise_rejection_tracker_job(JSContext *ctx, int argc,
50214
+ JSValueConst *argv)
50215
+ {
50216
+ JSRuntime *rt;
50217
+ JSPromiseData *s;
50218
+ JSValueConst promise;
50219
+
50220
+ assert(argc == 1);
50221
+
50222
+ rt = ctx->rt;
50223
+ promise = argv[0];
50224
+ s = JS_GetOpaque(promise, JS_CLASS_PROMISE);
50225
+
50226
+ if (!s || s->promise_state != JS_PROMISE_REJECTED)
50227
+ return JS_UNDEFINED; /* should never happen */
50228
+
50229
+ promise_trace(ctx, "promise_rejection_tracker_job\n");
50230
+
50231
+ // Check again in case the hook was removed.
50232
+ if (rt->host_promise_rejection_tracker)
50233
+ rt->host_promise_rejection_tracker(
50234
+ ctx, promise, s->promise_result, s->is_handled, rt->host_promise_rejection_tracker_opaque);
50235
+
50236
+ return JS_UNDEFINED;
50237
+ }
50238
+
50213
50239
void JS_SetPromiseHook(JSRuntime *rt, JSPromiseHook promise_hook, void *opaque)
50214
50240
{
50215
50241
rt->promise_hook = promise_hook;
@@ -50247,14 +50273,6 @@ static void fulfill_or_reject_promise(JSContext *ctx, JSValueConst promise,
50247
50273
}
50248
50274
}
50249
50275
50250
- if (s->promise_state == JS_PROMISE_REJECTED && !s->is_handled) {
50251
- JSRuntime *rt = ctx->rt;
50252
- if (rt->host_promise_rejection_tracker) {
50253
- rt->host_promise_rejection_tracker(ctx, promise, value, false,
50254
- rt->host_promise_rejection_tracker_opaque);
50255
- }
50256
- }
50257
-
50258
50276
list_for_each_safe(el, el1, &s->promise_reactions[is_reject]) {
50259
50277
rd = list_entry(el, JSPromiseReactionData, link);
50260
50278
args[0] = rd->resolving_funcs[0];
@@ -50272,6 +50290,12 @@ static void fulfill_or_reject_promise(JSContext *ctx, JSValueConst promise,
50272
50290
list_del(&rd->link);
50273
50291
promise_reaction_data_free(ctx->rt, rd);
50274
50292
}
50293
+
50294
+ if (s->promise_state == JS_PROMISE_REJECTED && !s->is_handled) {
50295
+ JSRuntime *rt = ctx->rt;
50296
+ if (rt->host_promise_rejection_tracker)
50297
+ JS_EnqueueJob(ctx, promise_rejection_tracker_job, 1, &promise);
50298
+ }
50275
50299
}
50276
50300
50277
50301
static JSValue js_promise_resolve_thenable_job(JSContext *ctx,
@@ -51018,10 +51042,8 @@ static __exception int perform_promise_then(JSContext *ctx,
51018
51042
JSValueConst args[5];
51019
51043
if (s->promise_state == JS_PROMISE_REJECTED && !s->is_handled) {
51020
51044
JSRuntime *rt = ctx->rt;
51021
- if (rt->host_promise_rejection_tracker) {
51022
- rt->host_promise_rejection_tracker(ctx, promise, s->promise_result,
51023
- true, rt->host_promise_rejection_tracker_opaque);
51024
- }
51045
+ if (rt->host_promise_rejection_tracker)
51046
+ JS_EnqueueJob(ctx, promise_rejection_tracker_job, 1, &promise);
51025
51047
}
51026
51048
i = s->promise_state - JS_PROMISE_FULFILLED;
51027
51049
rd = rd_array[i];
0 commit comments