no-op if module has been deallocated

This commit is contained in:
Ari Lazier 2015-11-16 17:57:06 -08:00
parent 159931e4ec
commit 52fa3e8b1c
1 changed files with 10 additions and 5 deletions

View File

@ -60,9 +60,10 @@ JSGlobalContextRef RealmReactGetJSGlobalContextForExecutor(id executor, bool cre
@end @end
#endif #endif
@interface RealmReact () <RCTBridgeModule> @interface RealmReact () <RCTBridgeModule> {
@property (weak) NSThread *currentJSThread; __weak NSThread *_currentJSThread;
@property (weak) NSRunLoop *currentJSRunLoop; __weak NSRunLoop *_currentJSRunLoop;
}
@end @end
static __weak RealmReact *s_currentRealmModule = nil; static __weak RealmReact *s_currentRealmModule = nil;
@ -183,8 +184,12 @@ static __weak RealmReact *s_currentRealmModule = nil;
else { else {
__weak __typeof__(self) weakSelf = self; __weak __typeof__(self) weakSelf = self;
[executor executeBlockOnJavaScriptQueue:^{ [executor executeBlockOnJavaScriptQueue:^{
weakSelf.currentJSThread = [NSThread currentThread]; RealmReact *self = weakSelf;
weakSelf.currentJSRunLoop = [NSRunLoop currentRunLoop]; if (!self) {
return;
}
self->_currentJSThread = [NSThread currentThread];
self->_currentJSRunLoop = [NSRunLoop currentRunLoop];
JSGlobalContextRef ctx = RealmReactGetJSGlobalContextForExecutor(executor, true); JSGlobalContextRef ctx = RealmReactGetJSGlobalContextForExecutor(executor, true);
RJSInitializeInContext(ctx); RJSInitializeInContext(ctx);
}]; }];