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:
Родитель
2be42abbc2
Коммит
99c7de2600
|
@ -44,19 +44,23 @@ typedef struct ModuleData {
|
||||||
@property (nonatomic, strong, readonly) JSContext *context;
|
@property (nonatomic, strong, readonly) JSContext *context;
|
||||||
@property (nonatomic, assign, readonly) JSGlobalContextRef ctx;
|
@property (nonatomic, assign, readonly) JSGlobalContextRef ctx;
|
||||||
|
|
||||||
- (instancetype)initWithJSContext:(JSContext *)context NS_DESIGNATED_INITIALIZER;
|
- (instancetype)initWithJSContext:(JSContext *)context
|
||||||
|
onThread:(NSThread *)javaScriptThread NS_DESIGNATED_INITIALIZER;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation RCTJavaScriptContext
|
@implementation RCTJavaScriptContext
|
||||||
{
|
{
|
||||||
RCTJavaScriptContext *_selfReference;
|
RCTJavaScriptContext *_selfReference;
|
||||||
|
NSThread *_javaScriptThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithJSContext:(JSContext *)context
|
- (instancetype)initWithJSContext:(JSContext *)context
|
||||||
|
onThread:(NSThread *)javaScriptThread
|
||||||
{
|
{
|
||||||
if ((self = [super init])) {
|
if ((self = [super init])) {
|
||||||
_context = context;
|
_context = context;
|
||||||
|
_javaScriptThread = javaScriptThread;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Explicitly introduce a retain cycle here - The RCTJSCExecutor might
|
* Explicitly introduce a retain cycle here - The RCTJSCExecutor might
|
||||||
|
@ -85,14 +89,14 @@ RCT_NOT_IMPLEMENTED(-(instancetype)init)
|
||||||
- (void)invalidate
|
- (void)invalidate
|
||||||
{
|
{
|
||||||
if (self.isValid) {
|
if (self.isValid) {
|
||||||
|
RCTAssertThread(_javaScriptThread, @"Must be invalidated on JS thread.");
|
||||||
|
|
||||||
_context = nil;
|
_context = nil;
|
||||||
_selfReference = nil;
|
_selfReference = nil;
|
||||||
}
|
_javaScriptThread = nil;
|
||||||
}
|
|
||||||
|
|
||||||
- (void)dealloc
|
|
||||||
{
|
|
||||||
CFRunLoopStop([[NSRunLoop currentRunLoop] getCFRunLoop]);
|
CFRunLoopStop([[NSRunLoop currentRunLoop] getCFRunLoop]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -213,7 +217,7 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
|
||||||
|
|
||||||
if (!_context) {
|
if (!_context) {
|
||||||
JSContext *context = [JSContext new];
|
JSContext *context = [JSContext new];
|
||||||
_context = [[RCTJavaScriptContext alloc] initWithJSContext:context];
|
_context = [[RCTJavaScriptContext alloc] initWithJSContext:context onThread:_javaScriptThread];
|
||||||
}
|
}
|
||||||
|
|
||||||
return _context;
|
return _context;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче