Index: test/cctest/test-api.cc |
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc |
index f4e8fe8e4bd36b6f4f934c962ce4f28a4100ffca..e9b2fce7f051ace5ded179f59d73dbdebb73bc60 100644 |
--- a/test/cctest/test-api.cc |
+++ b/test/cctest/test-api.cc |
@@ -21033,21 +21033,33 @@ TEST(RunMicrotasksIgnoresThrownExceptions) { |
} |
+uint8_t microtasks_completed_callback_count = 0; |
+ |
+ |
+static void MicrotasksCompletedCallback(v8::Isolate* isolate) { |
+ ++microtasks_completed_callback_count; |
+} |
+ |
+ |
TEST(SetAutorunMicrotasks) { |
LocalContext env; |
v8::HandleScope scope(env->GetIsolate()); |
+ env->GetIsolate()->AddMicrotasksCompletedCallback( |
+ &MicrotasksCompletedCallback); |
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()); |
+ CHECK_EQ(0u, microtasks_completed_callback_count); |
env->GetIsolate()->EnqueueMicrotask( |
Function::New(env.local(), MicrotaskOne).ToLocalChecked()); |
CompileRun("1+1;"); |
CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
+ CHECK_EQ(1u, microtasks_completed_callback_count); |
env->GetIsolate()->SetAutorunMicrotasks(false); |
env->GetIsolate()->EnqueueMicrotask( |
@@ -21057,20 +21069,24 @@ TEST(SetAutorunMicrotasks) { |
CompileRun("1+1;"); |
CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
+ CHECK_EQ(1u, microtasks_completed_callback_count); |
env->GetIsolate()->RunMicrotasks(); |
CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
+ CHECK_EQ(2u, microtasks_completed_callback_count); |
env->GetIsolate()->EnqueueMicrotask( |
Function::New(env.local(), MicrotaskTwo).ToLocalChecked()); |
CompileRun("1+1;"); |
CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
+ CHECK_EQ(2u, microtasks_completed_callback_count); |
env->GetIsolate()->RunMicrotasks(); |
CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
+ CHECK_EQ(3u, microtasks_completed_callback_count); |
env->GetIsolate()->SetAutorunMicrotasks(true); |
env->GetIsolate()->EnqueueMicrotask( |
@@ -21078,6 +21094,7 @@ TEST(SetAutorunMicrotasks) { |
CompileRun("1+1;"); |
CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
+ CHECK_EQ(4u, microtasks_completed_callback_count); |
env->GetIsolate()->EnqueueMicrotask( |
Function::New(env.local(), MicrotaskTwo).ToLocalChecked()); |
@@ -21086,11 +21103,22 @@ TEST(SetAutorunMicrotasks) { |
CompileRun("1+1;"); |
CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
+ CHECK_EQ(4u, microtasks_completed_callback_count); |
} |
CompileRun("1+1;"); |
CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
CHECK_EQ(4, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
+ CHECK_EQ(5u, microtasks_completed_callback_count); |
+ |
+ env->GetIsolate()->RemoveMicrotasksCompletedCallback( |
+ &MicrotasksCompletedCallback); |
+ env->GetIsolate()->EnqueueMicrotask( |
+ Function::New(env.local(), MicrotaskOne).ToLocalChecked()); |
+ CompileRun("1+1;"); |
+ CHECK_EQ(3, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
+ CHECK_EQ(4, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
+ CHECK_EQ(5u, microtasks_completed_callback_count); |
} |