Fix HermesExecutorFactory build error (#44423)

Summary:
https://github.com/facebook/react-native/commit/7af288e5 introduced a breaking change for whoever importing HermesExecutorFactory.h, because the `hermes/inspector-modern/chrome/HermesRuntimeTargetDelegate.h` is not a public header. Also the nested import is not ideal for CocoaPods or use_frameworks.
I think HermesRuntimeTargetDelegate could be an implementation detail that hide from header. This PR tries to turn the ownership declaration from std::optional to std::unique_ptr, so that we could hide the concrete type.

## Changelog:

[IOS] [FIXED] - Fixed `HermesExecutorFactory.h` build error when importing its private header

Pull Request resolved: https://github.com/facebook/react-native/pull/44423

Test Plan: should introduce no breaking change and ci passed

Reviewed By: cipolleschi

Differential Revision: D57041498

Pulled By: huntie

fbshipit-source-id: bfa10c7307458813d99c52313682dd62bea80f19
This commit is contained in:
Kudo Chien
2024-05-07 03:06:54 -07:00
committed by Facebook GitHub Bot
parent 362abb9ffe
commit 2d46dbe6ce
2 changed files with 5 additions and 4 deletions
@@ -13,6 +13,7 @@
#include <jsi/decorator.h>
#include <jsinspector-modern/InspectorFlags.h>
#include <hermes/inspector-modern/chrome/HermesRuntimeTargetDelegate.h>
#include <hermes/inspector-modern/chrome/Registration.h>
#include <hermes/inspector/RuntimeAdapter.h>
@@ -258,7 +259,9 @@ HermesExecutor::HermesExecutor(
jsinspector_modern::RuntimeTargetDelegate&
HermesExecutor::getRuntimeTargetDelegate() {
if (!targetDelegate_) {
targetDelegate_.emplace(hermesRuntime_);
targetDelegate_ =
std::make_unique<jsinspector_modern::HermesRuntimeTargetDelegate>(
hermesRuntime_);
}
return *targetDelegate_;
}
@@ -8,7 +8,6 @@
#pragma once
#include <hermes/hermes.h>
#include <hermes/inspector-modern/chrome/HermesRuntimeTargetDelegate.h>
#include <jsireact/JSIExecutor.h>
#include <utility>
@@ -62,8 +61,7 @@ class HermesExecutor : public JSIExecutor {
JSIScopedTimeoutInvoker timeoutInvoker_;
std::shared_ptr<jsi::Runtime> runtime_;
std::shared_ptr<hermes::HermesRuntime> hermesRuntime_;
std::optional<jsinspector_modern::HermesRuntimeTargetDelegate>
targetDelegate_;
std::unique_ptr<jsinspector_modern::RuntimeTargetDelegate> targetDelegate_;
};
} // namespace facebook::react