| 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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 "debug.Debug.setScriptBreakPointById(%d,%d,%d)", | 204 "debug.Debug.setScriptBreakPointById(%d,%d,%d)", |
| 205 script_id, line, column); | 205 script_id, line, column); |
| 206 } else { | 206 } else { |
| 207 // Column not specified set script break point on line. | 207 // Column not specified set script break point on line. |
| 208 SNPrintF(buffer, | 208 SNPrintF(buffer, |
| 209 "debug.Debug.setScriptBreakPointById(%d,%d)", | 209 "debug.Debug.setScriptBreakPointById(%d,%d)", |
| 210 script_id, line); | 210 script_id, line); |
| 211 } | 211 } |
| 212 buffer[SMALL_STRING_BUFFER_SIZE - 1] = '\0'; | 212 buffer[SMALL_STRING_BUFFER_SIZE - 1] = '\0'; |
| 213 { | 213 { |
| 214 v8::TryCatch try_catch; | 214 v8::TryCatch try_catch(isolate); |
| 215 v8::Handle<v8::String> str = | 215 v8::Handle<v8::String> str = |
| 216 v8::String::NewFromUtf8(isolate, buffer.start()); | 216 v8::String::NewFromUtf8(isolate, buffer.start()); |
| 217 v8::Handle<v8::Value> value = v8::Script::Compile(str)->Run(); | 217 v8::Handle<v8::Value> value = v8::Script::Compile(str)->Run(); |
| 218 CHECK(!try_catch.HasCaught()); | 218 CHECK(!try_catch.HasCaught()); |
| 219 return value->Int32Value(); | 219 return value->Int32Value(); |
| 220 } | 220 } |
| 221 } | 221 } |
| 222 | 222 |
| 223 | 223 |
| 224 // Set a break point in a script identified by name using the global Debug | 224 // Set a break point in a script identified by name using the global Debug |
| 225 // object. | 225 // object. |
| 226 static int SetScriptBreakPointByNameFromJS(v8::Isolate* isolate, | 226 static int SetScriptBreakPointByNameFromJS(v8::Isolate* isolate, |
| 227 const char* script_name, int line, | 227 const char* script_name, int line, |
| 228 int column) { | 228 int column) { |
| 229 EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer; | 229 EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer; |
| 230 if (column >= 0) { | 230 if (column >= 0) { |
| 231 // Column specified set script break point on precise location. | 231 // Column specified set script break point on precise location. |
| 232 SNPrintF(buffer, | 232 SNPrintF(buffer, |
| 233 "debug.Debug.setScriptBreakPointByName(\"%s\",%d,%d)", | 233 "debug.Debug.setScriptBreakPointByName(\"%s\",%d,%d)", |
| 234 script_name, line, column); | 234 script_name, line, column); |
| 235 } else { | 235 } else { |
| 236 // Column not specified set script break point on line. | 236 // Column not specified set script break point on line. |
| 237 SNPrintF(buffer, | 237 SNPrintF(buffer, |
| 238 "debug.Debug.setScriptBreakPointByName(\"%s\",%d)", | 238 "debug.Debug.setScriptBreakPointByName(\"%s\",%d)", |
| 239 script_name, line); | 239 script_name, line); |
| 240 } | 240 } |
| 241 buffer[SMALL_STRING_BUFFER_SIZE - 1] = '\0'; | 241 buffer[SMALL_STRING_BUFFER_SIZE - 1] = '\0'; |
| 242 { | 242 { |
| 243 v8::TryCatch try_catch; | 243 v8::TryCatch try_catch(isolate); |
| 244 v8::Handle<v8::String> str = | 244 v8::Handle<v8::String> str = |
| 245 v8::String::NewFromUtf8(isolate, buffer.start()); | 245 v8::String::NewFromUtf8(isolate, buffer.start()); |
| 246 v8::Handle<v8::Value> value = v8::Script::Compile(str)->Run(); | 246 v8::Handle<v8::Value> value = v8::Script::Compile(str)->Run(); |
| 247 CHECK(!try_catch.HasCaught()); | 247 CHECK(!try_catch.HasCaught()); |
| 248 return value->Int32Value(); | 248 return value->Int32Value(); |
| 249 } | 249 } |
| 250 } | 250 } |
| 251 | 251 |
| 252 | 252 |
| 253 // Clear a break point. | 253 // Clear a break point. |
| (...skipping 3762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4016 | 4016 |
| 4017 v8::V8::AddMessageListener(MessageCallbackCount); | 4017 v8::V8::AddMessageListener(MessageCallbackCount); |
| 4018 v8::Debug::SetDebugEventListener(DebugEventCounter); | 4018 v8::Debug::SetDebugEventListener(DebugEventCounter); |
| 4019 // Break on uncaught exception | 4019 // Break on uncaught exception |
| 4020 ChangeBreakOnException(false, true); | 4020 ChangeBreakOnException(false, true); |
| 4021 DebugEventCounterClear(); | 4021 DebugEventCounterClear(); |
| 4022 MessageCallbackCountClear(); | 4022 MessageCallbackCountClear(); |
| 4023 | 4023 |
| 4024 // ReThrow native error | 4024 // ReThrow native error |
| 4025 { | 4025 { |
| 4026 v8::TryCatch tryCatch; | 4026 v8::TryCatch tryCatch(env->GetIsolate()); |
| 4027 env->GetIsolate()->ThrowException(v8::Exception::TypeError( | 4027 env->GetIsolate()->ThrowException(v8::Exception::TypeError( |
| 4028 v8::String::NewFromUtf8(env->GetIsolate(), "Type error"))); | 4028 v8::String::NewFromUtf8(env->GetIsolate(), "Type error"))); |
| 4029 CHECK(tryCatch.HasCaught()); | 4029 CHECK(tryCatch.HasCaught()); |
| 4030 tryCatch.ReThrow(); | 4030 tryCatch.ReThrow(); |
| 4031 } | 4031 } |
| 4032 CHECK_EQ(1, exception_hit_count); | 4032 CHECK_EQ(1, exception_hit_count); |
| 4033 CHECK_EQ(1, uncaught_exception_hit_count); | 4033 CHECK_EQ(1, uncaught_exception_hit_count); |
| 4034 CHECK_EQ(0, message_callback_count); // FIXME: Should it be 1 ? | 4034 CHECK_EQ(0, message_callback_count); // FIXME: Should it be 1 ? |
| 4035 CHECK(!debug_event_listener_callback.IsEmpty()); | 4035 CHECK(!debug_event_listener_callback.IsEmpty()); |
| 4036 | 4036 |
| (...skipping 1558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5595 // Function to test passing an additional parameter to a JavaScript function | 5595 // Function to test passing an additional parameter to a JavaScript function |
| 5596 // called in the debugger. It also tests that functions called in the debugger | 5596 // called in the debugger. It also tests that functions called in the debugger |
| 5597 // can throw exceptions. | 5597 // can throw exceptions. |
| 5598 static void CheckDataParameter( | 5598 static void CheckDataParameter( |
| 5599 const v8::FunctionCallbackInfo<v8::Value>& args) { | 5599 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 5600 v8::Handle<v8::String> data = | 5600 v8::Handle<v8::String> data = |
| 5601 v8::String::NewFromUtf8(args.GetIsolate(), "Test"); | 5601 v8::String::NewFromUtf8(args.GetIsolate(), "Test"); |
| 5602 CHECK(v8::Debug::Call(debugger_call_with_data, data)->IsString()); | 5602 CHECK(v8::Debug::Call(debugger_call_with_data, data)->IsString()); |
| 5603 | 5603 |
| 5604 for (int i = 0; i < 3; i++) { | 5604 for (int i = 0; i < 3; i++) { |
| 5605 v8::TryCatch catcher; | 5605 v8::TryCatch catcher(args.GetIsolate()); |
| 5606 CHECK(v8::Debug::Call(debugger_call_with_data).IsEmpty()); | 5606 CHECK(v8::Debug::Call(debugger_call_with_data).IsEmpty()); |
| 5607 CHECK(catcher.HasCaught()); | 5607 CHECK(catcher.HasCaught()); |
| 5608 CHECK(catcher.Exception()->IsString()); | 5608 CHECK(catcher.Exception()->IsString()); |
| 5609 } | 5609 } |
| 5610 } | 5610 } |
| 5611 | 5611 |
| 5612 | 5612 |
| 5613 // Function to test using a JavaScript with closure in the debugger. | 5613 // Function to test using a JavaScript with closure in the debugger. |
| 5614 static void CheckClosure(const v8::FunctionCallbackInfo<v8::Value>& args) { | 5614 static void CheckClosure(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 5615 CHECK(v8::Debug::Call(debugger_call_with_closure)->IsNumber()); | 5615 CHECK(v8::Debug::Call(debugger_call_with_closure)->IsNumber()); |
| (...skipping 1644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7260 static void DebugEventStepNext( | 7260 static void DebugEventStepNext( |
| 7261 const v8::Debug::EventDetails& event_details) { | 7261 const v8::Debug::EventDetails& event_details) { |
| 7262 v8::DebugEvent event = event_details.GetEvent(); | 7262 v8::DebugEvent event = event_details.GetEvent(); |
| 7263 if (event == v8::Break) { | 7263 if (event == v8::Break) { |
| 7264 PrepareStep(StepNext); | 7264 PrepareStep(StepNext); |
| 7265 } | 7265 } |
| 7266 } | 7266 } |
| 7267 | 7267 |
| 7268 | 7268 |
| 7269 static void RunScriptInANewCFrame(const char* source) { | 7269 static void RunScriptInANewCFrame(const char* source) { |
| 7270 v8::TryCatch try_catch; | 7270 v8::TryCatch try_catch(CcTest::isolate()); |
| 7271 CompileRun(source); | 7271 CompileRun(source); |
| 7272 CHECK(try_catch.HasCaught()); | 7272 CHECK(try_catch.HasCaught()); |
| 7273 } | 7273 } |
| 7274 | 7274 |
| 7275 | 7275 |
| 7276 TEST(Regress131642) { | 7276 TEST(Regress131642) { |
| 7277 // Bug description: | 7277 // Bug description: |
| 7278 // When doing StepNext through the first script, the debugger is not reset | 7278 // When doing StepNext through the first script, the debugger is not reset |
| 7279 // after exiting through exception. A flawed implementation enabling the | 7279 // after exiting through exception. A flawed implementation enabling the |
| 7280 // debugger to step into Array.prototype.forEach breaks inside the callback | 7280 // debugger to step into Array.prototype.forEach breaks inside the callback |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7440 }; | 7440 }; |
| 7441 | 7441 |
| 7442 | 7442 |
| 7443 TEST(DebugBreakOffThreadTerminate) { | 7443 TEST(DebugBreakOffThreadTerminate) { |
| 7444 DebugLocalContext env; | 7444 DebugLocalContext env; |
| 7445 v8::Isolate* isolate = env->GetIsolate(); | 7445 v8::Isolate* isolate = env->GetIsolate(); |
| 7446 v8::HandleScope scope(isolate); | 7446 v8::HandleScope scope(isolate); |
| 7447 v8::Debug::SetDebugEventListener(DebugBreakTriggerTerminate); | 7447 v8::Debug::SetDebugEventListener(DebugBreakTriggerTerminate); |
| 7448 TerminationThread terminator(isolate); | 7448 TerminationThread terminator(isolate); |
| 7449 terminator.Start(); | 7449 terminator.Start(); |
| 7450 v8::TryCatch try_catch; | 7450 v8::TryCatch try_catch(env->GetIsolate()); |
| 7451 v8::Debug::DebugBreak(isolate); | 7451 v8::Debug::DebugBreak(isolate); |
| 7452 CompileRun("while (true);"); | 7452 CompileRun("while (true);"); |
| 7453 CHECK(try_catch.HasTerminated()); | 7453 CHECK(try_catch.HasTerminated()); |
| 7454 } | 7454 } |
| 7455 | 7455 |
| 7456 | 7456 |
| 7457 static void DebugEventExpectNoException( | 7457 static void DebugEventExpectNoException( |
| 7458 const v8::Debug::EventDetails& event_details) { | 7458 const v8::Debug::EventDetails& event_details) { |
| 7459 v8::DebugEvent event = event_details.GetEvent(); | 7459 v8::DebugEvent event = event_details.GetEvent(); |
| 7460 CHECK_NE(v8::Exception, event); | 7460 CHECK_NE(v8::Exception, event); |
| 7461 } | 7461 } |
| 7462 | 7462 |
| 7463 | 7463 |
| 7464 static void TryCatchWrappedThrowCallback( | 7464 static void TryCatchWrappedThrowCallback( |
| 7465 const v8::FunctionCallbackInfo<v8::Value>& args) { | 7465 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 7466 v8::TryCatch try_catch; | 7466 v8::TryCatch try_catch(args.GetIsolate()); |
| 7467 CompileRun("throw 'rejection';"); | 7467 CompileRun("throw 'rejection';"); |
| 7468 CHECK(try_catch.HasCaught()); | 7468 CHECK(try_catch.HasCaught()); |
| 7469 } | 7469 } |
| 7470 | 7470 |
| 7471 | 7471 |
| 7472 TEST(DebugPromiseInterceptedByTryCatch) { | 7472 TEST(DebugPromiseInterceptedByTryCatch) { |
| 7473 DebugLocalContext env; | 7473 DebugLocalContext env; |
| 7474 v8::Isolate* isolate = env->GetIsolate(); | 7474 v8::Isolate* isolate = env->GetIsolate(); |
| 7475 v8::HandleScope scope(isolate); | 7475 v8::HandleScope scope(isolate); |
| 7476 v8::Debug::SetDebugEventListener(&DebugEventExpectNoException); | 7476 v8::Debug::SetDebugEventListener(&DebugEventExpectNoException); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7600 "let y = 2; \n" | 7600 "let y = 2; \n" |
| 7601 "debugger; \n" | 7601 "debugger; \n" |
| 7602 "x * y", | 7602 "x * y", |
| 7603 30); | 7603 30); |
| 7604 ExpectInt32( | 7604 ExpectInt32( |
| 7605 "x = 1; y = 2; \n" | 7605 "x = 1; y = 2; \n" |
| 7606 "debugger;" | 7606 "debugger;" |
| 7607 "x * y", | 7607 "x * y", |
| 7608 30); | 7608 30); |
| 7609 } | 7609 } |
| OLD | NEW |