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 JavaScriptCore;
extern JSGlobalContextRef RealmReactGetJSGlobalContextForExecutor(id executor);
extern JSGlobalContextRef RealmReactGetJSGlobalContextForExecutor(id executor, bool create);
@interface RealmReact : NSObject

View File

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

View File

@ -43,7 +43,7 @@ static id<RCTJavaScriptExecutor> s_currentJavaScriptExecutor;
s_currentJavaScriptExecutor = [bridge valueForKey:@"javaScriptExecutor"];
// 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) {
JSGlobalContextSetIncludesNativeCallStackWhenReportingExceptions(ctx, false);
}