| OLD | NEW |
| 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 20699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20710 TEST(EnqueueMicrotask) { | 20710 TEST(EnqueueMicrotask) { |
| 20711 LocalContext env; | 20711 LocalContext env; |
| 20712 v8::HandleScope scope(env->GetIsolate()); | 20712 v8::HandleScope scope(env->GetIsolate()); |
| 20713 CompileRun( | 20713 CompileRun( |
| 20714 "var ext1Calls = 0;" | 20714 "var ext1Calls = 0;" |
| 20715 "var ext2Calls = 0;"); | 20715 "var ext2Calls = 0;"); |
| 20716 CompileRun("1+1;"); | 20716 CompileRun("1+1;"); |
| 20717 CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value()); | 20717 CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value()); |
| 20718 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); | 20718 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); |
| 20719 | 20719 |
| 20720 v8::V8::EnqueueMicrotask(env->GetIsolate(), | 20720 env->GetIsolate()->EnqueueMicrotask( |
| 20721 Function::New(env->GetIsolate(), MicrotaskOne)); | 20721 Function::New(env->GetIsolate(), MicrotaskOne)); |
| 20722 CompileRun("1+1;"); | 20722 CompileRun("1+1;"); |
| 20723 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value()); | 20723 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value()); |
| 20724 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); | 20724 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); |
| 20725 | 20725 |
| 20726 v8::V8::EnqueueMicrotask(env->GetIsolate(), | 20726 env->GetIsolate()->EnqueueMicrotask( |
| 20727 Function::New(env->GetIsolate(), MicrotaskOne)); | 20727 Function::New(env->GetIsolate(), MicrotaskOne)); |
| 20728 v8::V8::EnqueueMicrotask(env->GetIsolate(), | 20728 env->GetIsolate()->EnqueueMicrotask( |
| 20729 Function::New(env->GetIsolate(), MicrotaskTwo)); | 20729 Function::New(env->GetIsolate(), MicrotaskTwo)); |
| 20730 CompileRun("1+1;"); | 20730 CompileRun("1+1;"); |
| 20731 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); | 20731 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); |
| 20732 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value()); | 20732 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value()); |
| 20733 | 20733 |
| 20734 v8::V8::EnqueueMicrotask(env->GetIsolate(), | 20734 env->GetIsolate()->EnqueueMicrotask( |
| 20735 Function::New(env->GetIsolate(), MicrotaskTwo)); | 20735 Function::New(env->GetIsolate(), MicrotaskTwo)); |
| 20736 CompileRun("1+1;"); | 20736 CompileRun("1+1;"); |
| 20737 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); | 20737 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); |
| 20738 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value()); | 20738 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value()); |
| 20739 | 20739 |
| 20740 CompileRun("1+1;"); | 20740 CompileRun("1+1;"); |
| 20741 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); | 20741 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); |
| 20742 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value()); | 20742 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value()); |
| 20743 } | 20743 } |
| 20744 | 20744 |
| 20745 | 20745 |
| 20746 TEST(SetAutorunMicrotasks) { | 20746 TEST(SetAutorunMicrotasks) { |
| 20747 LocalContext env; | 20747 LocalContext env; |
| 20748 v8::HandleScope scope(env->GetIsolate()); | 20748 v8::HandleScope scope(env->GetIsolate()); |
| 20749 CompileRun( | 20749 CompileRun( |
| 20750 "var ext1Calls = 0;" | 20750 "var ext1Calls = 0;" |
| 20751 "var ext2Calls = 0;"); | 20751 "var ext2Calls = 0;"); |
| 20752 CompileRun("1+1;"); | 20752 CompileRun("1+1;"); |
| 20753 CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value()); | 20753 CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value()); |
| 20754 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); | 20754 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); |
| 20755 | 20755 |
| 20756 v8::V8::EnqueueMicrotask(env->GetIsolate(), | 20756 env->GetIsolate()->EnqueueMicrotask( |
| 20757 Function::New(env->GetIsolate(), MicrotaskOne)); | 20757 Function::New(env->GetIsolate(), MicrotaskOne)); |
| 20758 CompileRun("1+1;"); | 20758 CompileRun("1+1;"); |
| 20759 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value()); | 20759 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value()); |
| 20760 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); | 20760 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); |
| 20761 | 20761 |
| 20762 V8::SetAutorunMicrotasks(env->GetIsolate(), false); | 20762 env->GetIsolate()->SetAutorunMicrotasks(false); |
| 20763 v8::V8::EnqueueMicrotask(env->GetIsolate(), | 20763 env->GetIsolate()->EnqueueMicrotask( |
| 20764 Function::New(env->GetIsolate(), MicrotaskOne)); | 20764 Function::New(env->GetIsolate(), MicrotaskOne)); |
| 20765 v8::V8::EnqueueMicrotask(env->GetIsolate(), | 20765 env->GetIsolate()->EnqueueMicrotask( |
| 20766 Function::New(env->GetIsolate(), MicrotaskTwo)); | 20766 Function::New(env->GetIsolate(), MicrotaskTwo)); |
| 20767 CompileRun("1+1;"); | 20767 CompileRun("1+1;"); |
| 20768 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value()); | 20768 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value()); |
| 20769 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); | 20769 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); |
| 20770 | 20770 |
| 20771 V8::RunMicrotasks(env->GetIsolate()); | 20771 env->GetIsolate()->RunMicrotasks(); |
| 20772 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); | 20772 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); |
| 20773 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value()); | 20773 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value()); |
| 20774 | 20774 |
| 20775 v8::V8::EnqueueMicrotask(env->GetIsolate(), | 20775 env->GetIsolate()->EnqueueMicrotask( |
| 20776 Function::New(env->GetIsolate(), MicrotaskTwo)); | 20776 Function::New(env->GetIsolate(), MicrotaskTwo)); |
| 20777 CompileRun("1+1;"); | 20777 CompileRun("1+1;"); |
| 20778 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); | 20778 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); |
| 20779 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value()); | 20779 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value()); |
| 20780 | 20780 |
| 20781 V8::RunMicrotasks(env->GetIsolate()); | 20781 env->GetIsolate()->RunMicrotasks(); |
| 20782 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); | 20782 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); |
| 20783 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value()); | 20783 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value()); |
| 20784 | 20784 |
| 20785 V8::SetAutorunMicrotasks(env->GetIsolate(), true); | 20785 env->GetIsolate()->SetAutorunMicrotasks(true); |
| 20786 v8::V8::EnqueueMicrotask(env->GetIsolate(), | 20786 env->GetIsolate()->EnqueueMicrotask( |
| 20787 Function::New(env->GetIsolate(), MicrotaskTwo)); | 20787 Function::New(env->GetIsolate(), MicrotaskTwo)); |
| 20788 CompileRun("1+1;"); | 20788 CompileRun("1+1;"); |
| 20789 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); | 20789 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); |
| 20790 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value()); | 20790 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value()); |
| 20791 |
| 20792 env->GetIsolate()->EnqueueMicrotask( |
| 20793 Function::New(env->GetIsolate(), MicrotaskTwo)); |
| 20794 { |
| 20795 v8::Isolate::SuppressMicrotaskExecutionScope scope(env->GetIsolate()); |
| 20796 CompileRun("1+1;"); |
| 20797 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); |
| 20798 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value()); |
| 20799 } |
| 20800 |
| 20801 CompileRun("1+1;"); |
| 20802 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); |
| 20803 CHECK_EQ(4, CompileRun("ext2Calls")->Int32Value()); |
| 20791 } | 20804 } |
| 20792 | 20805 |
| 20793 | 20806 |
| 20794 static int probes_counter = 0; | 20807 static int probes_counter = 0; |
| 20795 static int misses_counter = 0; | 20808 static int misses_counter = 0; |
| 20796 static int updates_counter = 0; | 20809 static int updates_counter = 0; |
| 20797 | 20810 |
| 20798 | 20811 |
| 20799 static int* LookupCounter(const char* name) { | 20812 static int* LookupCounter(const char* name) { |
| 20800 if (strcmp(name, "c:V8.MegamorphicStubCacheProbes") == 0) { | 20813 if (strcmp(name, "c:V8.MegamorphicStubCacheProbes") == 0) { |
| (...skipping 1534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 22335 CompileRun( | 22348 CompileRun( |
| 22336 "var x1 = 0;\n" | 22349 "var x1 = 0;\n" |
| 22337 "var x2 = 0;\n" | 22350 "var x2 = 0;\n" |
| 22338 "function f1(x) { x1 = x; return x+1 };\n" | 22351 "function f1(x) { x1 = x; return x+1 };\n" |
| 22339 "function f2(x) { x2 = x; return x+1 };\n"); | 22352 "function f2(x) { x2 = x; return x+1 };\n"); |
| 22340 Handle<Function> f1 = Handle<Function>::Cast(global->Get(v8_str("f1"))); | 22353 Handle<Function> f1 = Handle<Function>::Cast(global->Get(v8_str("f1"))); |
| 22341 Handle<Function> f2 = Handle<Function>::Cast(global->Get(v8_str("f2"))); | 22354 Handle<Function> f2 = Handle<Function>::Cast(global->Get(v8_str("f2"))); |
| 22342 | 22355 |
| 22343 p->Chain(f1); | 22356 p->Chain(f1); |
| 22344 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); | 22357 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); |
| 22345 V8::RunMicrotasks(isolate); | 22358 isolate->RunMicrotasks(); |
| 22346 CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value()); | 22359 CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value()); |
| 22347 | 22360 |
| 22348 p->Catch(f2); | 22361 p->Catch(f2); |
| 22349 V8::RunMicrotasks(isolate); | 22362 isolate->RunMicrotasks(); |
| 22350 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); | 22363 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); |
| 22351 | 22364 |
| 22352 r->Catch(f2); | 22365 r->Catch(f2); |
| 22353 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); | 22366 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); |
| 22354 V8::RunMicrotasks(isolate); | 22367 isolate->RunMicrotasks(); |
| 22355 CHECK_EQ(2, global->Get(v8_str("x2"))->Int32Value()); | 22368 CHECK_EQ(2, global->Get(v8_str("x2"))->Int32Value()); |
| 22356 | 22369 |
| 22357 r->Chain(f1); | 22370 r->Chain(f1); |
| 22358 V8::RunMicrotasks(isolate); | 22371 isolate->RunMicrotasks(); |
| 22359 CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value()); | 22372 CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value()); |
| 22360 | 22373 |
| 22361 // Chaining pending promises. | 22374 // Chaining pending promises. |
| 22362 CompileRun("x1 = x2 = 0;"); | 22375 CompileRun("x1 = x2 = 0;"); |
| 22363 pr = v8::Promise::Resolver::New(isolate); | 22376 pr = v8::Promise::Resolver::New(isolate); |
| 22364 rr = v8::Promise::Resolver::New(isolate); | 22377 rr = v8::Promise::Resolver::New(isolate); |
| 22365 | 22378 |
| 22366 pr->GetPromise()->Chain(f1); | 22379 pr->GetPromise()->Chain(f1); |
| 22367 rr->GetPromise()->Catch(f2); | 22380 rr->GetPromise()->Catch(f2); |
| 22368 V8::RunMicrotasks(isolate); | 22381 isolate->RunMicrotasks(); |
| 22369 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); | 22382 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); |
| 22370 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); | 22383 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); |
| 22371 | 22384 |
| 22372 pr->Resolve(v8::Integer::New(isolate, 1)); | 22385 pr->Resolve(v8::Integer::New(isolate, 1)); |
| 22373 rr->Reject(v8::Integer::New(isolate, 2)); | 22386 rr->Reject(v8::Integer::New(isolate, 2)); |
| 22374 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); | 22387 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); |
| 22375 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); | 22388 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); |
| 22376 | 22389 |
| 22377 V8::RunMicrotasks(isolate); | 22390 isolate->RunMicrotasks(); |
| 22378 CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value()); | 22391 CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value()); |
| 22379 CHECK_EQ(2, global->Get(v8_str("x2"))->Int32Value()); | 22392 CHECK_EQ(2, global->Get(v8_str("x2"))->Int32Value()); |
| 22380 | 22393 |
| 22381 // Multi-chaining. | 22394 // Multi-chaining. |
| 22382 CompileRun("x1 = x2 = 0;"); | 22395 CompileRun("x1 = x2 = 0;"); |
| 22383 pr = v8::Promise::Resolver::New(isolate); | 22396 pr = v8::Promise::Resolver::New(isolate); |
| 22384 pr->GetPromise()->Chain(f1)->Chain(f2); | 22397 pr->GetPromise()->Chain(f1)->Chain(f2); |
| 22385 pr->Resolve(v8::Integer::New(isolate, 3)); | 22398 pr->Resolve(v8::Integer::New(isolate, 3)); |
| 22386 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); | 22399 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); |
| 22387 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); | 22400 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); |
| 22388 V8::RunMicrotasks(isolate); | 22401 isolate->RunMicrotasks(); |
| 22389 CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value()); | 22402 CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value()); |
| 22390 CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value()); | 22403 CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value()); |
| 22391 | 22404 |
| 22392 CompileRun("x1 = x2 = 0;"); | 22405 CompileRun("x1 = x2 = 0;"); |
| 22393 rr = v8::Promise::Resolver::New(isolate); | 22406 rr = v8::Promise::Resolver::New(isolate); |
| 22394 rr->GetPromise()->Catch(f1)->Chain(f2); | 22407 rr->GetPromise()->Catch(f1)->Chain(f2); |
| 22395 rr->Reject(v8::Integer::New(isolate, 3)); | 22408 rr->Reject(v8::Integer::New(isolate, 3)); |
| 22396 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); | 22409 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); |
| 22397 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); | 22410 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); |
| 22398 V8::RunMicrotasks(isolate); | 22411 isolate->RunMicrotasks(); |
| 22399 CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value()); | 22412 CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value()); |
| 22400 CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value()); | 22413 CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value()); |
| 22401 } | 22414 } |
| 22402 | 22415 |
| 22403 | 22416 |
| 22404 TEST(DisallowJavascriptExecutionScope) { | 22417 TEST(DisallowJavascriptExecutionScope) { |
| 22405 LocalContext context; | 22418 LocalContext context; |
| 22406 v8::Isolate* isolate = context->GetIsolate(); | 22419 v8::Isolate* isolate = context->GetIsolate(); |
| 22407 v8::HandleScope scope(isolate); | 22420 v8::HandleScope scope(isolate); |
| 22408 v8::Isolate::DisallowJavascriptExecutionScope no_js( | 22421 v8::Isolate::DisallowJavascriptExecutionScope no_js( |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 22486 v8::internal::FLAG_stack_size = 150; | 22499 v8::internal::FLAG_stack_size = 150; |
| 22487 LocalContext current; | 22500 LocalContext current; |
| 22488 v8::Isolate* isolate = current->GetIsolate(); | 22501 v8::Isolate* isolate = current->GetIsolate(); |
| 22489 v8::HandleScope scope(isolate); | 22502 v8::HandleScope scope(isolate); |
| 22490 V8::SetCaptureStackTraceForUncaughtExceptions( | 22503 V8::SetCaptureStackTraceForUncaughtExceptions( |
| 22491 true, 10, v8::StackTrace::kDetailed); | 22504 true, 10, v8::StackTrace::kDetailed); |
| 22492 v8::TryCatch try_catch; | 22505 v8::TryCatch try_catch; |
| 22493 CompileRun("(function f(x) { f(x+1); })(0)"); | 22506 CompileRun("(function f(x) { f(x+1); })(0)"); |
| 22494 CHECK(try_catch.HasCaught()); | 22507 CHECK(try_catch.HasCaught()); |
| 22495 } | 22508 } |
| OLD | NEW |