| Index: src/debug.cc
|
| diff --git a/src/debug.cc b/src/debug.cc
|
| index e2964a91f55d4daa5b267cb77c24fb3acc789da9..66fb65218bb0fa7814c91928c59dd432ac1d7f4a 100644
|
| --- a/src/debug.cc
|
| +++ b/src/debug.cc
|
| @@ -565,7 +565,7 @@ void Debug::ThreadInit() {
|
| thread_local_.step_into_fp_ = 0;
|
| thread_local_.step_out_fp_ = 0;
|
| // TODO(isolates): frames_are_dropped_?
|
| - thread_local_.debugger_entry_ = NULL;
|
| + thread_local_.current_debug_scope_ = NULL;
|
| thread_local_.restarter_frame_function_pointer_ = NULL;
|
| thread_local_.promise_on_stack_ = NULL;
|
| }
|
| @@ -894,8 +894,8 @@ void Debug::Break(Arguments args, JavaScriptFrame* frame) {
|
| if (break_disabled_) return;
|
|
|
| // Enter the debugger.
|
| - EnterDebugger debugger(isolate_);
|
| - if (debugger.FailedToEnter()) return;
|
| + DebugScope debug_scope(this);
|
| + if (debug_scope.failed()) return;
|
|
|
| // Postpone interrupt during breakpoint processing.
|
| PostponeInterruptsScope postpone(isolate_);
|
| @@ -1348,7 +1348,7 @@ void Debug::PrepareStep(StepAction step_action,
|
|
|
| PrepareForBreakPoints();
|
|
|
| - ASSERT(is_entered());
|
| + ASSERT(in_debug_scope());
|
|
|
| // Remember this step action and count.
|
| thread_local_.last_step_action_ = step_action;
|
| @@ -2458,7 +2458,7 @@ bool Debug::IsDebugGlobal(GlobalObject* global) {
|
| void Debug::ClearMirrorCache() {
|
| PostponeInterruptsScope postpone(isolate_);
|
| HandleScope scope(isolate_);
|
| - ASSERT(isolate_->context() == *Debug::debug_context());
|
| + AssertDebugContext();
|
|
|
| // Clear the mirror cache.
|
| Handle<Object> fun = Object::GetProperty(
|
| @@ -2514,7 +2514,7 @@ void Debug::AfterGarbageCollection() {
|
| MaybeHandle<Object> Debug::MakeJSObject(const char* constructor_name,
|
| int argc,
|
| Handle<Object> argv[]) {
|
| - ASSERT(isolate_->context() == *debug_context());
|
| + AssertDebugContext();
|
| // Create the execution state object.
|
| Handle<Object> constructor = Object::GetProperty(
|
| isolate_, isolate_->global_object(), constructor_name).ToHandleChecked();
|
| @@ -2581,7 +2581,7 @@ MaybeHandle<Object> Debug::MakeScriptCollectedEvent(int id) {
|
|
|
|
|
| void Debug::OnException(Handle<Object> exception, bool uncaught) {
|
| - if (is_entered() || ignore_events()) return;
|
| + if (in_debug_scope() || ignore_events()) return;
|
|
|
| HandleScope scope(isolate_);
|
| Handle<Object> promise = GetPromiseForUncaughtException();
|
| @@ -2596,9 +2596,8 @@ void Debug::OnException(Handle<Object> exception, bool uncaught) {
|
| if (!break_on_exception_) return;
|
| }
|
|
|
| - // Enter the debugger.
|
| - EnterDebugger debugger(isolate_);
|
| - if (debugger.FailedToEnter()) return;
|
| + DebugScope debug_scope(this);
|
| + if (debug_scope.failed()) return;
|
|
|
| // Clear all current stepping setup.
|
| ClearStepping();
|
| @@ -2619,8 +2618,8 @@ void Debug::OnException(Handle<Object> exception, bool uncaught) {
|
|
|
| void Debug::OnDebugBreak(Handle<Object> break_points_hit,
|
| bool auto_continue) {
|
| - // Debugger has already been entered by caller.
|
| - ASSERT(isolate_->context() == *debug_context());
|
| + // The caller provided for DebugScope.
|
| + AssertDebugContext();
|
| // Bail out if there is no listener for this event
|
| if (ignore_events()) return;
|
|
|
| @@ -2638,12 +2637,11 @@ void Debug::OnDebugBreak(Handle<Object> break_points_hit,
|
|
|
|
|
| void Debug::OnBeforeCompile(Handle<Script> script) {
|
| - if (is_entered() || ignore_events()) return;
|
| + if (in_debug_scope() || ignore_events()) return;
|
|
|
| HandleScope scope(isolate_);
|
| - // Enter the debugger.
|
| - EnterDebugger debugger(isolate_);
|
| - if (debugger.FailedToEnter()) return;
|
| + DebugScope debug_scope(this);
|
| + if (debug_scope.failed()) return;
|
|
|
| // Create the event data object.
|
| Handle<Object> event_data;
|
| @@ -2664,15 +2662,14 @@ void Debug::OnAfterCompile(Handle<Script> script,
|
| if (script_cache_ != NULL) script_cache_->Add(script);
|
|
|
| // No more to do if not debugging.
|
| - if (is_entered() || ignore_events()) return;
|
| + if (in_debug_scope() || ignore_events()) return;
|
|
|
| HandleScope scope(isolate_);
|
| // Store whether in debugger before entering debugger.
|
| - bool in_debugger = is_entered();
|
| + bool was_in_scope = in_debug_scope();
|
|
|
| - // Enter the debugger.
|
| - EnterDebugger debugger(isolate_);
|
| - if (debugger.FailedToEnter()) return;
|
| + DebugScope debug_scope(this);
|
| + if (debug_scope.failed()) return;
|
|
|
| // If debugging there might be script break points registered for this
|
| // script. Make sure that these break points are set.
|
| @@ -2703,7 +2700,7 @@ void Debug::OnAfterCompile(Handle<Script> script,
|
| return;
|
| }
|
| // Bail out based on state or if there is no listener for this event
|
| - if (in_debugger && (after_compile_flags & SEND_WHEN_DEBUGGING) == 0) return;
|
| + if (was_in_scope && (after_compile_flags & SEND_WHEN_DEBUGGING) == 0) return;
|
|
|
| // Create the compile state object.
|
| Handle<Object> event_data;
|
| @@ -2716,12 +2713,11 @@ void Debug::OnAfterCompile(Handle<Script> script,
|
|
|
|
|
| void Debug::OnScriptCollected(int id) {
|
| - if (is_entered() || ignore_events()) return;
|
| + if (in_debug_scope() || ignore_events()) return;
|
|
|
| HandleScope scope(isolate_);
|
| - // Enter the debugger.
|
| - EnterDebugger debugger(isolate_);
|
| - if (debugger.FailedToEnter()) return;
|
| + DebugScope debug_scope(this);
|
| + if (debug_scope.failed()) return;
|
|
|
| // Create the script collected state object.
|
| Handle<Object> event_data;
|
| @@ -2806,7 +2802,7 @@ void Debug::CallEventCallback(v8::DebugEvent event,
|
|
|
|
|
| Handle<Context> Debug::GetDebugContext() {
|
| - EnterDebugger debugger(isolate_);
|
| + DebugScope debug_scope(this);
|
| // The global handle may be destroyed soon after. Return it reboxed.
|
| return handle(*debug_context(), isolate_);
|
| }
|
| @@ -2845,7 +2841,7 @@ void Debug::NotifyMessageHandler(v8::DebugEvent event,
|
| // The debug command interrupt flag might have been set when the command was
|
| // added. It should be enough to clear the flag only once while we are in the
|
| // debugger.
|
| - ASSERT(is_entered());
|
| + ASSERT(in_debug_scope());
|
| isolate_->stack_guard()->ClearDebugCommand();
|
|
|
| // Notify the debugger that a debug event has occurred unless auto continue is
|
| @@ -2967,7 +2963,7 @@ void Debug::SetEventListener(Handle<Object> callback,
|
| void Debug::SetMessageHandler(v8::Debug::MessageHandler handler) {
|
| message_handler_ = handler;
|
| UpdateState();
|
| - if (handler == NULL && is_entered()) {
|
| + if (handler == NULL && in_debug_scope()) {
|
| // Send an empty command to the debugger if in a break to make JavaScript
|
| // run again if the debugger is closed.
|
| EnqueueCommandMessage(Vector<const uint16_t>::empty());
|
| @@ -2978,12 +2974,12 @@ void Debug::SetMessageHandler(v8::Debug::MessageHandler handler) {
|
|
|
| void Debug::UpdateState() {
|
| is_active_ = message_handler_ != NULL || !event_listener_.is_null();
|
| - if (is_active_ || is_entered()) {
|
| + if (is_active_ || in_debug_scope()) {
|
| // Note that the debug context could have already been loaded to
|
| // bootstrap test cases.
|
| isolate_->compilation_cache()->Disable();
|
| is_active_ = Load();
|
| - } else if (is_loaded() && !is_active_) {
|
| + } else if (is_loaded()) {
|
| isolate_->compilation_cache()->Enable();
|
| Unload();
|
| }
|
| @@ -3013,7 +3009,7 @@ void Debug::EnqueueCommandMessage(Vector<const uint16_t> command,
|
| command_received_.Signal();
|
|
|
| // Set the debug command break flag to have the command processed.
|
| - if (!is_entered()) isolate_->stack_guard()->RequestDebugCommand();
|
| + if (!in_debug_scope()) isolate_->stack_guard()->RequestDebugCommand();
|
| }
|
|
|
|
|
| @@ -3022,16 +3018,13 @@ void Debug::EnqueueDebugCommand(v8::Debug::ClientData* client_data) {
|
| event_command_queue_.Put(message);
|
|
|
| // Set the debug command break flag to have the command processed.
|
| - if (!is_entered()) isolate_->stack_guard()->RequestDebugCommand();
|
| + if (!in_debug_scope()) isolate_->stack_guard()->RequestDebugCommand();
|
| }
|
|
|
|
|
| MaybeHandle<Object> Debug::Call(Handle<JSFunction> fun, Handle<Object> data) {
|
| - // Enter the debugger.
|
| - EnterDebugger debugger(isolate_);
|
| - if (debugger.FailedToEnter()) {
|
| - return isolate_->factory()->undefined_value();
|
| - }
|
| + DebugScope debug_scope(this);
|
| + if (debug_scope.failed()) return isolate_->factory()->undefined_value();
|
|
|
| // Create the execution state.
|
| Handle<Object> exec_state;
|
| @@ -3089,9 +3082,8 @@ void Debug::ProcessDebugMessages(bool debug_command_only) {
|
| if (check.HasOverflowed()) return;
|
|
|
| HandleScope scope(isolate_);
|
| - // Enter the debugger. Just continue if we fail to enter the debugger.
|
| - EnterDebugger debugger(isolate_);
|
| - if (debugger.FailedToEnter()) return;
|
| + DebugScope debug_scope(this);
|
| + if (debug_scope.failed()) return;
|
|
|
| // Notify the debug event listeners. Indicate auto continue if the break was
|
| // a debug command break.
|
| @@ -3099,59 +3091,54 @@ void Debug::ProcessDebugMessages(bool debug_command_only) {
|
| }
|
|
|
|
|
| -EnterDebugger::EnterDebugger(Isolate* isolate)
|
| - : isolate_(isolate),
|
| - prev_(isolate_->debug()->debugger_entry()),
|
| - save_(isolate_) {
|
| - Debug* debug = isolate_->debug();
|
| -
|
| +DebugScope::DebugScope(Debug* debug) : debug_(debug),
|
| + prev_(debug->debugger_entry()),
|
| + save_(debug_->isolate_) {
|
| // Link recursive debugger entry.
|
| - debug->thread_local_.debugger_entry_ = this;
|
| + debug_->thread_local_.current_debug_scope_ = this;
|
|
|
| // Store the previous break id and frame id.
|
| - break_id_ = debug->break_id();
|
| - break_frame_id_ = debug->break_frame_id();
|
| + break_id_ = debug_->break_id();
|
| + break_frame_id_ = debug_->break_frame_id();
|
|
|
| // Create the new break info. If there is no JavaScript frames there is no
|
| // break frame id.
|
| - JavaScriptFrameIterator it(isolate_);
|
| + JavaScriptFrameIterator it(isolate());
|
| bool has_js_frames = !it.done();
|
| - debug->thread_local_.break_frame_id_ = has_js_frames ? it.frame()->id()
|
| - : StackFrame::NO_ID;
|
| - debug->SetNextBreakId();
|
| + debug_->thread_local_.break_frame_id_ = has_js_frames ? it.frame()->id()
|
| + : StackFrame::NO_ID;
|
| + debug_->SetNextBreakId();
|
|
|
| - debug->UpdateState();
|
| + debug_->UpdateState();
|
| // Make sure that debugger is loaded and enter the debugger context.
|
| // The previous context is kept in save_.
|
| - load_failed_ = !debug->is_loaded();
|
| - if (!load_failed_) isolate_->set_context(*debug->debug_context());
|
| + failed_ = !debug_->is_loaded();
|
| + if (!failed_) isolate()->set_context(*debug->debug_context());
|
| }
|
|
|
|
|
| -EnterDebugger::~EnterDebugger() {
|
| - Debug* debug = isolate_->debug();
|
|
|
| - // Restore to the previous break state.
|
| - debug->thread_local_.break_frame_id_ = break_frame_id_;
|
| - debug->thread_local_.break_id_ = break_id_;
|
| -
|
| - // Check for leaving the debugger.
|
| - if (!load_failed_ && prev_ == NULL) {
|
| +DebugScope::~DebugScope() {
|
| + if (!failed_ && prev_ == NULL) {
|
| // Clear mirror cache when leaving the debugger. Skip this if there is a
|
| // pending exception as clearing the mirror cache calls back into
|
| // JavaScript. This can happen if the v8::Debug::Call is used in which
|
| // case the exception should end up in the calling code.
|
| - if (!isolate_->has_pending_exception()) debug->ClearMirrorCache();
|
| + if (!isolate()->has_pending_exception()) debug_->ClearMirrorCache();
|
|
|
| // If there are commands in the queue when leaving the debugger request
|
| // that these commands are processed.
|
| - if (debug->has_commands()) isolate_->stack_guard()->RequestDebugCommand();
|
| + if (debug_->has_commands()) isolate()->stack_guard()->RequestDebugCommand();
|
| }
|
|
|
| // Leaving this debugger entry.
|
| - debug->thread_local_.debugger_entry_ = prev_;
|
| + debug_->thread_local_.current_debug_scope_ = prev_;
|
| +
|
| + // Restore to the previous break state.
|
| + debug_->thread_local_.break_frame_id_ = break_frame_id_;
|
| + debug_->thread_local_.break_id_ = break_id_;
|
|
|
| - debug->UpdateState();
|
| + debug_->UpdateState();
|
| }
|
|
|
|
|
|
|