From 52fa3e8b1caf86e51048d6566f65df655064e78f Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Mon, 16 Nov 2015 17:57:06 -0800 Subject: [PATCH] no-op if module has been deallocated --- ReactNative/RealmReact.mm | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ReactNative/RealmReact.mm b/ReactNative/RealmReact.mm index 5456b15b..83489de6 100644 --- a/ReactNative/RealmReact.mm +++ b/ReactNative/RealmReact.mm @@ -60,9 +60,10 @@ JSGlobalContextRef RealmReactGetJSGlobalContextForExecutor(id executor, bool cre @end #endif -@interface RealmReact () -@property (weak) NSThread *currentJSThread; -@property (weak) NSRunLoop *currentJSRunLoop; +@interface RealmReact () { + __weak NSThread *_currentJSThread; + __weak NSRunLoop *_currentJSRunLoop; +} @end static __weak RealmReact *s_currentRealmModule = nil; @@ -183,8 +184,12 @@ static __weak RealmReact *s_currentRealmModule = nil; else { __weak __typeof__(self) weakSelf = self; [executor executeBlockOnJavaScriptQueue:^{ - weakSelf.currentJSThread = [NSThread currentThread]; - weakSelf.currentJSRunLoop = [NSRunLoop currentRunLoop]; + RealmReact *self = weakSelf; + if (!self) { + return; + } + self->_currentJSThread = [NSThread currentThread]; + self->_currentJSRunLoop = [NSRunLoop currentRunLoop]; JSGlobalContextRef ctx = RealmReactGetJSGlobalContextForExecutor(executor, true); RJSInitializeInContext(ctx); }];