diff --git a/packages/react-native/ReactCommon/react/runtime/platform/ios/React-RuntimeApple.podspec b/packages/react-native/ReactCommon/react/runtime/platform/ios/React-RuntimeApple.podspec index 1e9917b8737d7e..f6f2272e26a1f3 100644 --- a/packages/react-native/ReactCommon/react/runtime/platform/ios/React-RuntimeApple.podspec +++ b/packages/react-native/ReactCommon/react/runtime/platform/ios/React-RuntimeApple.podspec @@ -73,5 +73,7 @@ Pod::Spec.new do |s| s.exclude_files = "ReactCommon/RCTHermesInstance.{mm,h}" end + s.exclude_files += "ReactCommon/RCTJermesInstance.{mm,h}" + add_rn_third_party_dependencies(s) end diff --git a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTJermesInstance.h b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTJermesInstance.h new file mode 100644 index 00000000000000..a104707cbe9c18 --- /dev/null +++ b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTJermesInstance.h @@ -0,0 +1,41 @@ +/* + * 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. + */ + +#import + +#import +#import +#import +#import +#import + +namespace facebook::react { + +using CrashManagerProvider = + std::function()>; + +// ObjC++ wrapper for HermesInstance.cpp +class RCTJermesInstance : public JSRuntimeFactory { + public: + RCTJermesInstance(); + RCTJermesInstance(CrashManagerProvider crashManagerProvider); + RCTJermesInstance( + CrashManagerProvider crashManagerProvider, + bool allocInOldGenBeforeTTI); + + std::unique_ptr createJSRuntime( + std::shared_ptr msgQueueThread) noexcept override; + + ~RCTJermesInstance() override{}; + + private: + CrashManagerProvider _crashManagerProvider; + std::unique_ptr _hermesInstance; + bool _allocInOldGenBeforeTTI; +}; + +} // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTJermesInstance.mm b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTJermesInstance.mm new file mode 100644 index 00000000000000..a14b2ce6f3a776 --- /dev/null +++ b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTJermesInstance.mm @@ -0,0 +1,33 @@ +/* + * 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. + */ + +#import "RCTJermesInstance.h" + +namespace facebook::react { + +RCTJermesInstance::RCTJermesInstance() : RCTJermesInstance(nullptr, false) {} + +RCTJermesInstance::RCTJermesInstance(CrashManagerProvider crashManagerProvider) + : RCTJermesInstance(std::move(crashManagerProvider), false) +{ +} + +RCTJermesInstance::RCTJermesInstance(CrashManagerProvider crashManagerProvider, bool allocInOldGenBeforeTTI) + : _crashManagerProvider(std::move(crashManagerProvider)), + _hermesInstance(std::make_unique()), + _allocInOldGenBeforeTTI(allocInOldGenBeforeTTI) +{ +} + +std::unique_ptr RCTJermesInstance::createJSRuntime( + std::shared_ptr msgQueueThread) noexcept +{ + return _hermesInstance->createJSRuntime( + _crashManagerProvider ? _crashManagerProvider() : nullptr, std::move(msgQueueThread), _allocInOldGenBeforeTTI); +} + +} // namespace facebook::react