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
- (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.
*/
@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
/**
@ -89,6 +95,15 @@ RCT_EXTERN NSString *const RCTFBJSValueClassKey;
*/
- (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
* 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 {
BOOL useCustomJSCLibrary;
BOOL tryBytecode;
NSThread *javaScriptThread;
JSContext *context;
RCTJSCWrapper *jscWrapper;
@ -154,6 +155,7 @@ RCT_NOT_IMPLEMENTED(-(instancetype)init)
{
// Set at init time:
BOOL _useCustomJSCLibrary;
BOOL _tryBytecode;
NSThread *_javaScriptThread;
// Set at setUp time:
@ -238,11 +240,19 @@ static NSThread *newJavaScriptThread(void)
}
- (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);
if (self = [super init]) {
_useCustomJSCLibrary = useCustomJSCLibrary;
_tryBytecode = tryBytecode;
_valid = YES;
_javaScriptThread = newJavaScriptThread();
}
@ -265,6 +275,7 @@ static NSThread *newJavaScriptThread(void)
{
if (self = [super init]) {
_useCustomJSCLibrary = data.useCustomJSCLibrary;
_tryBytecode = data.tryBytecode;
_valid = YES;
_javaScriptThread = data.javaScriptThread;
_jscWrapper = data.jscWrapper;
@ -502,7 +513,9 @@ static void installBasicSynchronousHooksOnContext(JSContext *context)
- (int32_t)bytecodeFileFormatVersion
{
return _jscWrapper->JSBytecodeFileFormatVersion;
return _tryBytecode
? _jscWrapper->JSBytecodeFileFormatVersion
: JSNoBytecodeFileFormatVersion;
}
- (NSString *)contextName
@ -978,10 +991,12 @@ static NSData *loadRAMBundle(NSURL *sourceURL, NSError **error, RandomAccessBund
}
- (instancetype)initWithUseCustomJSCLibrary:(BOOL)useCustomJSCLibrary
tryBytecode:(BOOL)tryBytecode
{
if (self = [super init]) {
_semaphore = dispatch_semaphore_create(0);
_useCustomJSCLibrary = useCustomJSCLibrary;
_tryBytecode = tryBytecode;
_javaScriptThread = newJavaScriptThread();
[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);
return {
.useCustomJSCLibrary = _useCustomJSCLibrary,
.tryBytecode = _tryBytecode,
.javaScriptThread = _javaScriptThread,
.context = _context,
.jscWrapper = _jscWrapper,