| 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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 | 387 |
| 388 return debugged_functions; | 388 return debugged_functions; |
| 389 } | 389 } |
| 390 | 390 |
| 391 | 391 |
| 392 // Check that the debugger has been fully unloaded. | 392 // Check that the debugger has been fully unloaded. |
| 393 void CheckDebuggerUnloaded(bool check_functions) { | 393 void CheckDebuggerUnloaded(bool check_functions) { |
| 394 // Check that the debugger context is cleared and that there is no debug | 394 // Check that the debugger context is cleared and that there is no debug |
| 395 // information stored for the debugger. | 395 // information stored for the debugger. |
| 396 CHECK(CcTest::i_isolate()->debug()->debug_context().is_null()); | 396 CHECK(CcTest::i_isolate()->debug()->debug_context().is_null()); |
| 397 CHECK_EQ(NULL, CcTest::i_isolate()->debug()->debug_info_list_); | 397 CHECK(!CcTest::i_isolate()->debug()->debug_info_list_); |
| 398 | 398 |
| 399 // Collect garbage to ensure weak handles are cleared. | 399 // Collect garbage to ensure weak handles are cleared. |
| 400 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 400 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 401 CcTest::heap()->CollectAllGarbage(Heap::kMakeHeapIterableMask); | 401 CcTest::heap()->CollectAllGarbage(Heap::kMakeHeapIterableMask); |
| 402 | 402 |
| 403 // Iterate the head and check that there are no debugger related objects left. | 403 // Iterate the head and check that there are no debugger related objects left. |
| 404 HeapIterator iterator(CcTest::heap()); | 404 HeapIterator iterator(CcTest::heap()); |
| 405 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { | 405 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
| 406 CHECK(!obj->IsDebugInfo()); | 406 CHECK(!obj->IsDebugInfo()); |
| 407 CHECK(!obj->IsBreakPointInfo()); | 407 CHECK(!obj->IsBreakPointInfo()); |
| (...skipping 1733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2141 g = v8::Local<v8::Function>::Cast( | 2141 g = v8::Local<v8::Function>::Cast( |
| 2142 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "g"))); | 2142 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "g"))); |
| 2143 | 2143 |
| 2144 // Check that a break point was hit when the script was run. | 2144 // Check that a break point was hit when the script was run. |
| 2145 CHECK_EQ(1, break_point_hit_count); | 2145 CHECK_EQ(1, break_point_hit_count); |
| 2146 CHECK_EQ(0, StrLength(last_function_hit)); | 2146 CHECK_EQ(0, StrLength(last_function_hit)); |
| 2147 | 2147 |
| 2148 // Call f and check that the script break point. | 2148 // Call f and check that the script break point. |
| 2149 f->Call(env->Global(), 0, NULL); | 2149 f->Call(env->Global(), 0, NULL); |
| 2150 CHECK_EQ(2, break_point_hit_count); | 2150 CHECK_EQ(2, break_point_hit_count); |
| 2151 CHECK_EQ("f", last_function_hit); | 2151 CHECK_EQ(0, strcmp("f", last_function_hit)); |
| 2152 | 2152 |
| 2153 // Call g and check that the script break point. | 2153 // Call g and check that the script break point. |
| 2154 g->Call(env->Global(), 0, NULL); | 2154 g->Call(env->Global(), 0, NULL); |
| 2155 CHECK_EQ(3, break_point_hit_count); | 2155 CHECK_EQ(3, break_point_hit_count); |
| 2156 CHECK_EQ("g", last_function_hit); | 2156 CHECK_EQ(0, strcmp("g", last_function_hit)); |
| 2157 | 2157 |
| 2158 // Clear the script break point on g and set one on h. | 2158 // Clear the script break point on g and set one on h. |
| 2159 ClearBreakPointFromJS(env->GetIsolate(), sbp3); | 2159 ClearBreakPointFromJS(env->GetIsolate(), sbp3); |
| 2160 int sbp4 = | 2160 int sbp4 = |
| 2161 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 6, -1); | 2161 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 6, -1); |
| 2162 | 2162 |
| 2163 // Call g and check that the script break point in h is hit. | 2163 // Call g and check that the script break point in h is hit. |
| 2164 g->Call(env->Global(), 0, NULL); | 2164 g->Call(env->Global(), 0, NULL); |
| 2165 CHECK_EQ(4, break_point_hit_count); | 2165 CHECK_EQ(4, break_point_hit_count); |
| 2166 CHECK_EQ("h", last_function_hit); | 2166 CHECK_EQ(0, strcmp("h", last_function_hit)); |
| 2167 | 2167 |
| 2168 // Clear break points in f and h. Set a new one in the script between | 2168 // Clear break points in f and h. Set a new one in the script between |
| 2169 // functions f and g and test that there is no break points in f and g any | 2169 // functions f and g and test that there is no break points in f and g any |
| 2170 // more. | 2170 // more. |
| 2171 ClearBreakPointFromJS(env->GetIsolate(), sbp2); | 2171 ClearBreakPointFromJS(env->GetIsolate(), sbp2); |
| 2172 ClearBreakPointFromJS(env->GetIsolate(), sbp4); | 2172 ClearBreakPointFromJS(env->GetIsolate(), sbp4); |
| 2173 int sbp5 = | 2173 int sbp5 = |
| 2174 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 4, -1); | 2174 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 4, -1); |
| 2175 break_point_hit_count = 0; | 2175 break_point_hit_count = 0; |
| 2176 f->Call(env->Global(), 0, NULL); | 2176 f->Call(env->Global(), 0, NULL); |
| (...skipping 2058 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4235 // Call all functions with different argument count. | 4235 // Call all functions with different argument count. |
| 4236 break_point_hit_count = 0; | 4236 break_point_hit_count = 0; |
| 4237 for (unsigned int i = 0; i < arraysize(argv); i++) { | 4237 for (unsigned int i = 0; i < arraysize(argv); i++) { |
| 4238 f0->Call(env->Global(), i, argv); | 4238 f0->Call(env->Global(), i, argv); |
| 4239 f1->Call(env->Global(), i, argv); | 4239 f1->Call(env->Global(), i, argv); |
| 4240 f2->Call(env->Global(), i, argv); | 4240 f2->Call(env->Global(), i, argv); |
| 4241 f3->Call(env->Global(), i, argv); | 4241 f3->Call(env->Global(), i, argv); |
| 4242 } | 4242 } |
| 4243 | 4243 |
| 4244 // One break for each function called. | 4244 // One break for each function called. |
| 4245 CHECK_EQ(4 * arraysize(argv), break_point_hit_count); | 4245 CHECK(4 * arraysize(argv) == break_point_hit_count); |
| 4246 | 4246 |
| 4247 // Get rid of the debug event listener. | 4247 // Get rid of the debug event listener. |
| 4248 v8::Debug::SetDebugEventListener(NULL); | 4248 v8::Debug::SetDebugEventListener(NULL); |
| 4249 CheckDebuggerUnloaded(); | 4249 CheckDebuggerUnloaded(); |
| 4250 } | 4250 } |
| 4251 | 4251 |
| 4252 | 4252 |
| 4253 // Test to ensure that JavaScript code keeps running while the debug break | 4253 // Test to ensure that JavaScript code keeps running while the debug break |
| 4254 // through the stack limit flag is set but breaks are disabled. | 4254 // through the stack limit flag is set but breaks are disabled. |
| 4255 TEST(DisableBreak) { | 4255 TEST(DisableBreak) { |
| (...skipping 1412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5668 isolate, "debugger_call_with_data"))); | 5668 isolate, "debugger_call_with_data"))); |
| 5669 | 5669 |
| 5670 // Compile a function capturing closure. | 5670 // Compile a function capturing closure. |
| 5671 debugger_call_with_closure = | 5671 debugger_call_with_closure = |
| 5672 v8::Local<v8::Function>::Cast(v8::Script::Compile( | 5672 v8::Local<v8::Function>::Cast(v8::Script::Compile( |
| 5673 v8::String::NewFromUtf8(isolate, | 5673 v8::String::NewFromUtf8(isolate, |
| 5674 debugger_call_with_closure_source))->Run()); | 5674 debugger_call_with_closure_source))->Run()); |
| 5675 | 5675 |
| 5676 // Calling a function through the debugger returns 0 frames if there are | 5676 // Calling a function through the debugger returns 0 frames if there are |
| 5677 // no JavaScript frames. | 5677 // no JavaScript frames. |
| 5678 CHECK_EQ(v8::Integer::New(isolate, 0), | 5678 CHECK(v8::Integer::New(isolate, 0)->Equals(v8::Debug::Call(frame_count))); |
| 5679 v8::Debug::Call(frame_count)); | |
| 5680 | 5679 |
| 5681 // Test that the number of frames can be retrieved. | 5680 // Test that the number of frames can be retrieved. |
| 5682 v8::Script::Compile( | 5681 v8::Script::Compile( |
| 5683 v8::String::NewFromUtf8(isolate, "CheckFrameCount(1)"))->Run(); | 5682 v8::String::NewFromUtf8(isolate, "CheckFrameCount(1)"))->Run(); |
| 5684 v8::Script::Compile(v8::String::NewFromUtf8(isolate, | 5683 v8::Script::Compile(v8::String::NewFromUtf8(isolate, |
| 5685 "function f() {" | 5684 "function f() {" |
| 5686 " CheckFrameCount(2);" | 5685 " CheckFrameCount(2);" |
| 5687 "}; f()"))->Run(); | 5686 "}; f()"))->Run(); |
| 5688 | 5687 |
| 5689 // Test that the source line can be retrieved. | 5688 // Test that the source line can be retrieved. |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5966 v8::ScriptOrigin origin1 = | 5965 v8::ScriptOrigin origin1 = |
| 5967 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "name")); | 5966 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "name")); |
| 5968 v8::Handle<v8::Script> script1 = v8::Script::Compile(script, &origin1); | 5967 v8::Handle<v8::Script> script1 = v8::Script::Compile(script, &origin1); |
| 5969 script1->Run(); | 5968 script1->Run(); |
| 5970 v8::Local<v8::Function> f; | 5969 v8::Local<v8::Function> f; |
| 5971 f = v8::Local<v8::Function>::Cast( | 5970 f = v8::Local<v8::Function>::Cast( |
| 5972 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); | 5971 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); |
| 5973 | 5972 |
| 5974 f->Call(env->Global(), 0, NULL); | 5973 f->Call(env->Global(), 0, NULL); |
| 5975 CHECK_EQ(1, break_point_hit_count); | 5974 CHECK_EQ(1, break_point_hit_count); |
| 5976 CHECK_EQ("name", last_script_name_hit); | 5975 CHECK_EQ(0, strcmp("name", last_script_name_hit)); |
| 5977 | 5976 |
| 5978 // Compile the same script again without setting data. As the compilation | 5977 // Compile the same script again without setting data. As the compilation |
| 5979 // cache is disabled when debugging expect the data to be missing. | 5978 // cache is disabled when debugging expect the data to be missing. |
| 5980 v8::Script::Compile(script, &origin1)->Run(); | 5979 v8::Script::Compile(script, &origin1)->Run(); |
| 5981 f = v8::Local<v8::Function>::Cast( | 5980 f = v8::Local<v8::Function>::Cast( |
| 5982 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); | 5981 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); |
| 5983 f->Call(env->Global(), 0, NULL); | 5982 f->Call(env->Global(), 0, NULL); |
| 5984 CHECK_EQ(2, break_point_hit_count); | 5983 CHECK_EQ(2, break_point_hit_count); |
| 5985 CHECK_EQ("name", last_script_name_hit); | 5984 CHECK_EQ(0, strcmp("name", last_script_name_hit)); |
| 5986 | 5985 |
| 5987 v8::Local<v8::String> data_obj_source = v8::String::NewFromUtf8( | 5986 v8::Local<v8::String> data_obj_source = v8::String::NewFromUtf8( |
| 5988 env->GetIsolate(), | 5987 env->GetIsolate(), |
| 5989 "({ a: 'abc',\n" | 5988 "({ a: 'abc',\n" |
| 5990 " b: 123,\n" | 5989 " b: 123,\n" |
| 5991 " toString: function() { return this.a + ' ' + this.b; }\n" | 5990 " toString: function() { return this.a + ' ' + this.b; }\n" |
| 5992 "})\n"); | 5991 "})\n"); |
| 5993 v8::Script::Compile(data_obj_source)->Run(); | 5992 v8::Script::Compile(data_obj_source)->Run(); |
| 5994 v8::ScriptOrigin origin2 = | 5993 v8::ScriptOrigin origin2 = |
| 5995 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "new name")); | 5994 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "new name")); |
| 5996 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2); | 5995 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2); |
| 5997 script2->Run(); | 5996 script2->Run(); |
| 5998 f = v8::Local<v8::Function>::Cast( | 5997 f = v8::Local<v8::Function>::Cast( |
| 5999 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); | 5998 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); |
| 6000 f->Call(env->Global(), 0, NULL); | 5999 f->Call(env->Global(), 0, NULL); |
| 6001 CHECK_EQ(3, break_point_hit_count); | 6000 CHECK_EQ(3, break_point_hit_count); |
| 6002 CHECK_EQ("new name", last_script_name_hit); | 6001 CHECK_EQ(0, strcmp("new name", last_script_name_hit)); |
| 6003 | 6002 |
| 6004 v8::Handle<v8::Script> script3 = v8::Script::Compile(script, &origin2); | 6003 v8::Handle<v8::Script> script3 = v8::Script::Compile(script, &origin2); |
| 6005 script3->Run(); | 6004 script3->Run(); |
| 6006 f = v8::Local<v8::Function>::Cast( | 6005 f = v8::Local<v8::Function>::Cast( |
| 6007 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); | 6006 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); |
| 6008 f->Call(env->Global(), 0, NULL); | 6007 f->Call(env->Global(), 0, NULL); |
| 6009 CHECK_EQ(4, break_point_hit_count); | 6008 CHECK_EQ(4, break_point_hit_count); |
| 6010 } | 6009 } |
| 6011 | 6010 |
| 6012 | 6011 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6197 v8::Local<v8::Value> result = f->Call(env->Global(), argc, argv); | 6196 v8::Local<v8::Value> result = f->Call(env->Global(), argc, argv); |
| 6198 CHECK_EQ(12, result->Int32Value()); | 6197 CHECK_EQ(12, result->Int32Value()); |
| 6199 | 6198 |
| 6200 v8::Debug::SetDebugEventListener(DebugEventDebugBreak); | 6199 v8::Debug::SetDebugEventListener(DebugEventDebugBreak); |
| 6201 v8::Debug::DebugBreak(env->GetIsolate()); | 6200 v8::Debug::DebugBreak(env->GetIsolate()); |
| 6202 result = f->Call(env->Global(), argc, argv); | 6201 result = f->Call(env->Global(), argc, argv); |
| 6203 | 6202 |
| 6204 // Check that there was only one break event. Matching RegExp should not | 6203 // Check that there was only one break event. Matching RegExp should not |
| 6205 // cause Break events. | 6204 // cause Break events. |
| 6206 CHECK_EQ(1, break_point_hit_count); | 6205 CHECK_EQ(1, break_point_hit_count); |
| 6207 CHECK_EQ("f", last_function_hit); | 6206 CHECK_EQ(0, strcmp("f", last_function_hit)); |
| 6208 } | 6207 } |
| 6209 #endif // V8_INTERPRETED_REGEXP | 6208 #endif // V8_INTERPRETED_REGEXP |
| 6210 | 6209 |
| 6211 | 6210 |
| 6212 // Common part of EvalContextData and NestedBreakEventContextData tests. | 6211 // Common part of EvalContextData and NestedBreakEventContextData tests. |
| 6213 static void ExecuteScriptForContextCheck( | 6212 static void ExecuteScriptForContextCheck( |
| 6214 v8::Debug::MessageHandler message_handler) { | 6213 v8::Debug::MessageHandler message_handler) { |
| 6215 // Create a context. | 6214 // Create a context. |
| 6216 v8::Handle<v8::Context> context_1; | 6215 v8::Handle<v8::Context> context_1; |
| 6217 v8::Handle<v8::ObjectTemplate> global_template = | 6216 v8::Handle<v8::ObjectTemplate> global_template = |
| (...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6923 v8::Local<v8::Context> context2 = v8::Debug::GetDebugContext(); | 6922 v8::Local<v8::Context> context2 = v8::Debug::GetDebugContext(); |
| 6924 CHECK(v8::Utils::OpenHandle(*context1).is_identical_to( | 6923 CHECK(v8::Utils::OpenHandle(*context1).is_identical_to( |
| 6925 v8::Utils::OpenHandle(*context2))); | 6924 v8::Utils::OpenHandle(*context2))); |
| 6926 v8::Debug::SetDebugEventListener(NULL); | 6925 v8::Debug::SetDebugEventListener(NULL); |
| 6927 } | 6926 } |
| 6928 | 6927 |
| 6929 | 6928 |
| 6930 static v8::Handle<v8::Value> expected_callback_data; | 6929 static v8::Handle<v8::Value> expected_callback_data; |
| 6931 static void DebugEventContextChecker(const v8::Debug::EventDetails& details) { | 6930 static void DebugEventContextChecker(const v8::Debug::EventDetails& details) { |
| 6932 CHECK(details.GetEventContext() == expected_context); | 6931 CHECK(details.GetEventContext() == expected_context); |
| 6933 CHECK_EQ(expected_callback_data, details.GetCallbackData()); | 6932 CHECK(expected_callback_data->Equals(details.GetCallbackData())); |
| 6934 } | 6933 } |
| 6935 | 6934 |
| 6936 | 6935 |
| 6937 // Check that event details contain context where debug event occured. | 6936 // Check that event details contain context where debug event occured. |
| 6938 TEST(DebugEventContext) { | 6937 TEST(DebugEventContext) { |
| 6939 v8::Isolate* isolate = CcTest::isolate(); | 6938 v8::Isolate* isolate = CcTest::isolate(); |
| 6940 v8::HandleScope scope(isolate); | 6939 v8::HandleScope scope(isolate); |
| 6941 expected_context = v8::Context::New(isolate); | 6940 expected_context = v8::Context::New(isolate); |
| 6942 expected_callback_data = v8::Int32::New(isolate, 2010); | 6941 expected_callback_data = v8::Int32::New(isolate, 2010); |
| 6943 v8::Debug::SetDebugEventListener(DebugEventContextChecker, | 6942 v8::Debug::SetDebugEventListener(DebugEventContextChecker, |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7435 " var a; \n" | 7434 " var a; \n" |
| 7436 "} \n" | 7435 "} \n" |
| 7437 "function bar() { \n" | 7436 "function bar() { \n" |
| 7438 " return \"bar\"; \n" | 7437 " return \"bar\"; \n" |
| 7439 "}; \n" | 7438 "}; \n" |
| 7440 "a = b = c = 2; \n" | 7439 "a = b = c = 2; \n" |
| 7441 "bar(); \n"; | 7440 "bar(); \n"; |
| 7442 v8::Local<v8::Value> result = ParserCacheCompileRun(source); | 7441 v8::Local<v8::Value> result = ParserCacheCompileRun(source); |
| 7443 CHECK(result->IsString()); | 7442 CHECK(result->IsString()); |
| 7444 v8::String::Utf8Value utf8(result); | 7443 v8::String::Utf8Value utf8(result); |
| 7445 CHECK_EQ("bar", *utf8); | 7444 CHECK_EQ(0, strcmp("bar", *utf8)); |
| 7446 | 7445 |
| 7447 v8::Debug::SetDebugEventListener(NULL); | 7446 v8::Debug::SetDebugEventListener(NULL); |
| 7448 CheckDebuggerUnloaded(); | 7447 CheckDebuggerUnloaded(); |
| 7449 } | 7448 } |
| 7450 | 7449 |
| 7451 | 7450 |
| 7452 static void DebugBreakStackTraceListener( | 7451 static void DebugBreakStackTraceListener( |
| 7453 const v8::Debug::EventDetails& event_details) { | 7452 const v8::Debug::EventDetails& event_details) { |
| 7454 v8::StackTrace::CurrentStackTrace(CcTest::isolate(), 10); | 7453 v8::StackTrace::CurrentStackTrace(CcTest::isolate(), 10); |
| 7455 } | 7454 } |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7672 "let y = 2; \n" | 7671 "let y = 2; \n" |
| 7673 "debugger; \n" | 7672 "debugger; \n" |
| 7674 "x * y", | 7673 "x * y", |
| 7675 30); | 7674 30); |
| 7676 ExpectInt32( | 7675 ExpectInt32( |
| 7677 "x = 1; y = 2; \n" | 7676 "x = 1; y = 2; \n" |
| 7678 "debugger;" | 7677 "debugger;" |
| 7679 "x * y", | 7678 "x * y", |
| 7680 30); | 7679 30); |
| 7681 } | 7680 } |
| OLD | NEW |