Skip to content

Commit 3201e5f

Browse files
committed
[JSC] Early return in microtask draining when termination happens
https://bugs.webkit.org/show_bug.cgi?id=257163 rdar://109401883 Reviewed by Mark Lam. This is Debug only, JSC shell only issue. Early returning from microtask draining when termination happens. * JSTests/stress/exception-check-unhandled-promise-rejection-in-shell.js: Added. (async foo): * Source/JavaScriptCore/runtime/VM.cpp: (JSC::VM::didExhaustMicrotaskQueue): (JSC::VM::drainMicrotasks): Canonical link: https://commits.webkit.org/264390@main
1 parent 6483fe3 commit 3201e5f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//@ runDefault("--watchdog=100", "--watchdog-exception-ok")
2+
async function foo() {
3+
await undefined;
4+
throw new Error();
5+
}
6+
7+
setUnhandledRejectionCallback(foo);
8+
foo();
9+
drainMicrotasks();

Source/JavaScriptCore/runtime/VM.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,8 @@ void VM::didExhaustMicrotaskQueue()
12401240
continue;
12411241

12421242
callPromiseRejectionCallback(promise);
1243+
if (UNLIKELY(hasPendingTerminationException()))
1244+
return;
12431245
}
12441246
} while (!m_aboutToBeNotifiedRejectedPromises.isEmpty());
12451247
}
@@ -1258,10 +1260,14 @@ void VM::drainMicrotasks()
12581260
while (!m_microtaskQueue.isEmpty()) {
12591261
auto task = m_microtaskQueue.dequeue();
12601262
task.run();
1263+
if (UNLIKELY(hasPendingTerminationException()))
1264+
return;
12611265
if (m_onEachMicrotaskTick)
12621266
m_onEachMicrotaskTick(*this);
12631267
}
12641268
didExhaustMicrotaskQueue();
1269+
if (UNLIKELY(hasPendingTerminationException()))
1270+
return;
12651271
} while (!m_microtaskQueue.isEmpty());
12661272
}
12671273
finalizeSynchronousJSExecution();

0 commit comments

Comments
 (0)