Fix [JSValue ...] & [JSContext ...] access with custom JSC

Reviewed By: bnham

Differential Revision: D3859956

fbshipit-source-id: 966aba9a267371eb553b8be574fa247b21930d1c
This commit is contained in:
Dan Caspi
2016-09-27 09:33:10 -07:00
committed by Facebook Github Bot 0
parent 449c195941
commit dfcfb90baa
2 changed files with 25 additions and 0 deletions

View File

@@ -27,6 +27,23 @@ RCT_EXTERN NSString *const RCTJSCThreadName;
*/
RCT_EXTERN NSString *const RCTJavaScriptContextCreatedNotification;
/**
* A key to a reference to a JSContext class, held in the the current thread's
* dictionary. The reference would point to the JSContext class in the JS VM
* used in React (or ComponenetScript). It is recommended not to access it
* through the thread's dictionary, but rather to use the `FBJSCurrentContext()`
* accessor, which will return the current JSContext in the currently used VM.
*/
RCT_EXTERN NSString *const RCTFBJSContextClassKey;
/**
* A key to a reference to a JSValue class, held in the the current thread's
* dictionary. The reference would point to the JSValue class in the JS VM
* used in React (or ComponenetScript). It is recommended not to access it
* through the thread's dictionary, but rather to use the `FBJSValue()` accessor.
*/
RCT_EXTERN NSString *const RCTFBJSValueClassKey;
/**
* @experimental
* May be used to pre-create the JSContext to make RCTJSCExecutor creation less costly.

View File

@@ -34,6 +34,8 @@
NSString *const RCTJSCThreadName = @"com.facebook.react.JavaScript";
NSString *const RCTJavaScriptContextCreatedNotification = @"RCTJavaScriptContextCreatedNotification";
RCT_EXTERN NSString *const RCTFBJSContextClassKey = @"_RCTFBJSContextClassKey";
RCT_EXTERN NSString *const RCTFBJSValueClassKey = @"_RCTFBJSValueClassKey";
static NSString *const RCTJSCProfilerEnabledDefaultsKey = @"RCTJSCProfilerEnabled";
@@ -346,6 +348,12 @@ static NSThread *newJavaScriptThread(void)
installBasicSynchronousHooksOnContext(context);
}
NSMutableDictionary *threadDictionary = [[NSThread currentThread] threadDictionary];
if (!threadDictionary[RCTFBJSContextClassKey] || !threadDictionary[RCTFBJSValueClassKey]) {
threadDictionary[RCTFBJSContextClassKey] = self->_jscWrapper->JSContext;
threadDictionary[RCTFBJSValueClassKey] = self->_jscWrapper->JSValue;
}
__weak RCTJSCExecutor *weakSelf = self;
context[@"nativeRequireModuleConfig"] = ^NSArray *(NSString *moduleName) {