Setting runtime options for JSC on iOS

Reviewed By: michalgr

Differential Revision: D4104084

fbshipit-source-id: 517f833343948c59e5f77cede8a60574ca1e40c0
This commit is contained in:
Dan Caspi 2016-11-08 08:40:30 -08:00 committed by Facebook Github Bot
parent b6a38e80e0
commit 47d9cb4dac
3 changed files with 11 additions and 1 deletions

View File

@ -339,6 +339,7 @@ static NSThread *newJavaScriptThread(void)
[self->_performanceLogger markStopForTag:RCTPLJSCWrapperOpenLibrary];
RCTAssert(self->_context == nil, @"Didn't expect to set up twice");
self->_jscWrapper->configureJSCForIOS();
context = [self->_jscWrapper->JSContext new];
self->_context = [[RCTJavaScriptContext alloc] initWithJSContext:context onThread:self->_javaScriptThread];
[[NSNotificationCenter defaultCenter] postNotificationName:RCTJavaScriptContextCreatedNotification
@ -990,6 +991,7 @@ static NSData *loadRAMBundle(NSURL *sourceURL, NSError **error, RandomAccessBund
- (void)_createContext
{
_jscWrapper = RCTJSCWrapperCreate(_useCustomJSCLibrary);
_jscWrapper->configureJSCForIOS();
_context = [_jscWrapper->JSContext new];
installBasicSynchronousHooksOnContext(_context);
dispatch_semaphore_signal(_semaphore);

View File

@ -11,6 +11,7 @@
#import "RCTDefines.h"
typedef void (*voidWithNoParamsFuncType)();
typedef JSStringRef (*JSStringCreateWithCFStringFuncType)(CFStringRef);
typedef JSStringRef (*JSStringCreateWithUTF8CStringFuncType)(const char *);
typedef void (*JSStringReleaseFuncType)(JSStringRef);
@ -50,6 +51,7 @@ typedef struct RCTJSCWrapper {
JSValueIsNullFuncType JSValueIsNull;
JSEvaluateScriptFuncType JSEvaluateScript;
JSEvaluateBytecodeBundleFuncType JSEvaluateBytecodeBundle;
voidWithNoParamsFuncType configureJSCForIOS;
const int32_t JSBytecodeFileFormatVersion;
Class JSContext;
Class JSValue;

View File

@ -27,6 +27,10 @@ UNIMPLEMENTED_SYSTEM_JSC_FUNCTION(JSEvaluateBytecodeBundle)
#undef UNIMPLEMENTED_SYSTEM_JSC_FUNCTION
// A no-op function, to replace void functions that do no exist in the system JSC
// with a function that does nothing.
static void noOpSystemJSCFunc(void *args...){ }
void __attribute__((visibility("hidden"),weak)) RCTCustomJSCInit(__unused void *handle) {
return;
}
@ -70,8 +74,9 @@ static RCTJSCWrapper *RCTSetUpSystemLibraryPointers()
.JSValueIsUndefined = JSValueIsUndefined,
.JSValueIsNull = JSValueIsNull,
.JSEvaluateScript = JSEvaluateScript,
.JSBytecodeFileFormatVersion = JSNoBytecodeFileFormatVersion,
.JSEvaluateBytecodeBundle = (JSEvaluateBytecodeBundleFuncType)UnimplementedJSEvaluateBytecodeBundle,
.configureJSCForIOS = (voidWithNoParamsFuncType)noOpSystemJSCFunc,
.JSBytecodeFileFormatVersion = JSNoBytecodeFileFormatVersion,
.JSContext = [JSContext class],
.JSValue = [JSValue class],
};
@ -100,6 +105,7 @@ static RCTJSCWrapper *RCTSetUpCustomLibraryPointers()
.JSValueIsNull = (JSValueIsNullFuncType)dlsym(libraryHandle, "JSValueIsNull"),
.JSEvaluateScript = (JSEvaluateScriptFuncType)dlsym(libraryHandle, "JSEvaluateScript"),
.JSEvaluateBytecodeBundle = (JSEvaluateBytecodeBundleFuncType)dlsym(libraryHandle, "JSEvaluateBytecodeBundle"),
.configureJSCForIOS = (voidWithNoParamsFuncType)dlsym(libraryHandle, "configureJSCForIOS"),
.JSBytecodeFileFormatVersion = *(const int32_t *)dlsym(libraryHandle, "JSBytecodeFileFormatVersion"),
.JSContext = (__bridge Class)dlsym(libraryHandle, "OBJC_CLASS_$_JSContext"),
.JSValue = (__bridge Class)dlsym(libraryHandle, "OBJC_CLASS_$_JSValue"),