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

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

Issue 620673005: Introduce HasPendingMicrotasks API. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 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 fc0281a0bdf6f3375db2d1627d4fb4a661ac548a..aa338e08a9c426fe281d6d63d62712f238119ce1 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -21146,7 +21146,8 @@ static void MicrotaskThree(void* data) {
TEST(EnqueueMicrotask) {
LocalContext env;
- v8::HandleScope scope(env->GetIsolate());
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
CompileRun(
"var ext1Calls = 0;"
"var ext2Calls = 0;");
@@ -21154,22 +21155,22 @@ TEST(EnqueueMicrotask) {
CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value());
CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value());
- env->GetIsolate()->EnqueueMicrotask(
- Function::New(env->GetIsolate(), MicrotaskOne));
+ CHECK(!isolate->HasPendingMicrotasks());
+ isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskOne));
+ CHECK(isolate->HasPendingMicrotasks());
CompileRun("1+1;");
CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value());
CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value());
- env->GetIsolate()->EnqueueMicrotask(
- Function::New(env->GetIsolate(), MicrotaskOne));
- env->GetIsolate()->EnqueueMicrotask(
- Function::New(env->GetIsolate(), MicrotaskTwo));
+ CHECK(!isolate->HasPendingMicrotasks());
+ isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskOne));
+ isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskTwo));
+ CHECK(isolate->HasPendingMicrotasks());
CompileRun("1+1;");
CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value());
CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value());
- env->GetIsolate()->EnqueueMicrotask(
- Function::New(env->GetIsolate(), MicrotaskTwo));
+ isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskTwo));
CompileRun("1+1;");
CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value());
CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value());
@@ -21179,18 +21180,16 @@ TEST(EnqueueMicrotask) {
CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value());
g_passed_to_three = NULL;
- env->GetIsolate()->EnqueueMicrotask(MicrotaskThree);
+ isolate->EnqueueMicrotask(MicrotaskThree);
CompileRun("1+1;");
CHECK_EQ(NULL, g_passed_to_three);
CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value());
CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value());
int dummy;
- env->GetIsolate()->EnqueueMicrotask(
- Function::New(env->GetIsolate(), MicrotaskOne));
- env->GetIsolate()->EnqueueMicrotask(MicrotaskThree, &dummy);
- env->GetIsolate()->EnqueueMicrotask(
- Function::New(env->GetIsolate(), MicrotaskTwo));
+ isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskOne));
+ isolate->EnqueueMicrotask(MicrotaskThree, &dummy);
+ isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskTwo));
CompileRun("1+1;");
CHECK_EQ(&dummy, g_passed_to_three);
CHECK_EQ(3, CompileRun("ext1Calls")->Int32Value());
@@ -21224,10 +21223,8 @@ TEST(RunMicrotasksIgnoresThrownExceptions) {
CompileRun(
"var exception1Calls = 0;"
"var exception2Calls = 0;");
- isolate->EnqueueMicrotask(
- Function::New(isolate, MicrotaskExceptionOne));
- isolate->EnqueueMicrotask(
- Function::New(isolate, MicrotaskExceptionTwo));
+ isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskExceptionOne));
+ isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskExceptionTwo));
TryCatch try_catch;
CompileRun("1+1;");
CHECK(!try_catch.HasCaught());
@@ -21238,7 +21235,8 @@ TEST(RunMicrotasksIgnoresThrownExceptions) {
TEST(SetAutorunMicrotasks) {
LocalContext env;
- v8::HandleScope scope(env->GetIsolate());
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
CompileRun(
"var ext1Calls = 0;"
"var ext2Calls = 0;");
@@ -21246,46 +21244,40 @@ TEST(SetAutorunMicrotasks) {
CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value());
CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value());
- env->GetIsolate()->EnqueueMicrotask(
- Function::New(env->GetIsolate(), MicrotaskOne));
+ isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskOne));
CompileRun("1+1;");
CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value());
CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value());
- env->GetIsolate()->SetAutorunMicrotasks(false);
- env->GetIsolate()->EnqueueMicrotask(
- Function::New(env->GetIsolate(), MicrotaskOne));
- env->GetIsolate()->EnqueueMicrotask(
- Function::New(env->GetIsolate(), MicrotaskTwo));
+ isolate->SetAutorunMicrotasks(false);
+ isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskOne));
+ isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskTwo));
CompileRun("1+1;");
CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value());
CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value());
- env->GetIsolate()->RunMicrotasks();
+ isolate->RunMicrotasks();
CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value());
CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value());
- env->GetIsolate()->EnqueueMicrotask(
- Function::New(env->GetIsolate(), MicrotaskTwo));
+ isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskTwo));
CompileRun("1+1;");
CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value());
CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value());
- env->GetIsolate()->RunMicrotasks();
+ isolate->RunMicrotasks();
CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value());
CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value());
- env->GetIsolate()->SetAutorunMicrotasks(true);
- env->GetIsolate()->EnqueueMicrotask(
- Function::New(env->GetIsolate(), MicrotaskTwo));
+ isolate->SetAutorunMicrotasks(true);
+ isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskTwo));
CompileRun("1+1;");
CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value());
CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value());
- env->GetIsolate()->EnqueueMicrotask(
- Function::New(env->GetIsolate(), MicrotaskTwo));
+ isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskTwo));
{
- v8::Isolate::SuppressMicrotaskExecutionScope scope(env->GetIsolate());
+ v8::Isolate::SuppressMicrotaskExecutionScope scope(isolate);
CompileRun("1+1;");
CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value());
CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value());
@@ -21316,6 +21308,31 @@ TEST(RunMicrotasksWithoutEnteringContext) {
}
+bool g_the_only_microtask_called = false;
+
+
+static void TheOnlyMicrotask(void* data) {
+ g_the_only_microtask_called = true;
+ v8::Isolate* isolate = static_cast<v8::Isolate*>(data);
+ CHECK(!isolate->HasPendingMicrotasks());
+}
+
+
+TEST(HasPendingMicrotasks) {
+ LocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope scope(isolate);
+
+ g_the_only_microtask_called = false;
+ CHECK(!isolate->HasPendingMicrotasks());
+ isolate->EnqueueMicrotask(TheOnlyMicrotask, isolate);
+ CHECK(isolate->HasPendingMicrotasks());
+ CompileRun("1+1;");
+ CHECK(g_the_only_microtask_called);
+ CHECK(!isolate->HasPendingMicrotasks());
+}
+
+
static void DebugEventInObserver(const v8::Debug::EventDetails& event_details) {
v8::DebugEvent event = event_details.GetEvent();
if (event != v8::Break) return;
« 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