From 3740c943e7aa4a6c64e75aab3130d633e68450e0 Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Sat, 27 Dec 2025 16:43:19 -0800 Subject: [PATCH] Make TurboModuleBinding constructor private Summary: The TurboModuleBinding constructor actually doesn't need to be public! It's only called from BridgelessTurboModuleProxy or TurboModuleBinding::install. Changelog: [General][Breaking] Make the TurboModuleBinding constructor private. Reviewed By: christophpurrer Differential Revision: D89751218 --- .../core/ReactCommon/TurboModuleBinding.cpp | 13 +++++++------ .../core/ReactCommon/TurboModuleBinding.h | 10 +++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp b/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp index 195811f9876..f826fe16253 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp @@ -19,7 +19,7 @@ namespace facebook::react { class BridgelessNativeModuleProxy : public jsi::HostObject { TurboModuleBinding turboBinding_; - std::unique_ptr legacyBinding_; + std::optional legacyBinding_; public: BridgelessNativeModuleProxy( @@ -32,11 +32,12 @@ class BridgelessNativeModuleProxy : public jsi::HostObject { std::move(moduleProvider), longLivedObjectCollection), legacyBinding_( - legacyModuleProvider ? std::make_unique( - runtime, - std::move(legacyModuleProvider), - longLivedObjectCollection) - : nullptr) {} + legacyModuleProvider + ? std::make_optional(TurboModuleBinding( + runtime, + std::move(legacyModuleProvider), + longLivedObjectCollection)) + : std::nullopt) {} jsi::Value get(jsi::Runtime& runtime, const jsi::PropNameID& name) override { /** diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.h b/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.h index ef94423c04e..a6aece1e39e 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.h +++ b/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.h @@ -33,16 +33,16 @@ class TurboModuleBinding final { TurboModuleProviderFunctionType &&legacyModuleProvider = nullptr, std::shared_ptr longLivedObjectCollection = nullptr); - TurboModuleBinding( - jsi::Runtime &runtime, - TurboModuleProviderFunctionType &&moduleProvider, - std::shared_ptr longLivedObjectCollection); - ~TurboModuleBinding(); private: friend BridgelessNativeModuleProxy; + TurboModuleBinding( + jsi::Runtime &runtime, + TurboModuleProviderFunctionType &&moduleProvider, + std::shared_ptr longLivedObjectCollection); + /** * A lookup function exposed to JS to get an instance of a TurboModule * for the given name.