File tree Expand file tree Collapse file tree
packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -171,10 +171,19 @@ - (void)dealloc
171171
172172- (void )callFunctionOnJSModule : (NSString *)moduleName method : (NSString *)method args : (NSArray *)args
173173{
174- if (_valid) {
175- _reactInstance->callFunctionOnModule (
176- [moduleName UTF8String ], [method UTF8String ], convertIdToFollyDynamic (args ? args : @[]));
174+ // Convert outside the lock: the payload can be large, and -invalidate blocks on
175+ // _invalidationMutex.
176+ auto dynamicArgs = convertIdToFollyDynamic (args ? args : @[]);
177+ std::string moduleNameString = [moduleName UTF8String ] ?: " " ;
178+ std::string methodString = [method UTF8String ] ?: " " ;
179+
180+ // This is called from arbitrary threads, while -invalidate destroys _reactInstance on
181+ // the JS thread, so checking _valid and dereferencing have to happen as one step.
182+ std::lock_guard<std::mutex> lock (_invalidationMutex);
183+ if (!_valid || !_reactInstance) {
184+ return ;
177185 }
186+ _reactInstance->callFunctionOnModule (moduleNameString, methodString, std::move (dynamicArgs));
178187}
179188
180189- (void )invalidate
You can’t perform that action at this time.
0 commit comments