diff --git a/.circleci/configurations/top_level.yml b/.circleci/configurations/top_level.yml index 5d3281d3640..165b2be7969 100644 --- a/.circleci/configurations/top_level.yml +++ b/.circleci/configurations/top_level.yml @@ -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" }} diff --git a/.github/workflows/ios-tests.yml b/.github/workflows/ios-tests.yml index cdfe1189593..a8ccb3cbf49 100644 --- a/.github/workflows/ios-tests.yml +++ b/.github/workflows/ios-tests.yml @@ -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 diff --git a/packages/react-native/ReactCommon/hermes/inspector-modern/chrome/HermesRuntimeAgentDelegateNew.cpp b/packages/react-native/ReactCommon/hermes/inspector-modern/chrome/HermesRuntimeAgentDelegateNew.cpp index 2f628aef9d1..18f3104c53a 100644 --- a/packages/react-native/ReactCommon/hermes/inspector-modern/chrome/HermesRuntimeAgentDelegateNew.cpp +++ b/packages/react-native/ReactCommon/hermes/inspector-modern/chrome/HermesRuntimeAgentDelegateNew.cpp @@ -24,6 +24,25 @@ using namespace facebook::hermes; 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(wrapper)) { + return std::move(typedWrapper->state_); + } + return {}; + } + + private: + HermesState state_; + }; + public: Impl( FrontendChannel frontendChannel, @@ -44,24 +63,15 @@ 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; - } + std::move(frontendChannel), + HermesStateWrapper::unwrapDestructively( + previouslyExportedState.get()))) {} - /** - * 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 { // 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; @@ -73,6 +83,10 @@ class HermesRuntimeAgentDelegateNew::Impl final : public RuntimeAgentDelegate { return true; } + std::unique_ptr getExportedState() override { + return std::make_unique(hermes_->getState()); + } + private: std::unique_ptr hermes_; }; @@ -100,6 +114,11 @@ bool HermesRuntimeAgentDelegateNew::handleRequest( return impl_->handleRequest(req); } +std::unique_ptr +HermesRuntimeAgentDelegateNew::getExportedState() { + return impl_->getExportedState(); +} + } // namespace facebook::react::jsinspector_modern #endif // HERMES_ENABLE_DEBUGGER diff --git a/packages/react-native/ReactCommon/hermes/inspector-modern/chrome/HermesRuntimeAgentDelegateNew.h b/packages/react-native/ReactCommon/hermes/inspector-modern/chrome/HermesRuntimeAgentDelegateNew.h index 3a8e959b23f..674bc8d049c 100644 --- a/packages/react-native/ReactCommon/hermes/inspector-modern/chrome/HermesRuntimeAgentDelegateNew.h +++ b/packages/react-native/ReactCommon/hermes/inspector-modern/chrome/HermesRuntimeAgentDelegateNew.h @@ -66,6 +66,9 @@ class HermesRuntimeAgentDelegateNew : public RuntimeAgentDelegate { */ bool handleRequest(const cdp::PreparsedRequest& req) override; + std::unique_ptr getExportedState() + override; + private: class Impl; diff --git a/packages/react-native/ReactCommon/jsinspector-modern/tests/JsiIntegrationTest.cpp b/packages/react-native/ReactCommon/jsinspector-modern/tests/JsiIntegrationTest.cpp index 4501770b9ac..6aea1c35a0b 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/tests/JsiIntegrationTest.cpp +++ b/packages/react-native/ReactCommon/jsinspector-modern/tests/JsiIntegrationTest.cpp @@ -559,16 +559,23 @@ TYPED_TEST(JsiIntegrationHermesTest, EvaluateExpressionInExecutionContext) { std::to_string(executionContextId))); } -// TODO(T178858701): Restore breakpoint reload persistence under -// HermesRuntimeAgentDelegateNew -TYPED_TEST(JsiIntegrationHermesLegacyTest, ResolveBreakpointAfterReload) { +TYPED_TEST(JsiIntegrationHermesTest, ResolveBreakpointAfterReload) { this->connect(); InSequence s; - this->expectMessageFromPage(JsonParsed(AtJsonPtr("/id", 1))); + this->expectMessageFromPage(JsonEq(R"({ + "id": 1, + "result": {} + })")); this->toPage_->sendMessage(R"({ "id": 1, + "method": "Debugger.enable" + })"); + + this->expectMessageFromPage(JsonParsed(AtJsonPtr("/id", 2))); + this->toPage_->sendMessage(R"({ + "id": 2, "method": "Debugger.setBreakpointByUrl", "params": {"lineNumber": 2, "url": "breakpointTest.js"} })"); @@ -576,11 +583,11 @@ TYPED_TEST(JsiIntegrationHermesLegacyTest, ResolveBreakpointAfterReload) { this->reload(); this->expectMessageFromPage(JsonEq(R"({ - "id": 2, + "id": 3, "result": {} })")); this->toPage_->sendMessage(R"({ - "id": 2, + "id": 3, "method": "Debugger.enable" })");