Skip to content

Commit

Permalink
[JSC] Early return in microtask draining when termination happens
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Constellation committed May 23, 2023
1 parent 6483fe3 commit 3201e5f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
@@ -0,0 +1,9 @@
//@ runDefault("--watchdog=100", "--watchdog-exception-ok")
async function foo() {
await undefined;
throw new Error();
}

setUnhandledRejectionCallback(foo);
foo();
drainMicrotasks();
6 changes: 6 additions & 0 deletions Source/JavaScriptCore/runtime/VM.cpp
Expand Up @@ -1240,6 +1240,8 @@ void VM::didExhaustMicrotaskQueue()
continue;

callPromiseRejectionCallback(promise);
if (UNLIKELY(hasPendingTerminationException()))
return;
}
} while (!m_aboutToBeNotifiedRejectedPromises.isEmpty());
}
Expand All @@ -1258,10 +1260,14 @@ void VM::drainMicrotasks()
while (!m_microtaskQueue.isEmpty()) {
auto task = m_microtaskQueue.dequeue();
task.run();
if (UNLIKELY(hasPendingTerminationException()))
return;
if (m_onEachMicrotaskTick)
m_onEachMicrotaskTick(*this);
}
didExhaustMicrotaskQueue();
if (UNLIKELY(hasPendingTerminationException()))
return;
} while (!m_microtaskQueue.isEmpty());
}
finalizeSynchronousJSExecution();
Expand Down

0 comments on commit 3201e5f

Please sign in to comment.