Chromium Code Reviews| Index: src/debug.cc |
| diff --git a/src/debug.cc b/src/debug.cc |
| index dadaa915d48e0fb17467097156c89047e57edf98..641d7e5a6463f5ccb49e1b14605415ed3a3b02db 100644 |
| --- a/src/debug.cc |
| +++ b/src/debug.cc |
| @@ -37,6 +37,7 @@ Debug::Debug(Isolate* isolate) |
| disable_break_(false), |
| break_on_exception_(false), |
| break_on_uncaught_exception_(false), |
| + current_promise_catch_handler_(NULL), |
| debug_break_return_(NULL), |
| debug_break_slot_(NULL), |
| isolate_(isolate) { |
| @@ -1317,6 +1318,53 @@ bool Debug::IsBreakOnException(ExceptionBreakType type) { |
| } |
| +void Debug::PromiseHandlePrologue(Handle<JSFunction> promise_getter) { |
| + ASSERT(current_promise_getter_.is_null()); |
| + current_promise_getter_ = Handle<JSFunction>::cast( |
| + isolate_->global_handles()->Create(*promise_getter)); |
| + current_promise_catch_handler_ = |
| + StackHandler::FromAddress(Isolate::handler(isolate_->thread_local_top())); |
| +} |
| + |
| + |
| +void Debug::PromiseHandleEpilogue() { |
| + current_promise_catch_handler_ = NULL; |
|
aandrey
2014/04/30 13:58:26
maybe add ASSERT(!current_promise_getter_.is_null(
Yang
2014/04/30 14:14:58
would make sense, but some runtime fuzzing tests w
|
| + Handle<Object> promise_getter; |
| + if (!current_promise_getter_.ToHandle(&promise_getter)) return; |
| + isolate_->global_handles()->Destroy(promise_getter.location()); |
| + current_promise_getter_ = MaybeHandle<JSFunction>(); |
| +} |
| + |
| + |
| +Handle<Object> Debug::GetPromiseForUncaughtException() { |
| + Handle<JSFunction> promise_getter; |
| + Handle<Object> undefined = isolate_->factory()->undefined_value(); |
| + if (current_promise_getter_.ToHandle(&promise_getter)) { |
| + // Find the top-most try-catch handler. |
| + StackHandler* handler = StackHandler::FromAddress( |
| + Isolate::handler(isolate_->thread_local_top())); |
| + while (handler != NULL && !handler->is_catch()) { |
| + handler = handler->next(); |
| + } |
| +#ifdef DEBUG |
| + // Make sure that our promise catch handler is in the list of handlers, |
| + // even if it's not the top-most try-catch handler. |
| + StackHandler* temp = handler; |
| + while (temp != current_promise_catch_handler_ && !temp->is_catch()) { |
| + temp = temp->next(); |
| + CHECK(temp != NULL); |
| + } |
| +#endif // DEBUG |
| + |
| + if (handler == current_promise_catch_handler_) { |
| + return Execution::Call( |
| + isolate_, promise_getter, undefined, 0, NULL).ToHandleChecked(); |
| + } |
| + } |
| + return undefined; |
| +} |
| + |
| + |
| void Debug::PrepareStep(StepAction step_action, |
| int step_count, |
| StackFrame::Id frame_id) { |
| @@ -2640,9 +2688,7 @@ MaybeHandle<Object> Debugger::MakeScriptCollectedEvent(int id) { |
| } |
| -void Debugger::OnException(Handle<Object> exception, |
| - bool uncaught, |
| - Handle<Object> promise) { |
| +void Debugger::OnException(Handle<Object> exception, bool uncaught) { |
| HandleScope scope(isolate_); |
| Debug* debug = isolate_->debug(); |
| @@ -2650,6 +2696,9 @@ void Debugger::OnException(Handle<Object> exception, |
| if (debug->InDebugger()) return; |
| if (!Debugger::EventActive(v8::Exception)) return; |
| + Handle<Object> promise = debug->GetPromiseForUncaughtException(); |
| + uncaught |= !promise->IsUndefined(); |
| + |
| // Bail out if exception breaks are not active |
| if (uncaught) { |
| // Uncaught exceptions are reported by either flags. |
| @@ -2667,10 +2716,6 @@ void Debugger::OnException(Handle<Object> exception, |
| // Clear all current stepping setup. |
| debug->ClearStepping(); |
| - // Determine event; |
| - DebugEvent event = promise->IsUndefined() |
| - ? v8::Exception : v8::PendingExceptionInPromise; |
| - |
| // Create the event data object. |
| Handle<Object> event_data; |
| // Bail out and don't call debugger if exception. |
| @@ -2680,7 +2725,7 @@ void Debugger::OnException(Handle<Object> exception, |
| } |
| // Process debug event. |
| - ProcessDebugEvent(event, Handle<JSObject>::cast(event_data), false); |
| + ProcessDebugEvent(v8::Exception, Handle<JSObject>::cast(event_data), false); |
| // Return to continue execution from where the exception was thrown. |
| } |
| @@ -3162,7 +3207,8 @@ void Debugger::SetMessageHandler(v8::Debug::MessageHandler2 handler) { |
| void Debugger::ListenersChanged() { |
| - if (IsDebuggerActive()) { |
| + bool active = IsDebuggerActive(); |
| + if (active) { |
| // Disable the compilation cache when the debugger is active. |
| isolate_->compilation_cache()->Disable(); |
| debugger_unload_pending_ = false; |