From 47d9cb4dacca6d11c7de74ef4f053427f29dc3c7 Mon Sep 17 00:00:00 2001 From: Dan Caspi Date: Tue, 8 Nov 2016 08:40:30 -0800 Subject: [PATCH] Setting runtime options for JSC on iOS Reviewed By: michalgr Differential Revision: D4104084 fbshipit-source-id: 517f833343948c59e5f77cede8a60574ca1e40c0 --- React/Executors/RCTJSCExecutor.mm | 2 ++ React/Executors/RCTJSCWrapper.h | 2 ++ React/Executors/RCTJSCWrapper.mm | 8 +++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/React/Executors/RCTJSCExecutor.mm b/React/Executors/RCTJSCExecutor.mm index 6e465461b..9f98abf51 100644 --- a/React/Executors/RCTJSCExecutor.mm +++ b/React/Executors/RCTJSCExecutor.mm @@ -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); diff --git a/React/Executors/RCTJSCWrapper.h b/React/Executors/RCTJSCWrapper.h index e112320cb..8a30806c1 100644 --- a/React/Executors/RCTJSCWrapper.h +++ b/React/Executors/RCTJSCWrapper.h @@ -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; diff --git a/React/Executors/RCTJSCWrapper.mm b/React/Executors/RCTJSCWrapper.mm index 70662d3e7..ef7190050 100644 --- a/React/Executors/RCTJSCWrapper.mm +++ b/React/Executors/RCTJSCWrapper.mm @@ -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"),