Skip to content

Commit

Permalink
Rename JSEngineInstance -> JSRuntimeFactory (facebook#41548)
Browse files Browse the repository at this point in the history
Summary:

`JSEngineInstance` is a misnomer - this interface actually creates `jsi::Runtime`s and doesn't represent an "instance of a JS engine". This diff renames it to `JSRuntimeFactory`.

Changelog: [Internal]

Reviewed By: huntie, arushikesarwani94

Differential Revision: D51447882
  • Loading branch information
motiz88 authored and facebook-github-bot committed Nov 20, 2023
1 parent e832378 commit 7f5703b
Show file tree
Hide file tree
Showing 23 changed files with 63 additions and 63 deletions.
8 changes: 4 additions & 4 deletions packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#import <react/config/ReactNativeConfig.h>
#import <react/renderer/runtimescheduler/RuntimeScheduler.h>
#import <react/renderer/runtimescheduler/RuntimeSchedulerCallInvoker.h>
#import <react/runtime/JSEngineInstance.h>
#import <react/runtime/JSRuntimeFactory.h>

static NSString *const kRNConcurrentRoot = @"concurrentRoot";

Expand Down Expand Up @@ -293,8 +293,8 @@ - (void)createReactHost
_reactHost = [[RCTHost alloc] initWithBundleURL:[self bundleURL]
hostDelegate:nil
turboModuleManagerDelegate:self
jsEngineProvider:^std::shared_ptr<facebook::react::JSEngineInstance>() {
return [weakSelf createJSEngineInstance];
jsEngineProvider:^std::shared_ptr<facebook::react::JSRuntimeFactory>() {
return [weakSelf createJSRuntimeFactory];
}];
[_reactHost setBundleURLProvider:^NSURL *() {
return [weakSelf bundleURL];
Expand All @@ -303,7 +303,7 @@ - (void)createReactHost
[_reactHost start];
}

- (std::shared_ptr<facebook::react::JSEngineInstance>)createJSEngineInstance
- (std::shared_ptr<facebook::react::JSRuntimeFactory>)createJSRuntimeFactory
{
#if USE_HERMES
return std::make_shared<facebook::react::RCTHermesInstance>(_reactNativeConfig, nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ object DefaultReactHost {
if (reactHost == null) {
val jsBundleLoader =
JSBundleLoader.createAssetLoader(context, "assets://$jsBundleAssetPath", true)
val jsEngineInstance = if (isHermesEnabled) HermesInstance() else JSCInstance()
val jsRuntimeFactory = if (isHermesEnabled) HermesInstance() else JSCInstance()
val defaultReactHostDelegate =
DefaultReactHostDelegate(
jsMainModulePath = jsMainModulePath,
jsBundleLoader = jsBundleLoader,
reactPackages = packageList,
jsEngineInstance = jsEngineInstance,
jsRuntimeFactory = jsRuntimeFactory,
turboModuleManagerDelegateBuilder = DefaultTurboModuleManagerDelegate.Builder())
val reactJsExceptionHandler = ReactJsExceptionHandler { _ -> }
val componentFactory = ComponentFactory()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import com.facebook.react.bridge.JSBundleLoader
import com.facebook.react.common.annotations.UnstableReactNativeAPI
import com.facebook.react.fabric.ReactNativeConfig
import com.facebook.react.runtime.BindingsInstaller
import com.facebook.react.runtime.JSEngineInstance
import com.facebook.react.runtime.JSRuntimeFactory
import com.facebook.react.runtime.ReactHostDelegate
import com.facebook.react.runtime.hermes.HermesInstance

Expand All @@ -28,7 +28,7 @@ import com.facebook.react.runtime.hermes.HermesInstance
* @param jsBundleLoader Bundle loader to use when setting up JS environment. <p>Example:
* [JSBundleLoader.createFileLoader(application, bundleFile)]
* @param reactPackages list of reactPackages to expose Native Modules and View Components to JS
* @param jsEngineInstance Object that holds a native reference to the javascript engine
* @param jsRuntimeFactory Object that holds a native reference to the JS Runtime factory
* @param bindingsInstaller Object that holds a native C++ references that allow host applications
* to install C++ objects into jsi::Runtime during the initialization of React Native
* @param reactNativeConfig ReactNative Configuration that allows to customize the behavior of
Expand All @@ -42,7 +42,7 @@ class DefaultReactHostDelegate(
override val jsMainModulePath: String,
override val jsBundleLoader: JSBundleLoader,
override val reactPackages: List<ReactPackage> = emptyList(),
override val jsEngineInstance: JSEngineInstance = HermesInstance(),
override val jsRuntimeFactory: JSRuntimeFactory = HermesInstance(),
override val bindingsInstaller: BindingsInstaller = DefaultBindingsInstaller(),
private val reactNativeConfig: ReactNativeConfig = ReactNativeConfig.DEFAULT_CONFIG,
private val exceptionHandler: (Exception) -> Unit = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import com.facebook.soloader.SoLoader;

@Nullsafe(Nullsafe.Mode.LOCAL)
public class JSCInstance extends JSEngineInstance {
public class JSCInstance extends JSRuntimeFactory {
static {
SoLoader.loadLibrary("jscinstance");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
import com.facebook.soloader.SoLoader;

@Nullsafe(Nullsafe.Mode.LOCAL)
public abstract class JSEngineInstance {
public abstract class JSRuntimeFactory {
static {
SoLoader.loadLibrary("rninstance");
}

@DoNotStrip private final HybridData mHybridData;

protected JSEngineInstance(HybridData hybridData) {
protected JSRuntimeFactory(HybridData hybridData) {
mHybridData = hybridData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ interface ReactHostDelegate {
val reactPackages: List<ReactPackage>

/** Object that holds a native reference to the javascript engine */
val jsEngineInstance: JSEngineInstance
val jsRuntimeFactory: JSRuntimeFactory

/**
* Bundle loader to use when setting up JS environment. <p>Example:
Expand Down Expand Up @@ -68,7 +68,7 @@ interface ReactHostDelegate {
class ReactHostDelegateBase(
override val jsMainModulePath: String,
override val jsBundleLoader: JSBundleLoader,
override val jsEngineInstance: JSEngineInstance,
override val jsRuntimeFactory: JSRuntimeFactory,
override val turboModuleManagerDelegateBuilder:
ReactPackageTurboModuleManagerDelegate.Builder,
override val reactPackages: List<ReactPackage> = emptyList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void onHostDestroy() {
}
});

JSEngineInstance jsEngineInstance = mDelegate.getJsEngineInstance();
JSRuntimeFactory jsRuntimeFactory = mDelegate.getJsRuntimeFactory();
BindingsInstaller bindingsInstaller = mDelegate.getBindingsInstaller();
// Notify JS if profiling is enabled
boolean isProfiling =
Expand All @@ -177,7 +177,7 @@ public void onHostDestroy() {
boolean useModernRuntimeScheduler = ReactFeatureFlags.useModernRuntimeScheduler;
mHybridData =
initHybrid(
jsEngineInstance,
jsRuntimeFactory,
jsMessageQueueThread,
nativeModulesMessageQueueThread,
mJavaTimerManager,
Expand Down Expand Up @@ -432,7 +432,7 @@ public Collection<NativeModule> getNativeModules() {

@DoNotStrip
private native HybridData initHybrid(
JSEngineInstance jsEngineInstance,
JSRuntimeFactory jsRuntimeFactory,
MessageQueueThread jsMessageQueueThread,
MessageQueueThread nativeModulesMessageQueueThread,
JavaTimerManager timerManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ package com.facebook.react.runtime.hermes
import com.facebook.jni.HybridData
import com.facebook.jni.annotations.DoNotStrip
import com.facebook.react.fabric.ReactNativeConfig
import com.facebook.react.runtime.JSEngineInstance
import com.facebook.react.runtime.JSRuntimeFactory
import com.facebook.soloader.SoLoader

class HermesInstance constructor(reactNativeConfig: ReactNativeConfig?) :
JSEngineInstance(initHybrid(reactNativeConfig as Any?)) {
JSRuntimeFactory(initHybrid(reactNativeConfig as Any?)) {

constructor() : this(null)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
#include <jni.h>
#include <jsi/jsi.h>
#include <react/config/ReactNativeConfig.h>
#include <react/runtime/JSEngineInstance.h>
#include <react/runtime/JSRuntimeFactory.h>
#include <react/runtime/hermes/HermesInstance.h>
#include "../../jni/JJSEngineInstance.h"
#include "../../jni/JJSRuntimeFactory.h"

namespace facebook::react {

class JHermesInstance
: public jni::HybridClass<JHermesInstance, JJSEngineInstance> {
: public jni::HybridClass<JHermesInstance, JJSRuntimeFactory> {
public:
static constexpr auto kJavaDescriptor =
"Lcom/facebook/react/runtime/hermes/HermesInstance;";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

#include <fbjni/fbjni.h>
#include <jni.h>
#include <react/runtime/JSEngineInstance.h>
#include <react/runtime/JSRuntimeFactory.h>

namespace facebook::react {

class JJSEngineInstance : public jni::HybridClass<JJSEngineInstance>,
public JSEngineInstance {
class JJSRuntimeFactory : public jni::HybridClass<JJSRuntimeFactory>,
public JSRuntimeFactory {
public:
static auto constexpr kJavaDescriptor =
"Lcom/facebook/react/runtime/JSEngineInstance;";
"Lcom/facebook/react/runtime/JSRuntimeFactory;";

private:
friend HybridBase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
namespace facebook::react {

JReactInstance::JReactInstance(
jni::alias_ref<JJSEngineInstance::javaobject> jsEngineInstance,
jni::alias_ref<JJSRuntimeFactory::javaobject> jsRuntimeFactory,
jni::alias_ref<JavaMessageQueueThread::javaobject> jsMessageQueueThread,
jni::alias_ref<JavaMessageQueueThread::javaobject> nativeMessageQueueThread,
jni::alias_ref<JJavaTimerManager::javaobject> javaTimerManager,
Expand Down Expand Up @@ -62,7 +62,7 @@ JReactInstance::JReactInstance(
jBindingsInstaller_ = jni::make_global(jBindingsInstaller);

instance_ = std::make_unique<ReactInstance>(
jsEngineInstance->cthis()->createJSRuntime(sharedJSMessageQueueThread),
jsRuntimeFactory->cthis()->createJSRuntime(sharedJSMessageQueueThread),
sharedJSMessageQueueThread,
timerManager,
std::move(jsErrorHandlingFunc),
Expand Down Expand Up @@ -110,7 +110,7 @@ JReactInstance::JReactInstance(

jni::local_ref<JReactInstance::jhybriddata> JReactInstance::initHybrid(
jni::alias_ref<jhybridobject> /* unused */,
jni::alias_ref<JJSEngineInstance::javaobject> jsEngineInstance,
jni::alias_ref<JJSRuntimeFactory::javaobject> jsRuntimeFactory,
jni::alias_ref<JavaMessageQueueThread::javaobject> jsMessageQueueThread,
jni::alias_ref<JavaMessageQueueThread::javaobject> nativeMessageQueueThread,
jni::alias_ref<JJavaTimerManager::javaobject> javaTimerManager,
Expand All @@ -120,7 +120,7 @@ jni::local_ref<JReactInstance::jhybriddata> JReactInstance::initHybrid(
bool isProfiling,
bool useModernRuntimeScheduler) {
return makeCxxInstance(
jsEngineInstance,
jsRuntimeFactory,
jsMessageQueueThread,
nativeMessageQueueThread,
javaTimerManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
#include <react/jni/JRuntimeScheduler.h>
#include <react/jni/JSLoader.h>
#include <react/jni/ReadableNativeMap.h>
#include <react/runtime/JSEngineInstance.h>
#include <react/runtime/JSRuntimeFactory.h>
#include <react/runtime/PlatformTimerRegistry.h>
#include <react/runtime/ReactInstance.h>

#include "JBindingsInstaller.h"
#include "JJSEngineInstance.h"
#include "JJSRuntimeFactory.h"
#include "JJSTimerExecutor.h"
#include "JJavaTimerManager.h"
#include "JReactExceptionManager.h"
Expand All @@ -37,7 +37,7 @@ class JReactInstance : public jni::HybridClass<JReactInstance> {

static jni::local_ref<jhybriddata> initHybrid(
jni::alias_ref<jhybridobject>,
jni::alias_ref<JJSEngineInstance::javaobject> jsEngineInstance,
jni::alias_ref<JJSRuntimeFactory::javaobject> jsRuntimeFactory,
jni::alias_ref<JavaMessageQueueThread::javaobject> jsMessageQueueThread,
jni::alias_ref<JavaMessageQueueThread::javaobject>
nativeMessageQueueThread,
Expand Down Expand Up @@ -83,7 +83,7 @@ class JReactInstance : public jni::HybridClass<JReactInstance> {
friend HybridBase;

explicit JReactInstance(
jni::alias_ref<JJSEngineInstance::javaobject> jsEngineInstance,
jni::alias_ref<JJSRuntimeFactory::javaobject> jsRuntimeFactory,
jni::alias_ref<JavaMessageQueueThread::javaobject> jsMessageQueueThread,
jni::alias_ref<JavaMessageQueueThread::javaobject>
nativeMessageQueueThread,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
#include <jsc/JSCRuntime.h>
#include <jsi/jsi.h>
#include <react/jni/ReadableNativeMap.h>
#include <react/runtime/JSEngineInstance.h>
#include <react/runtime/jni/JJSEngineInstance.h>
#include <react/runtime/JSRuntimeFactory.h>
#include <react/runtime/jni/JJSRuntimeFactory.h>

namespace facebook::react {

class JSCInstance : public jni::HybridClass<JSCInstance, JJSEngineInstance> {
class JSCInstance : public jni::HybridClass<JSCInstance, JJSRuntimeFactory> {
public:
static constexpr auto kJavaDescriptor =
"Lcom/facebook/react/runtime/JSCInstance;";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ class ReactHostDelegateTest {
val jsBundleLoader: JSBundleLoader = Mockito.mock(JSBundleLoader::class.java)
val turboModuleManagerDelegateBuilderMock: ReactPackageTurboModuleManagerDelegate.Builder =
Mockito.mock(ReactPackageTurboModuleManagerDelegate.Builder::class.java)
val hermesInstance: JSEngineInstance = Mockito.mock(HermesInstance::class.java)
val hermesInstance: JSRuntimeFactory = Mockito.mock(HermesInstance::class.java)
val jsMainModulePathMocked = "mockedJSMainModulePath"
val delegate =
DefaultReactHostDelegate(
jsMainModulePath = jsMainModulePathMocked,
jsBundleLoader = jsBundleLoader,
jsEngineInstance = hermesInstance,
jsRuntimeFactory = hermesInstance,
turboModuleManagerDelegateBuilder = turboModuleManagerDelegateBuilderMock)

assertThat(delegate.jsMainModulePath).isEqualTo(jsMainModulePathMocked)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
namespace facebook::react {

/**
* Interface for a class that creates and owns an instance of a JS VM
* Interface for a class that creates instances of a JS VM
*/
class JSEngineInstance {
class JSRuntimeFactory {
public:
virtual std::unique_ptr<jsi::Runtime> createJSRuntime(
std::shared_ptr<MessageQueueThread> msgQueueThread) noexcept = 0;

virtual ~JSEngineInstance() = default;
virtual ~JSRuntimeFactory() = default;
};

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ - (void)setUp
_subject = [[RCTHost alloc] initWithBundleURL:OCMClassMock([NSURL class])
hostDelegate:_mockHostDelegate
turboModuleManagerDelegate:OCMProtocolMock(@protocol(RCTTurboModuleManagerDelegate))
jsEngineProvider:^std::shared_ptr<facebook::react::JSEngineInstance>() {
jsEngineProvider:^std::shared_ptr<facebook::react::JSRuntimeFactory>() {
return std::make_shared<facebook::react::RCTHermesInstance>();
}];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import <cxxreact/MessageQueueThread.h>
#import <hermes/Public/CrashManager.h>
#import <jsi/jsi.h>
#import <react/runtime/JSEngineInstance.h>
#import <react/runtime/JSRuntimeFactory.h>
#import <react/runtime/hermes/HermesInstance.h>

namespace facebook {
Expand All @@ -19,7 +19,7 @@ using CrashManagerProvider =
std::function<std::shared_ptr<::hermes::vm::CrashManager>()>;

// ObjC++ wrapper for HermesInstance.cpp
class RCTHermesInstance : public JSEngineInstance {
class RCTHermesInstance : public JSRuntimeFactory {
public:
RCTHermesInstance();
RCTHermesInstance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#import <React/RCTDefines.h>
#import <react/renderer/core/ReactPrimitives.h>
#import <react/runtime/JSEngineInstance.h>
#import <react/runtime/JSRuntimeFactory.h>

#import "RCTInstance.h"

Expand Down Expand Up @@ -53,7 +53,7 @@ NS_ASSUME_NONNULL_BEGIN

@end

typedef std::shared_ptr<facebook::react::JSEngineInstance> (^RCTHostJSEngineProvider)(void);
typedef std::shared_ptr<facebook::react::JSRuntimeFactory> (^RCTHostJSEngineProvider)(void);

@interface RCTHost : NSObject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ - (void)start
[_instance invalidate];
}
_instance = [[RCTInstance alloc] initWithDelegate:self
jsEngineInstance:[self _provideJSEngine]
jsRuntimeFactory:[self _provideJSEngine]
bundleManager:_bundleManager
turboModuleManagerDelegate:_turboModuleManagerDelegate
onInitialBundleLoad:_onInitialBundleLoad
Expand Down Expand Up @@ -214,7 +214,7 @@ - (void)didReceiveReloadCommand
}

_instance = [[RCTInstance alloc] initWithDelegate:self
jsEngineInstance:[self _provideJSEngine]
jsRuntimeFactory:[self _provideJSEngine]
bundleManager:_bundleManager
turboModuleManagerDelegate:_turboModuleManagerDelegate
onInitialBundleLoad:_onInitialBundleLoad
Expand Down Expand Up @@ -301,10 +301,10 @@ - (void)_attachSurface:(RCTFabricSurface *)surface
return surfaces;
}

- (std::shared_ptr<facebook::react::JSEngineInstance>)_provideJSEngine
- (std::shared_ptr<facebook::react::JSRuntimeFactory>)_provideJSEngine
{
RCTAssert(_jsEngineProvider, @"_jsEngineProvider must be non-nil");
std::shared_ptr<facebook::react::JSEngineInstance> jsEngine = _jsEngineProvider();
std::shared_ptr<facebook::react::JSRuntimeFactory> jsEngine = _jsEngineProvider();
RCTAssert(jsEngine != nullptr, @"_jsEngineProvider must return a nonnull pointer");

return jsEngine;
Expand Down
Loading

0 comments on commit 7f5703b

Please sign in to comment.