Index: test/cctest/test-api.cc |
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc |
index f473f5ccb2b64d4d3be0cad4817077bcf493bd57..d206e3dec8f5e5d5756345c30ef03b007c3625dd 100644 |
--- a/test/cctest/test-api.cc |
+++ b/test/cctest/test-api.cc |
@@ -20550,6 +20550,93 @@ TEST(CallCompletedCallbackTwoExceptions) { |
} |
+void ExternalMicrotaskOne() { |
Sven Panne
2014/02/10 14:22:02
Nit: static. Reduces the probability of linker cla
rafaelw
2014/02/11 00:28:52
Done.
|
+ v8::HandleScope scope(CcTest::isolate()); |
Sven Panne
2014/02/10 14:22:03
Calling CcTest::isolate() is a strong indicator th
rafaelw
2014/02/11 00:28:52
Good to know. Done.
|
+ CompileRun("ext1Calls++;"); |
+} |
+ |
+ |
+void ExternalMicrotaskTwo() { |
+ v8::HandleScope scope(CcTest::isolate()); |
+ CompileRun("ext2Calls++;"); |
+} |
+ |
+ |
+TEST(EnqueueExternalMicrotask) { |
+ LocalContext env; |
+ v8::HandleScope scope(env->GetIsolate()); |
+ CompileRun( |
+ "var ext1Calls = 0;" |
+ "var ext2Calls = 0;"); |
+ CompileRun("1+1;"); |
+ CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value()); |
+ CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); |
+ |
+ v8::V8::EnqueueExternalMicrotask(env->GetIsolate(), ExternalMicrotaskOne); |
+ CompileRun("1+1;"); |
+ CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value()); |
+ CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); |
+ |
+ v8::V8::EnqueueExternalMicrotask(env->GetIsolate(), ExternalMicrotaskOne); |
+ v8::V8::EnqueueExternalMicrotask(env->GetIsolate(), ExternalMicrotaskTwo); |
+ CompileRun("1+1;"); |
+ CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); |
+ CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value()); |
+ |
+ v8::V8::EnqueueExternalMicrotask(env->GetIsolate(), ExternalMicrotaskTwo); |
+ CompileRun("1+1;"); |
+ CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); |
+ CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value()); |
+ |
+ CompileRun("1+1;"); |
+ CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); |
+ CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value()); |
+} |
+ |
+ |
+TEST(SetAutorunMicrotasks) { |
+ LocalContext env; |
+ v8::HandleScope scope(env->GetIsolate()); |
+ CompileRun( |
+ "var ext1Calls = 0;" |
+ "var ext2Calls = 0;"); |
+ CompileRun("1+1;"); |
+ CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value()); |
+ CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); |
+ |
+ v8::V8::EnqueueExternalMicrotask(env->GetIsolate(), ExternalMicrotaskOne); |
+ CompileRun("1+1;"); |
+ CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value()); |
+ CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); |
+ |
+ V8::SetAutorunMicrotasks(env->GetIsolate(), false); |
+ v8::V8::EnqueueExternalMicrotask(env->GetIsolate(), ExternalMicrotaskOne); |
+ v8::V8::EnqueueExternalMicrotask(env->GetIsolate(), ExternalMicrotaskTwo); |
+ CompileRun("1+1;"); |
+ CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value()); |
+ CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); |
+ |
+ V8::RunMicrotasks(env->GetIsolate()); |
+ CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); |
+ CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value()); |
+ |
+ v8::V8::EnqueueExternalMicrotask(env->GetIsolate(), ExternalMicrotaskTwo); |
+ CompileRun("1+1;"); |
+ CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); |
+ CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value()); |
+ |
+ V8::RunMicrotasks(env->GetIsolate()); |
+ CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); |
+ CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value()); |
+ |
+ V8::SetAutorunMicrotasks(env->GetIsolate(), true); |
+ v8::V8::EnqueueExternalMicrotask(env->GetIsolate(), ExternalMicrotaskTwo); |
+ CompileRun("1+1;"); |
+ CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); |
+ CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value()); |
+} |
+ |
+ |
static int probes_counter = 0; |
static int misses_counter = 0; |
static int updates_counter = 0; |