flag to create jscontext

This commit is contained in:
Ari Lazier 2015-10-19 11:28:50 -07:00
parent f02fb05af4
commit cfd618db32
3 changed files with 5 additions and 5 deletions

View File

@ -19,7 +19,7 @@
@import Foundation; @import Foundation;
@import JavaScriptCore; @import JavaScriptCore;
extern JSGlobalContextRef RealmReactGetJSGlobalContextForExecutor(id executor); extern JSGlobalContextRef RealmReactGetJSGlobalContextForExecutor(id executor, bool create);
@interface RealmReact : NSObject @interface RealmReact : NSObject

View File

@ -29,14 +29,14 @@
- (JSGlobalContextRef)ctx; - (JSGlobalContextRef)ctx;
@end @end
JSGlobalContextRef RealmReactGetJSGlobalContextForExecutor(id executor) { JSGlobalContextRef RealmReactGetJSGlobalContextForExecutor(id executor, bool create) {
Ivar contextIvar = class_getInstanceVariable([executor class], "_context"); Ivar contextIvar = class_getInstanceVariable([executor class], "_context");
if (!contextIvar) { if (!contextIvar) {
return NULL; return NULL;
} }
id rctJSContext = contextIvar ? object_getIvar(executor, contextIvar) : nil; id rctJSContext = contextIvar ? object_getIvar(executor, contextIvar) : nil;
if (!rctJSContext) { if (!rctJSContext && create) {
Class RCTJavaScriptContext = NSClassFromString(@"RCTJavaScriptContext"); Class RCTJavaScriptContext = NSClassFromString(@"RCTJavaScriptContext");
if (RCTJavaScriptContext) { if (RCTJavaScriptContext) {
JSGlobalContextRef ctx = JSGlobalContextCreate(NULL); JSGlobalContextRef ctx = JSGlobalContextCreate(NULL);
@ -119,7 +119,7 @@ JSGlobalContextRef RealmReactGetJSGlobalContextForExecutor(id executor) {
} }
[executor executeBlockOnJavaScriptQueue:^{ [executor executeBlockOnJavaScriptQueue:^{
JSGlobalContextRef ctx = RealmReactGetJSGlobalContextForExecutor(executor); JSGlobalContextRef ctx = RealmReactGetJSGlobalContextForExecutor(executor, true);
[RealmJS initializeContext:ctx]; [RealmJS initializeContext:ctx];
}]; }];
} }

View File

@ -43,7 +43,7 @@ static id<RCTJavaScriptExecutor> s_currentJavaScriptExecutor;
s_currentJavaScriptExecutor = [bridge valueForKey:@"javaScriptExecutor"]; s_currentJavaScriptExecutor = [bridge valueForKey:@"javaScriptExecutor"];
// FIXME: Remove this nonsense once the crashes go away when a test fails! // FIXME: Remove this nonsense once the crashes go away when a test fails!
JSGlobalContextRef ctx = RealmReactGetJSGlobalContextForExecutor(s_currentJavaScriptExecutor); JSGlobalContextRef ctx = RealmReactGetJSGlobalContextForExecutor(s_currentJavaScriptExecutor, false);
if (ctx) { if (ctx) {
JSGlobalContextSetIncludesNativeCallStackWhenReportingExceptions(ctx, false); JSGlobalContextSetIncludesNativeCallStackWhenReportingExceptions(ctx, false);
} }