diff --git a/React/Executors/RCTJSCExecutor.h b/React/Executors/RCTJSCExecutor.h index 1a96c2e8e..c988b5b44 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 3fe8ca9a3..b83262d87 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