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 20630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20641 | 20641 |
20642 | 20642 |
20643 TEST(CallCompletedCallback) { | 20643 TEST(CallCompletedCallback) { |
20644 LocalContext env; | 20644 LocalContext env; |
20645 v8::HandleScope scope(env->GetIsolate()); | 20645 v8::HandleScope scope(env->GetIsolate()); |
20646 v8::Handle<v8::FunctionTemplate> recursive_runtime = | 20646 v8::Handle<v8::FunctionTemplate> recursive_runtime = |
20647 v8::FunctionTemplate::New(env->GetIsolate(), RecursiveCall); | 20647 v8::FunctionTemplate::New(env->GetIsolate(), RecursiveCall); |
20648 env->Global()->Set(v8_str("recursion"), | 20648 env->Global()->Set(v8_str("recursion"), |
20649 recursive_runtime->GetFunction()); | 20649 recursive_runtime->GetFunction()); |
20650 // Adding the same callback a second time has no effect. | 20650 // Adding the same callback a second time has no effect. |
20651 v8::V8::AddCallCompletedCallback(CallCompletedCallback1); | 20651 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback1); |
20652 v8::V8::AddCallCompletedCallback(CallCompletedCallback1); | 20652 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback1); |
20653 v8::V8::AddCallCompletedCallback(CallCompletedCallback2); | 20653 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback2); |
20654 i::OS::Print("--- Script (1) ---\n"); | 20654 i::OS::Print("--- Script (1) ---\n"); |
20655 Local<Script> script = v8::Script::Compile( | 20655 Local<Script> script = v8::Script::Compile( |
20656 v8::String::NewFromUtf8(env->GetIsolate(), "recursion(0)")); | 20656 v8::String::NewFromUtf8(env->GetIsolate(), "recursion(0)")); |
20657 script->Run(); | 20657 script->Run(); |
20658 CHECK_EQ(3, callback_fired); | 20658 CHECK_EQ(3, callback_fired); |
20659 | 20659 |
20660 i::OS::Print("\n--- Script (2) ---\n"); | 20660 i::OS::Print("\n--- Script (2) ---\n"); |
20661 callback_fired = 0; | 20661 callback_fired = 0; |
20662 v8::V8::RemoveCallCompletedCallback(CallCompletedCallback1); | 20662 env->GetIsolate()->RemoveCallCompletedCallback(CallCompletedCallback1); |
20663 script->Run(); | 20663 script->Run(); |
20664 CHECK_EQ(2, callback_fired); | 20664 CHECK_EQ(2, callback_fired); |
20665 | 20665 |
20666 i::OS::Print("\n--- Function ---\n"); | 20666 i::OS::Print("\n--- Function ---\n"); |
20667 callback_fired = 0; | 20667 callback_fired = 0; |
20668 Local<Function> recursive_function = | 20668 Local<Function> recursive_function = |
20669 Local<Function>::Cast(env->Global()->Get(v8_str("recursion"))); | 20669 Local<Function>::Cast(env->Global()->Get(v8_str("recursion"))); |
20670 v8::Handle<Value> args[] = { v8_num(0) }; | 20670 v8::Handle<Value> args[] = { v8_num(0) }; |
20671 recursive_function->Call(env->Global(), 1, args); | 20671 recursive_function->Call(env->Global(), 1, args); |
20672 CHECK_EQ(2, callback_fired); | 20672 CHECK_EQ(2, callback_fired); |
20673 } | 20673 } |
20674 | 20674 |
20675 | 20675 |
20676 void CallCompletedCallbackNoException() { | 20676 void CallCompletedCallbackNoException() { |
20677 v8::HandleScope scope(CcTest::isolate()); | 20677 v8::HandleScope scope(CcTest::isolate()); |
20678 CompileRun("1+1;"); | 20678 CompileRun("1+1;"); |
20679 } | 20679 } |
20680 | 20680 |
20681 | 20681 |
20682 void CallCompletedCallbackException() { | 20682 void CallCompletedCallbackException() { |
20683 v8::HandleScope scope(CcTest::isolate()); | 20683 v8::HandleScope scope(CcTest::isolate()); |
20684 CompileRun("throw 'second exception';"); | 20684 CompileRun("throw 'second exception';"); |
20685 } | 20685 } |
20686 | 20686 |
20687 | 20687 |
20688 TEST(CallCompletedCallbackOneException) { | 20688 TEST(CallCompletedCallbackOneException) { |
20689 LocalContext env; | 20689 LocalContext env; |
20690 v8::HandleScope scope(env->GetIsolate()); | 20690 v8::HandleScope scope(env->GetIsolate()); |
20691 v8::V8::AddCallCompletedCallback(CallCompletedCallbackNoException); | 20691 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallbackNoException); |
20692 CompileRun("throw 'exception';"); | 20692 CompileRun("throw 'exception';"); |
20693 } | 20693 } |
20694 | 20694 |
20695 | 20695 |
20696 TEST(CallCompletedCallbackTwoExceptions) { | 20696 TEST(CallCompletedCallbackTwoExceptions) { |
20697 LocalContext env; | 20697 LocalContext env; |
20698 v8::HandleScope scope(env->GetIsolate()); | 20698 v8::HandleScope scope(env->GetIsolate()); |
20699 v8::V8::AddCallCompletedCallback(CallCompletedCallbackException); | 20699 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallbackException); |
20700 CompileRun("throw 'first exception';"); | 20700 CompileRun("throw 'first exception';"); |
20701 } | 20701 } |
20702 | 20702 |
20703 | 20703 |
20704 static void MicrotaskOne(const v8::FunctionCallbackInfo<Value>& info) { | 20704 static void MicrotaskOne(const v8::FunctionCallbackInfo<Value>& info) { |
20705 v8::HandleScope scope(info.GetIsolate()); | 20705 v8::HandleScope scope(info.GetIsolate()); |
20706 CompileRun("ext1Calls++;"); | 20706 CompileRun("ext1Calls++;"); |
20707 } | 20707 } |
20708 | 20708 |
20709 | 20709 |
(...skipping 1782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22492 v8::internal::FLAG_stack_size = 150; | 22492 v8::internal::FLAG_stack_size = 150; |
22493 LocalContext current; | 22493 LocalContext current; |
22494 v8::Isolate* isolate = current->GetIsolate(); | 22494 v8::Isolate* isolate = current->GetIsolate(); |
22495 v8::HandleScope scope(isolate); | 22495 v8::HandleScope scope(isolate); |
22496 V8::SetCaptureStackTraceForUncaughtExceptions( | 22496 V8::SetCaptureStackTraceForUncaughtExceptions( |
22497 true, 10, v8::StackTrace::kDetailed); | 22497 true, 10, v8::StackTrace::kDetailed); |
22498 v8::TryCatch try_catch; | 22498 v8::TryCatch try_catch; |
22499 CompileRun("(function f(x) { f(x+1); })(0)"); | 22499 CompileRun("(function f(x) { f(x+1); })(0)"); |
22500 CHECK(try_catch.HasCaught()); | 22500 CHECK(try_catch.HasCaught()); |
22501 } | 22501 } |
OLD | NEW |