Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: test/cctest/test-debug.cc

Issue 2531543002: [debug] mark more unused debug API as deprecated. (Closed)
Patch Set: . Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/inspector/v8-debugger.cc ('k') | test/debugger/test-api.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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 }
OLDNEW
« no previous file with comments | « src/inspector/v8-debugger.cc ('k') | test/debugger/test-api.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698