Index: test/cctest/test-api.cc |
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc |
index b0d80ed49a7d9a2da309aaa969e736a4ead97a83..7eb6a5510b60c8fb0c0b2c4c51371bc31c0bf4d8 100644 |
--- a/test/cctest/test-api.cc |
+++ b/test/cctest/test-api.cc |
@@ -20921,12 +20921,16 @@ TEST(CallCompletedCallbackTwoExceptions) { |
static void MicrotaskOne(const v8::FunctionCallbackInfo<Value>& info) { |
v8::HandleScope scope(info.GetIsolate()); |
+ v8::MicrotasksScope microtasks(info.GetIsolate(), |
+ v8::MicrotasksScope::kDoNotRunMicrotasks); |
CompileRun("ext1Calls++;"); |
} |
static void MicrotaskTwo(const v8::FunctionCallbackInfo<Value>& info) { |
v8::HandleScope scope(info.GetIsolate()); |
+ v8::MicrotasksScope microtasks(info.GetIsolate(), |
+ v8::MicrotasksScope::kDoNotRunMicrotasks); |
CompileRun("ext2Calls++;"); |
} |
@@ -21061,7 +21065,7 @@ TEST(SetAutorunMicrotasks) { |
CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
CHECK_EQ(1u, microtasks_completed_callback_count); |
- env->GetIsolate()->SetAutorunMicrotasks(false); |
+ env->GetIsolate()->SetMicrotasksPolicy(v8::MicrotasksPolicy::kExplicit); |
env->GetIsolate()->EnqueueMicrotask( |
Function::New(env.local(), MicrotaskOne).ToLocalChecked()); |
env->GetIsolate()->EnqueueMicrotask( |
@@ -21088,7 +21092,7 @@ TEST(SetAutorunMicrotasks) { |
CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
CHECK_EQ(3u, microtasks_completed_callback_count); |
- env->GetIsolate()->SetAutorunMicrotasks(true); |
+ env->GetIsolate()->SetMicrotasksPolicy(v8::MicrotasksPolicy::kAuto); |
env->GetIsolate()->EnqueueMicrotask( |
Function::New(env.local(), MicrotaskTwo).ToLocalChecked()); |
CompileRun("1+1;"); |
@@ -21125,7 +21129,7 @@ TEST(SetAutorunMicrotasks) { |
TEST(RunMicrotasksWithoutEnteringContext) { |
v8::Isolate* isolate = CcTest::isolate(); |
HandleScope handle_scope(isolate); |
- isolate->SetAutorunMicrotasks(false); |
+ isolate->SetMicrotasksPolicy(v8::MicrotasksPolicy::kExplicit); |
Local<Context> context = Context::New(isolate); |
{ |
Context::Scope context_scope(context); |
@@ -21138,7 +21142,147 @@ TEST(RunMicrotasksWithoutEnteringContext) { |
Context::Scope context_scope(context); |
CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(context).FromJust()); |
} |
- isolate->SetAutorunMicrotasks(true); |
+ isolate->SetMicrotasksPolicy(v8::MicrotasksPolicy::kAuto); |
+} |
+ |
+ |
+TEST(ScopedMicrotasks) { |
+ LocalContext env; |
+ v8::HandleScope handles(env->GetIsolate()); |
+ env->GetIsolate()->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped); |
+ { |
+ v8::MicrotasksScope scope1(env->GetIsolate(), |
+ v8::MicrotasksScope::kDoNotRunMicrotasks); |
+ env->GetIsolate()->EnqueueMicrotask( |
+ Function::New(env.local(), MicrotaskOne).ToLocalChecked()); |
+ CompileRun( |
+ "var ext1Calls = 0;" |
+ "var ext2Calls = 0;"); |
+ CompileRun("1+1;"); |
+ CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
+ CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
+ { |
+ v8::MicrotasksScope scope2(env->GetIsolate(), |
+ v8::MicrotasksScope::kRunMicrotasks); |
+ CompileRun("1+1;"); |
+ CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
+ CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
+ { |
+ v8::MicrotasksScope scope3(env->GetIsolate(), |
+ v8::MicrotasksScope::kRunMicrotasks); |
+ CompileRun("1+1;"); |
+ CHECK_EQ(0, |
+ CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
+ CHECK_EQ(0, |
+ CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
+ } |
+ CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
+ CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
+ } |
+ CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
+ CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
+ env->GetIsolate()->EnqueueMicrotask( |
+ Function::New(env.local(), MicrotaskTwo).ToLocalChecked()); |
+ } |
+ |
+ { |
+ v8::MicrotasksScope scope(env->GetIsolate(), |
+ v8::MicrotasksScope::kDoNotRunMicrotasks); |
+ CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
+ CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
+ } |
+ |
+ { |
+ v8::MicrotasksScope scope1(env->GetIsolate(), |
+ v8::MicrotasksScope::kRunMicrotasks); |
+ CompileRun("1+1;"); |
+ CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
+ CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
+ { |
+ v8::MicrotasksScope scope2(env->GetIsolate(), |
+ v8::MicrotasksScope::kDoNotRunMicrotasks); |
+ } |
+ CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
+ CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
+ } |
+ |
+ { |
+ v8::MicrotasksScope scope(env->GetIsolate(), |
+ v8::MicrotasksScope::kDoNotRunMicrotasks); |
+ CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
+ CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
+ env->GetIsolate()->EnqueueMicrotask( |
+ Function::New(env.local(), MicrotaskTwo).ToLocalChecked()); |
+ } |
+ |
+ { |
+ v8::Isolate::SuppressMicrotaskExecutionScope scope1(env->GetIsolate()); |
+ { |
+ v8::MicrotasksScope scope2(env->GetIsolate(), |
+ v8::MicrotasksScope::kRunMicrotasks); |
+ } |
+ v8::MicrotasksScope scope3(env->GetIsolate(), |
+ v8::MicrotasksScope::kDoNotRunMicrotasks); |
+ CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
+ CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
+ } |
+ |
+ { |
+ v8::MicrotasksScope scope1(env->GetIsolate(), |
+ v8::MicrotasksScope::kRunMicrotasks); |
+ v8::MicrotasksScope::PerformCheckpoint(env->GetIsolate()); |
+ CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
+ CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
+ } |
+ |
+ { |
+ v8::MicrotasksScope scope(env->GetIsolate(), |
+ v8::MicrotasksScope::kDoNotRunMicrotasks); |
+ CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
+ CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
+ } |
+ |
+ v8::MicrotasksScope::PerformCheckpoint(env->GetIsolate()); |
+ |
+ { |
+ v8::MicrotasksScope scope(env->GetIsolate(), |
+ v8::MicrotasksScope::kDoNotRunMicrotasks); |
+ CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
+ CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
+ env->GetIsolate()->EnqueueMicrotask( |
+ Function::New(env.local(), MicrotaskTwo).ToLocalChecked()); |
+ } |
+ |
+ v8::MicrotasksScope::PerformCheckpoint(env->GetIsolate()); |
+ |
+ { |
+ v8::MicrotasksScope scope(env->GetIsolate(), |
+ v8::MicrotasksScope::kDoNotRunMicrotasks); |
+ CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
+ CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
+ } |
+ |
+ env->GetIsolate()->EnqueueMicrotask( |
+ Function::New(env.local(), MicrotaskOne).ToLocalChecked()); |
+ { |
+ v8::Isolate::SuppressMicrotaskExecutionScope scope1(env->GetIsolate()); |
+ v8::MicrotasksScope::PerformCheckpoint(env->GetIsolate()); |
+ v8::MicrotasksScope scope2(env->GetIsolate(), |
+ v8::MicrotasksScope::kDoNotRunMicrotasks); |
+ CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
+ CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
+ } |
+ |
+ v8::MicrotasksScope::PerformCheckpoint(env->GetIsolate()); |
+ |
+ { |
+ v8::MicrotasksScope scope(env->GetIsolate(), |
+ v8::MicrotasksScope::kDoNotRunMicrotasks); |
+ CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
+ CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
+ } |
+ |
+ env->GetIsolate()->SetMicrotasksPolicy(v8::MicrotasksPolicy::kAuto); |
} |
@@ -21161,7 +21305,7 @@ TEST(Regress385349) { |
i::FLAG_allow_natives_syntax = true; |
v8::Isolate* isolate = CcTest::isolate(); |
HandleScope handle_scope(isolate); |
- isolate->SetAutorunMicrotasks(false); |
+ isolate->SetMicrotasksPolicy(v8::MicrotasksPolicy::kExplicit); |
Local<Context> context = Context::New(isolate); |
v8::Debug::SetDebugEventListener(isolate, DebugEventInObserver); |
{ |
@@ -21171,7 +21315,7 @@ TEST(Regress385349) { |
"obj.a = 0;"); |
} |
isolate->RunMicrotasks(); |
- isolate->SetAutorunMicrotasks(true); |
+ isolate->SetMicrotasksPolicy(v8::MicrotasksPolicy::kAuto); |
v8::Debug::SetDebugEventListener(isolate, nullptr); |
} |