Commit f0dd3d5f authored by Yang Guo's avatar Yang Guo Committed by Commit Bot

Do not run microtasks when there are scheduled exceptions

Running microtasks with exceptions scheduled violates varios invariants
within the microtasks code.

Bug: v8:9652
Change-Id: I78c868feed5b742e225cad19e55216f0ef250af4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1767261Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Andrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63380}
parent 585943d4
......@@ -8688,7 +8688,11 @@ MicrotasksScope::MicrotasksScope(Isolate* isolate,
MicrotasksScope::~MicrotasksScope() {
if (run_) {
microtask_queue_->DecrementMicrotasksScopeDepth();
if (MicrotasksPolicy::kScoped == microtask_queue_->microtasks_policy()) {
if (MicrotasksPolicy::kScoped == microtask_queue_->microtasks_policy() &&
!isolate_->has_scheduled_exception()) {
DCHECK_IMPLIES(isolate_->has_scheduled_exception(),
isolate_->scheduled_exception() ==
i::ReadOnlyRoots(isolate_).termination_exception());
microtask_queue_->PerformCheckpoint(reinterpret_cast<Isolate*>(isolate_));
}
}
......
......@@ -19951,6 +19951,71 @@ TEST(ScopedMicrotasks) {
LocalContext env;
v8::HandleScope handles(env->GetIsolate());
env->GetIsolate()->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped);
{
v8::MicrotasksScope scope1(env->GetIsolate(),
v8::MicrotasksScope::kRunMicrotasks);
env->GetIsolate()->EnqueueMicrotask(
Function::New(env.local(), MicrotaskOne).ToLocalChecked());
CompileRun("var ext1Calls = 0;");
}
{
v8::MicrotasksScope scope1(env->GetIsolate(),
v8::MicrotasksScope::kRunMicrotasks);
ExpectInt32("ext1Calls", 1);
}
{
v8::MicrotasksScope scope1(env->GetIsolate(),
v8::MicrotasksScope::kRunMicrotasks);
env->GetIsolate()->EnqueueMicrotask(
Function::New(env.local(), MicrotaskOne).ToLocalChecked());
CompileRun("throw new Error()");
}
{
v8::MicrotasksScope scope1(env->GetIsolate(),
v8::MicrotasksScope::kRunMicrotasks);
ExpectInt32("ext1Calls", 2);
}
{
v8::MicrotasksScope scope1(env->GetIsolate(),
v8::MicrotasksScope::kRunMicrotasks);
env->GetIsolate()->EnqueueMicrotask(
Function::New(env.local(), MicrotaskOne).ToLocalChecked());
v8::TryCatch try_catch(env->GetIsolate());
CompileRun("throw new Error()");
}
{
v8::MicrotasksScope scope1(env->GetIsolate(),
v8::MicrotasksScope::kRunMicrotasks);
ExpectInt32("ext1Calls", 3);
}
{
v8::MicrotasksScope scope1(env->GetIsolate(),
v8::MicrotasksScope::kRunMicrotasks);
env->GetIsolate()->EnqueueMicrotask(
Function::New(env.local(), MicrotaskOne).ToLocalChecked());
env->GetIsolate()->TerminateExecution();
{
v8::MicrotasksScope scope2(env->GetIsolate(),
v8::MicrotasksScope::kRunMicrotasks);
env->GetIsolate()->EnqueueMicrotask(
Function::New(env.local(), MicrotaskOne).ToLocalChecked());
}
}
env->GetIsolate()->CancelTerminateExecution();
{
v8::MicrotasksScope scope1(env->GetIsolate(),
v8::MicrotasksScope::kRunMicrotasks);
ExpectInt32("ext1Calls", 3);
env->GetIsolate()->EnqueueMicrotask(
Function::New(env.local(), MicrotaskOne).ToLocalChecked());
}
{
v8::MicrotasksScope scope1(env->GetIsolate(),
v8::MicrotasksScope::kRunMicrotasks);
ExpectInt32("ext1Calls", 4);
}
{
v8::MicrotasksScope scope1(env->GetIsolate(),
v8::MicrotasksScope::kDoNotRunMicrotasks);
......
......@@ -64,3 +64,10 @@ Pause inside microtask and terminate execution
}
}
}
Terminate execution with pending microtasks
{
id : <messageId>
result : {
}
}
......@@ -55,6 +55,18 @@ let {session, contextGroup, Protocol} =
.then(InspectorTest.logMessage);
await Protocol.Debugger.disable();
InspectorTest.log('Terminate execution with pending microtasks');
Protocol.Debugger.enable();
const paused2 = Protocol.Debugger.oncePaused();
Protocol.Runtime.evaluate({expression: `
Promise.resolve().then(() => { console.log('FAIL: microtask ran'); });
debugger;
for (;;) {}
`});
await paused2;
Protocol.Runtime.terminateExecution().then(InspectorTest.logMessage);
await Protocol.Debugger.resume();
await Protocol.Runtime.disable();
InspectorTest.completeTest();
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment