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 1501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 5684 |
5688 TEST(GetMirror) { | |
5689 DebugLocalContext env; | |
5690 v8::Isolate* isolate = env->GetIsolate(); | |
5691 v8::HandleScope scope(isolate); | |
5692 v8::Local<v8::Context> context = env.context(); | |
5693 v8::Local<v8::Value> obj = | |
5694 v8::Debug::GetMirror(context, v8_str(isolate, "hodja")).ToLocalChecked(); | |
5695 v8::ScriptCompiler::Source source(v8_str( | |
5696 "function runTest(mirror) {" | |
5697 " return mirror.isString() && (mirror.length() == 5);" | |
5698 "}" | |
5699 "" | |
5700 "runTest;")); | |
5701 v8::Local<v8::Function> run_test = v8::Local<v8::Function>::Cast( | |
5702 v8::ScriptCompiler::CompileUnboundScript(isolate, &source) | |
5703 .ToLocalChecked() | |
5704 ->BindToCurrentContext() | |
5705 ->Run(context) | |
5706 .ToLocalChecked()); | |
5707 v8::Local<v8::Value> result = | |
5708 run_test->Call(context, env->Global(), 1, &obj).ToLocalChecked(); | |
5709 CHECK(result->IsTrue()); | |
5710 } | |
5711 | |
5712 | |
5713 // Test that the debug break flag works with function.apply. | 5685 // Test that the debug break flag works with function.apply. |
5714 TEST(DebugBreakFunctionApply) { | 5686 TEST(DebugBreakFunctionApply) { |
5715 DebugLocalContext env; | 5687 DebugLocalContext env; |
5716 v8::HandleScope scope(env->GetIsolate()); | 5688 v8::HandleScope scope(env->GetIsolate()); |
5717 v8::Local<v8::Context> context = env.context(); | 5689 v8::Local<v8::Context> context = env.context(); |
5718 | 5690 |
5719 // Create a function for testing breaking in apply. | 5691 // Create a function for testing breaking in apply. |
5720 v8::Local<v8::Function> foo = CompileFunction( | 5692 v8::Local<v8::Function> foo = CompileFunction( |
5721 &env, | 5693 &env, |
5722 "function baz(x) { }" | 5694 "function baz(x) { }" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5841 } | 5813 } |
5842 | 5814 |
5843 | 5815 |
5844 TEST(NoDebugContextWhenDebuggerDisabled) { | 5816 TEST(NoDebugContextWhenDebuggerDisabled) { |
5845 v8::HandleScope scope(CcTest::isolate()); | 5817 v8::HandleScope scope(CcTest::isolate()); |
5846 v8::Local<v8::Context> context = | 5818 v8::Local<v8::Context> context = |
5847 v8::Debug::GetDebugContext(CcTest::isolate()); | 5819 v8::Debug::GetDebugContext(CcTest::isolate()); |
5848 CHECK(context.IsEmpty()); | 5820 CHECK(context.IsEmpty()); |
5849 } | 5821 } |
5850 | 5822 |
5851 static void DebugEventCheckContext( | |
5852 const v8::Debug::EventDetails& event_details) { | |
5853 if (event_details.GetEvent() == v8::Break) { | |
5854 v8::Isolate* isolate = event_details.GetIsolate(); | |
5855 CHECK(v8::Debug::GetDebuggedContext(isolate) | |
5856 .ToLocalChecked() | |
5857 ->Global() | |
5858 ->Equals(isolate->GetCurrentContext(), | |
5859 event_details.GetEventContext()->Global()) | |
5860 .FromJust()); | |
5861 } | |
5862 } | |
5863 | |
5864 static void CheckContext(const v8::FunctionCallbackInfo<v8::Value>& args) { | |
5865 CHECK(v8::Debug::GetDebuggedContext(args.GetIsolate()).IsEmpty()); | |
5866 } | |
5867 | |
5868 TEST(DebuggedContext) { | |
5869 DebugLocalContext env; | |
5870 v8::Isolate* isolate = env->GetIsolate(); | |
5871 | |
5872 v8::Debug::SetDebugEventListener(isolate, DebugEventCheckContext); | |
5873 | |
5874 v8::Local<v8::Function> foo = | |
5875 CompileFunction(&env, "function foo(){bar=0;}", "foo"); | |
5876 | |
5877 SetBreakPoint(foo, 0); | |
5878 foo->Call(env.context(), env->Global(), 0, nullptr).ToLocalChecked(); | |
5879 | |
5880 v8::Local<v8::Function> fun = v8::FunctionTemplate::New(isolate, CheckContext) | |
5881 ->GetFunction(env.context()) | |
5882 .ToLocalChecked(); | |
5883 fun->Call(env.context(), env->Global(), 0, nullptr).ToLocalChecked(); | |
5884 } | |
5885 | |
5886 static v8::Local<v8::Value> expected_callback_data; | 5823 static v8::Local<v8::Value> expected_callback_data; |
5887 static void DebugEventContextChecker(const v8::Debug::EventDetails& details) { | 5824 static void DebugEventContextChecker(const v8::Debug::EventDetails& details) { |
5888 CHECK(details.GetEventContext() == expected_context); | 5825 CHECK(details.GetEventContext() == expected_context); |
5889 CHECK(expected_callback_data->Equals(details.GetEventContext(), | 5826 CHECK(expected_callback_data->Equals(details.GetEventContext(), |
5890 details.GetCallbackData()) | 5827 details.GetCallbackData()) |
5891 .FromJust()); | 5828 .FromJust()); |
5892 } | 5829 } |
5893 | 5830 |
5894 | 5831 |
5895 // 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... |
6857 "function foo() {\n" | 6794 "function foo() {\n" |
6858 " try { throw new Error(); } catch (e) {}\n" | 6795 " try { throw new Error(); } catch (e) {}\n" |
6859 "}\n" | 6796 "}\n" |
6860 "debugger;\n" | 6797 "debugger;\n" |
6861 "foo();\n" | 6798 "foo();\n" |
6862 "foo();\n"); | 6799 "foo();\n"); |
6863 | 6800 |
6864 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr); | 6801 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr); |
6865 CHECK_EQ(break_point_hit_count, 4); | 6802 CHECK_EQ(break_point_hit_count, 4); |
6866 } | 6803 } |
OLD | NEW |