Skip to content

Commit a4a5a17

Browse files
committed
Fix unhandled promise rejection tracker, again
Delay checking for unhandled rejections so we can make sure to check after other promise jobs have ran.
1 parent 7e8abe1 commit a4a5a17

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

quickjs.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50221,6 +50221,9 @@ static JSValue promise_rejection_tracker_job(JSContext *ctx, int argc,
5022150221
JSRuntime *rt;
5022250222
JSPromiseData *s;
5022350223
JSValueConst promise;
50224+
struct list_head *el, *el1;
50225+
JSJobEntry *job;
50226+
bool has_other_jobs;
5022450227

5022550228
assert(argc == 1);
5022650229

@@ -50233,6 +50236,22 @@ static JSValue promise_rejection_tracker_job(JSContext *ctx, int argc,
5023350236

5023450237
promise_trace(ctx, "promise_rejection_tracker_job\n");
5023550238

50239+
// Push the rejection tracker jobs to the end of the queue if there are other jobs.
50240+
// This allows us to handle rejections that get added later and thus would handle the
50241+
// rejection _after_ we check for it.
50242+
has_other_jobs = false;
50243+
list_for_each_safe(el, el1, &rt->job_list) {
50244+
job = list_entry(el, JSJobEntry, link);
50245+
if (job->job_func != promise_rejection_tracker_job) {
50246+
has_other_jobs = true;
50247+
break;
50248+
}
50249+
}
50250+
if (has_other_jobs) {
50251+
JS_EnqueueJob(ctx, promise_rejection_tracker_job, 1, &promise);
50252+
return JS_UNDEFINED;
50253+
}
50254+
5023650255
// Check again in case the hook was removed.
5023750256
if (rt->host_promise_rejection_tracker)
5023850257
rt->host_promise_rejection_tracker(
File renamed without changes.

tests/bug39/2.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*---
2+
flags: [qjs:track-promise-rejections]
3+
---*/
4+
5+
const error = await Promise.resolve().then(() => Promise.reject('reject')).catch(e => e)
6+
print('Got this error:', error)

tests/bug39/3.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*---
2+
flags: [qjs:track-promise-rejections]
3+
---*/
4+
5+
const promise = Promise.reject('reject')
6+
const error = await Promise.resolve().then(() => promise).catch(e => e)
7+
print('Got this error:', error)

0 commit comments

Comments
 (0)