Skip to content

Commit

Permalink
introduce unstable_enableSyncVoidMethods config
Browse files Browse the repository at this point in the history
Differential Revision: D50028200

fbshipit-source-id: 343379309c335f82679b17473af976a25e751c45
  • Loading branch information
philIip authored and facebook-github-bot committed Oct 9, 2023
1 parent a2d0eb6 commit 5267f85
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public TurboModuleManager(
(CallInvokerHolderImpl) jsCallInvokerHolder,
(NativeMethodCallInvokerHolderImpl) nativeMethodCallInvokerHolder,
delegate);
installJSIBindings(shouldEnableLegacyModuleInterop());
installJSIBindings(shouldEnableLegacyModuleInterop(), enableSyncVoidMethods());

mEagerInitModuleNames =
delegate == null ? new ArrayList<>() : delegate.getEagerInitModuleNames();
Expand Down Expand Up @@ -116,6 +116,10 @@ private boolean shouldRouteTurboModulesThroughLegacyModuleInterop() {
&& mDelegate.unstable_shouldRouteTurboModulesThroughLegacyModuleInterop();
}

private boolean enableSyncVoidMethods() {
return mDelegate != null && mDelegate.unstable_enableSyncVoidMethods();
}

@Override
@NonNull
public List<String> getEagerInitModuleNames() {
Expand Down Expand Up @@ -417,7 +421,8 @@ private native HybridData initHybrid(
NativeMethodCallInvokerHolderImpl nativeMethodCallInvoker,
TurboModuleManagerDelegate tmmDelegate);

private native void installJSIBindings(boolean shouldCreateLegacyModules);
private native void installJSIBindings(
boolean shouldCreateLegacyModules, boolean enableSyncVoidMethods);

@Override
public void initialize() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,9 @@ public boolean unstable_shouldRouteTurboModulesThroughLegacyModuleInterop() {
return false;
}

public boolean unstable_enableSyncVoidMethods() {
return false;
}

protected synchronized void maybeLoadOtherSoLibraries() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ void TurboModuleManager::registerNatives() {
});
}

TurboModuleProviderFunctionType
TurboModuleManager::createTurboModuleProvider() {
TurboModuleProviderFunctionType TurboModuleManager::createTurboModuleProvider(
bool enableSyncVoidMethods) {
return [turboModuleCache_ = std::weak_ptr<ModuleCache>(turboModuleCache_),
jsCallInvoker_ = std::weak_ptr<CallInvoker>(jsCallInvoker_),
nativeMethodCallInvoker_ =
Expand Down Expand Up @@ -209,8 +209,8 @@ TurboModuleManager::createTurboModuleProvider() {
};
}

TurboModuleProviderFunctionType
TurboModuleManager::createLegacyModuleProvider() {
TurboModuleProviderFunctionType TurboModuleManager::createLegacyModuleProvider(
bool enableSyncVoidMethods) {
return [legacyModuleCache_ = std::weak_ptr<ModuleCache>(legacyModuleCache_),
jsCallInvoker_ = std::weak_ptr<CallInvoker>(jsCallInvoker_),
nativeMethodCallInvoker_ =
Expand Down Expand Up @@ -302,21 +302,27 @@ TurboModuleManager::createLegacyModuleProvider() {
};
}

void TurboModuleManager::installJSIBindings(bool shouldCreateLegacyModules) {
void TurboModuleManager::installJSIBindings(
bool shouldCreateLegacyModules,
bool enableSyncVoidMethods) {
if (!jsCallInvoker_) {
return; // Runtime doesn't exist when attached to Chrome debugger.
}

bool isInteropLayerDisabled = !shouldCreateLegacyModules;

runtimeExecutor_([this, isInteropLayerDisabled](jsi::Runtime& runtime) {
runtimeExecutor_([this, isInteropLayerDisabled, enableSyncVoidMethods](
jsi::Runtime& runtime) {
if (isInteropLayerDisabled) {
TurboModuleBinding::install(runtime, createTurboModuleProvider());
TurboModuleBinding::install(
runtime, createTurboModuleProvider(enableSyncVoidMethods));
return;
}

TurboModuleBinding::install(
runtime, createTurboModuleProvider(), createLegacyModuleProvider());
runtime,
createTurboModuleProvider(enableSyncVoidMethods),
createLegacyModuleProvider(enableSyncVoidMethods));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,20 @@ class TurboModuleManager : public jni::HybridClass<TurboModuleManager> {
std::shared_ptr<ModuleCache> turboModuleCache_;
std::shared_ptr<ModuleCache> legacyModuleCache_;

void installJSIBindings(bool shouldCreateLegacyModules);
void installJSIBindings(
bool shouldCreateLegacyModules,
bool enableSyncVoidMethods);
explicit TurboModuleManager(
jni::alias_ref<TurboModuleManager::jhybridobject> jThis,
RuntimeExecutor runtimeExecutor,
std::shared_ptr<CallInvoker> jsCallInvoker,
std::shared_ptr<NativeMethodCallInvoker> nativeMethodCallInvoker,
jni::alias_ref<TurboModuleManagerDelegate::javaobject> delegate);

TurboModuleProviderFunctionType createTurboModuleProvider();
TurboModuleProviderFunctionType createLegacyModuleProvider();
TurboModuleProviderFunctionType createTurboModuleProvider(
bool enableSyncVoidMethods);
TurboModuleProviderFunctionType createLegacyModuleProvider(
bool enableSyncVoidMethods);
};

} // namespace facebook::react

0 comments on commit 5267f85

Please sign in to comment.