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 4107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4118 v8::Number::New(isolate, 1), v8::Number::New(isolate, 1)}; | 4118 v8::Number::New(isolate, 1), v8::Number::New(isolate, 1)}; |
4119 | 4119 |
4120 // Call all functions to make sure that they are compiled. | 4120 // Call all functions to make sure that they are compiled. |
4121 f0->Call(context, env->Global(), 0, NULL).ToLocalChecked(); | 4121 f0->Call(context, env->Global(), 0, NULL).ToLocalChecked(); |
4122 f1->Call(context, env->Global(), 0, NULL).ToLocalChecked(); | 4122 f1->Call(context, env->Global(), 0, NULL).ToLocalChecked(); |
4123 f2->Call(context, env->Global(), 0, NULL).ToLocalChecked(); | 4123 f2->Call(context, env->Global(), 0, NULL).ToLocalChecked(); |
4124 f3->Call(context, env->Global(), 0, NULL).ToLocalChecked(); | 4124 f3->Call(context, env->Global(), 0, NULL).ToLocalChecked(); |
4125 | 4125 |
4126 // Set the debug break flag. | 4126 // Set the debug break flag. |
4127 v8::Debug::DebugBreak(env->GetIsolate()); | 4127 v8::Debug::DebugBreak(env->GetIsolate()); |
4128 CHECK(v8::Debug::CheckDebugBreak(env->GetIsolate())); | |
4129 | 4128 |
4130 // Call all functions with different argument count. | 4129 // Call all functions with different argument count. |
4131 break_point_hit_count = 0; | 4130 break_point_hit_count = 0; |
4132 for (unsigned int i = 0; i < arraysize(argv); i++) { | 4131 for (unsigned int i = 0; i < arraysize(argv); i++) { |
4133 f0->Call(context, env->Global(), i, argv).ToLocalChecked(); | 4132 f0->Call(context, env->Global(), i, argv).ToLocalChecked(); |
4134 f1->Call(context, env->Global(), i, argv).ToLocalChecked(); | 4133 f1->Call(context, env->Global(), i, argv).ToLocalChecked(); |
4135 f2->Call(context, env->Global(), i, argv).ToLocalChecked(); | 4134 f2->Call(context, env->Global(), i, argv).ToLocalChecked(); |
4136 f3->Call(context, env->Global(), i, argv).ToLocalChecked(); | 4135 f3->Call(context, env->Global(), i, argv).ToLocalChecked(); |
4137 } | 4136 } |
4138 | 4137 |
(...skipping 15 matching lines...) Expand all Loading... |
4154 // Register a debug event listener which sets the break flag and counts. | 4153 // Register a debug event listener which sets the break flag and counts. |
4155 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventCounter); | 4154 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventCounter); |
4156 | 4155 |
4157 v8::Local<v8::Context> context = env.context(); | 4156 v8::Local<v8::Context> context = env.context(); |
4158 // Create a function for testing stepping. | 4157 // Create a function for testing stepping. |
4159 const char* src = "function f() {g()};function g(){i=0; while(i<10){i++}}"; | 4158 const char* src = "function f() {g()};function g(){i=0; while(i<10){i++}}"; |
4160 v8::Local<v8::Function> f = CompileFunction(&env, src, "f"); | 4159 v8::Local<v8::Function> f = CompileFunction(&env, src, "f"); |
4161 | 4160 |
4162 // Set, test and cancel debug break. | 4161 // Set, test and cancel debug break. |
4163 v8::Debug::DebugBreak(env->GetIsolate()); | 4162 v8::Debug::DebugBreak(env->GetIsolate()); |
4164 CHECK(v8::Debug::CheckDebugBreak(env->GetIsolate())); | |
4165 v8::Debug::CancelDebugBreak(env->GetIsolate()); | 4163 v8::Debug::CancelDebugBreak(env->GetIsolate()); |
4166 CHECK(!v8::Debug::CheckDebugBreak(env->GetIsolate())); | |
4167 | 4164 |
4168 // Set the debug break flag. | 4165 // Set the debug break flag. |
4169 v8::Debug::DebugBreak(env->GetIsolate()); | 4166 v8::Debug::DebugBreak(env->GetIsolate()); |
4170 | 4167 |
4171 // Call all functions with different argument count. | 4168 // Call all functions with different argument count. |
4172 break_point_hit_count = 0; | 4169 break_point_hit_count = 0; |
4173 f->Call(context, env->Global(), 0, NULL).ToLocalChecked(); | 4170 f->Call(context, env->Global(), 0, NULL).ToLocalChecked(); |
4174 CHECK_EQ(1, break_point_hit_count); | 4171 CHECK_EQ(1, break_point_hit_count); |
4175 | 4172 |
4176 { | 4173 { |
(...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5255 // Enter and run function in the second context. | 5252 // Enter and run function in the second context. |
5256 { | 5253 { |
5257 v8::Context::Scope context_scope(context_2); | 5254 v8::Context::Scope context_scope(context_2); |
5258 expected_context = context_2; | 5255 expected_context = context_2; |
5259 expected_context_data = data_2; | 5256 expected_context_data = data_2; |
5260 v8::Local<v8::Function> f = CompileFunction(isolate, source, "f"); | 5257 v8::Local<v8::Function> f = CompileFunction(isolate, source, "f"); |
5261 f->Call(context_2, context_2->Global(), 0, NULL).ToLocalChecked(); | 5258 f->Call(context_2, context_2->Global(), 0, NULL).ToLocalChecked(); |
5262 } | 5259 } |
5263 | 5260 |
5264 // Two times compile event and two times break event. | 5261 // Two times compile event and two times break event. |
5265 CHECK_GT(event_listener_hit_count, 4); | 5262 CHECK_GT(event_listener_hit_count, 3); |
5266 | 5263 |
5267 v8::Debug::SetDebugEventListener(isolate, nullptr); | 5264 v8::Debug::SetDebugEventListener(isolate, nullptr); |
5268 CheckDebuggerUnloaded(isolate); | 5265 CheckDebuggerUnloaded(isolate); |
5269 } | 5266 } |
5270 | 5267 |
5271 // Debug event listener which issues a debug break when it hits a break event. | 5268 // Debug event listener which issues a debug break when it hits a break event. |
5272 static int event_listener_break_hit_count = 0; | 5269 static int event_listener_break_hit_count = 0; |
5273 static void DebugBreakEventListener(const v8::Debug::EventDetails& details) { | 5270 static void DebugBreakEventListener(const v8::Debug::EventDetails& details) { |
5274 // Schedule a debug break for break events. | 5271 // Schedule a debug break for break events. |
5275 if (details.GetEvent() == v8::Break) { | 5272 if (details.GetEvent() == v8::Break) { |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5677 v8::Debug::DebugBreak(env->GetIsolate()); | 5674 v8::Debug::DebugBreak(env->GetIsolate()); |
5678 f->Call(context, env->Global(), 0, NULL).ToLocalChecked(); | 5675 f->Call(context, env->Global(), 0, NULL).ToLocalChecked(); |
5679 // There should be one more break event when the script is evaluated in 'f'. | 5676 // There should be one more break event when the script is evaluated in 'f'. |
5680 CHECK_EQ(2, break_point_hit_count); | 5677 CHECK_EQ(2, break_point_hit_count); |
5681 | 5678 |
5682 // Get rid of the debug event listener. | 5679 // Get rid of the debug event listener. |
5683 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr); | 5680 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr); |
5684 CheckDebuggerUnloaded(env->GetIsolate()); | 5681 CheckDebuggerUnloaded(env->GetIsolate()); |
5685 } | 5682 } |
5686 | 5683 |
5687 TEST(GetMirror) { | |
5688 DebugLocalContext env; | |
5689 v8::Isolate* isolate = env->GetIsolate(); | |
5690 v8::HandleScope scope(isolate); | |
5691 v8::Local<v8::Context> context = env.context(); | |
5692 v8::Local<v8::Value> obj = | |
5693 v8::Debug::GetMirror(context, v8_str(isolate, "hodja")).ToLocalChecked(); | |
5694 v8::ScriptCompiler::Source source( | |
5695 v8_str("function runTest(mirror) {" | |
5696 " return mirror.isString() && (mirror.length() == 5);" | |
5697 "}" | |
5698 "" | |
5699 "runTest;")); | |
5700 v8::Local<v8::Function> run_test = v8::Local<v8::Function>::Cast( | |
5701 v8::ScriptCompiler::CompileUnboundScript(isolate, &source) | |
5702 .ToLocalChecked() | |
5703 ->BindToCurrentContext() | |
5704 ->Run(context) | |
5705 .ToLocalChecked()); | |
5706 v8::Local<v8::Value> result = | |
5707 run_test->Call(context, env->Global(), 1, &obj).ToLocalChecked(); | |
5708 CHECK(result->IsTrue()); | |
5709 } | |
5710 | 5684 |
5711 // Test that the debug break flag works with function.apply. | 5685 // Test that the debug break flag works with function.apply. |
5712 TEST(DebugBreakFunctionApply) { | 5686 TEST(DebugBreakFunctionApply) { |
5713 DebugLocalContext env; | 5687 DebugLocalContext env; |
5714 v8::HandleScope scope(env->GetIsolate()); | 5688 v8::HandleScope scope(env->GetIsolate()); |
5715 v8::Local<v8::Context> context = env.context(); | 5689 v8::Local<v8::Context> context = env.context(); |
5716 | 5690 |
5717 // Create a function for testing breaking in apply. | 5691 // Create a function for testing breaking in apply. |
5718 v8::Local<v8::Function> foo = CompileFunction( | 5692 v8::Local<v8::Function> foo = CompileFunction( |
5719 &env, | 5693 &env, |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5839 } | 5813 } |
5840 | 5814 |
5841 | 5815 |
5842 TEST(NoDebugContextWhenDebuggerDisabled) { | 5816 TEST(NoDebugContextWhenDebuggerDisabled) { |
5843 v8::HandleScope scope(CcTest::isolate()); | 5817 v8::HandleScope scope(CcTest::isolate()); |
5844 v8::Local<v8::Context> context = | 5818 v8::Local<v8::Context> context = |
5845 v8::Debug::GetDebugContext(CcTest::isolate()); | 5819 v8::Debug::GetDebugContext(CcTest::isolate()); |
5846 CHECK(context.IsEmpty()); | 5820 CHECK(context.IsEmpty()); |
5847 } | 5821 } |
5848 | 5822 |
5849 static void DebugEventCheckContext( | |
5850 const v8::Debug::EventDetails& event_details) { | |
5851 if (event_details.GetEvent() == v8::Break) { | |
5852 v8::Isolate* isolate = event_details.GetIsolate(); | |
5853 CHECK(v8::Debug::GetDebuggedContext(isolate) | |
5854 .ToLocalChecked() | |
5855 ->Global() | |
5856 ->Equals(isolate->GetCurrentContext(), | |
5857 event_details.GetEventContext()->Global()) | |
5858 .FromJust()); | |
5859 } | |
5860 } | |
5861 | |
5862 static void CheckContext(const v8::FunctionCallbackInfo<v8::Value>& args) { | |
5863 CHECK(v8::Debug::GetDebuggedContext(args.GetIsolate()).IsEmpty()); | |
5864 } | |
5865 | |
5866 TEST(DebuggedContext) { | |
5867 DebugLocalContext env; | |
5868 v8::Isolate* isolate = env->GetIsolate(); | |
5869 | |
5870 v8::Debug::SetDebugEventListener(isolate, DebugEventCheckContext); | |
5871 | |
5872 v8::Local<v8::Function> foo = | |
5873 CompileFunction(&env, "function foo(){bar=0;}", "foo"); | |
5874 | |
5875 SetBreakPoint(foo, 0); | |
5876 foo->Call(env.context(), env->Global(), 0, nullptr).ToLocalChecked(); | |
5877 | |
5878 v8::Local<v8::Function> fun = v8::FunctionTemplate::New(isolate, CheckContext) | |
5879 ->GetFunction(env.context()) | |
5880 .ToLocalChecked(); | |
5881 fun->Call(env.context(), env->Global(), 0, nullptr).ToLocalChecked(); | |
5882 } | |
5883 | |
5884 static v8::Local<v8::Value> expected_callback_data; | 5823 static v8::Local<v8::Value> expected_callback_data; |
5885 static void DebugEventContextChecker(const v8::Debug::EventDetails& details) { | 5824 static void DebugEventContextChecker(const v8::Debug::EventDetails& details) { |
5886 CHECK(details.GetEventContext() == expected_context); | 5825 CHECK(details.GetEventContext() == expected_context); |
5887 CHECK(expected_callback_data->Equals(details.GetEventContext(), | 5826 CHECK(expected_callback_data->Equals(details.GetEventContext(), |
5888 details.GetCallbackData()) | 5827 details.GetCallbackData()) |
5889 .FromJust()); | 5828 .FromJust()); |
5890 } | 5829 } |
5891 | 5830 |
5892 | 5831 |
5893 // Check that event details contain context where debug event occured. | 5832 // Check that event details contain context where debug event occured. |
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6855 "function foo() {\n" | 6794 "function foo() {\n" |
6856 " try { throw new Error(); } catch (e) {}\n" | 6795 " try { throw new Error(); } catch (e) {}\n" |
6857 "}\n" | 6796 "}\n" |
6858 "debugger;\n" | 6797 "debugger;\n" |
6859 "foo();\n" | 6798 "foo();\n" |
6860 "foo();\n"); | 6799 "foo();\n"); |
6861 | 6800 |
6862 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr); | 6801 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr); |
6863 CHECK_EQ(break_point_hit_count, 4); | 6802 CHECK_EQ(break_point_hit_count, 4); |
6864 } | 6803 } |
OLD | NEW |