Skip to content

Commit

Permalink
make getModuleInstanceFromClass: required
Browse files Browse the repository at this point in the history
Summary:
Changelog: [iOS][Breaking]

continuing getting rid of optional methods, but this does have a behavioral change. if the delegate does not provide the module instance, then we lazily create it. before we were returning nil, idk why. this will be a breaking change if you have any classes that conform to `RCTTurboModuleManagerDelegate`

#saynotoruntimechecks

Reviewed By: cipolleschi

Differential Revision: D45022139

fbshipit-source-id: 9635332caf3db7bb9306f99ee5c0d577091d38ea
  • Loading branch information
philIip authored and facebook-github-bot committed Apr 20, 2023
1 parent fbf196d commit 5a7799e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ RCT_EXTERN void RCTTurboModuleSetBindingMode(facebook::react::TurboModuleBinding
*/
- (Class)getModuleClassFromName:(const char *)name;

@optional

/**
* Given a module class, provide an instance for it. If not provided, default initializer is used.
* Given a module class, provide an instance for it. If nil is returned, default initializer is used.
*/
- (id<RCTTurboModule>)getModuleInstanceFromClass:(Class)moduleClass;

@optional

/**
* Create an instance of a TurboModule without relying on any ObjC++ module instance.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,27 +478,13 @@ - (TurboModuleHolder *)_getOrCreateTurboModuleHolder:(const char *)moduleName
*/

TurboModulePerfLogger::moduleCreateConstructStart(moduleName, moduleId);
if ([_delegate respondsToSelector:@selector(getModuleInstanceFromClass:)]) {
if (RCTTurboModuleManagerDelegateLockingDisabled()) {
module = [_delegate getModuleInstanceFromClass:moduleClass];
} else {
std::lock_guard<std::mutex> delegateGuard(_turboModuleManagerDelegateMutex);
module = [_delegate getModuleInstanceFromClass:moduleClass];
}

/**
* If the application is unable to create the TurboModule object from its class:
* abort TurboModule creation, and early return nil.
*/
if (!module) {
RCTLogError(
@"TurboModuleManager delegate %@ returned nil TurboModule object for module with name=\"%s\" and class=%@",
NSStringFromClass([_delegate class]),
moduleName,
NSStringFromClass(moduleClass));
return nil;
}
if (RCTTurboModuleManagerDelegateLockingDisabled()) {
module = [_delegate getModuleInstanceFromClass:moduleClass];
} else {
std::lock_guard<std::mutex> delegateGuard(_turboModuleManagerDelegateMutex);
module = [_delegate getModuleInstanceFromClass:moduleClass];
}
if (!module) {
module = [moduleClass new];
}
TurboModulePerfLogger::moduleCreateConstructEnd(moduleName, moduleId);
Expand Down

0 comments on commit 5a7799e

Please sign in to comment.