From 0c8e925a18b7deeeb18f1ae20e10f5f06de30ba8 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Fri, 17 Feb 2017 02:29:56 -0800 Subject: [PATCH] Move initializedExecutorWithContextProvider API Reviewed By: dcaspi Differential Revision: D4558591 fbshipit-source-id: 821d6a6d4e42d1c67559fde102a0558eb623733b --- React/Executors/RCTJSCExecutor.h | 59 +++++++++++++++---------------- React/Executors/RCTJSCExecutor.mm | 25 ++++++------- 2 files changed, 39 insertions(+), 45 deletions(-) diff --git a/React/Executors/RCTJSCExecutor.h b/React/Executors/RCTJSCExecutor.h index 1a96c2e8e81..c988b5b44ea 100644 --- a/React/Executors/RCTJSCExecutor.h +++ b/React/Executors/RCTJSCExecutor.h @@ -44,28 +44,6 @@ RCT_EXTERN NSString *const RCTFBJSContextClassKey; */ RCT_EXTERN NSString *const RCTFBJSValueClassKey; -/** - * @experimental - * May be used to pre-create the JSContext to make RCTJSCExecutor creation less costly. - * Avoid using this; it's experimental and is not likely to be supported long-term. - */ -@interface RCTJSContextProvider : NSObject - -- (instancetype)initWithUseCustomJSCLibrary:(BOOL)useCustomJSCLibrary - tryBytecode:(BOOL)tryBytecode; - -/** - * Marks whether the provider uses the custom implementation of JSC and not the system one. - */ -@property (nonatomic, readonly, assign) BOOL useCustomJSCLibrary; - -/** - * Marks whether it is safe to try and run bytecode if given the choice. - */ -@property (nonatomic, readonly) BOOL tryBytecode; - -@end - /** * Uses a JavaScriptCore context as the execution engine. */ @@ -104,14 +82,6 @@ RCT_EXTERN NSString *const RCTFBJSValueClassKey; - (instancetype)initWithUseCustomJSCLibrary:(BOOL)useCustomJSCLibrary tryBytecode:(BOOL)tryBytecode; -/** - * @experimental - * Pass a RCTJSContextProvider object to use an NSThread/JSContext pair that have already been created. - * The underlying JSContext will be returned in the JSContext pointer if it is non-NULL. - */ -+ (instancetype)initializedExecutorWithContextProvider:(RCTJSContextProvider *)JSContextProvider - JSContext:(JSContext **)JSContext; - /** * @experimental * synchronouslyExecuteApplicationScript:sourceURL:JSContext:error: @@ -140,3 +110,32 @@ RCT_EXTERN NSString *const RCTFBJSValueClassKey; - (JSContext *)jsContext; @end + +/** + * @experimental + * May be used to pre-create the JSContext to make RCTJSCExecutor creation less costly. + * Avoid using this; it's experimental and is not likely to be supported long-term. + */ +@interface RCTJSContextProvider : NSObject + +- (instancetype)initWithUseCustomJSCLibrary:(BOOL)useCustomJSCLibrary + tryBytecode:(BOOL)tryBytecode; + +/** + * Marks whether the provider uses the custom implementation of JSC and not the system one. + */ +@property (nonatomic, readonly, assign) BOOL useCustomJSCLibrary; + +/** + * Marks whether it is safe to try and run bytecode if given the choice. + */ +@property (nonatomic, readonly) BOOL tryBytecode; + +/** + * @experimental + * Create an RCTJSCExecutor from an provider instance. This may only be called once. + * The underlying JSContext will be returned in the JSContext pointer if it is non-NULL. + */ +- (RCTJSCExecutor *)createExecutorWithContext:(JSContext **)JSContext; + +@end diff --git a/React/Executors/RCTJSCExecutor.mm b/React/Executors/RCTJSCExecutor.mm index 3fe8ca9a3eb..b83262d87df 100644 --- a/React/Executors/RCTJSCExecutor.mm +++ b/React/Executors/RCTJSCExecutor.mm @@ -92,11 +92,6 @@ struct RCTJSContextData { JSContext *context; }; -@interface RCTJSContextProvider () -/** May only be called once, or deadlock will result. */ -- (RCTJSContextData)data; -@end - @interface RCTJavaScriptContext : NSObject @property (nonatomic, strong, readonly) JSContext *context; @@ -258,16 +253,6 @@ static NSThread *newJavaScriptThread(void) return self; } -+ (instancetype)initializedExecutorWithContextProvider:(RCTJSContextProvider *)JSContextProvider - JSContext:(JSContext **)JSContext -{ - const RCTJSContextData data = JSContextProvider.data; - if (JSContext) { - *JSContext = data.context; - } - return [[RCTJSCExecutor alloc] initWithJSContextData:data]; -} - - (instancetype)initWithJSContextData:(const RCTJSContextData &)data { if (self = [super init]) { @@ -1051,4 +1036,14 @@ static NSData *loadRAMBundle(NSURL *sourceURL, NSError **error, RandomAccessBund }; } + +- (RCTJSCExecutor *)createExecutorWithContext:(JSContext **)JSContext +{ + const RCTJSContextData data = self.data; + if (JSContext) { + *JSContext = data.context; + } + return [[RCTJSCExecutor alloc] initWithJSContextData:data]; +} + @end