mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Refactor: Simplify signature of TurboModuleBinding::getModule
Summary: Previously, the signature of TurboModuleBinding::getModule was https://www.internalfb.com/code/fbsource/[839b8756fb58bf8cfa38a7d9f90b4b2b99889a37]/xplat/jsi/jsi/jsi.h?lines=111-112 **Problem:** TurboModuleBinding::getModule couldn't be called from [global.nativeModuleProxy](https://www.internalfb.com/code/fbsource/[cacaf79996c24c52fcedc90933b77dcf3411cf54]/xplat/ReactNative/venice/ReactInstance.cpp?lines=25-46) (i.e: jsi::HostObject::get), where only the prop name was available: https://www.internalfb.com/code/fbsource/[839b8756fb58bf8cfa38a7d9f90b4b2b99889a37]/xplat/jsi/jsi/jsi.h?lines=133 ## Changes This diff simplifies the signature of TurboModuleBinding::getModule to accept only what it needs: a jsi::Runtime, and moduleName This way, TurboModuleBinding::getModule can be called from: - jsi::HostFunction (for [global.__turboModuleProxy](https://www.internalfb.com/code/fbsource/[cc6106d532afd3f179b586d6acb4e99edb09bb96]/xplat/js/react-native-github/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp?lines=34-48)) - **new:** jsi::HostObject::get (for [global.nativeModuleProxy](https://www.internalfb.com/code/fbsource/[cacaf79996c24c52fcedc90933b77dcf3411cf54]/xplat/ReactNative/venice/ReactInstance.cpp?lines=25-46)). Changelog: [Internal] Reviewed By: javache, cortinico Differential Revision: D43993198 fbshipit-source-id: e1207a129b1033f96d2753c88d372bb7eb4364f3
This commit is contained in:
committed by
Facebook GitHub Bot
parent
2d41e6642e
commit
aa28ea01d2
@@ -44,7 +44,12 @@ void TurboModuleBinding::install(
|
||||
const jsi::Value &thisVal,
|
||||
const jsi::Value *args,
|
||||
size_t count) {
|
||||
return binding.getModule(rt, thisVal, args, count);
|
||||
if (count < 1) {
|
||||
throw std::invalid_argument(
|
||||
"__turboModuleProxy must be called with at least 1 argument");
|
||||
}
|
||||
std::string moduleName = args[0].getString(rt).utf8(rt);
|
||||
return binding.getModule(rt, moduleName);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -54,15 +59,7 @@ TurboModuleBinding::~TurboModuleBinding() {
|
||||
|
||||
jsi::Value TurboModuleBinding::getModule(
|
||||
jsi::Runtime &runtime,
|
||||
const jsi::Value &thisVal,
|
||||
const jsi::Value *args,
|
||||
size_t count) const {
|
||||
if (count < 1) {
|
||||
throw std::invalid_argument(
|
||||
"__turboModuleProxy must be called with at least 1 argument");
|
||||
}
|
||||
std::string moduleName = args[0].getString(runtime).utf8(runtime);
|
||||
|
||||
const std::string &moduleName) const {
|
||||
std::shared_ptr<TurboModule> module;
|
||||
{
|
||||
SystraceSection s(
|
||||
|
||||
@@ -45,11 +45,8 @@ class TurboModuleBinding {
|
||||
* A lookup function exposed to JS to get an instance of a TurboModule
|
||||
* for the given name.
|
||||
*/
|
||||
jsi::Value getModule(
|
||||
jsi::Runtime &runtime,
|
||||
const jsi::Value &thisVal,
|
||||
const jsi::Value *args,
|
||||
size_t count) const;
|
||||
jsi::Value getModule(jsi::Runtime &runtime, const std::string &moduleName)
|
||||
const;
|
||||
|
||||
TurboModuleProviderFunctionType moduleProvider_;
|
||||
TurboModuleBindingMode bindingMode_;
|
||||
|
||||
Reference in New Issue
Block a user