Skip to content

Commit

Permalink
Refactor: Simplify signature of TurboModuleBinding::getModule
Browse files Browse the repository at this point in the history
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
  • Loading branch information
RSNara authored and facebook-github-bot committed Mar 15, 2023
1 parent 2d41e66 commit aa28ea0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}));
}

Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down

0 comments on commit aa28ea0

Please sign in to comment.