Skip to content

Commit 0452dfe

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 b1500a2 commit 0452dfe

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

quickjs.c

+14
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,17 @@ static JSValue promise_rejection_tracker_job(JSContext *ctx, int argc,
5023350236

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

50239+
has_other_jobs = false;
50240+
list_for_each_safe(el, el1, &rt->job_list) {
50241+
job = list_entry(el, JSJobEntry, link);
50242+
if (job->job_func != promise_rejection_tracker_job)
50243+
has_other_jobs = true;
50244+
}
50245+
if (has_other_jobs) {
50246+
JS_EnqueueJob(ctx, promise_rejection_tracker_job, 1, &promise);
50247+
return JS_UNDEFINED;
50248+
}
50249+
5023650250
// Check again in case the hook was removed.
5023750251
if (rt->host_promise_rejection_tracker)
5023850252
rt->host_promise_rejection_tracker(
File renamed without changes.

tests/bug39/2.js

+6
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

+7
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)