diff --git a/API/hermes/cdp/CDPAgent.cpp b/API/hermes/cdp/CDPAgent.cpp index 10e577e72c4..db4cb5975e5 100644 --- a/API/hermes/cdp/CDPAgent.cpp +++ b/API/hermes/cdp/CDPAgent.cpp @@ -63,10 +63,14 @@ class CDPAgentImpl { /// Process a CDP command encoded in \p json. void handleCommand(std::string json); - /// Enable the Runtime domain without processing a CDP command or send a CDP - /// response. + /// Enable the Runtime domain without processing a CDP command or sending a + /// CDP response. void enableRuntimeDomain(); + /// Enable the Debugger domain without processing a CDP command or sending a + /// CDP response. + void enableDebuggerDomain(); + /// Extract state to be persisted across reloads. State getState(); @@ -92,10 +96,14 @@ class CDPAgentImpl { /// handler. void handleCommand(std::shared_ptr command); - /// Enable the Runtime domain without processing a CDP command or send a CDP - /// response. + /// Enable the Runtime domain without processing a CDP command or sending a + /// CDP response. void enableRuntimeDomain(); + /// Enable the Debugger domain without processing a CDP command or sending a + /// CDP response. + void enableDebuggerDomain(); + /// Get the Debugger domain state to be persisted. std::unique_ptr getDebuggerDomainState(); @@ -220,6 +228,13 @@ void CDPAgentImpl::enableRuntimeDomain() { }); } +void CDPAgentImpl::enableDebuggerDomain() { + runtimeTaskRunner_.enqueueTask( + [domainAgents = domainAgents_](HermesRuntime &) { + domainAgents->enableDebuggerDomain(); + }); +} + State CDPAgentImpl::getState() { // This function might not be called on the runtime thread. Functions on // DomainAgents expect to be called on the runtime thread because they @@ -366,6 +381,11 @@ void CDPAgentImpl::DomainAgents::enableRuntimeDomain() { runtimeAgent_->enable(); } +void CDPAgentImpl::DomainAgents::enableDebuggerDomain() { + std::lock_guard lock(mutex_); + debuggerAgent_->enable(); +} + std::unique_ptr CDPAgentImpl::DomainAgents::getDebuggerDomainState() { std::lock_guard lock(mutex_); @@ -413,6 +433,10 @@ void CDPAgent::enableRuntimeDomain() { impl_->enableRuntimeDomain(); } +void CDPAgent::enableDebuggerDomain() { + impl_->enableDebuggerDomain(); +} + State CDPAgent::getState() { return impl_->getState(); } diff --git a/API/hermes/cdp/CDPAgent.h b/API/hermes/cdp/CDPAgent.h index 386208269d8..56b03874ff5 100644 --- a/API/hermes/cdp/CDPAgent.h +++ b/API/hermes/cdp/CDPAgent.h @@ -101,10 +101,14 @@ class HERMES_EXPORT CDPAgent { /// arbitrary threads. void handleCommand(std::string json); - /// Enable the Runtime domain without processing a CDP command or send a CDP - /// response. This can be called from arbitrary threads. + /// Enable the Runtime domain without processing a CDP command or sending a + /// CDP response. This can be called from arbitrary threads. void enableRuntimeDomain(); + /// Enable the Debugger domain without processing a CDP command or sending a + /// CDP response. This can be called from arbitrary threads. + void enableDebuggerDomain(); + /// Extract state to be persisted across reloads. This can be called from /// arbitrary threads. State getState(); diff --git a/API/hermes/cdp/DebuggerDomainAgent.cpp b/API/hermes/cdp/DebuggerDomainAgent.cpp index 7d9986a62e1..79e33819442 100644 --- a/API/hermes/cdp/DebuggerDomainAgent.cpp +++ b/API/hermes/cdp/DebuggerDomainAgent.cpp @@ -105,9 +105,8 @@ std::unique_ptr DebuggerDomainAgent::getState() { return state; } -void DebuggerDomainAgent::enable(const m::debugger::EnableRequest &req) { +void DebuggerDomainAgent::enable() { if (enabled_) { - sendResponseToClient(m::makeOkResponse(req.id)); return; } enabled_ = true; @@ -162,7 +161,11 @@ void DebuggerDomainAgent::enable(const m::debugger::EnableRequest &req) { paused_ = true; sendPausedNotificationToClient(); } +} +void DebuggerDomainAgent::enable(const m::debugger::EnableRequest &req) { + // Match V8 behavior of returning success even if domain is already enabled + enable(); sendResponseToClient(m::makeOkResponse(req.id)); } diff --git a/API/hermes/cdp/DebuggerDomainAgent.h b/API/hermes/cdp/DebuggerDomainAgent.h index 3d2e8f7bb65..37da0cdd08b 100644 --- a/API/hermes/cdp/DebuggerDomainAgent.h +++ b/API/hermes/cdp/DebuggerDomainAgent.h @@ -90,6 +90,9 @@ class DebuggerDomainAgent : public DomainAgent { /// Extract state to be persisted across reloads. std::unique_ptr getState(); + /// Enables the Debugger domain without processing CDP message or sending a + /// CDP response. It will still send CDP notifications if needed. + void enable(); /// Handles Debugger.enable request /// @cdp Debugger.enable If domain is already enabled, will return success. void enable(const m::debugger::EnableRequest &req); diff --git a/API/hermes/cdp/RuntimeDomainAgent.h b/API/hermes/cdp/RuntimeDomainAgent.h index b4065ff9c32..4a69e143baf 100644 --- a/API/hermes/cdp/RuntimeDomainAgent.h +++ b/API/hermes/cdp/RuntimeDomainAgent.h @@ -35,7 +35,7 @@ class RuntimeDomainAgent : public DomainAgent { ConsoleMessageDispatcher &consoleMessageDispatcher); ~RuntimeDomainAgent(); - /// Enables the Runtime domain without processing CDP message or send a CDP + /// Enables the Runtime domain without processing CDP message or sending a CDP /// response. It will still send CDP notifications if needed. void enable(); /// Handles Runtime.enable request