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 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 unified diff | Download patch | Annotate | Revision Log
« 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 21128 matching lines...) Expand 10 before | Expand all | Expand 10 after
21139 void* g_passed_to_three = NULL; 21139 void* g_passed_to_three = NULL;
21140 21140
21141 21141
21142 static void MicrotaskThree(void* data) { 21142 static void MicrotaskThree(void* data) {
21143 g_passed_to_three = data; 21143 g_passed_to_three = data;
21144 } 21144 }
21145 21145
21146 21146
21147 TEST(EnqueueMicrotask) { 21147 TEST(EnqueueMicrotask) {
21148 LocalContext env; 21148 LocalContext env;
21149 v8::HandleScope scope(env->GetIsolate()); 21149 v8::Isolate* isolate = env->GetIsolate();
21150 v8::HandleScope scope(isolate);
21150 CompileRun( 21151 CompileRun(
21151 "var ext1Calls = 0;" 21152 "var ext1Calls = 0;"
21152 "var ext2Calls = 0;"); 21153 "var ext2Calls = 0;");
21153 CompileRun("1+1;"); 21154 CompileRun("1+1;");
21154 CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value()); 21155 CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value());
21155 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); 21156 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value());
21156 21157
21157 env->GetIsolate()->EnqueueMicrotask( 21158 CHECK(!isolate->HasPendingMicrotasks());
21158 Function::New(env->GetIsolate(), MicrotaskOne)); 21159 isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskOne));
21160 CHECK(isolate->HasPendingMicrotasks());
21159 CompileRun("1+1;"); 21161 CompileRun("1+1;");
21160 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value()); 21162 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value());
21161 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); 21163 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value());
21162 21164
21163 env->GetIsolate()->EnqueueMicrotask( 21165 CHECK(!isolate->HasPendingMicrotasks());
21164 Function::New(env->GetIsolate(), MicrotaskOne)); 21166 isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskOne));
21165 env->GetIsolate()->EnqueueMicrotask( 21167 isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskTwo));
21166 Function::New(env->GetIsolate(), MicrotaskTwo)); 21168 CHECK(isolate->HasPendingMicrotasks());
21167 CompileRun("1+1;"); 21169 CompileRun("1+1;");
21168 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); 21170 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value());
21169 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value()); 21171 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value());
21170 21172
21171 env->GetIsolate()->EnqueueMicrotask( 21173 isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskTwo));
21172 Function::New(env->GetIsolate(), MicrotaskTwo));
21173 CompileRun("1+1;"); 21174 CompileRun("1+1;");
21174 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); 21175 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value());
21175 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value()); 21176 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value());
21176 21177
21177 CompileRun("1+1;"); 21178 CompileRun("1+1;");
21178 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); 21179 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value());
21179 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value()); 21180 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value());
21180 21181
21181 g_passed_to_three = NULL; 21182 g_passed_to_three = NULL;
21182 env->GetIsolate()->EnqueueMicrotask(MicrotaskThree); 21183 isolate->EnqueueMicrotask(MicrotaskThree);
21183 CompileRun("1+1;"); 21184 CompileRun("1+1;");
21184 CHECK_EQ(NULL, g_passed_to_three); 21185 CHECK_EQ(NULL, g_passed_to_three);
21185 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); 21186 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value());
21186 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value()); 21187 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value());
21187 21188
21188 int dummy; 21189 int dummy;
21189 env->GetIsolate()->EnqueueMicrotask( 21190 isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskOne));
21190 Function::New(env->GetIsolate(), MicrotaskOne)); 21191 isolate->EnqueueMicrotask(MicrotaskThree, &dummy);
21191 env->GetIsolate()->EnqueueMicrotask(MicrotaskThree, &dummy); 21192 isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskTwo));
21192 env->GetIsolate()->EnqueueMicrotask(
21193 Function::New(env->GetIsolate(), MicrotaskTwo));
21194 CompileRun("1+1;"); 21193 CompileRun("1+1;");
21195 CHECK_EQ(&dummy, g_passed_to_three); 21194 CHECK_EQ(&dummy, g_passed_to_three);
21196 CHECK_EQ(3, CompileRun("ext1Calls")->Int32Value()); 21195 CHECK_EQ(3, CompileRun("ext1Calls")->Int32Value());
21197 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value()); 21196 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value());
21198 g_passed_to_three = NULL; 21197 g_passed_to_three = NULL;
21199 } 21198 }
21200 21199
21201 21200
21202 static void MicrotaskExceptionOne( 21201 static void MicrotaskExceptionOne(
21203 const v8::FunctionCallbackInfo<Value>& info) { 21202 const v8::FunctionCallbackInfo<Value>& info) {
(...skipping 13 matching lines...) Expand all
21217 } 21216 }
21218 21217
21219 21218
21220 TEST(RunMicrotasksIgnoresThrownExceptions) { 21219 TEST(RunMicrotasksIgnoresThrownExceptions) {
21221 LocalContext env; 21220 LocalContext env;
21222 v8::Isolate* isolate = env->GetIsolate(); 21221 v8::Isolate* isolate = env->GetIsolate();
21223 v8::HandleScope scope(isolate); 21222 v8::HandleScope scope(isolate);
21224 CompileRun( 21223 CompileRun(
21225 "var exception1Calls = 0;" 21224 "var exception1Calls = 0;"
21226 "var exception2Calls = 0;"); 21225 "var exception2Calls = 0;");
21227 isolate->EnqueueMicrotask( 21226 isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskExceptionOne));
21228 Function::New(isolate, MicrotaskExceptionOne)); 21227 isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskExceptionTwo));
21229 isolate->EnqueueMicrotask(
21230 Function::New(isolate, MicrotaskExceptionTwo));
21231 TryCatch try_catch; 21228 TryCatch try_catch;
21232 CompileRun("1+1;"); 21229 CompileRun("1+1;");
21233 CHECK(!try_catch.HasCaught()); 21230 CHECK(!try_catch.HasCaught());
21234 CHECK_EQ(1, CompileRun("exception1Calls")->Int32Value()); 21231 CHECK_EQ(1, CompileRun("exception1Calls")->Int32Value());
21235 CHECK_EQ(1, CompileRun("exception2Calls")->Int32Value()); 21232 CHECK_EQ(1, CompileRun("exception2Calls")->Int32Value());
21236 } 21233 }
21237 21234
21238 21235
21239 TEST(SetAutorunMicrotasks) { 21236 TEST(SetAutorunMicrotasks) {
21240 LocalContext env; 21237 LocalContext env;
21241 v8::HandleScope scope(env->GetIsolate()); 21238 v8::Isolate* isolate = env->GetIsolate();
21239 v8::HandleScope scope(isolate);
21242 CompileRun( 21240 CompileRun(
21243 "var ext1Calls = 0;" 21241 "var ext1Calls = 0;"
21244 "var ext2Calls = 0;"); 21242 "var ext2Calls = 0;");
21245 CompileRun("1+1;"); 21243 CompileRun("1+1;");
21246 CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value()); 21244 CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value());
21247 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); 21245 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value());
21248 21246
21249 env->GetIsolate()->EnqueueMicrotask( 21247 isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskOne));
21250 Function::New(env->GetIsolate(), MicrotaskOne));
21251 CompileRun("1+1;"); 21248 CompileRun("1+1;");
21252 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value()); 21249 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value());
21253 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); 21250 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value());
21254 21251
21255 env->GetIsolate()->SetAutorunMicrotasks(false); 21252 isolate->SetAutorunMicrotasks(false);
21256 env->GetIsolate()->EnqueueMicrotask( 21253 isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskOne));
21257 Function::New(env->GetIsolate(), MicrotaskOne)); 21254 isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskTwo));
21258 env->GetIsolate()->EnqueueMicrotask(
21259 Function::New(env->GetIsolate(), MicrotaskTwo));
21260 CompileRun("1+1;"); 21255 CompileRun("1+1;");
21261 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value()); 21256 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value());
21262 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); 21257 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value());
21263 21258
21264 env->GetIsolate()->RunMicrotasks(); 21259 isolate->RunMicrotasks();
21265 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); 21260 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value());
21266 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value()); 21261 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value());
21267 21262
21268 env->GetIsolate()->EnqueueMicrotask( 21263 isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskTwo));
21269 Function::New(env->GetIsolate(), MicrotaskTwo));
21270 CompileRun("1+1;"); 21264 CompileRun("1+1;");
21271 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); 21265 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value());
21272 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value()); 21266 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value());
21273 21267
21274 env->GetIsolate()->RunMicrotasks(); 21268 isolate->RunMicrotasks();
21275 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); 21269 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value());
21276 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value()); 21270 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value());
21277 21271
21278 env->GetIsolate()->SetAutorunMicrotasks(true); 21272 isolate->SetAutorunMicrotasks(true);
21279 env->GetIsolate()->EnqueueMicrotask( 21273 isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskTwo));
21280 Function::New(env->GetIsolate(), MicrotaskTwo));
21281 CompileRun("1+1;"); 21274 CompileRun("1+1;");
21282 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); 21275 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value());
21283 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value()); 21276 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value());
21284 21277
21285 env->GetIsolate()->EnqueueMicrotask( 21278 isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskTwo));
21286 Function::New(env->GetIsolate(), MicrotaskTwo));
21287 { 21279 {
21288 v8::Isolate::SuppressMicrotaskExecutionScope scope(env->GetIsolate()); 21280 v8::Isolate::SuppressMicrotaskExecutionScope scope(isolate);
21289 CompileRun("1+1;"); 21281 CompileRun("1+1;");
21290 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); 21282 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value());
21291 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value()); 21283 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value());
21292 } 21284 }
21293 21285
21294 CompileRun("1+1;"); 21286 CompileRun("1+1;");
21295 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); 21287 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value());
21296 CHECK_EQ(4, CompileRun("ext2Calls")->Int32Value()); 21288 CHECK_EQ(4, CompileRun("ext2Calls")->Int32Value());
21297 } 21289 }
21298 21290
(...skipping 10 matching lines...) Expand all
21309 } 21301 }
21310 isolate->RunMicrotasks(); 21302 isolate->RunMicrotasks();
21311 { 21303 {
21312 Context::Scope context_scope(context); 21304 Context::Scope context_scope(context);
21313 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value()); 21305 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value());
21314 } 21306 }
21315 isolate->SetAutorunMicrotasks(true); 21307 isolate->SetAutorunMicrotasks(true);
21316 } 21308 }
21317 21309
21318 21310
21311 bool g_the_only_microtask_called = false;
21312
21313
21314 static void TheOnlyMicrotask(void* data) {
21315 g_the_only_microtask_called = true;
21316 v8::Isolate* isolate = static_cast<v8::Isolate*>(data);
21317 CHECK(!isolate->HasPendingMicrotasks());
21318 }
21319
21320
21321 TEST(HasPendingMicrotasks) {
21322 LocalContext env;
21323 v8::Isolate* isolate = env->GetIsolate();
21324 v8::HandleScope scope(isolate);
21325
21326 g_the_only_microtask_called = false;
21327 CHECK(!isolate->HasPendingMicrotasks());
21328 isolate->EnqueueMicrotask(TheOnlyMicrotask, isolate);
21329 CHECK(isolate->HasPendingMicrotasks());
21330 CompileRun("1+1;");
21331 CHECK(g_the_only_microtask_called);
21332 CHECK(!isolate->HasPendingMicrotasks());
21333 }
21334
21335
21319 static void DebugEventInObserver(const v8::Debug::EventDetails& event_details) { 21336 static void DebugEventInObserver(const v8::Debug::EventDetails& event_details) {
21320 v8::DebugEvent event = event_details.GetEvent(); 21337 v8::DebugEvent event = event_details.GetEvent();
21321 if (event != v8::Break) return; 21338 if (event != v8::Break) return;
21322 Handle<Object> exec_state = event_details.GetExecutionState(); 21339 Handle<Object> exec_state = event_details.GetExecutionState();
21323 Handle<Value> break_id = exec_state->Get(v8_str("break_id")); 21340 Handle<Value> break_id = exec_state->Get(v8_str("break_id"));
21324 CompileRun("function f(id) { new FrameDetails(id, 0); }"); 21341 CompileRun("function f(id) { new FrameDetails(id, 0); }");
21325 Handle<Function> fun = Handle<Function>::Cast( 21342 Handle<Function> fun = Handle<Function>::Cast(
21326 CcTest::global()->Get(v8_str("f"))->ToObject()); 21343 CcTest::global()->Get(v8_str("f"))->ToObject());
21327 fun->Call(CcTest::global(), 1, &break_id); 21344 fun->Call(CcTest::global(), 1, &break_id);
21328 } 21345 }
(...skipping 2371 matching lines...) Expand 10 before | Expand all | Expand 10 after
23700 " var foobXXXXX"; // Too many bytes which look like incomplete chars! 23717 " var foobXXXXX"; // Too many bytes which look like incomplete chars!
23701 char chunk2[] = 23718 char chunk2[] =
23702 "r = 13;\n" 23719 "r = 13;\n"
23703 " return foob\xeb\x91\x80\x80\x80r;\n" 23720 " return foob\xeb\x91\x80\x80\x80r;\n"
23704 "}\n"; 23721 "}\n";
23705 for (int i = 0; i < 5; ++i) chunk1[strlen(chunk1) - 5 + i] = reference[i]; 23722 for (int i = 0; i < 5; ++i) chunk1[strlen(chunk1) - 5 + i] = reference[i];
23706 23723
23707 const char* chunks[] = {chunk1, chunk2, "foo();", NULL}; 23724 const char* chunks[] = {chunk1, chunk2, "foo();", NULL};
23708 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, false); 23725 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, false);
23709 } 23726 }
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