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

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

Issue 154283002: V8 Microtask Queue & API (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: pre-review Created 6 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
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;
« include/v8.h ('K') | « src/v8natives.js ('k') | test/mjsunit/fuzz-natives-part3.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698