Skip to content

Commit

Permalink
Initialize the RuntimeScheduler and TurboModule bindings via RuntimeE…
Browse files Browse the repository at this point in the history
…xecutor

In order to minimize the dependency on the JSI runtime holder, this
switches the initialization of TurboModules and RuntimeScheduler
bindings to use the RuntimeExecutor, which hands us back the Runtime
instance.
  • Loading branch information
rozele committed Nov 15, 2023
1 parent 20a4c9b commit 13890a0
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions vnext/Shared/OInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,17 +361,15 @@ InstanceImpl::InstanceImpl(
winrt::Microsoft::ReactNative::ReactPropertyBag(propertyBag), m_runtimeScheduler);
}

// Using runOnQueueSync because initializeBridge calls createJSExecutor with runOnQueueSync,
// so this is an attempt to keep the same semantics for exiting this method with TurboModuleManager
// initialized.
m_jsThread->runOnQueueSync([propertyBag,
innerInstance = m_innerInstance,
runtimeHolder = m_devSettings->jsiRuntimeHolder,
runtimeScheduler = m_runtimeScheduler,
turboModuleRegistry = m_turboModuleRegistry,
longLivedObjectCollection = m_longLivedObjectCollection]() {
// Use RuntimeExecutor so non-ABI JSExecutorFactory instances passed in through DevSettings
// can use the same logic
runtimeExecutor([propertyBag,
innerInstance = m_innerInstance,
runtimeScheduler = m_runtimeScheduler,
turboModuleRegistry = m_turboModuleRegistry,
longLivedObjectCollection = m_longLivedObjectCollection](jsi::Runtime &runtime) {
if (runtimeScheduler) {
RuntimeSchedulerBinding::createAndInstallIfNeeded(*runtimeHolder->getRuntime(), runtimeScheduler);
RuntimeSchedulerBinding::createAndInstallIfNeeded(runtime, runtimeScheduler);
}
auto turboModuleManager = std::make_shared<TurboModuleManager>(
turboModuleRegistry,
Expand All @@ -386,10 +384,7 @@ InstanceImpl::InstanceImpl(
};

TurboModuleBinding::install(
*runtimeHolder->getRuntime(),
std::function(binding),
TurboModuleBindingMode::HostObject,
longLivedObjectCollection);
runtime, std::function(binding), TurboModuleBindingMode::HostObject, longLivedObjectCollection);

// init TurboModule
for (const auto &moduleName : turboModuleManager->getEagerInitModuleNames()) {
Expand Down

0 comments on commit 13890a0

Please sign in to comment.