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())); | |
4128 | 4129 |
Yang
2016/12/01 09:04:33
Let's not restore tests.
| |
4129 // Call all functions with different argument count. | 4130 // Call all functions with different argument count. |
4130 break_point_hit_count = 0; | 4131 break_point_hit_count = 0; |
4131 for (unsigned int i = 0; i < arraysize(argv); i++) { | 4132 for (unsigned int i = 0; i < arraysize(argv); i++) { |
4132 f0->Call(context, env->Global(), i, argv).ToLocalChecked(); | 4133 f0->Call(context, env->Global(), i, argv).ToLocalChecked(); |
4133 f1->Call(context, env->Global(), i, argv).ToLocalChecked(); | 4134 f1->Call(context, env->Global(), i, argv).ToLocalChecked(); |
4134 f2->Call(context, env->Global(), i, argv).ToLocalChecked(); | 4135 f2->Call(context, env->Global(), i, argv).ToLocalChecked(); |
4135 f3->Call(context, env->Global(), i, argv).ToLocalChecked(); | 4136 f3->Call(context, env->Global(), i, argv).ToLocalChecked(); |
4136 } | 4137 } |
4137 | 4138 |
4138 // One break for each function called. | 4139 // One break for each function called. |
(...skipping 14 matching lines...) Expand all Loading... | |
4153 // Register a debug event listener which sets the break flag and counts. | 4154 // Register a debug event listener which sets the break flag and counts. |
4154 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventCounter); | 4155 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventCounter); |
4155 | 4156 |
4156 v8::Local<v8::Context> context = env.context(); | 4157 v8::Local<v8::Context> context = env.context(); |
4157 // Create a function for testing stepping. | 4158 // Create a function for testing stepping. |
4158 const char* src = "function f() {g()};function g(){i=0; while(i<10){i++}}"; | 4159 const char* src = "function f() {g()};function g(){i=0; while(i<10){i++}}"; |
4159 v8::Local<v8::Function> f = CompileFunction(&env, src, "f"); | 4160 v8::Local<v8::Function> f = CompileFunction(&env, src, "f"); |
4160 | 4161 |
4161 // Set, test and cancel debug break. | 4162 // Set, test and cancel debug break. |
4162 v8::Debug::DebugBreak(env->GetIsolate()); | 4163 v8::Debug::DebugBreak(env->GetIsolate()); |
4164 CHECK(v8::Debug::CheckDebugBreak(env->GetIsolate())); | |
4163 v8::Debug::CancelDebugBreak(env->GetIsolate()); | 4165 v8::Debug::CancelDebugBreak(env->GetIsolate()); |
4166 CHECK(!v8::Debug::CheckDebugBreak(env->GetIsolate())); | |
4164 | 4167 |
4165 // Set the debug break flag. | 4168 // Set the debug break flag. |
4166 v8::Debug::DebugBreak(env->GetIsolate()); | 4169 v8::Debug::DebugBreak(env->GetIsolate()); |
4167 | 4170 |
4168 // Call all functions with different argument count. | 4171 // Call all functions with different argument count. |
4169 break_point_hit_count = 0; | 4172 break_point_hit_count = 0; |
4170 f->Call(context, env->Global(), 0, NULL).ToLocalChecked(); | 4173 f->Call(context, env->Global(), 0, NULL).ToLocalChecked(); |
4171 CHECK_EQ(1, break_point_hit_count); | 4174 CHECK_EQ(1, break_point_hit_count); |
4172 | 4175 |
4173 { | 4176 { |
(...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5252 // Enter and run function in the second context. | 5255 // Enter and run function in the second context. |
5253 { | 5256 { |
5254 v8::Context::Scope context_scope(context_2); | 5257 v8::Context::Scope context_scope(context_2); |
5255 expected_context = context_2; | 5258 expected_context = context_2; |
5256 expected_context_data = data_2; | 5259 expected_context_data = data_2; |
5257 v8::Local<v8::Function> f = CompileFunction(isolate, source, "f"); | 5260 v8::Local<v8::Function> f = CompileFunction(isolate, source, "f"); |
5258 f->Call(context_2, context_2->Global(), 0, NULL).ToLocalChecked(); | 5261 f->Call(context_2, context_2->Global(), 0, NULL).ToLocalChecked(); |
5259 } | 5262 } |
5260 | 5263 |
5261 // Two times compile event and two times break event. | 5264 // Two times compile event and two times break event. |
5262 CHECK_GT(event_listener_hit_count, 3); | 5265 CHECK_GT(event_listener_hit_count, 4); |
5263 | 5266 |
5264 v8::Debug::SetDebugEventListener(isolate, nullptr); | 5267 v8::Debug::SetDebugEventListener(isolate, nullptr); |
5265 CheckDebuggerUnloaded(isolate); | 5268 CheckDebuggerUnloaded(isolate); |
5266 } | 5269 } |
5267 | 5270 |
5268 // Debug event listener which issues a debug break when it hits a break event. | 5271 // Debug event listener which issues a debug break when it hits a break event. |
5269 static int event_listener_break_hit_count = 0; | 5272 static int event_listener_break_hit_count = 0; |
5270 static void DebugBreakEventListener(const v8::Debug::EventDetails& details) { | 5273 static void DebugBreakEventListener(const v8::Debug::EventDetails& details) { |
5271 // Schedule a debug break for break events. | 5274 // Schedule a debug break for break events. |
5272 if (details.GetEvent() == v8::Break) { | 5275 if (details.GetEvent() == v8::Break) { |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5674 v8::Debug::DebugBreak(env->GetIsolate()); | 5677 v8::Debug::DebugBreak(env->GetIsolate()); |
5675 f->Call(context, env->Global(), 0, NULL).ToLocalChecked(); | 5678 f->Call(context, env->Global(), 0, NULL).ToLocalChecked(); |
5676 // There should be one more break event when the script is evaluated in 'f'. | 5679 // There should be one more break event when the script is evaluated in 'f'. |
5677 CHECK_EQ(2, break_point_hit_count); | 5680 CHECK_EQ(2, break_point_hit_count); |
5678 | 5681 |
5679 // Get rid of the debug event listener. | 5682 // Get rid of the debug event listener. |
5680 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr); | 5683 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr); |
5681 CheckDebuggerUnloaded(env->GetIsolate()); | 5684 CheckDebuggerUnloaded(env->GetIsolate()); |
5682 } | 5685 } |
5683 | 5686 |
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 } | |
5684 | 5710 |
5685 // Test that the debug break flag works with function.apply. | 5711 // Test that the debug break flag works with function.apply. |
5686 TEST(DebugBreakFunctionApply) { | 5712 TEST(DebugBreakFunctionApply) { |
5687 DebugLocalContext env; | 5713 DebugLocalContext env; |
5688 v8::HandleScope scope(env->GetIsolate()); | 5714 v8::HandleScope scope(env->GetIsolate()); |
5689 v8::Local<v8::Context> context = env.context(); | 5715 v8::Local<v8::Context> context = env.context(); |
5690 | 5716 |
5691 // Create a function for testing breaking in apply. | 5717 // Create a function for testing breaking in apply. |
5692 v8::Local<v8::Function> foo = CompileFunction( | 5718 v8::Local<v8::Function> foo = CompileFunction( |
5693 &env, | 5719 &env, |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5813 } | 5839 } |
5814 | 5840 |
5815 | 5841 |
5816 TEST(NoDebugContextWhenDebuggerDisabled) { | 5842 TEST(NoDebugContextWhenDebuggerDisabled) { |
5817 v8::HandleScope scope(CcTest::isolate()); | 5843 v8::HandleScope scope(CcTest::isolate()); |
5818 v8::Local<v8::Context> context = | 5844 v8::Local<v8::Context> context = |
5819 v8::Debug::GetDebugContext(CcTest::isolate()); | 5845 v8::Debug::GetDebugContext(CcTest::isolate()); |
5820 CHECK(context.IsEmpty()); | 5846 CHECK(context.IsEmpty()); |
5821 } | 5847 } |
5822 | 5848 |
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 | |
5823 static v8::Local<v8::Value> expected_callback_data; | 5884 static v8::Local<v8::Value> expected_callback_data; |
5824 static void DebugEventContextChecker(const v8::Debug::EventDetails& details) { | 5885 static void DebugEventContextChecker(const v8::Debug::EventDetails& details) { |
5825 CHECK(details.GetEventContext() == expected_context); | 5886 CHECK(details.GetEventContext() == expected_context); |
5826 CHECK(expected_callback_data->Equals(details.GetEventContext(), | 5887 CHECK(expected_callback_data->Equals(details.GetEventContext(), |
5827 details.GetCallbackData()) | 5888 details.GetCallbackData()) |
5828 .FromJust()); | 5889 .FromJust()); |
5829 } | 5890 } |
5830 | 5891 |
5831 | 5892 |
5832 // Check that event details contain context where debug event occured. | 5893 // Check that event details contain context where debug event occured. |
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6794 "function foo() {\n" | 6855 "function foo() {\n" |
6795 " try { throw new Error(); } catch (e) {}\n" | 6856 " try { throw new Error(); } catch (e) {}\n" |
6796 "}\n" | 6857 "}\n" |
6797 "debugger;\n" | 6858 "debugger;\n" |
6798 "foo();\n" | 6859 "foo();\n" |
6799 "foo();\n"); | 6860 "foo();\n"); |
6800 | 6861 |
6801 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr); | 6862 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr); |
6802 CHECK_EQ(break_point_hit_count, 4); | 6863 CHECK_EQ(break_point_hit_count, 4); |
6803 } | 6864 } |
OLD | NEW |