Skip to content

Commit

Permalink
Merge branch 'main' into add-es14-array-tosorted
Browse files Browse the repository at this point in the history
  • Loading branch information
robik authored Feb 6, 2024
2 parents 862ebd4 + 340726e commit d908a0d
Show file tree
Hide file tree
Showing 308 changed files with 29,855 additions and 2,315 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ jobs:
name: Run Hermes regression tests
command: |
cmake -S hermes -B build -G 'Visual Studio 16 2019'
cmake --build build --target check-hermes
cmake --build build --target check-hermes -- -m /p:UseMultiToolTask=true -m /p:EnforceProcessCountAcrossBuilds=true
windows:
executor:
Expand Down Expand Up @@ -396,9 +396,9 @@ jobs:
if (-not $?) { throw "Failed to configure Hermes" }
cmake -S hermes -B build_hdb -G 'Visual Studio 16 2019' -Ax64 $Env:RELEASE_FLAGS
if (-not $?) { throw "Failed to configure Hermes" }
cmake --build ./build --config Release
cmake --build ./build --config Release -- -m /p:UseMultiToolTask=true -m /p:EnforceProcessCountAcrossBuilds=true
if (-not $?) { throw "Failed to build Hermes" }
cmake --build ./build_hdb --config Release --target hdb
cmake --build ./build_hdb --config Release --target hdb -- -m /p:UseMultiToolTask=true -m /p:EnforceProcessCountAcrossBuilds=true
if (-not $?) { throw "Failed to build Hermes" }
- run:
Expand Down
11 changes: 9 additions & 2 deletions API/hermes/AsyncDebuggerAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ void AsyncDebuggerAPI::processInterruptWhilePaused() {
}
if (!eventCallbacks_.empty()) {
lock.unlock();
runInterrupts();
// Specifically don't run all interrupts if one of the interrupts sets the
// next command. Once the next command has been set, we'll exit didPause.
runInterrupts(false);
lock.lock();
}
}
Expand All @@ -211,13 +213,18 @@ std::optional<InterruptCallback> AsyncDebuggerAPI::takeNextInterruptCallback() {
return func;
}

void AsyncDebuggerAPI::runInterrupts() {
void AsyncDebuggerAPI::runInterrupts(bool ignoreNextCommand) {
std::optional<InterruptCallback> entry = takeNextInterruptCallback();
while (entry.has_value()) {
InterruptCallback func = entry.value();
if (func) {
func(runtime_);
}

if (!ignoreNextCommand && !isWaitingForCommand_) {
break;
}

entry = takeNextInterruptCallback();
}
}
Expand Down
6 changes: 4 additions & 2 deletions API/hermes/AsyncDebuggerAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ class HERMES_EXPORT AsyncDebuggerAPI : private debugger::EventObserver {
/// Dequeues the next InterruptCallback if any.
std::optional<InterruptCallback> takeNextInterruptCallback();

/// Runs every InterruptCallback that has been queued up so far.
void runInterrupts();
/// If \p ignoreNextCommand is true, then runs every InterruptCallback that
/// has been queued up so far. If \p ignoreNextCommand is false, then attempt
/// to run all interrupts, but will stop if any interrupt sets a next command.
void runInterrupts(bool ignoreNextCommand = true);

/// Returns the next DebuggerEventCallback to execute if any.
std::optional<DebuggerEventCallback> takeNextEventCallback();
Expand Down
1 change: 1 addition & 0 deletions API/hermes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ if(HERMES_ENABLE_DEBUGGER)
set(CDP_API_SOURCES
cdp/CDPAgent.cpp
cdp/DebuggerDomainAgent.cpp
cdp/RuntimeDomainAgent.cpp
)

set(INSPECTOR_API_SOURCES
Expand Down
52 changes: 49 additions & 3 deletions API/hermes/cdp/CDPAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "CDPAgent.h"
#include "DebuggerDomainAgent.h"
#include "RuntimeDomainAgent.h"

#include <hermes/inspector/chrome/MessageConverters.h>
#include <hermes/inspector/chrome/MessageTypes.h>
Expand All @@ -26,6 +27,7 @@ using namespace facebook::hermes::inspector_modern::chrome;
class CDPAgentImpl {
public:
CDPAgentImpl(
int32_t executionContextID,
HermesRuntime &runtime,
AsyncDebuggerAPI &asyncDebuggerAPI,
EnqueueRuntimeTaskFunc enqueueRuntimeTaskCallback,
Expand All @@ -46,6 +48,7 @@ class CDPAgentImpl {
struct DomainAgents {
// Create a new collection of domain agents.
DomainAgents(
int32_t executionContextID,
HermesRuntime &runtime,
AsyncDebuggerAPI &asyncDebuggerAPI,
SynchronizedOutboundCallback messageCallback);
Expand All @@ -60,6 +63,10 @@ class CDPAgentImpl {
/// handler.
void handleCommand(std::shared_ptr<message::Request> command);

/// Execution context ID associated with the HermesRuntime. This is used by
/// domain agents when sending notifications to identify the runtime the
/// notification is coming from.
int32_t executionContextID_;
HermesRuntime &runtime_;
debugger::AsyncDebuggerAPI &asyncDebuggerAPI_;

Expand All @@ -68,6 +75,7 @@ class CDPAgentImpl {
SynchronizedOutboundCallback messageCallback_;

std::unique_ptr<DebuggerDomainAgent> debuggerAgent_;
std::unique_ptr<RuntimeDomainAgent> runtimeAgent_;
};

/// Callback function for sending CDP response back. This is using the
Expand All @@ -83,13 +91,15 @@ class CDPAgentImpl {
};

CDPAgentImpl::CDPAgentImpl(
int32_t executionContextID,
HermesRuntime &runtime,
debugger::AsyncDebuggerAPI &asyncDebuggerAPI,
EnqueueRuntimeTaskFunc enqueueRuntimeTaskCallback,
SynchronizedOutboundCallback messageCallback)
: messageCallback_(std::move(messageCallback)),
runtimeTaskRunner_(asyncDebuggerAPI, enqueueRuntimeTaskCallback),
domainAgents_(std::make_shared<DomainAgents>(
executionContextID,
runtime,
asyncDebuggerAPI,
messageCallback_)) {}
Expand Down Expand Up @@ -128,6 +138,7 @@ void CDPAgentImpl::handleCommand(std::string 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
return;
}

Expand All @@ -140,20 +151,25 @@ void CDPAgentImpl::handleCommand(std::string json) {
}

CDPAgentImpl::DomainAgents::DomainAgents(
int32_t executionContextID,
HermesRuntime &runtime,
AsyncDebuggerAPI &asyncDebuggerAPI,
SynchronizedOutboundCallback messageCallback)
: runtime_(runtime),
: executionContextID_(executionContextID),
runtime_(runtime),
asyncDebuggerAPI_(asyncDebuggerAPI),
messageCallback_(std::move(messageCallback)) {}

void CDPAgentImpl::DomainAgents::initialize() {
debuggerAgent_ = std::make_unique<DebuggerDomainAgent>(
runtime_, asyncDebuggerAPI_, messageCallback_);
executionContextID_, runtime_, asyncDebuggerAPI_, messageCallback_);
runtimeAgent_ = std::make_unique<RuntimeDomainAgent>(
executionContextID_, runtime_, messageCallback_);
}

void CDPAgentImpl::DomainAgents::dispose() {
debuggerAgent_.reset();
runtimeAgent_.reset();
}

void CDPAgentImpl::DomainAgents::handleCommand(
Expand All @@ -175,6 +191,29 @@ void CDPAgentImpl::DomainAgents::handleCommand(
} else if (command->method == "Debugger.disable") {
debuggerAgent_->disable(
static_cast<m::debugger::DisableRequest &>(*command));
} else if (command->method == "Debugger.pause") {
debuggerAgent_->pause(static_cast<m::debugger::PauseRequest &>(*command));
} else if (command->method == "Debugger.resume") {
debuggerAgent_->resume(static_cast<m::debugger::ResumeRequest &>(*command));
} else if (command->method == "Debugger.stepInto") {
debuggerAgent_->stepInto(
static_cast<m::debugger::StepIntoRequest &>(*command));
} else if (command->method == "Debugger.stepOut") {
debuggerAgent_->stepOut(
static_cast<m::debugger::StepOutRequest &>(*command));
} else if (command->method == "Debugger.stepOver") {
debuggerAgent_->stepOver(
static_cast<m::debugger::StepOverRequest &>(*command));
} else if (command->method == "Debugger.setPauseOnExceptions") {
debuggerAgent_->setPauseOnExceptions(
static_cast<m::debugger::SetPauseOnExceptionsRequest &>(*command));
} else if (command->method == "Runtime.enable") {
runtimeAgent_->enable(static_cast<m::runtime::EnableRequest &>(*command));
} else if (command->method == "Runtime.disable") {
runtimeAgent_->disable(static_cast<m::runtime::DisableRequest &>(*command));
} else if (command->method == "Runtime.getHeapUsage") {
runtimeAgent_->getHeapUsage(
static_cast<m::runtime::GetHeapUsageRequest &>(*command));
} else {
messageCallback_(message::makeErrorResponse(
command->id,
Expand All @@ -185,20 +224,27 @@ void CDPAgentImpl::DomainAgents::handleCommand(
}

std::unique_ptr<CDPAgent> CDPAgent::create(
int32_t executionContextID,
HermesRuntime &runtime,
debugger::AsyncDebuggerAPI &asyncDebuggerAPI,
EnqueueRuntimeTaskFunc enqueueRuntimeTaskCallback,
OutboundMessageFunc messageCallback) {
return std::unique_ptr<CDPAgent>(new CDPAgent(
runtime, asyncDebuggerAPI, enqueueRuntimeTaskCallback, messageCallback));
executionContextID,
runtime,
asyncDebuggerAPI,
enqueueRuntimeTaskCallback,
messageCallback));
}

CDPAgent::CDPAgent(
int32_t executionContextID,
HermesRuntime &runtime,
debugger::AsyncDebuggerAPI &asyncDebuggerAPI,
EnqueueRuntimeTaskFunc enqueueRuntimeTaskCallback,
OutboundMessageFunc messageCallback)
: impl_(std::make_unique<CDPAgentImpl>(
executionContextID,
runtime,
asyncDebuggerAPI,
enqueueRuntimeTaskCallback,
Expand Down
2 changes: 2 additions & 0 deletions API/hermes/cdp/CDPAgent.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class HERMES_EXPORT CDPAgent {
/// Hide the constructor so users can only construct via static create
/// methods.
CDPAgent(
int32_t executionContextID,
HermesRuntime &runtime,
debugger::AsyncDebuggerAPI &asyncDebuggerAPI,
debugger::EnqueueRuntimeTaskFunc enqueueRuntimeTaskCallback,
Expand All @@ -48,6 +49,7 @@ class HERMES_EXPORT CDPAgent {
/// Create a new CDP Agent. This can be done on an arbitrary thread; the
/// runtime will not be accessed during execution of this function.
static std::unique_ptr<CDPAgent> create(
int32_t executionContextID,
HermesRuntime &runtime,
debugger::AsyncDebuggerAPI &asyncDebuggerAPI,
debugger::EnqueueRuntimeTaskFunc enqueueRuntimeTaskCallback,
Expand Down
Loading

0 comments on commit d908a0d

Please sign in to comment.