From 24c361f1653c082a93a371256e6c72d43bf9d0cb Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Wed, 6 Mar 2024 07:13:54 -0800 Subject: [PATCH] Pass whole RuntimeTargetDelegate from RN instead of aggregating its methods (#43346) Summary: Changelog: [Internal] (Continuing the theme of reducing integration boilerplate from D54537844.) This diff changes both `JSExecutor` (Bridge) and `JSRuntime` (Bridgeless) to no longer implement `RuntimeTargetDelegate`. Instead, each of them exposes a `getRuntimeTargetDelegate()` method that returns a stable reference to a target delegate that it *owns*. To facilitate this, we create a new `FallbackRuntimeTargetDelegate` for use in non-Hermes cases. This replaces *almost* all direct uses of `FallbackRuntimeAgentDelegate` outside of `jsinspector`. I'll follow up in a separate diff to deal with the last case and make the fallback agent delegate fully private. As a result, changing the `RuntimeTargetDelegate` interface (which we'll need to do for console support) becomes much easier: we only have unit test mocks + two concrete `RuntimeTargetDelegate` implementations (one fallback, one Hermes) to update for each API change. Differential Revision: D54585658 --- .../ReactCommon/cxxreact/JSExecutor.cpp | 18 +++------ .../ReactCommon/cxxreact/JSExecutor.h | 26 +++++++------ .../ReactCommon/cxxreact/NativeToJsBridge.cpp | 2 +- .../hermes/executor/HermesExecutorFactory.cpp | 18 ++------- .../hermes/executor/HermesExecutorFactory.h | 11 +----- .../chrome/HermesRuntimeAgentDelegate.cpp | 3 ++ .../FallbackRuntimeTargetDelegate.cpp | 29 ++++++++++++++ .../FallbackRuntimeTargetDelegate.h | 38 +++++++++++++++++++ .../ReactCommon/jsinspector-modern/ReactCdp.h | 2 +- .../tests/JsiIntegrationTest.cpp | 6 ++- ...JsiIntegrationTestGenericEngineAdapter.cpp | 22 ++++------- .../JsiIntegrationTestGenericEngineAdapter.h | 12 ++---- .../JsiIntegrationTestHermesEngineAdapter.cpp | 21 +++------- .../JsiIntegrationTestHermesEngineAdapter.h | 12 ++---- .../react/runtime/JSRuntimeFactory.cpp | 18 +++------ .../react/runtime/JSRuntimeFactory.h | 25 +++++++----- .../react/runtime/ReactInstance.cpp | 4 +- .../react/runtime/hermes/HermesInstance.cpp | 17 ++------- 18 files changed, 148 insertions(+), 136 deletions(-) create mode 100644 packages/react-native/ReactCommon/jsinspector-modern/FallbackRuntimeTargetDelegate.cpp create mode 100644 packages/react-native/ReactCommon/jsinspector-modern/FallbackRuntimeTargetDelegate.h diff --git a/packages/react-native/ReactCommon/cxxreact/JSExecutor.cpp b/packages/react-native/ReactCommon/cxxreact/JSExecutor.cpp index f188cfe93304ca..263ab90bb5cb31 100644 --- a/packages/react-native/ReactCommon/cxxreact/JSExecutor.cpp +++ b/packages/react-native/ReactCommon/cxxreact/JSExecutor.cpp @@ -35,18 +35,12 @@ double JSExecutor::performanceNow() { return duration / NANOSECONDS_IN_MILLISECOND; } -std::unique_ptr -JSExecutor::createAgentDelegate( - jsinspector_modern::FrontendChannel frontendChannel, - jsinspector_modern::SessionState& sessionState, - std::unique_ptr, - const jsinspector_modern::ExecutionContextDescription& - executionContextDescription, - RuntimeExecutor runtimeExecutor) { - (void)executionContextDescription; - (void)runtimeExecutor; - return std::make_unique( - std::move(frontendChannel), sessionState, getDescription()); +jsinspector_modern::RuntimeTargetDelegate& +JSExecutor::getRuntimeTargetDelegate() { + if (!runtimeTargetDelegate_) { + runtimeTargetDelegate_.emplace(getDescription()); + } + return *runtimeTargetDelegate_; } } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/cxxreact/JSExecutor.h b/packages/react-native/ReactCommon/cxxreact/JSExecutor.h index 757997aec84067..469f4ca6fd73d5 100644 --- a/packages/react-native/ReactCommon/cxxreact/JSExecutor.h +++ b/packages/react-native/ReactCommon/cxxreact/JSExecutor.h @@ -55,7 +55,7 @@ class JSExecutorFactory { virtual ~JSExecutorFactory() {} }; -class RN_EXPORT JSExecutor : public jsinspector_modern::RuntimeTargetDelegate { +class RN_EXPORT JSExecutor { public: /** * Prepares the JS runtime for React Native by installing global variables. @@ -130,7 +130,7 @@ class RN_EXPORT JSExecutor : public jsinspector_modern::RuntimeTargetDelegate { virtual void handleMemoryPressure([[maybe_unused]] int pressureLevel) {} virtual void destroy() {} - virtual ~JSExecutor() override {} + virtual ~JSExecutor() = default; virtual void flush() {} @@ -141,17 +141,19 @@ class RN_EXPORT JSExecutor : public jsinspector_modern::RuntimeTargetDelegate { static double performanceNow(); /** - * Create a RuntimeAgentDelegate that can be used to debug the JS VM instance. + * Get a reference to the \c RuntimeTargetDelegate owned (or implemented) by + * this executor. This reference must remain valid for the duration of the + * executor's lifetime. */ - virtual std::unique_ptr - createAgentDelegate( - jsinspector_modern::FrontendChannel frontendChannel, - jsinspector_modern::SessionState& sessionState, - std::unique_ptr - previouslyExportedState, - const jsinspector_modern::ExecutionContextDescription& - executionContextDescription, - RuntimeExecutor runtimeExecutor) override; + virtual jsinspector_modern::RuntimeTargetDelegate& getRuntimeTargetDelegate(); + + private: + /** + * Initialized by \c getRuntimeTargetDelegate if not overridden, and then + * never changes. + */ + std::optional + runtimeTargetDelegate_; }; } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/cxxreact/NativeToJsBridge.cpp b/packages/react-native/ReactCommon/cxxreact/NativeToJsBridge.cpp index f23ce412fae178..b6234eb9366429 100644 --- a/packages/react-native/ReactCommon/cxxreact/NativeToJsBridge.cpp +++ b/packages/react-native/ReactCommon/cxxreact/NativeToJsBridge.cpp @@ -345,7 +345,7 @@ NativeToJsBridge::getDecoratedNativeMethodCallInvoker( jsinspector_modern::RuntimeTargetDelegate& NativeToJsBridge::getInspectorTargetDelegate() { - return *m_executor; + return m_executor->getRuntimeTargetDelegate(); } } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/hermes/executor/HermesExecutorFactory.cpp b/packages/react-native/ReactCommon/hermes/executor/HermesExecutorFactory.cpp index 9a537f4cf01f85..56a8398f0b544a 100644 --- a/packages/react-native/ReactCommon/hermes/executor/HermesExecutorFactory.cpp +++ b/packages/react-native/ReactCommon/hermes/executor/HermesExecutorFactory.cpp @@ -256,21 +256,9 @@ HermesExecutor::HermesExecutor( targetDelegate_{ std::shared_ptr(runtime_, &hermesRuntime)} {} -std::unique_ptr -HermesExecutor::createAgentDelegate( - jsinspector_modern::FrontendChannel frontendChannel, - jsinspector_modern::SessionState& sessionState, - std::unique_ptr - previouslyExportedState, - const jsinspector_modern::ExecutionContextDescription& - executionContextDescription, - RuntimeExecutor runtimeExecutor) { - return targetDelegate_.createAgentDelegate( - std::move(frontendChannel), - sessionState, - std::move(previouslyExportedState), - executionContextDescription, - std::move(runtimeExecutor)); +jsinspector_modern::RuntimeTargetDelegate& +HermesExecutor::getRuntimeTargetDelegate() { + return targetDelegate_; } } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/hermes/executor/HermesExecutorFactory.h b/packages/react-native/ReactCommon/hermes/executor/HermesExecutorFactory.h index c0ee1b8edc0a94..4056d42ef5259b 100644 --- a/packages/react-native/ReactCommon/hermes/executor/HermesExecutorFactory.h +++ b/packages/react-native/ReactCommon/hermes/executor/HermesExecutorFactory.h @@ -55,15 +55,8 @@ class HermesExecutor : public JSIExecutor { RuntimeInstaller runtimeInstaller, hermes::HermesRuntime& hermesRuntime); - virtual std::unique_ptr - createAgentDelegate( - jsinspector_modern::FrontendChannel frontendChannel, - jsinspector_modern::SessionState& sessionState, - std::unique_ptr - previouslyExportedState, - const jsinspector_modern::ExecutionContextDescription& - executionContextDescription, - RuntimeExecutor runtimeExecutor) override; + jsinspector_modern::RuntimeTargetDelegate& getRuntimeTargetDelegate() + override; private: JSIScopedTimeoutInvoker timeoutInvoker_; diff --git a/packages/react-native/ReactCommon/hermes/inspector-modern/chrome/HermesRuntimeAgentDelegate.cpp b/packages/react-native/ReactCommon/hermes/inspector-modern/chrome/HermesRuntimeAgentDelegate.cpp index b12b32e5aa51db..3b1d1caa11c1e0 100644 --- a/packages/react-native/ReactCommon/hermes/inspector-modern/chrome/HermesRuntimeAgentDelegate.cpp +++ b/packages/react-native/ReactCommon/hermes/inspector-modern/chrome/HermesRuntimeAgentDelegate.cpp @@ -14,6 +14,9 @@ #include #include #else // HERMES_ENABLE_DEBUGGER +// TODO(moti): FallbackRuntimeAgentDelegate should be private. We should fall +// back at the *TargetDelegate* level, in HermesRuntimeTargetDelegate, rather +// than within HermesRuntimeAgentDelegate. #include #endif // HERMES_ENABLE_DEBUGGER diff --git a/packages/react-native/ReactCommon/jsinspector-modern/FallbackRuntimeTargetDelegate.cpp b/packages/react-native/ReactCommon/jsinspector-modern/FallbackRuntimeTargetDelegate.cpp new file mode 100644 index 00000000000000..cd2cb9ab44f74e --- /dev/null +++ b/packages/react-native/ReactCommon/jsinspector-modern/FallbackRuntimeTargetDelegate.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include "FallbackRuntimeTargetDelegate.h" +#include "FallbackRuntimeAgentDelegate.h" + +namespace facebook::react::jsinspector_modern { + +FallbackRuntimeTargetDelegate::FallbackRuntimeTargetDelegate( + std::string engineDescription) + : engineDescription_{std::move(engineDescription)} {} + +std::unique_ptr +FallbackRuntimeTargetDelegate::createAgentDelegate( + FrontendChannel channel, + SessionState& sessionState, + std::unique_ptr + /*previouslyExportedState*/, + const ExecutionContextDescription& /*executionContextDescription*/, + RuntimeExecutor /*runtimeExecutor*/) { + return std::make_unique( + std::move(channel), sessionState, engineDescription_); +} + +} // namespace facebook::react::jsinspector_modern diff --git a/packages/react-native/ReactCommon/jsinspector-modern/FallbackRuntimeTargetDelegate.h b/packages/react-native/ReactCommon/jsinspector-modern/FallbackRuntimeTargetDelegate.h new file mode 100644 index 00000000000000..923a0d301ee022 --- /dev/null +++ b/packages/react-native/ReactCommon/jsinspector-modern/FallbackRuntimeTargetDelegate.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include "InspectorInterfaces.h" +#include "RuntimeTarget.h" +#include "SessionState.h" + +#include + +namespace facebook::react::jsinspector_modern { + +/** + * A RuntimeTargetDelegate that stubs out debugging functionality for a + * JavaScript runtime that does not natively support debugging. + */ +class FallbackRuntimeTargetDelegate : public RuntimeTargetDelegate { + public: + explicit FallbackRuntimeTargetDelegate(std::string engineDescription); + + std::unique_ptr createAgentDelegate( + FrontendChannel channel, + SessionState& sessionState, + std::unique_ptr + previouslyExportedState, + const ExecutionContextDescription& executionContextDescription, + RuntimeExecutor runtimeExecutor) override; + + private: + std::string engineDescription_; +}; + +} // namespace facebook::react::jsinspector_modern diff --git a/packages/react-native/ReactCommon/jsinspector-modern/ReactCdp.h b/packages/react-native/ReactCommon/jsinspector-modern/ReactCdp.h index 979232da29ff1e..23c9d3eaeeea52 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/ReactCdp.h +++ b/packages/react-native/ReactCommon/jsinspector-modern/ReactCdp.h @@ -8,7 +8,7 @@ #pragma once #include -#include +#include #include #include #include diff --git a/packages/react-native/ReactCommon/jsinspector-modern/tests/JsiIntegrationTest.cpp b/packages/react-native/ReactCommon/jsinspector-modern/tests/JsiIntegrationTest.cpp index 4c4ff8b475abc3..ae8300ef9799e6 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/tests/JsiIntegrationTest.cpp +++ b/packages/react-native/ReactCommon/jsinspector-modern/tests/JsiIntegrationTest.cpp @@ -55,7 +55,8 @@ class JsiIntegrationPortableTest : public Test, private HostTargetDelegate { JsiIntegrationPortableTest() : engineAdapter_{immediateExecutor_} { instance_ = &page_->registerInstance(instanceTargetDelegate_); runtimeTarget_ = &instance_->registerRuntime( - *engineAdapter_, engineAdapter_->getRuntimeExecutor()); + engineAdapter_->getRuntimeTargetDelegate(), + engineAdapter_->getRuntimeExecutor()); } ~JsiIntegrationPortableTest() override { @@ -96,7 +97,8 @@ class JsiIntegrationPortableTest : public Test, private HostTargetDelegate { engineAdapter_.emplace(immediateExecutor_); instance_ = &page_->registerInstance(instanceTargetDelegate_); runtimeTarget_ = &instance_->registerRuntime( - *engineAdapter_, engineAdapter_->getRuntimeExecutor()); + engineAdapter_->getRuntimeTargetDelegate(), + engineAdapter_->getRuntimeExecutor()); } MockRemoteConnection& fromPage() { diff --git a/packages/react-native/ReactCommon/jsinspector-modern/tests/engines/JsiIntegrationTestGenericEngineAdapter.cpp b/packages/react-native/ReactCommon/jsinspector-modern/tests/engines/JsiIntegrationTestGenericEngineAdapter.cpp index b9de7fd82a674a..e7afe3e74667bd 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/tests/engines/JsiIntegrationTestGenericEngineAdapter.cpp +++ b/packages/react-native/ReactCommon/jsinspector-modern/tests/engines/JsiIntegrationTestGenericEngineAdapter.cpp @@ -18,20 +18,14 @@ namespace facebook::react::jsinspector_modern { JsiIntegrationTestGenericEngineAdapter::JsiIntegrationTestGenericEngineAdapter( folly::Executor& jsExecutor) - : runtime_{hermes::makeHermesRuntime()}, jsExecutor_{jsExecutor} {} - -std::unique_ptr -JsiIntegrationTestGenericEngineAdapter::createAgentDelegate( - FrontendChannel frontendChannel, - SessionState& sessionState, - std::unique_ptr, - const ExecutionContextDescription& /*executionContextDescription*/, - RuntimeExecutor /*runtimeExecutor*/) { - return std::unique_ptr( - new FallbackRuntimeAgentDelegate( - frontendChannel, - sessionState, - "Generic engine (" + runtime_->description() + ")")); + : runtime_{hermes::makeHermesRuntime()}, + jsExecutor_{jsExecutor}, + runtimeTargetDelegate_{ + "Generic engine (" + runtime_->description() + ")"} {} + +RuntimeTargetDelegate& +JsiIntegrationTestGenericEngineAdapter::getRuntimeTargetDelegate() { + return runtimeTargetDelegate_; } jsi::Runtime& JsiIntegrationTestGenericEngineAdapter::getRuntime() diff --git a/packages/react-native/ReactCommon/jsinspector-modern/tests/engines/JsiIntegrationTestGenericEngineAdapter.h b/packages/react-native/ReactCommon/jsinspector-modern/tests/engines/JsiIntegrationTestGenericEngineAdapter.h index 5a03ae654f0bab..b6016e25c32179 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/tests/engines/JsiIntegrationTestGenericEngineAdapter.h +++ b/packages/react-native/ReactCommon/jsinspector-modern/tests/engines/JsiIntegrationTestGenericEngineAdapter.h @@ -7,6 +7,7 @@ #pragma once +#include #include #include @@ -21,17 +22,11 @@ namespace facebook::react::jsinspector_modern { * JSI-compatible engine, with no engine-specific CDP support. Uses Hermes under * the hood, without Hermes's CDP support. */ -class JsiIntegrationTestGenericEngineAdapter : public RuntimeTargetDelegate { +class JsiIntegrationTestGenericEngineAdapter { public: explicit JsiIntegrationTestGenericEngineAdapter(folly::Executor& jsExecutor); - virtual std::unique_ptr createAgentDelegate( - FrontendChannel frontendChannel, - SessionState& sessionState, - std::unique_ptr - previouslyExportedState, - const ExecutionContextDescription& executionContextDescription, - RuntimeExecutor runtimeExecutor) override; + RuntimeTargetDelegate& getRuntimeTargetDelegate(); jsi::Runtime& getRuntime() const noexcept; @@ -40,6 +35,7 @@ class JsiIntegrationTestGenericEngineAdapter : public RuntimeTargetDelegate { private: std::unique_ptr runtime_; folly::Executor& jsExecutor_; + jsinspector_modern::FallbackRuntimeTargetDelegate runtimeTargetDelegate_; }; } // namespace facebook::react::jsinspector_modern diff --git a/packages/react-native/ReactCommon/jsinspector-modern/tests/engines/JsiIntegrationTestHermesEngineAdapter.cpp b/packages/react-native/ReactCommon/jsinspector-modern/tests/engines/JsiIntegrationTestHermesEngineAdapter.cpp index bffc056dd7ec4f..eb4fdfdedf9ecf 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/tests/engines/JsiIntegrationTestHermesEngineAdapter.cpp +++ b/packages/react-native/ReactCommon/jsinspector-modern/tests/engines/JsiIntegrationTestHermesEngineAdapter.cpp @@ -17,22 +17,11 @@ JsiIntegrationTestHermesEngineAdapter::JsiIntegrationTestHermesEngineAdapter( folly::Executor& jsExecutor) : runtime_{hermes::makeHermesRuntime()}, jsExecutor_{jsExecutor}, - targetDelegate_{runtime_} {} - -std::unique_ptr -JsiIntegrationTestHermesEngineAdapter::createAgentDelegate( - FrontendChannel frontendChannel, - SessionState& sessionState, - std::unique_ptr - previouslyExportedState, - const ExecutionContextDescription& executionContextDescription, - RuntimeExecutor runtimeExecutor) { - return targetDelegate_.createAgentDelegate( - std::move(frontendChannel), - sessionState, - std::move(previouslyExportedState), - executionContextDescription, - std::move(runtimeExecutor)); + runtimeTargetDelegate_{runtime_} {} + +RuntimeTargetDelegate& +JsiIntegrationTestHermesEngineAdapter::getRuntimeTargetDelegate() { + return runtimeTargetDelegate_; } jsi::Runtime& JsiIntegrationTestHermesEngineAdapter::getRuntime() diff --git a/packages/react-native/ReactCommon/jsinspector-modern/tests/engines/JsiIntegrationTestHermesEngineAdapter.h b/packages/react-native/ReactCommon/jsinspector-modern/tests/engines/JsiIntegrationTestHermesEngineAdapter.h index d2291661394bcb..dd0f273eb17b28 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/tests/engines/JsiIntegrationTestHermesEngineAdapter.h +++ b/packages/react-native/ReactCommon/jsinspector-modern/tests/engines/JsiIntegrationTestHermesEngineAdapter.h @@ -22,17 +22,11 @@ namespace facebook::react::jsinspector_modern { * An engine adapter for JsiIntegrationTest that uses Hermes (and Hermes's * CDP support). */ -class JsiIntegrationTestHermesEngineAdapter : public RuntimeTargetDelegate { +class JsiIntegrationTestHermesEngineAdapter { public: explicit JsiIntegrationTestHermesEngineAdapter(folly::Executor& jsExecutor); - virtual std::unique_ptr createAgentDelegate( - FrontendChannel frontendChannel, - SessionState& sessionState, - std::unique_ptr - previouslyExportedState, - const ExecutionContextDescription& executionContextDescription, - RuntimeExecutor runtimeExecutor) override; + RuntimeTargetDelegate& getRuntimeTargetDelegate(); jsi::Runtime& getRuntime() const noexcept; @@ -41,7 +35,7 @@ class JsiIntegrationTestHermesEngineAdapter : public RuntimeTargetDelegate { private: std::shared_ptr runtime_; folly::Executor& jsExecutor_; - HermesRuntimeTargetDelegate targetDelegate_; + HermesRuntimeTargetDelegate runtimeTargetDelegate_; }; } // namespace facebook::react::jsinspector_modern diff --git a/packages/react-native/ReactCommon/react/runtime/JSRuntimeFactory.cpp b/packages/react-native/ReactCommon/react/runtime/JSRuntimeFactory.cpp index e868f1c12691d4..ed5b97fa432f5d 100644 --- a/packages/react-native/ReactCommon/react/runtime/JSRuntimeFactory.cpp +++ b/packages/react-native/ReactCommon/react/runtime/JSRuntimeFactory.cpp @@ -18,18 +18,12 @@ JSIRuntimeHolder::JSIRuntimeHolder(std::unique_ptr runtime) assert(runtime_ != nullptr); } -std::unique_ptr -JSIRuntimeHolder::createAgentDelegate( - jsinspector_modern::FrontendChannel frontendChannel, - jsinspector_modern::SessionState& sessionState, - std::unique_ptr, - const jsinspector_modern::ExecutionContextDescription& - executionContextDescription, - RuntimeExecutor runtimeExecutor) { - (void)executionContextDescription; - (void)runtimeExecutor; - return std::make_unique( - std::move(frontendChannel), sessionState, runtime_->description()); +jsinspector_modern::RuntimeTargetDelegate& +JSRuntime::getRuntimeTargetDelegate() { + if (!runtimeTargetDelegate_) { + runtimeTargetDelegate_.emplace(getRuntime().description()); + } + return *runtimeTargetDelegate_; } } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/runtime/JSRuntimeFactory.h b/packages/react-native/ReactCommon/react/runtime/JSRuntimeFactory.h index 34d1cace4e5ce3..dca9c1ac25c7b0 100644 --- a/packages/react-native/ReactCommon/react/runtime/JSRuntimeFactory.h +++ b/packages/react-native/ReactCommon/react/runtime/JSRuntimeFactory.h @@ -17,11 +17,26 @@ namespace facebook::react { /** * An interface that represents an instance of a JS VM */ -class JSRuntime : public jsinspector_modern::RuntimeTargetDelegate { +class JSRuntime { public: virtual jsi::Runtime& getRuntime() noexcept = 0; virtual ~JSRuntime() = default; + + /** + * Get a reference to the \c RuntimeTargetDelegate owned (or implemented) by + * this JSRuntime. This reference must remain valid for the duration of the + * JSRuntime's lifetime. + */ + virtual jsinspector_modern::RuntimeTargetDelegate& getRuntimeTargetDelegate(); + + private: + /** + * Initialized by \c getRuntimeTargetDelegate if not overridden, and then + * never changes. + */ + std::optional + runtimeTargetDelegate_; }; /** @@ -41,14 +56,6 @@ class JSRuntimeFactory { class JSIRuntimeHolder : public JSRuntime { public: jsi::Runtime& getRuntime() noexcept override; - std::unique_ptr createAgentDelegate( - jsinspector_modern::FrontendChannel frontendChannel, - jsinspector_modern::SessionState& sessionState, - std::unique_ptr - previouslyExportedState, - const jsinspector_modern::ExecutionContextDescription& - executionContextDescription, - RuntimeExecutor runtimeExecutor) override; explicit JSIRuntimeHolder(std::unique_ptr runtime); diff --git a/packages/react-native/ReactCommon/react/runtime/ReactInstance.cpp b/packages/react-native/ReactCommon/react/runtime/ReactInstance.cpp index 392ab7513d0b91..c95b10d7575c17 100644 --- a/packages/react-native/ReactCommon/react/runtime/ReactInstance.cpp +++ b/packages/react-native/ReactCommon/react/runtime/ReactInstance.cpp @@ -103,8 +103,8 @@ ReactInstance::ReactInstance( // * On Android it's because we explicitly wait for the instance // creation task to finish before starting the destruction. inspectorTarget_ = &hostTarget.registerInstance(*this); - runtimeInspectorTarget_ = - &inspectorTarget_->registerRuntime(*runtime_, runtimeExecutor); + runtimeInspectorTarget_ = &inspectorTarget_->registerRuntime( + runtime_->getRuntimeTargetDelegate(), runtimeExecutor); runtimeExecutorThatWaitsForInspectorSetup->flush(); }); diff --git a/packages/react-native/ReactCommon/react/runtime/hermes/HermesInstance.cpp b/packages/react-native/ReactCommon/react/runtime/hermes/HermesInstance.cpp index 58e8af3c62d19d..3a32d353ce851c 100644 --- a/packages/react-native/ReactCommon/react/runtime/hermes/HermesInstance.cpp +++ b/packages/react-native/ReactCommon/react/runtime/hermes/HermesInstance.cpp @@ -101,20 +101,9 @@ class HermesJSRuntime : public JSRuntime { return *runtime_; } - std::unique_ptr createAgentDelegate( - jsinspector_modern::FrontendChannel frontendChannel, - jsinspector_modern::SessionState& sessionState, - std::unique_ptr - previouslyExportedState, - const jsinspector_modern::ExecutionContextDescription& - executionContextDescription, - RuntimeExecutor runtimeExecutor) override { - return targetDelegate_.createAgentDelegate( - std::move(frontendChannel), - sessionState, - std::move(previouslyExportedState), - executionContextDescription, - std::move(runtimeExecutor)); + jsinspector_modern::RuntimeTargetDelegate& getRuntimeTargetDelegate() + override { + return targetDelegate_; } private: