BC Kill-switch

Reviewed By: javache

Differential Revision: D4159923

fbshipit-source-id: 9814c76d04f7230fda7693efac3f6623cc882ccf
This commit is contained in:
Ashok Menon
2016-11-11 05:21:39 -08:00
committed by Facebook Github Bot
parent 8288bc2006
commit 58aa9afaed
2 changed files with 33 additions and 2 deletions

View File

@@ -51,13 +51,19 @@ RCT_EXTERN NSString *const RCTFBJSValueClassKey;
*/ */
@interface RCTJSContextProvider : NSObject @interface RCTJSContextProvider : NSObject
- (instancetype)initWithUseCustomJSCLibrary:(BOOL)useCustomJSCLibrary; - (instancetype)initWithUseCustomJSCLibrary:(BOOL)useCustomJSCLibrary
tryBytecode:(BOOL)tryBytecode;
/** /**
* Marks whether the provider uses the custom implementation of JSC and not the system one. * Marks whether the provider uses the custom implementation of JSC and not the system one.
*/ */
@property (nonatomic, readonly, assign) BOOL useCustomJSCLibrary; @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 @end
/** /**
@@ -89,6 +95,15 @@ RCT_EXTERN NSString *const RCTFBJSValueClassKey;
*/ */
- (instancetype)initWithUseCustomJSCLibrary:(BOOL)useCustomJSCLibrary; - (instancetype)initWithUseCustomJSCLibrary:(BOOL)useCustomJSCLibrary;
/**
* @experimental
* Inits a new executor instance with given configuration flags. Please refer to
* the documentation for `RCTJSContextProvider` for more information as to their
* purpose.
*/
- (instancetype)initWithUseCustomJSCLibrary:(BOOL)useCustomJSCLibrary
tryBytecode:(BOOL)tryBytecode;
/** /**
* @experimental * @experimental
* Pass a RCTJSContextProvider object to use an NSThread/JSContext pair that have already been created. * Pass a RCTJSContextProvider object to use an NSThread/JSContext pair that have already been created.

View File

@@ -83,6 +83,7 @@ struct TaggedScript {
struct RCTJSContextData { struct RCTJSContextData {
BOOL useCustomJSCLibrary; BOOL useCustomJSCLibrary;
BOOL tryBytecode;
NSThread *javaScriptThread; NSThread *javaScriptThread;
JSContext *context; JSContext *context;
RCTJSCWrapper *jscWrapper; RCTJSCWrapper *jscWrapper;
@@ -154,6 +155,7 @@ RCT_NOT_IMPLEMENTED(-(instancetype)init)
{ {
// Set at init time: // Set at init time:
BOOL _useCustomJSCLibrary; BOOL _useCustomJSCLibrary;
BOOL _tryBytecode;
NSThread *_javaScriptThread; NSThread *_javaScriptThread;
// Set at setUp time: // Set at setUp time:
@@ -238,11 +240,19 @@ static NSThread *newJavaScriptThread(void)
} }
- (instancetype)initWithUseCustomJSCLibrary:(BOOL)useCustomJSCLibrary - (instancetype)initWithUseCustomJSCLibrary:(BOOL)useCustomJSCLibrary
{
return [self initWithUseCustomJSCLibrary:useCustomJSCLibrary
tryBytecode:NO];
}
- (instancetype)initWithUseCustomJSCLibrary:(BOOL)useCustomJSCLibrary
tryBytecode:(BOOL)tryBytecode
{ {
RCT_PROFILE_BEGIN_EVENT(0, @"-[RCTJSCExecutor init]", nil); RCT_PROFILE_BEGIN_EVENT(0, @"-[RCTJSCExecutor init]", nil);
if (self = [super init]) { if (self = [super init]) {
_useCustomJSCLibrary = useCustomJSCLibrary; _useCustomJSCLibrary = useCustomJSCLibrary;
_tryBytecode = tryBytecode;
_valid = YES; _valid = YES;
_javaScriptThread = newJavaScriptThread(); _javaScriptThread = newJavaScriptThread();
} }
@@ -265,6 +275,7 @@ static NSThread *newJavaScriptThread(void)
{ {
if (self = [super init]) { if (self = [super init]) {
_useCustomJSCLibrary = data.useCustomJSCLibrary; _useCustomJSCLibrary = data.useCustomJSCLibrary;
_tryBytecode = data.tryBytecode;
_valid = YES; _valid = YES;
_javaScriptThread = data.javaScriptThread; _javaScriptThread = data.javaScriptThread;
_jscWrapper = data.jscWrapper; _jscWrapper = data.jscWrapper;
@@ -502,7 +513,9 @@ static void installBasicSynchronousHooksOnContext(JSContext *context)
- (int32_t)bytecodeFileFormatVersion - (int32_t)bytecodeFileFormatVersion
{ {
return _jscWrapper->JSBytecodeFileFormatVersion; return _tryBytecode
? _jscWrapper->JSBytecodeFileFormatVersion
: JSNoBytecodeFileFormatVersion;
} }
- (NSString *)contextName - (NSString *)contextName
@@ -978,10 +991,12 @@ static NSData *loadRAMBundle(NSURL *sourceURL, NSError **error, RandomAccessBund
} }
- (instancetype)initWithUseCustomJSCLibrary:(BOOL)useCustomJSCLibrary - (instancetype)initWithUseCustomJSCLibrary:(BOOL)useCustomJSCLibrary
tryBytecode:(BOOL)tryBytecode
{ {
if (self = [super init]) { if (self = [super init]) {
_semaphore = dispatch_semaphore_create(0); _semaphore = dispatch_semaphore_create(0);
_useCustomJSCLibrary = useCustomJSCLibrary; _useCustomJSCLibrary = useCustomJSCLibrary;
_tryBytecode = tryBytecode;
_javaScriptThread = newJavaScriptThread(); _javaScriptThread = newJavaScriptThread();
[self performSelector:@selector(_createContext) onThread:_javaScriptThread withObject:nil waitUntilDone:NO]; [self performSelector:@selector(_createContext) onThread:_javaScriptThread withObject:nil waitUntilDone:NO];
} }
@@ -1003,6 +1018,7 @@ static NSData *loadRAMBundle(NSURL *sourceURL, NSError **error, RandomAccessBund
dispatch_semaphore_wait(_semaphore, DISPATCH_TIME_FOREVER); dispatch_semaphore_wait(_semaphore, DISPATCH_TIME_FOREVER);
return { return {
.useCustomJSCLibrary = _useCustomJSCLibrary, .useCustomJSCLibrary = _useCustomJSCLibrary,
.tryBytecode = _tryBytecode,
.javaScriptThread = _javaScriptThread, .javaScriptThread = _javaScriptThread,
.context = _context, .context = _context,
.jscWrapper = _jscWrapper, .jscWrapper = _jscWrapper,