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

Side by Side 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, 9 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 unified diff | Download patch
« no previous file with comments | « src/isolate.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 21015 matching lines...) Expand 10 before | Expand all | Expand 10 after
21026 TryCatch try_catch(isolate); 21026 TryCatch try_catch(isolate);
21027 CompileRun("1+1;"); 21027 CompileRun("1+1;");
21028 CHECK(!try_catch.HasCaught()); 21028 CHECK(!try_catch.HasCaught());
21029 CHECK_EQ(1, 21029 CHECK_EQ(1,
21030 CompileRun("exception1Calls")->Int32Value(env.local()).FromJust()); 21030 CompileRun("exception1Calls")->Int32Value(env.local()).FromJust());
21031 CHECK_EQ(1, 21031 CHECK_EQ(1,
21032 CompileRun("exception2Calls")->Int32Value(env.local()).FromJust()); 21032 CompileRun("exception2Calls")->Int32Value(env.local()).FromJust());
21033 } 21033 }
21034 21034
21035 21035
21036 uint8_t microtasks_completed_callback_count = 0;
21037
21038
21039 static void MicrotasksCompletedCallback(v8::Isolate* isolate) {
21040 ++microtasks_completed_callback_count;
21041 }
21042
21043
21036 TEST(SetAutorunMicrotasks) { 21044 TEST(SetAutorunMicrotasks) {
21037 LocalContext env; 21045 LocalContext env;
21038 v8::HandleScope scope(env->GetIsolate()); 21046 v8::HandleScope scope(env->GetIsolate());
21047 env->GetIsolate()->AddMicrotasksCompletedCallback(
21048 &MicrotasksCompletedCallback);
21039 CompileRun( 21049 CompileRun(
21040 "var ext1Calls = 0;" 21050 "var ext1Calls = 0;"
21041 "var ext2Calls = 0;"); 21051 "var ext2Calls = 0;");
21042 CompileRun("1+1;"); 21052 CompileRun("1+1;");
21043 CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); 21053 CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust());
21044 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); 21054 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust());
21055 CHECK_EQ(0u, microtasks_completed_callback_count);
21045 21056
21046 env->GetIsolate()->EnqueueMicrotask( 21057 env->GetIsolate()->EnqueueMicrotask(
21047 Function::New(env.local(), MicrotaskOne).ToLocalChecked()); 21058 Function::New(env.local(), MicrotaskOne).ToLocalChecked());
21048 CompileRun("1+1;"); 21059 CompileRun("1+1;");
21049 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); 21060 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust());
21050 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); 21061 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust());
21062 CHECK_EQ(1u, microtasks_completed_callback_count);
21051 21063
21052 env->GetIsolate()->SetAutorunMicrotasks(false); 21064 env->GetIsolate()->SetAutorunMicrotasks(false);
21053 env->GetIsolate()->EnqueueMicrotask( 21065 env->GetIsolate()->EnqueueMicrotask(
21054 Function::New(env.local(), MicrotaskOne).ToLocalChecked()); 21066 Function::New(env.local(), MicrotaskOne).ToLocalChecked());
21055 env->GetIsolate()->EnqueueMicrotask( 21067 env->GetIsolate()->EnqueueMicrotask(
21056 Function::New(env.local(), MicrotaskTwo).ToLocalChecked()); 21068 Function::New(env.local(), MicrotaskTwo).ToLocalChecked());
21057 CompileRun("1+1;"); 21069 CompileRun("1+1;");
21058 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); 21070 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust());
21059 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); 21071 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust());
21072 CHECK_EQ(1u, microtasks_completed_callback_count);
21060 21073
21061 env->GetIsolate()->RunMicrotasks(); 21074 env->GetIsolate()->RunMicrotasks();
21062 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); 21075 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust());
21063 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); 21076 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust());
21077 CHECK_EQ(2u, microtasks_completed_callback_count);
21064 21078
21065 env->GetIsolate()->EnqueueMicrotask( 21079 env->GetIsolate()->EnqueueMicrotask(
21066 Function::New(env.local(), MicrotaskTwo).ToLocalChecked()); 21080 Function::New(env.local(), MicrotaskTwo).ToLocalChecked());
21067 CompileRun("1+1;"); 21081 CompileRun("1+1;");
21068 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); 21082 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust());
21069 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); 21083 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust());
21084 CHECK_EQ(2u, microtasks_completed_callback_count);
21070 21085
21071 env->GetIsolate()->RunMicrotasks(); 21086 env->GetIsolate()->RunMicrotasks();
21072 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); 21087 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust());
21073 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); 21088 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust());
21089 CHECK_EQ(3u, microtasks_completed_callback_count);
21074 21090
21075 env->GetIsolate()->SetAutorunMicrotasks(true); 21091 env->GetIsolate()->SetAutorunMicrotasks(true);
21076 env->GetIsolate()->EnqueueMicrotask( 21092 env->GetIsolate()->EnqueueMicrotask(
21077 Function::New(env.local(), MicrotaskTwo).ToLocalChecked()); 21093 Function::New(env.local(), MicrotaskTwo).ToLocalChecked());
21078 CompileRun("1+1;"); 21094 CompileRun("1+1;");
21079 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); 21095 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust());
21080 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); 21096 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust());
21097 CHECK_EQ(4u, microtasks_completed_callback_count);
21081 21098
21082 env->GetIsolate()->EnqueueMicrotask( 21099 env->GetIsolate()->EnqueueMicrotask(
21083 Function::New(env.local(), MicrotaskTwo).ToLocalChecked()); 21100 Function::New(env.local(), MicrotaskTwo).ToLocalChecked());
21084 { 21101 {
21085 v8::Isolate::SuppressMicrotaskExecutionScope scope(env->GetIsolate()); 21102 v8::Isolate::SuppressMicrotaskExecutionScope scope(env->GetIsolate());
21086 CompileRun("1+1;"); 21103 CompileRun("1+1;");
21087 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); 21104 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust());
21088 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); 21105 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust());
21106 CHECK_EQ(4u, microtasks_completed_callback_count);
21089 } 21107 }
21090 21108
21091 CompileRun("1+1;"); 21109 CompileRun("1+1;");
21092 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); 21110 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust());
21093 CHECK_EQ(4, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); 21111 CHECK_EQ(4, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust());
21112 CHECK_EQ(5u, microtasks_completed_callback_count);
21113
21114 env->GetIsolate()->RemoveMicrotasksCompletedCallback(
21115 &MicrotasksCompletedCallback);
21116 env->GetIsolate()->EnqueueMicrotask(
21117 Function::New(env.local(), MicrotaskOne).ToLocalChecked());
21118 CompileRun("1+1;");
21119 CHECK_EQ(3, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust());
21120 CHECK_EQ(4, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust());
21121 CHECK_EQ(5u, microtasks_completed_callback_count);
21094 } 21122 }
21095 21123
21096 21124
21097 TEST(RunMicrotasksWithoutEnteringContext) { 21125 TEST(RunMicrotasksWithoutEnteringContext) {
21098 v8::Isolate* isolate = CcTest::isolate(); 21126 v8::Isolate* isolate = CcTest::isolate();
21099 HandleScope handle_scope(isolate); 21127 HandleScope handle_scope(isolate);
21100 isolate->SetAutorunMicrotasks(false); 21128 isolate->SetAutorunMicrotasks(false);
21101 Local<Context> context = Context::New(isolate); 21129 Local<Context> context = Context::New(isolate);
21102 { 21130 {
21103 Context::Scope context_scope(context); 21131 Context::Scope context_scope(context);
(...skipping 3863 matching lines...) Expand 10 before | Expand all | Expand 10 after
24967 CHECK(proxy->GetTarget()->SameValue(target)); 24995 CHECK(proxy->GetTarget()->SameValue(target));
24968 CHECK(proxy->GetHandler()->SameValue(handler)); 24996 CHECK(proxy->GetHandler()->SameValue(handler));
24969 24997
24970 proxy->Revoke(); 24998 proxy->Revoke();
24971 CHECK(proxy->IsProxy()); 24999 CHECK(proxy->IsProxy());
24972 CHECK(!target->IsProxy()); 25000 CHECK(!target->IsProxy());
24973 CHECK(proxy->IsRevoked()); 25001 CHECK(proxy->IsRevoked());
24974 CHECK(proxy->GetTarget()->SameValue(target)); 25002 CHECK(proxy->GetTarget()->SameValue(target));
24975 CHECK(proxy->GetHandler()->IsNull()); 25003 CHECK(proxy->GetHandler()->IsNull());
24976 } 25004 }
OLDNEW
« 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