Skip to content

Commit

Permalink
Merge branch 'facebook:main' into convert-facebook-hermes-to-actions-…
Browse files Browse the repository at this point in the history
…20240206-163511
  • Loading branch information
robandpdx authored Mar 12, 2024
2 parents e1fa6df + b8cd4ff commit 05dfc57
Show file tree
Hide file tree
Showing 49 changed files with 2,121 additions and 1,253 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ jobs:
# Check out test262 at a pinned revision to reduce flakiness
git clone https://github.com/tc39/test262
cd test262
git checkout 19da3ca0757248f7595ee09d532bb83dd438f2b5
git checkout 62626e083bd506124aac6c799464d76c2c42851b
- run:
name: Build Hermes Compiler
command: |
Expand All @@ -691,7 +691,7 @@ jobs:
# Check out test262 at a pinned revision to reduce flakiness
git clone https://github.com/tc39/test262
cd test262
git checkout 19da3ca0757248f7595ee09d532bb83dd438f2b5
git checkout 62626e083bd506124aac6c799464d76c2c42851b
- run:
name: Run Hermes tests and test262 with Intl
command: |
Expand Down
4 changes: 4 additions & 0 deletions API/hermes/AsyncDebuggerAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ bool AsyncDebuggerAPI::isWaitingForCommand() {
return isWaitingForCommand_;
}

bool AsyncDebuggerAPI::isPaused() {
return inDidPause_;
}

bool AsyncDebuggerAPI::resumeFromPaused(AsyncDebugCommand command) {
if (!isWaitingForCommand_) {
return false;
Expand Down
5 changes: 5 additions & 0 deletions API/hermes/AsyncDebuggerAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ class HERMES_EXPORT AsyncDebuggerAPI : private debugger::EventObserver {
/// Should only be called from the runtime thread.
bool isWaitingForCommand();

/// Whether the runtime is currently paused for any reason (e.g. script
/// parsed, running interrupts, or waiting for a command).
/// Should only be called from the runtime thread.
bool isPaused();

/// Provide the next action to perform. Should only be called from the runtime
/// thread and only if the next command is expected to be set.
bool resumeFromPaused(AsyncDebugCommand command);
Expand Down
10 changes: 7 additions & 3 deletions API/hermes/RuntimeTaskRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,24 @@ void RuntimeTaskRunner::enqueueTask(RuntimeTask task) {
// access to the runtime, implying they are never concurrently executed.
std::shared_ptr<bool> alreadyRan = std::make_shared<bool>(false);

// Ask the integrator to run the task whenenver JavaScript is not running.
// Ask the integrator to run the task whenever JavaScript is not running.
enqueueRuntimeTask_([alreadyRan, task](HermesRuntime &runtime) {
if (!*alreadyRan) {
task(runtime);
// Make sure to set alreadyRan first before executing the RuntimeTask. The
// task could potentially trigger interrupts by calling into
// HermesRuntime, which might cause the callback queued with
// `triggerInterrupt_TS()` to run.
*alreadyRan = true;
task(runtime);
}
});

// Ask the AsyncDebuggerAPI to run the task whenever running JavaScript can
// be interrupted.
debugger_.triggerInterrupt_TS([alreadyRan, task](HermesRuntime &runtime) {
if (!*alreadyRan) {
task(runtime);
*alreadyRan = true;
task(runtime);
}
});
}
Expand Down
40 changes: 33 additions & 7 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 @@ -198,9 +206,10 @@ void CDPAgentImpl::initializeDomainAgents(State state) {
void CDPAgentImpl::handleCommand(std::string json) {
std::shared_ptr<message::Request> command = message::Request::fromJson(json);
if (!command) {
// Can't even parse the command to get the command ID, so there's no ID
// to respond to with an error message.
// TODO: return an error message
m::ErrorResponse resp;
resp.code = static_cast<int>(message::ErrorCode::ParseError);
resp.message = "Malformed JSON";
messageCallback_(resp.toJsonStr());
return;
}

Expand All @@ -219,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 @@ -258,6 +274,7 @@ void CDPAgentImpl::DomainAgents::initialize(State state) {
runtimeAgent_ = std::make_unique<RuntimeDomainAgent>(
executionContextID_,
runtime_,
asyncDebuggerAPI_,
messageCallback_,
objTable_,
consoleMessageStorage_,
Expand Down Expand Up @@ -364,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 @@ -411,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
10 changes: 7 additions & 3 deletions API/hermes/cdp/DebuggerDomainAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,11 @@ 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;
sendResponseToClient(m::makeOkResponse(req.id));

// The debugger just got enabled; inform the client about all scripts.
for (auto &srcLoc : runtime_.getDebugger().getLoadedScripts()) {
Expand Down Expand Up @@ -165,6 +163,12 @@ void DebuggerDomainAgent::enable(const m::debugger::EnableRequest &req) {
}
}

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));
}

void DebuggerDomainAgent::disable(const m::debugger::DisableRequest &req) {
if (!enabled_) {
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
3 changes: 2 additions & 1 deletion API/hermes/cdp/MessageInterfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define HERMES_CDP_MESSAGEINTERFACES_H

#include <memory>
#include <optional>
#include <string>
#include <unordered_map>
#include <variant>
Expand Down Expand Up @@ -53,7 +54,7 @@ struct Request : public Serializable {
struct Response : public Serializable {
Response() = default;

long long id = 0;
std::optional<long long> id = std::nullopt;
};

/// Notifications are sent from the target to the debugger. This is used to
Expand Down
Loading

0 comments on commit 05dfc57

Please sign in to comment.