Stop the runloop from invalidate instead of dealloc

Summary:We were calling `CFRunLoopStop` from `-dealloc` in the `JSCExecutor`, but dealloc
is not guaranteed to run in the same thread. Move it to `-invalidate` instead.

Reviewed By: javache

Differential Revision: D3092645

fb-gh-sync-id: 94b51fec4a9fe0784feeb83d1b0c41de1cd7c052
fbshipit-source-id: 94b51fec4a9fe0784feeb83d1b0c41de1cd7c052
This commit is contained in:
Tadeu Zagallo 2016-03-30 08:11:04 -07:00 коммит произвёл Facebook Github Bot 7
Родитель 2be42abbc2
Коммит 99c7de2600
1 изменённых файлов: 11 добавлений и 7 удалений

Просмотреть файл

@ -44,19 +44,23 @@ typedef struct ModuleData {
@property (nonatomic, strong, readonly) JSContext *context;
@property (nonatomic, assign, readonly) JSGlobalContextRef ctx;
- (instancetype)initWithJSContext:(JSContext *)context NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithJSContext:(JSContext *)context
onThread:(NSThread *)javaScriptThread NS_DESIGNATED_INITIALIZER;
@end
@implementation RCTJavaScriptContext
{
RCTJavaScriptContext *_selfReference;
NSThread *_javaScriptThread;
}
- (instancetype)initWithJSContext:(JSContext *)context
onThread:(NSThread *)javaScriptThread
{
if ((self = [super init])) {
_context = context;
_javaScriptThread = javaScriptThread;
/**
* Explicitly introduce a retain cycle here - The RCTJSCExecutor might
@ -85,15 +89,15 @@ RCT_NOT_IMPLEMENTED(-(instancetype)init)
- (void)invalidate
{
if (self.isValid) {
RCTAssertThread(_javaScriptThread, @"Must be invalidated on JS thread.");
_context = nil;
_selfReference = nil;
}
}
_javaScriptThread = nil;
- (void)dealloc
{
CFRunLoopStop([[NSRunLoop currentRunLoop] getCFRunLoop]);
}
}
@end
@ -213,7 +217,7 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
if (!_context) {
JSContext *context = [JSContext new];
_context = [[RCTJavaScriptContext alloc] initWithJSContext:context];
_context = [[RCTJavaScriptContext alloc] initWithJSContext:context onThread:_javaScriptThread];
}
return _context;