Repository: expo/expo
File: packages/expo-modules-core/android/src/main/cpp/installers/MainRuntimeInstaller.cpp (C++)

Code before:
    self,
    jsiContext
  );

  return jsiContext;
}

jni::local_ref<JSIContext::javaobject> MainRuntimeInstaller::install(
  jni::alias_ref<MainRuntimeInstaller::javaobject> self,
  jni::alias_ref<jni::JWeakReference<jobject>::javaobject> runtimeContextHolder,
  jlong jsRuntimePointer,
  jni::alias_ref<JNIDeallocator::javaobject> jniDeallocator,
  jni::alias_ref<react::JRuntimeExecutor::javaobject> runtimeExecutor
) noexcept {
  auto jsiContext = createJSIContext(
    runtimeContextHolder,
    jsRuntimePointer,
    jniDeallocator,
    std::make_shared<BridgelessJSCallInvoker>(runtimeExecutor->cthis()->get())
  );

  prepareRuntime(
    self,
    jsiContext
  );

  return jsiContext;
}

jni::local_ref<JSIContext::javaobject> MainRuntimeInstaller::createJSIContext(
  jni::alias_ref<jni::JWeakReference<jobject>::javaobject> runtimeContextHolder,
  jlong jsRuntimePointer,
  jni::alias_ref<JNIDeallocator::javaobject> jniDeallocator,
  std::shared_ptr<react::CallInvoker> callInvoker
) noexcept {
  auto cxxPart = std::make_unique<JSIContext>(
    jsRuntimePointer,
    std::move(jniDeallocator),
    std::move(callInvoker)
  );

  auto hybridData = jni::detail::HybridData::create();
  auto javaPart = JSIContext::newJavaInstance(
    hybridData,
    runtimeContextHolder
  );
  cxxPart->bindToJavaPart(javaPart);

  jni::detail::setNativePointer(hybridData, std::move(cxxPart));

  return javaPart;

Review comment (bug):
I think we don't need this anymore, and throwing an error here would be a better approach. I can change it in the following PR, so you can merge it as is.

Code after:

  prepareRuntime(
    self,
    jsiContext
  );

  return jsiContext;
}

jni::local_ref<JSIContext::javaobject> MainRuntimeInstaller::install(
  jni::alias_ref<MainRuntimeInstaller::javaobject> self,
  jni::alias_ref<jni::JWeakReference<jobject>::javaobject> runtimeContextHolder,
  jlong jsRuntimePointer,
  jni::alias_ref<JNIDeallocator::javaobject> jniDeallocator,
  jni::alias_ref<react::JRuntimeExecutor::javaobject> runtimeExecutor
) noexcept {
  auto *runtime = reinterpret_cast<jsi::Runtime *>(jsRuntimePointer);

  std::shared_ptr<react::CallInvoker> callInvoker;
  std::shared_ptr<react::RuntimeScheduler> runtimeScheduler;

  if (auto binding = react::RuntimeSchedulerBinding::getBinding(*runtime)) {
    runtimeScheduler = binding->getRuntimeScheduler();
    callInvoker = std::make_shared<react::RuntimeSchedulerCallInvoker>(runtimeScheduler);
  } else {
    callInvoker = std::make_shared<BridgelessJSCallInvoker>(runtimeExecutor->cthis()->get());
  }

  auto jsiContext = createJSIContext(
    runtimeContextHolder,
    jsRuntimePointer,
    jniDeallocator,
    callInvoker
  );

  prepareRuntime(
    self,
    jsiContext
  );

  return jsiContext;
}

jni::local_ref<JSIContext::javaobject> MainRuntimeInstaller::createJSIContext(
  jni::alias_ref<jni::JWeakReference<jobject>::javaobject> runtimeContextHolder,
  jlong jsRuntimePointer,
  jni::alias_ref<JNIDeallocator::javaobject> jniDeallocator,
  std::shared_ptr<react::CallInvoker> callInvoker
) noexcept {
  auto cxxPart = std::make_unique<JSIContext>(
    jsRuntimePointer,