Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/configurations/top_level.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ references:
# Cocoapods - RNTester
pods_cache_key: &pods_cache_key v11-pods-{{ .Environment.CIRCLE_JOB }}-{{ checksum "packages/rn-tester/Podfile.lock.bak" }}-{{ checksum "packages/rn-tester/Podfile" }}
cocoapods_cache_key: &cocoapods_cache_key v11-cocoapods-{{ .Environment.CIRCLE_JOB }}-{{ checksum "packages/rn-tester/Podfile.lock" }}-{{ checksum "packages/rn-tester/Podfile" }}-{{ checksum "/tmp/hermes/hermesversion" }}
rntester_podfile_lock_cache_key: &rntester_podfile_lock_cache_key v9-podfilelock-{{ .Environment.CIRCLE_JOB }}-{{ checksum "packages/rn-tester/Podfile" }}-{{ checksum "/tmp/week_year" }}-{{ checksum "/tmp/hermes/hermesversion" }}
rntester_podfile_lock_cache_key: &rntester_podfile_lock_cache_key v10-podfilelock-{{ .Environment.CIRCLE_JOB }}-{{ checksum "packages/rn-tester/Podfile" }}-{{ checksum "/tmp/week_year" }}-{{ checksum "/tmp/hermes/hermesversion" }}

# Cocoapods - Template
template_cocoapods_cache_key: &template_cocoapods_cache_key v6-cocoapods-{{ .Environment.CIRCLE_JOB }}-{{ checksum "/tmp/iOSTemplateProject/ios/Podfile.lock" }}-{{ checksum "/tmp/iOSTemplateProject/ios/Podfile" }}-{{ checksum "/tmp/hermes/hermesversion" }}-{{ checksum "packages/rn-tester/Podfile.lock" }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ios-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
uses: actions/cache@v3
with:
path: packages/rn-tester/Pods
key: v2-${{ runner.os }}-RNTesterPods-${{ hashFiles('packages/rn-tester/Podfile.lock') }}-${{ hashFiles('packages/rn-tester/Podfile') }}-${{ hashFiles('tmp/hermes/hermesversion') }}
key: v3-${{ runner.os }}-RNTesterPods-${{ hashFiles('packages/rn-tester/Podfile.lock') }}-${{ hashFiles('packages/rn-tester/Podfile') }}-${{ hashFiles('tmp/hermes/hermesversion') }}
- name: Pod Install
run: |
cd packages/rn-tester
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@
#include <hermes/inspector/chrome/CDPHandler.h>

#include <hermes/hermes.h>
#include <jsinspector-modern/CdpJson.h>
#include <jsinspector-modern/ReactCdp.h>

#include <chrono>

using namespace facebook::hermes;
using namespace std::chrono;

namespace facebook::react::jsinspector_modern {

Expand Down Expand Up @@ -124,11 +128,15 @@ class HermesRuntimeAgentDelegate::Impl final : public RuntimeAgentDelegate {
.origin = executionContextDescription.origin,
.name = executionContextDescription.name,
.auxData = std::nullopt,
.shouldSendNotifications = false})) {
.shouldSendNotifications = false})),
frontendChannel_(std::move(frontendChannel)) {
if (sessionState.isLogDomainEnabled) {
sendHermesIntegrationDescription();
}
hermes_->registerCallbacks(
/* msgCallback */
[frontendChannel =
std::move(frontendChannel)](const std::string& messageFromHermes) {
frontendChannel_](const std::string& messageFromHermes) {
frontendChannel(messageFromHermes);
;
},
Expand All @@ -145,6 +153,13 @@ class HermesRuntimeAgentDelegate::Impl final : public RuntimeAgentDelegate {
* agent expects another agent to respond to the request instead.
*/
bool handleRequest(const cdp::PreparsedRequest& req) override {
if (req.method == "Log.enable") {
sendHermesIntegrationDescription();

// The parent Agent should send a response.
return false;
}

// TODO: Change to string::starts_with when we're on C++20.
if (req.method.rfind("Log.", 0) == 0) {
// Since we know Hermes doesn't do anything useful with Log messages, but
Expand All @@ -165,7 +180,37 @@ class HermesRuntimeAgentDelegate::Impl final : public RuntimeAgentDelegate {
}

private:
/**
* Send a user-facing message describing the current Hermes integration. You
* must ensure that the frontend has enabled Log notifications (using
* Log.enable) prior to calling this function.
*/
void sendHermesIntegrationDescription() {
sendInfoLogEntry("Hermes integration: CDPHandler");
}

/**
* Send a simple Log.entryAdded notification with the given
* \param text. You must ensure that the frontend has enabled Log
* notifications (using Log.enable) prior to calling this function. In Chrome
* DevTools, the message will appear in the Console tab along with regular
* console messages.
*/
void sendInfoLogEntry(std::string_view text) {
frontendChannel_(cdp::jsonNotification(
"Log.entryAdded",
folly::dynamic::object(
"entry",
folly::dynamic::object(
"timestamp",
duration_cast<milliseconds>(
system_clock::now().time_since_epoch())
.count())("source", "other")(
"level", "info")("text", text))));
}

std::shared_ptr<HermesCDPHandler> hermes_;
FrontendChannel frontendChannel_;
};

HermesRuntimeAgentDelegate::HermesRuntimeAgentDelegate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,40 @@
#include <hermes/inspector/RuntimeAdapter.h>

#include <hermes/hermes.h>
#include <jsinspector-modern/CdpJson.h>
#include <jsinspector-modern/ReactCdp.h>

#include <chrono>

using namespace facebook::hermes;
using namespace std::chrono;

namespace facebook::react::jsinspector_modern {

class HermesRuntimeAgentDelegateNew::Impl final : public RuntimeAgentDelegate {
using HermesState = hermes::cdp::State;

struct HermesStateWrapper : public ExportedState {
explicit HermesStateWrapper(HermesState state) : state_(std::move(state)) {}

static HermesState unwrapDestructively(ExportedState* wrapper) {
if (!wrapper) {
return {};
}
if (auto* typedWrapper = dynamic_cast<HermesStateWrapper*>(wrapper)) {
return std::move(typedWrapper->state_);
}
return {};
}

private:
HermesState state_;
};

public:
Impl(
FrontendChannel frontendChannel,
SessionState& /*unused*/,
SessionState& sessionState,
std::unique_ptr<RuntimeAgentDelegate::ExportedState>
previouslyExportedState,
const ExecutionContextDescription& executionContextDescription,
Expand All @@ -44,24 +67,33 @@ class HermesRuntimeAgentDelegateNew::Impl final : public RuntimeAgentDelegate {
runtimeExecutor(
[&runtime, fn = std::move(fn)](auto&) { fn(runtime); });
},
std::move(frontendChannel))) {
// TODO(T178858701): Pass previouslyExportedState to CDPAgent
(void)previouslyExportedState;
frontendChannel,
HermesStateWrapper::unwrapDestructively(
previouslyExportedState.get()))),
frontendChannel_(frontendChannel) {
if (sessionState.isLogDomainEnabled) {
sendHermesIntegrationDescription();
}
if (sessionState.isRuntimeDomainEnabled) {
hermes_->enableRuntimeDomain();
}
if (sessionState.isDebuggerDomainEnabled) {
hermes_->enableDebuggerDomain();
}
}

/**
* Handle a CDP request. The response will be sent over the provided
* \c FrontendChannel synchronously or asynchronously.
* \param req The parsed request.
* \returns true if this agent has responded, or will respond asynchronously,
* to the request (with either a success or error message). False if the
* agent expects another agent to respond to the request instead.
*/
bool handleRequest(const cdp::PreparsedRequest& req) override {
if (req.method == "Log.enable") {
sendHermesIntegrationDescription();

// The parent Agent should send a response.
return false;
}

// TODO: Change to string::starts_with when we're on C++20.
if (req.method.rfind("Log.", 0) == 0) {
// Since we know Hermes doesn't do anything useful with Log messages, but
// our containing PageAgent will, just bail out early.
// Since we know Hermes doesn't do anything useful with Log messages,
// but our containing HostAgent will, bail out early.
// TODO: We need a way to negotiate this more dynamically with Hermes
// through the API.
return false;
Expand All @@ -73,8 +105,42 @@ class HermesRuntimeAgentDelegateNew::Impl final : public RuntimeAgentDelegate {
return true;
}

std::unique_ptr<ExportedState> getExportedState() override {
return std::make_unique<HermesStateWrapper>(hermes_->getState());
}

private:
/**
* Send a user-facing message describing the current Hermes integration. You
* must ensure that the frontend has enabled Log notifications (using
* Log.enable) prior to calling this function.
*/
void sendHermesIntegrationDescription() {
sendInfoLogEntry("Hermes integration: CDPAgent");
}

/**
* Send a simple Log.entryAdded notification with the given
* \param text. You must ensure that the frontend has enabled Log
* notifications (using Log.enable) prior to calling this function. In Chrome
* DevTools, the message will appear in the Console tab along with regular
* console messages.
*/
void sendInfoLogEntry(std::string_view text) {
frontendChannel_(cdp::jsonNotification(
"Log.entryAdded",
folly::dynamic::object(
"entry",
folly::dynamic::object(
"timestamp",
duration_cast<milliseconds>(
system_clock::now().time_since_epoch())
.count())("source", "other")(
"level", "info")("text", text))));
}

std::unique_ptr<hermes::cdp::CDPAgent> hermes_;
FrontendChannel frontendChannel_;
};

HermesRuntimeAgentDelegateNew::HermesRuntimeAgentDelegateNew(
Expand All @@ -100,6 +166,11 @@ bool HermesRuntimeAgentDelegateNew::handleRequest(
return impl_->handleRequest(req);
}

std::unique_ptr<RuntimeAgentDelegate::ExportedState>
HermesRuntimeAgentDelegateNew::getExportedState() {
return impl_->getExportedState();
}

} // namespace facebook::react::jsinspector_modern

#endif // HERMES_ENABLE_DEBUGGER
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class HermesRuntimeAgentDelegateNew : public RuntimeAgentDelegate {
*/
bool handleRequest(const cdp::PreparsedRequest& req) override;

std::unique_ptr<RuntimeAgentDelegate::ExportedState> getExportedState()
override;

private:
class Impl;

Expand Down
10 changes: 10 additions & 0 deletions packages/react-native/ReactCommon/jsinspector-modern/HostAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ void HostAgent::handleRequest(const cdp::PreparsedRequest& req) {
} else if (req.method == "Runtime.disable") {
sessionState_.isRuntimeDomainEnabled = false;

shouldSendOKResponse = true;
isFinishedHandlingRequest = false;
} else if (req.method == "Debugger.enable") {
sessionState_.isDebuggerDomainEnabled = true;

shouldSendOKResponse = true;
isFinishedHandlingRequest = false;
} else if (req.method == "Debugger.disable") {
sessionState_.isDebuggerDomainEnabled = false;

shouldSendOKResponse = true;
isFinishedHandlingRequest = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace facebook::react::jsinspector_modern {
struct SessionState {
public:
// TODO: Generalise this to arbitrary domains
bool isDebuggerDomainEnabled{false};
bool isLogDomainEnabled{false};
bool isRuntimeDomainEnabled{false};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,7 @@ TYPED_TEST(
std::to_string(executionContextId)));
}

// TODO(T178858701): Restore breakpoint reload persistence under
// HermesRuntimeAgentDelegateNew
TYPED_TEST(JsiIntegrationHermesLegacyTest, ResolveBreakpointAfterReload) {
TYPED_TEST(JsiIntegrationHermesTest, ResolveBreakpointAfterReload) {
this->connect();

InSequence s;
Expand Down