Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Unified Diff: test/cctest/test-api.cc

Issue 1731773005: Introduce MicrotasksCompletedCallback. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: DCHECK Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/isolate.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
« no previous file with comments | « src/isolate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698