diff --git a/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost.h b/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost.h index 603e795f1778ed..917e9544ee9be4 100644 --- a/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost.h +++ b/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost.h @@ -39,7 +39,6 @@ typedef std::shared_ptr (^RCTHostJSEngineProv @protocol RCTHostDelegate -- (std::shared_ptr)getJSEngine; - (NSURL *)getBundleURL; - (std::shared_ptr)createContextContainer; @@ -61,8 +60,7 @@ typedef std::shared_ptr (^RCTHostJSEngineProv - (instancetype)initWithHostDelegate:(id)hostDelegate turboModuleManagerDelegate:(id)turboModuleManagerDelegate bindingsInstallFunc:(facebook::react::ReactInstance::BindingsInstallFunc)bindingsInstallFunc - jsEngineProvider:(nullable RCTHostJSEngineProvider)jsEngineProvider NS_DESIGNATED_INITIALIZER - FB_OBJC_DIRECT; + jsEngineProvider:(RCTHostJSEngineProvider)jsEngineProvider NS_DESIGNATED_INITIALIZER FB_OBJC_DIRECT; /** * This function initializes an RCTInstance if one does not yet exist. This function is currently only called on the diff --git a/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost.mm b/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost.mm index 7826069b1a7838..e2f3e2a2c26a9c 100644 --- a/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost.mm +++ b/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost.mm @@ -58,7 +58,7 @@ + (void)initialize - (instancetype)initWithHostDelegate:(id)hostDelegate turboModuleManagerDelegate:(id)turboModuleManagerDelegate bindingsInstallFunc:(facebook::react::ReactInstance::BindingsInstallFunc)bindingsInstallFunc - jsEngineProvider:(nullable RCTHostJSEngineProvider)jsEngineProvider + jsEngineProvider:(RCTHostJSEngineProvider)jsEngineProvider { if (self = [super init]) { _hostDelegate = hostDelegate; @@ -149,14 +149,13 @@ - (void)preload } [self _refreshBundleURL]; RCTReloadCommandSetBundleURL(_bundleURL); - _instance = - [[RCTInstance alloc] initWithDelegate:self - jsEngineInstance:_jsEngineProvider ? _jsEngineProvider() : [_hostDelegate getJSEngine] - bundleManager:_bundleManager - turboModuleManagerDelegate:_turboModuleManagerDelegate - onInitialBundleLoad:_onInitialBundleLoad - bindingsInstallFunc:_bindingsInstallFunc - moduleRegistry:_moduleRegistry]; + _instance = [[RCTInstance alloc] initWithDelegate:self + jsEngineInstance:[self _provideJSEngine] + bundleManager:_bundleManager + turboModuleManagerDelegate:_turboModuleManagerDelegate + onInitialBundleLoad:_onInitialBundleLoad + bindingsInstallFunc:_bindingsInstallFunc + moduleRegistry:_moduleRegistry]; } - (RCTFabricSurface *)createSurfaceWithModuleName:(NSString *)moduleName @@ -218,14 +217,13 @@ - (void)didReceiveReloadCommand _surfaceStartBuffer = [NSMutableArray arrayWithArray:[self _getAttachedSurfaces]]; } - _instance = - [[RCTInstance alloc] initWithDelegate:self - jsEngineInstance:_jsEngineProvider ? _jsEngineProvider() : [_hostDelegate getJSEngine] - bundleManager:_bundleManager - turboModuleManagerDelegate:_turboModuleManagerDelegate - onInitialBundleLoad:_onInitialBundleLoad - bindingsInstallFunc:_bindingsInstallFunc - moduleRegistry:_moduleRegistry]; + _instance = [[RCTInstance alloc] initWithDelegate:self + jsEngineInstance:[self _provideJSEngine] + bundleManager:_bundleManager + turboModuleManagerDelegate:_turboModuleManagerDelegate + onInitialBundleLoad:_onInitialBundleLoad + bindingsInstallFunc:_bindingsInstallFunc + moduleRegistry:_moduleRegistry]; [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:RCTHostDidReloadNotification object:nil]]; @@ -278,6 +276,7 @@ - (void)registerSegmentWithId:(NSNumber *)segmentId path:(NSString *)path } #pragma mark - Private + - (void)_refreshBundleURL FB_OBJC_DIRECT { // Reset the _bundleURL ivar if the RCTHost delegate presents a new bundleURL @@ -308,4 +307,13 @@ - (void)_attachSurface:(RCTFabricSurface *)surface FB_OBJC_DIRECT return surfaces; } +- (std::shared_ptr)_provideJSEngine +{ + RCTAssert(_jsEngineProvider, @"_jsEngineProvider must be non-nil"); + std::shared_ptr jsEngine = _jsEngineProvider(); + RCTAssert(jsEngine != nullptr, @"_jsEngineProvider must return a nonnull pointer"); + + return jsEngine; +} + @end