diff --git a/include/v8-debug.h b/include/v8-debug.h index 948972e9b5..ea6828baea 100644 --- a/include/v8-debug.h +++ b/include/v8-debug.h @@ -16,9 +16,11 @@ namespace v8 { enum DebugEvent { Break = 1, Exception = 2, - AfterCompile = 3, - CompileError = 4, - AsyncTaskEvent = 5, + NewFunction = 3, + BeforeCompile = 4, + AfterCompile = 5, + CompileError = 6, + AsyncTaskEvent = 7, }; class V8_EXPORT Debug { @@ -142,7 +144,7 @@ class V8_EXPORT Debug { * * \param message the debug message handler message object * - * A MessageHandler does not take possession of the message data, + * A MessageHandler2 does not take possession of the message data, * and must not rely on the data persisting after the handler returns. */ typedef void (*MessageHandler)(const Message& message); @@ -164,8 +166,7 @@ class V8_EXPORT Debug { static void CancelDebugBreak(Isolate* isolate); // Check if a debugger break is scheduled in the given isolate. - V8_DEPRECATED("No longer supported", - static bool CheckDebugBreak(Isolate* isolate)); + static bool CheckDebugBreak(Isolate* isolate); // Message based interface. The message protocol is JSON. V8_DEPRECATED("No longer supported", @@ -203,9 +204,8 @@ class V8_EXPORT Debug { /** * Returns a mirror object for the given object. */ - V8_DEPRECATED("No longer supported", - static MaybeLocal GetMirror(Local context, - v8::Local obj)); + static MaybeLocal GetMirror(Local context, + v8::Local obj); /** * Makes V8 process all pending debug messages. @@ -254,9 +254,7 @@ class V8_EXPORT Debug { * While in the debug context, this method returns the top-most non-debug * context, if it exists. */ - V8_DEPRECATED( - "No longer supported", - static MaybeLocal GetDebuggedContext(Isolate* isolate)); + static MaybeLocal GetDebuggedContext(Isolate* isolate); /** * Enable/disable LiveEdit functionality for the given Isolate diff --git a/src/api.cc b/src/api.cc index 6ab8c72d8c..b8210986f6 100644 --- a/src/api.cc +++ b/src/api.cc @@ -8734,7 +8734,9 @@ bool Debug::CheckDebugBreak(Isolate* isolate) { void Debug::SetMessageHandler(Isolate* isolate, v8::Debug::MessageHandler handler) { - UNIMPLEMENTED(); + i::Isolate* i_isolate = reinterpret_cast(isolate); + ENTER_V8(i_isolate); + i_isolate->debug()->SetMessageHandler(handler); } @@ -8742,7 +8744,9 @@ void Debug::SendCommand(Isolate* isolate, const uint16_t* command, int length, ClientData* client_data) { - UNIMPLEMENTED(); + i::Isolate* internal_isolate = reinterpret_cast(isolate); + internal_isolate->debug()->EnqueueCommandMessage( + i::Vector(command, length), client_data); } @@ -8767,11 +8771,28 @@ MaybeLocal Debug::Call(Local context, MaybeLocal Debug::GetMirror(Local context, v8::Local obj) { - UNIMPLEMENTED(); - return MaybeLocal(); + PREPARE_FOR_EXECUTION(context, Debug, GetMirror, Value); + i::Debug* isolate_debug = isolate->debug(); + has_pending_exception = !isolate_debug->Load(); + RETURN_ON_FAILED_EXECUTION(Value); + i::Handle debug(isolate_debug->debug_context()->global_object()); + auto name = isolate->factory()->NewStringFromStaticChars("MakeMirror"); + auto fun_obj = i::JSReceiver::GetProperty(debug, name).ToHandleChecked(); + auto v8_fun = Utils::CallableToLocal(i::Handle::cast(fun_obj)); + const int kArgc = 1; + v8::Local argv[kArgc] = {obj}; + Local result; + has_pending_exception = + !v8_fun->Call(context, Utils::ToLocal(debug), kArgc, argv) + .ToLocal(&result); + RETURN_ON_FAILED_EXECUTION(Value); + RETURN_ESCAPED(result); +} + +void Debug::ProcessDebugMessages(Isolate* isolate) { + reinterpret_cast(isolate)->debug()->ProcessDebugMessages(true); } -void Debug::ProcessDebugMessages(Isolate* isolate) { UNIMPLEMENTED(); } Local Debug::GetDebugContext(Isolate* isolate) { i::Isolate* i_isolate = reinterpret_cast(isolate); @@ -8781,8 +8802,12 @@ Local Debug::GetDebugContext(Isolate* isolate) { MaybeLocal Debug::GetDebuggedContext(Isolate* isolate) { - UNIMPLEMENTED(); - return MaybeLocal(); + i::Isolate* i_isolate = reinterpret_cast(isolate); + ENTER_V8(i_isolate); + if (!i_isolate->debug()->in_debug_scope()) return MaybeLocal(); + i::Handle calling = i_isolate->GetCallingNativeContext(); + if (calling.is_null()) return MaybeLocal(); + return Utils::ToLocal(i::Handle::cast(calling)); } void Debug::SetLiveEditEnabled(Isolate* isolate, bool enable) { diff --git a/src/compiler.cc b/src/compiler.cc index 2d0cf06cbd..c5f84ebde5 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -962,6 +962,8 @@ Handle CompileToplevel(CompilationInfo* info) { FixedArray* array = isolate->native_context()->embedder_data(); script->set_context_data(array->get(v8::Context::kDebugIdIndex)); + isolate->debug()->OnBeforeCompile(script); + Handle result; { VMState state(info->isolate()); diff --git a/src/debug/debug.cc b/src/debug/debug.cc index 919f968658..65a708a8f7 100644 --- a/src/debug/debug.cc +++ b/src/debug/debug.cc @@ -38,6 +38,9 @@ Debug::Debug(Isolate* isolate) : debug_context_(Handle()), event_listener_(Handle()), event_listener_data_(Handle()), + message_handler_(NULL), + command_received_(0), + command_queue_(isolate->logger(), kQueueInitialSize), is_active_(false), is_suppressed_(false), live_edit_enabled_(true), // TODO(yangguo): set to false by default. @@ -522,7 +525,7 @@ void Debug::Break(JavaScriptFrame* frame) { // Clear all current stepping setup. ClearStepping(); // Notify the debug event listeners. - OnDebugBreak(break_points_hit); + OnDebugBreak(break_points_hit, false); return; } @@ -566,7 +569,7 @@ void Debug::Break(JavaScriptFrame* frame) { if (step_break) { // Notify the debug event listeners. - OnDebugBreak(isolate_->factory()->undefined_value()); + OnDebugBreak(isolate_->factory()->undefined_value(), false); } else { // Re-prepare to continue. PrepareStep(step_action); @@ -1744,11 +1747,11 @@ void Debug::OnException(Handle exception, Handle promise) { } // Process debug event. - ProcessDebugEvent(v8::Exception, Handle::cast(event_data)); + ProcessDebugEvent(v8::Exception, Handle::cast(event_data), false); // Return to continue execution from where the exception was thrown. } -void Debug::OnDebugBreak(Handle break_points_hit) { +void Debug::OnDebugBreak(Handle break_points_hit, bool auto_continue) { // The caller provided for DebugScope. AssertDebugContext(); // Bail out if there is no listener for this event @@ -1765,7 +1768,8 @@ void Debug::OnDebugBreak(Handle break_points_hit) { if (!MakeBreakEvent(break_points_hit).ToHandle(&event_data)) return; // Process debug event. - ProcessDebugEvent(v8::Break, Handle::cast(event_data)); + ProcessDebugEvent(v8::Break, Handle::cast(event_data), + auto_continue); } @@ -1773,6 +1777,9 @@ void Debug::OnCompileError(Handle