| 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 3738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3749 "try {\n" | 3749 "try {\n" |
| 3750 " throw 1;\n" | 3750 " throw 1;\n" |
| 3751 "} finally {\n" | 3751 "} finally {\n" |
| 3752 "}\n"); | 3752 "}\n"); |
| 3753 DebugEventCounterCheck(1, 1, 1); | 3753 DebugEventCounterCheck(1, 1, 1); |
| 3754 v8::Debug::SetDebugEventListener(isolate, nullptr); | 3754 v8::Debug::SetDebugEventListener(isolate, nullptr); |
| 3755 isolate->RemoveMessageListeners(try_finally_original_message); | 3755 isolate->RemoveMessageListeners(try_finally_original_message); |
| 3756 } | 3756 } |
| 3757 | 3757 |
| 3758 | 3758 |
| 3759 TEST(EvalJSInDebugEventListenerOnNativeReThrownException) { | |
| 3760 DebugLocalContext env; | |
| 3761 v8::HandleScope scope(env->GetIsolate()); | |
| 3762 env.ExposeDebug(); | |
| 3763 | |
| 3764 // Create functions for testing break on exception. | |
| 3765 v8::Local<v8::Function> noThrowJS = CompileFunction( | |
| 3766 &env, "function noThrowJS(){var a=[1]; a.push(2); return a.length;}", | |
| 3767 "noThrowJS"); | |
| 3768 | |
| 3769 debug_event_listener_callback = noThrowJS; | |
| 3770 debug_event_listener_callback_result = 2; | |
| 3771 | |
| 3772 env->GetIsolate()->AddMessageListener(MessageCallbackCount); | |
| 3773 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventCounter); | |
| 3774 // Break on uncaught exception | |
| 3775 ChangeBreakOnException(false, true); | |
| 3776 DebugEventCounterClear(); | |
| 3777 MessageCallbackCountClear(); | |
| 3778 | |
| 3779 // ReThrow native error | |
| 3780 { | |
| 3781 v8::TryCatch tryCatch(env->GetIsolate()); | |
| 3782 env->GetIsolate()->ThrowException( | |
| 3783 v8::Exception::TypeError(v8_str(env->GetIsolate(), "Type error"))); | |
| 3784 CHECK(tryCatch.HasCaught()); | |
| 3785 tryCatch.ReThrow(); | |
| 3786 } | |
| 3787 CHECK_EQ(1, exception_hit_count); | |
| 3788 CHECK_EQ(1, uncaught_exception_hit_count); | |
| 3789 CHECK_EQ(0, message_callback_count); // FIXME: Should it be 1 ? | |
| 3790 CHECK(!debug_event_listener_callback.IsEmpty()); | |
| 3791 | |
| 3792 debug_event_listener_callback.Clear(); | |
| 3793 } | |
| 3794 | |
| 3795 | |
| 3796 // Test break on exception from compiler errors. When compiling using | 3759 // Test break on exception from compiler errors. When compiling using |
| 3797 // v8::Script::Compile there is no JavaScript stack whereas when compiling using | 3760 // v8::Script::Compile there is no JavaScript stack whereas when compiling using |
| 3798 // eval there are JavaScript frames. | 3761 // eval there are JavaScript frames. |
| 3799 TEST(BreakOnCompileException) { | 3762 TEST(BreakOnCompileException) { |
| 3800 DebugLocalContext env; | 3763 DebugLocalContext env; |
| 3801 v8::HandleScope scope(env->GetIsolate()); | 3764 v8::HandleScope scope(env->GetIsolate()); |
| 3802 | 3765 |
| 3803 v8::Local<v8::Context> context = env.context(); | 3766 v8::Local<v8::Context> context = env.context(); |
| 3804 // For this test, we want to break on uncaught exceptions: | 3767 // For this test, we want to break on uncaught exceptions: |
| 3805 ChangeBreakOnException(false, true); | 3768 ChangeBreakOnException(false, true); |
| 3806 | 3769 |
| 3807 // Create a function for checking the function when hitting a break point. | 3770 // Create a function for checking the function when hitting a break point. |
| 3808 frame_count = CompileFunction(&env, frame_count_source, "frame_count"); | 3771 frame_count = CompileFunction(&env, frame_count_source, "frame_count"); |
| 3809 | 3772 |
| 3810 env->GetIsolate()->AddMessageListener(MessageCallbackCount); | 3773 env->GetIsolate()->AddMessageListener(MessageCallbackCount); |
| 3811 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventCounter); | 3774 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventCounter); |
| 3812 | 3775 |
| 3813 DebugEventCounterClear(); | 3776 DebugEventCounterClear(); |
| 3814 MessageCallbackCountClear(); | 3777 MessageCallbackCountClear(); |
| 3815 | 3778 |
| 3816 // Check initial state. | 3779 // Check initial state. |
| 3817 CHECK_EQ(0, exception_hit_count); | 3780 CHECK_EQ(0, exception_hit_count); |
| 3818 CHECK_EQ(0, uncaught_exception_hit_count); | 3781 CHECK_EQ(0, uncaught_exception_hit_count); |
| 3819 CHECK_EQ(0, message_callback_count); | 3782 CHECK_EQ(0, message_callback_count); |
| 3820 CHECK_EQ(-1, last_js_stack_height); | 3783 CHECK_EQ(-1, last_js_stack_height); |
| 3821 | 3784 |
| 3822 // Throws SyntaxError: Unexpected end of input | 3785 // Throws SyntaxError: Unexpected end of input |
| 3823 CHECK( | 3786 CHECK( |
| 3824 v8::Script::Compile(context, v8_str(env->GetIsolate(), "+++")).IsEmpty()); | 3787 v8::Script::Compile(context, v8_str(env->GetIsolate(), "+++")).IsEmpty()); |
| 3825 CHECK_EQ(1, exception_hit_count); | 3788 // Exceptions with no stack are skipped. |
| 3826 CHECK_EQ(1, uncaught_exception_hit_count); | 3789 CHECK_EQ(0, exception_hit_count); |
| 3790 CHECK_EQ(0, uncaught_exception_hit_count); |
| 3827 CHECK_EQ(1, message_callback_count); | 3791 CHECK_EQ(1, message_callback_count); |
| 3828 CHECK_EQ(0, last_js_stack_height); // No JavaScript stack. | 3792 CHECK_EQ(0, last_js_stack_height); // No JavaScript stack. |
| 3829 | 3793 |
| 3830 // Throws SyntaxError: Unexpected identifier | 3794 // Throws SyntaxError: Unexpected identifier |
| 3831 CHECK( | 3795 CHECK( |
| 3832 v8::Script::Compile(context, v8_str(env->GetIsolate(), "x x")).IsEmpty()); | 3796 v8::Script::Compile(context, v8_str(env->GetIsolate(), "x x")).IsEmpty()); |
| 3833 CHECK_EQ(2, exception_hit_count); | 3797 // Exceptions with no stack are skipped. |
| 3834 CHECK_EQ(2, uncaught_exception_hit_count); | 3798 CHECK_EQ(0, exception_hit_count); |
| 3799 CHECK_EQ(0, uncaught_exception_hit_count); |
| 3835 CHECK_EQ(2, message_callback_count); | 3800 CHECK_EQ(2, message_callback_count); |
| 3836 CHECK_EQ(0, last_js_stack_height); // No JavaScript stack. | 3801 CHECK_EQ(0, last_js_stack_height); // No JavaScript stack. |
| 3837 | 3802 |
| 3838 // Throws SyntaxError: Unexpected end of input | 3803 // Throws SyntaxError: Unexpected end of input |
| 3839 CHECK(v8::Script::Compile(context, v8_str(env->GetIsolate(), "eval('+++')")) | 3804 CHECK(v8::Script::Compile(context, v8_str(env->GetIsolate(), "eval('+++')")) |
| 3840 .ToLocalChecked() | 3805 .ToLocalChecked() |
| 3841 ->Run(context) | 3806 ->Run(context) |
| 3842 .IsEmpty()); | 3807 .IsEmpty()); |
| 3843 CHECK_EQ(3, exception_hit_count); | 3808 CHECK_EQ(1, exception_hit_count); |
| 3844 CHECK_EQ(3, uncaught_exception_hit_count); | 3809 CHECK_EQ(1, uncaught_exception_hit_count); |
| 3845 CHECK_EQ(3, message_callback_count); | 3810 CHECK_EQ(3, message_callback_count); |
| 3846 CHECK_EQ(1, last_js_stack_height); | 3811 CHECK_EQ(1, last_js_stack_height); |
| 3847 | 3812 |
| 3848 // Throws SyntaxError: Unexpected identifier | 3813 // Throws SyntaxError: Unexpected identifier |
| 3849 CHECK(v8::Script::Compile(context, v8_str(env->GetIsolate(), "eval('x x')")) | 3814 CHECK(v8::Script::Compile(context, v8_str(env->GetIsolate(), "eval('x x')")) |
| 3850 .ToLocalChecked() | 3815 .ToLocalChecked() |
| 3851 ->Run(context) | 3816 ->Run(context) |
| 3852 .IsEmpty()); | 3817 .IsEmpty()); |
| 3853 CHECK_EQ(4, exception_hit_count); | 3818 CHECK_EQ(2, exception_hit_count); |
| 3854 CHECK_EQ(4, uncaught_exception_hit_count); | 3819 CHECK_EQ(2, uncaught_exception_hit_count); |
| 3855 CHECK_EQ(4, message_callback_count); | 3820 CHECK_EQ(4, message_callback_count); |
| 3856 CHECK_EQ(1, last_js_stack_height); | 3821 CHECK_EQ(1, last_js_stack_height); |
| 3857 } | 3822 } |
| 3858 | 3823 |
| 3859 | 3824 |
| 3860 TEST(StepWithException) { | 3825 TEST(StepWithException) { |
| 3861 DebugLocalContext env; | 3826 DebugLocalContext env; |
| 3862 v8::HandleScope scope(env->GetIsolate()); | 3827 v8::HandleScope scope(env->GetIsolate()); |
| 3863 | 3828 |
| 3864 // For this test, we want to break on uncaught exceptions: | 3829 // For this test, we want to break on uncaught exceptions: |
| (...skipping 2787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6652 reinterpret_cast<void*>(isolate)); | 6617 reinterpret_cast<void*>(isolate)); |
| 6653 CHECK(!out_of_memory_callback_called); | 6618 CHECK(!out_of_memory_callback_called); |
| 6654 // The following allocation fails unless the out-of-memory callback | 6619 // The following allocation fails unless the out-of-memory callback |
| 6655 // increases the heap limit. | 6620 // increases the heap limit. |
| 6656 int length = 10 * i::MB / i::kPointerSize; | 6621 int length = 10 * i::MB / i::kPointerSize; |
| 6657 i_isolate->factory()->NewFixedArray(length, i::TENURED); | 6622 i_isolate->factory()->NewFixedArray(length, i::TENURED); |
| 6658 CHECK(out_of_memory_callback_called); | 6623 CHECK(out_of_memory_callback_called); |
| 6659 } | 6624 } |
| 6660 isolate->Dispose(); | 6625 isolate->Dispose(); |
| 6661 } | 6626 } |
| OLD | NEW |