From 28f5cf398ed8752d22f28e279f04910aadd5c677 Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Fri, 25 Apr 2014 07:03:05 +0000 Subject: [PATCH] Trigger debug event on not yet caught exception in promises. R=aandrey@chromium.org, rossberg@chromium.org, yurys@chromium.org BUG=v8:3093 LOG=Y Review URL: https://codereview.chromium.org/249503002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20956 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- include/v8-debug.h | 3 +- src/debug-debugger.js | 15 ++++-- src/debug.cc | 22 ++++++-- src/debug.h | 8 ++- src/execution.cc | 4 +- src/isolate.cc | 3 +- src/promise.js | 19 +++++-- src/runtime.cc | 15 +++++- src/runtime.h | 1 + test/mjsunit/es6/debug-promises-caught-all.js | 56 +++++++++++++++++++ test/mjsunit/es6/debug-promises-caught-uncaught.js | 42 +++++++++++++++ test/mjsunit/es6/debug-promises-throw-in-reject.js | 61 +++++++++++++++++++++ test/mjsunit/es6/debug-promises-uncaught-all.js | 62 ++++++++++++++++++++++ .../es6/debug-promises-uncaught-uncaught.js | 54 +++++++++++++++++++ .../mjsunit/es6/debug-promises-undefined-reject.js | 57 ++++++++++++++++++++ 15 files changed, 402 insertions(+), 20 deletions(-) create mode 100644 test/mjsunit/es6/debug-promises-caught-all.js create mode 100644 test/mjsunit/es6/debug-promises-caught-uncaught.js create mode 100644 test/mjsunit/es6/debug-promises-throw-in-reject.js create mode 100644 test/mjsunit/es6/debug-promises-uncaught-all.js create mode 100644 test/mjsunit/es6/debug-promises-uncaught-uncaught.js create mode 100644 test/mjsunit/es6/debug-promises-undefined-reject.js diff --git a/include/v8-debug.h b/include/v8-debug.h index 49916fe..6b2c278 100644 --- a/include/v8-debug.h +++ b/include/v8-debug.h @@ -43,7 +43,8 @@ enum DebugEvent { BeforeCompile = 4, AfterCompile = 5, ScriptCollected = 6, - BreakForCommand = 7 + UncaughtExceptionInPromise = 7, + BreakForCommand = 8 }; diff --git a/src/debug-debugger.js b/src/debug-debugger.js index d759fe5..aebef47 100644 --- a/src/debug-debugger.js +++ b/src/debug-debugger.js @@ -42,7 +42,8 @@ Debug.DebugEvent = { Break: 1, NewFunction: 3, BeforeCompile: 4, AfterCompile: 5, - ScriptCollected: 6 }; + ScriptCollected: 6, + PendingExceptionInPromise: 7 }; // Types of exceptions that can be broken upon. Debug.ExceptionBreak = { Caught : 0, @@ -1093,15 +1094,16 @@ BreakEvent.prototype.toJSONProtocol = function() { }; -function MakeExceptionEvent(exec_state, exception, uncaught) { - return new ExceptionEvent(exec_state, exception, uncaught); +function MakeExceptionEvent(exec_state, exception, uncaught, promise) { + return new ExceptionEvent(exec_state, exception, uncaught, promise); } -function ExceptionEvent(exec_state, exception, uncaught) { +function ExceptionEvent(exec_state, exception, uncaught, promise) { this.exec_state_ = exec_state; this.exception_ = exception; this.uncaught_ = uncaught; + this.promise_ = promise; } @@ -1125,6 +1127,11 @@ ExceptionEvent.prototype.uncaught = function() { }; +ExceptionEvent.prototype.promise = function() { + return this.promise_; +}; + + ExceptionEvent.prototype.func = function() { return this.exec_state_.frame(0).func(); }; diff --git a/src/debug.cc b/src/debug.cc index b41375b..c6a224e 100644 --- a/src/debug.cc +++ b/src/debug.cc @@ -2628,13 +2628,15 @@ MaybeHandle Debugger::MakeBreakEvent(Handle break_points_hit) { MaybeHandle Debugger::MakeExceptionEvent(Handle exception, - bool uncaught) { + bool uncaught, + Handle promise) { Handle exec_state; if (!MakeExecutionState().ToHandle(&exec_state)) return MaybeHandle(); // Create the new exception event object. Handle argv[] = { exec_state, exception, - isolate_->factory()->ToBoolean(uncaught) }; + isolate_->factory()->ToBoolean(uncaught), + promise }; return MakeJSObject(CStrVector("MakeExceptionEvent"), ARRAY_SIZE(argv), argv); } @@ -2664,7 +2666,9 @@ MaybeHandle Debugger::MakeScriptCollectedEvent(int id) { } -void Debugger::OnException(Handle exception, bool uncaught) { +void Debugger::OnException(Handle exception, + bool uncaught, + Handle promise) { HandleScope scope(isolate_); Debug* debug = isolate_->debug(); @@ -2688,13 +2692,21 @@ void Debugger::OnException(Handle exception, bool uncaught) { // Clear all current stepping setup. debug->ClearStepping(); + + // Determine event; + DebugEvent event = promise->IsUndefined() + ? v8::Exception : v8::UncaughtExceptionInPromise; + // Create the event data object. Handle event_data; // Bail out and don't call debugger if exception. - if (!MakeExceptionEvent(exception, uncaught).ToHandle(&event_data)) return; + if (!MakeExceptionEvent( + exception, uncaught, promise).ToHandle(&event_data)) { + return; + } // Process debug event. - ProcessDebugEvent(v8::Exception, Handle::cast(event_data), false); + ProcessDebugEvent(event, Handle::cast(event_data), false); // Return to continue execution from where the exception was thrown. } diff --git a/src/debug.h b/src/debug.h index b0a6892..b132243 100644 --- a/src/debug.h +++ b/src/debug.h @@ -793,13 +793,17 @@ class Debugger { MUST_USE_RESULT MaybeHandle MakeBreakEvent( Handle break_points_hit); MUST_USE_RESULT MaybeHandle MakeExceptionEvent( - Handle exception, bool uncaught); + Handle exception, + bool uncaught, + Handle promise); MUST_USE_RESULT MaybeHandle MakeCompileEvent( Handle