Skip to content

Commit

Permalink
CDPAgent::enableDebuggerDomain
Browse files Browse the repository at this point in the history
Summary: Adds the `CDPAgent::enableDebuggerDomain` as a direct parallel of the existing `CDPAgent::enableRuntimeDomain`.

Reviewed By: robhogan

Differential Revision: D54712524

fbshipit-source-id: efbfd0775d59803847d5478f355c197cbfeafae6
  • Loading branch information
motiz88 authored and facebook-github-bot committed Mar 12, 2024
1 parent 5f3fbb0 commit b0fb9c9
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
32 changes: 28 additions & 4 deletions API/hermes/cdp/CDPAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -92,10 +96,14 @@ class CDPAgentImpl {
/// handler.
void handleCommand(std::shared_ptr<message::Request> 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<DebuggerDomainState> getDebuggerDomainState();

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -366,6 +381,11 @@ void CDPAgentImpl::DomainAgents::enableRuntimeDomain() {
runtimeAgent_->enable();
}

void CDPAgentImpl::DomainAgents::enableDebuggerDomain() {
std::lock_guard<std::mutex> lock(mutex_);
debuggerAgent_->enable();
}

std::unique_ptr<DebuggerDomainState>
CDPAgentImpl::DomainAgents::getDebuggerDomainState() {
std::lock_guard<std::mutex> lock(mutex_);
Expand Down Expand Up @@ -413,6 +433,10 @@ void CDPAgent::enableRuntimeDomain() {
impl_->enableRuntimeDomain();
}

void CDPAgent::enableDebuggerDomain() {
impl_->enableDebuggerDomain();
}

State CDPAgent::getState() {
return impl_->getState();
}
Expand Down
8 changes: 6 additions & 2 deletions API/hermes/cdp/CDPAgent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 5 additions & 2 deletions API/hermes/cdp/DebuggerDomainAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ std::unique_ptr<DebuggerDomainState> 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;
Expand Down Expand Up @@ -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));
}

Expand Down
3 changes: 3 additions & 0 deletions API/hermes/cdp/DebuggerDomainAgent.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ class DebuggerDomainAgent : public DomainAgent {
/// Extract state to be persisted across reloads.
std::unique_ptr<DebuggerDomainState> 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);
Expand Down
2 changes: 1 addition & 1 deletion API/hermes/cdp/RuntimeDomainAgent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b0fb9c9

Please sign in to comment.