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(!CcTest::i_isolate()->debug()->debug_info_list_); | 397 CHECK_EQ(NULL, 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(0, strcmp("f", last_function_hit)); | 2151 CHECK_EQ("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(0, strcmp("g", last_function_hit)); | 2156 CHECK_EQ("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(0, strcmp("h", last_function_hit)); | 2166 CHECK_EQ("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(4 * arraysize(argv) == break_point_hit_count); | 4245 CHECK_EQ(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(v8::Integer::New(isolate, 0)->Equals(v8::Debug::Call(frame_count))); | 5678 CHECK_EQ(v8::Integer::New(isolate, 0), |
| 5679 v8::Debug::Call(frame_count)); |
5679 | 5680 |
5680 // Test that the number of frames can be retrieved. | 5681 // Test that the number of frames can be retrieved. |
5681 v8::Script::Compile( | 5682 v8::Script::Compile( |
5682 v8::String::NewFromUtf8(isolate, "CheckFrameCount(1)"))->Run(); | 5683 v8::String::NewFromUtf8(isolate, "CheckFrameCount(1)"))->Run(); |
5683 v8::Script::Compile(v8::String::NewFromUtf8(isolate, | 5684 v8::Script::Compile(v8::String::NewFromUtf8(isolate, |
5684 "function f() {" | 5685 "function f() {" |
5685 " CheckFrameCount(2);" | 5686 " CheckFrameCount(2);" |
5686 "}; f()"))->Run(); | 5687 "}; f()"))->Run(); |
5687 | 5688 |
5688 // Test that the source line can be retrieved. | 5689 // Test that the source line can be retrieved. |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5965 v8::ScriptOrigin origin1 = | 5966 v8::ScriptOrigin origin1 = |
5966 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "name")); | 5967 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "name")); |
5967 v8::Handle<v8::Script> script1 = v8::Script::Compile(script, &origin1); | 5968 v8::Handle<v8::Script> script1 = v8::Script::Compile(script, &origin1); |
5968 script1->Run(); | 5969 script1->Run(); |
5969 v8::Local<v8::Function> f; | 5970 v8::Local<v8::Function> f; |
5970 f = v8::Local<v8::Function>::Cast( | 5971 f = v8::Local<v8::Function>::Cast( |
5971 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); | 5972 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); |
5972 | 5973 |
5973 f->Call(env->Global(), 0, NULL); | 5974 f->Call(env->Global(), 0, NULL); |
5974 CHECK_EQ(1, break_point_hit_count); | 5975 CHECK_EQ(1, break_point_hit_count); |
5975 CHECK_EQ(0, strcmp("name", last_script_name_hit)); | 5976 CHECK_EQ("name", last_script_name_hit); |
5976 | 5977 |
5977 // Compile the same script again without setting data. As the compilation | 5978 // Compile the same script again without setting data. As the compilation |
5978 // cache is disabled when debugging expect the data to be missing. | 5979 // cache is disabled when debugging expect the data to be missing. |
5979 v8::Script::Compile(script, &origin1)->Run(); | 5980 v8::Script::Compile(script, &origin1)->Run(); |
5980 f = v8::Local<v8::Function>::Cast( | 5981 f = v8::Local<v8::Function>::Cast( |
5981 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); | 5982 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); |
5982 f->Call(env->Global(), 0, NULL); | 5983 f->Call(env->Global(), 0, NULL); |
5983 CHECK_EQ(2, break_point_hit_count); | 5984 CHECK_EQ(2, break_point_hit_count); |
5984 CHECK_EQ(0, strcmp("name", last_script_name_hit)); | 5985 CHECK_EQ("name", last_script_name_hit); |
5985 | 5986 |
5986 v8::Local<v8::String> data_obj_source = v8::String::NewFromUtf8( | 5987 v8::Local<v8::String> data_obj_source = v8::String::NewFromUtf8( |
5987 env->GetIsolate(), | 5988 env->GetIsolate(), |
5988 "({ a: 'abc',\n" | 5989 "({ a: 'abc',\n" |
5989 " b: 123,\n" | 5990 " b: 123,\n" |
5990 " toString: function() { return this.a + ' ' + this.b; }\n" | 5991 " toString: function() { return this.a + ' ' + this.b; }\n" |
5991 "})\n"); | 5992 "})\n"); |
5992 v8::Script::Compile(data_obj_source)->Run(); | 5993 v8::Script::Compile(data_obj_source)->Run(); |
5993 v8::ScriptOrigin origin2 = | 5994 v8::ScriptOrigin origin2 = |
5994 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "new name")); | 5995 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "new name")); |
5995 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2); | 5996 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2); |
5996 script2->Run(); | 5997 script2->Run(); |
5997 f = v8::Local<v8::Function>::Cast( | 5998 f = v8::Local<v8::Function>::Cast( |
5998 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); | 5999 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); |
5999 f->Call(env->Global(), 0, NULL); | 6000 f->Call(env->Global(), 0, NULL); |
6000 CHECK_EQ(3, break_point_hit_count); | 6001 CHECK_EQ(3, break_point_hit_count); |
6001 CHECK_EQ(0, strcmp("new name", last_script_name_hit)); | 6002 CHECK_EQ("new name", last_script_name_hit); |
6002 | 6003 |
6003 v8::Handle<v8::Script> script3 = v8::Script::Compile(script, &origin2); | 6004 v8::Handle<v8::Script> script3 = v8::Script::Compile(script, &origin2); |
6004 script3->Run(); | 6005 script3->Run(); |
6005 f = v8::Local<v8::Function>::Cast( | 6006 f = v8::Local<v8::Function>::Cast( |
6006 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); | 6007 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); |
6007 f->Call(env->Global(), 0, NULL); | 6008 f->Call(env->Global(), 0, NULL); |
6008 CHECK_EQ(4, break_point_hit_count); | 6009 CHECK_EQ(4, break_point_hit_count); |
6009 } | 6010 } |
6010 | 6011 |
6011 | 6012 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6196 v8::Local<v8::Value> result = f->Call(env->Global(), argc, argv); | 6197 v8::Local<v8::Value> result = f->Call(env->Global(), argc, argv); |
6197 CHECK_EQ(12, result->Int32Value()); | 6198 CHECK_EQ(12, result->Int32Value()); |
6198 | 6199 |
6199 v8::Debug::SetDebugEventListener(DebugEventDebugBreak); | 6200 v8::Debug::SetDebugEventListener(DebugEventDebugBreak); |
6200 v8::Debug::DebugBreak(env->GetIsolate()); | 6201 v8::Debug::DebugBreak(env->GetIsolate()); |
6201 result = f->Call(env->Global(), argc, argv); | 6202 result = f->Call(env->Global(), argc, argv); |
6202 | 6203 |
6203 // Check that there was only one break event. Matching RegExp should not | 6204 // Check that there was only one break event. Matching RegExp should not |
6204 // cause Break events. | 6205 // cause Break events. |
6205 CHECK_EQ(1, break_point_hit_count); | 6206 CHECK_EQ(1, break_point_hit_count); |
6206 CHECK_EQ(0, strcmp("f", last_function_hit)); | 6207 CHECK_EQ("f", last_function_hit); |
6207 } | 6208 } |
6208 #endif // V8_INTERPRETED_REGEXP | 6209 #endif // V8_INTERPRETED_REGEXP |
6209 | 6210 |
6210 | 6211 |
6211 // Common part of EvalContextData and NestedBreakEventContextData tests. | 6212 // Common part of EvalContextData and NestedBreakEventContextData tests. |
6212 static void ExecuteScriptForContextCheck( | 6213 static void ExecuteScriptForContextCheck( |
6213 v8::Debug::MessageHandler message_handler) { | 6214 v8::Debug::MessageHandler message_handler) { |
6214 // Create a context. | 6215 // Create a context. |
6215 v8::Handle<v8::Context> context_1; | 6216 v8::Handle<v8::Context> context_1; |
6216 v8::Handle<v8::ObjectTemplate> global_template = | 6217 v8::Handle<v8::ObjectTemplate> global_template = |
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6922 v8::Local<v8::Context> context2 = v8::Debug::GetDebugContext(); | 6923 v8::Local<v8::Context> context2 = v8::Debug::GetDebugContext(); |
6923 CHECK(v8::Utils::OpenHandle(*context1).is_identical_to( | 6924 CHECK(v8::Utils::OpenHandle(*context1).is_identical_to( |
6924 v8::Utils::OpenHandle(*context2))); | 6925 v8::Utils::OpenHandle(*context2))); |
6925 v8::Debug::SetDebugEventListener(NULL); | 6926 v8::Debug::SetDebugEventListener(NULL); |
6926 } | 6927 } |
6927 | 6928 |
6928 | 6929 |
6929 static v8::Handle<v8::Value> expected_callback_data; | 6930 static v8::Handle<v8::Value> expected_callback_data; |
6930 static void DebugEventContextChecker(const v8::Debug::EventDetails& details) { | 6931 static void DebugEventContextChecker(const v8::Debug::EventDetails& details) { |
6931 CHECK(details.GetEventContext() == expected_context); | 6932 CHECK(details.GetEventContext() == expected_context); |
6932 CHECK(expected_callback_data->Equals(details.GetCallbackData())); | 6933 CHECK_EQ(expected_callback_data, details.GetCallbackData()); |
6933 } | 6934 } |
6934 | 6935 |
6935 | 6936 |
6936 // Check that event details contain context where debug event occured. | 6937 // Check that event details contain context where debug event occured. |
6937 TEST(DebugEventContext) { | 6938 TEST(DebugEventContext) { |
6938 v8::Isolate* isolate = CcTest::isolate(); | 6939 v8::Isolate* isolate = CcTest::isolate(); |
6939 v8::HandleScope scope(isolate); | 6940 v8::HandleScope scope(isolate); |
6940 expected_context = v8::Context::New(isolate); | 6941 expected_context = v8::Context::New(isolate); |
6941 expected_callback_data = v8::Int32::New(isolate, 2010); | 6942 expected_callback_data = v8::Int32::New(isolate, 2010); |
6942 v8::Debug::SetDebugEventListener(DebugEventContextChecker, | 6943 v8::Debug::SetDebugEventListener(DebugEventContextChecker, |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7434 " var a; \n" | 7435 " var a; \n" |
7435 "} \n" | 7436 "} \n" |
7436 "function bar() { \n" | 7437 "function bar() { \n" |
7437 " return \"bar\"; \n" | 7438 " return \"bar\"; \n" |
7438 "}; \n" | 7439 "}; \n" |
7439 "a = b = c = 2; \n" | 7440 "a = b = c = 2; \n" |
7440 "bar(); \n"; | 7441 "bar(); \n"; |
7441 v8::Local<v8::Value> result = ParserCacheCompileRun(source); | 7442 v8::Local<v8::Value> result = ParserCacheCompileRun(source); |
7442 CHECK(result->IsString()); | 7443 CHECK(result->IsString()); |
7443 v8::String::Utf8Value utf8(result); | 7444 v8::String::Utf8Value utf8(result); |
7444 CHECK_EQ(0, strcmp("bar", *utf8)); | 7445 CHECK_EQ("bar", *utf8); |
7445 | 7446 |
7446 v8::Debug::SetDebugEventListener(NULL); | 7447 v8::Debug::SetDebugEventListener(NULL); |
7447 CheckDebuggerUnloaded(); | 7448 CheckDebuggerUnloaded(); |
7448 } | 7449 } |
7449 | 7450 |
7450 | 7451 |
7451 static void DebugBreakStackTraceListener( | 7452 static void DebugBreakStackTraceListener( |
7452 const v8::Debug::EventDetails& event_details) { | 7453 const v8::Debug::EventDetails& event_details) { |
7453 v8::StackTrace::CurrentStackTrace(CcTest::isolate(), 10); | 7454 v8::StackTrace::CurrentStackTrace(CcTest::isolate(), 10); |
7454 } | 7455 } |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7671 "let y = 2; \n" | 7672 "let y = 2; \n" |
7672 "debugger; \n" | 7673 "debugger; \n" |
7673 "x * y", | 7674 "x * y", |
7674 30); | 7675 30); |
7675 ExpectInt32( | 7676 ExpectInt32( |
7676 "x = 1; y = 2; \n" | 7677 "x = 1; y = 2; \n" |
7677 "debugger;" | 7678 "debugger;" |
7678 "x * y", | 7679 "x * y", |
7679 30); | 7680 30); |
7680 } | 7681 } |
OLD | NEW |