Thread the JSI runtime descriptor up into the RCTDevMenu title

Reviewed By: javache

Differential Revision: D5643014

fbshipit-source-id: 977be5729c57c0d01ff67b268031ad6fdbf88a07
This commit is contained in:
Marc Horowitz 2017-09-05 14:47:06 -07:00 committed by Facebook Github Bot
parent 7d4a5b67d4
commit d48f08cad6
10 changed files with 69 additions and 1 deletions

View File

@ -63,6 +63,7 @@ typedef NS_ENUM(NSUInteger, RCTBridgeFields) {
@synthesize loading = _loading; @synthesize loading = _loading;
@synthesize valid = _valid; @synthesize valid = _valid;
@synthesize performanceLogger = _performanceLogger; @synthesize performanceLogger = _performanceLogger;
@synthesize bridgeDescription = _bridgeDescription;
- (instancetype)initWithParentBridge:(RCTBridge *)bridge - (instancetype)initWithParentBridge:(RCTBridge *)bridge
{ {

View File

@ -35,6 +35,9 @@ RCT_EXTERN void RCTVerifyAllModulesExported(NSArray *extraModules);
@property (nonatomic, assign) CFMutableDictionaryRef flowIDMap; @property (nonatomic, assign) CFMutableDictionaryRef flowIDMap;
@property (nonatomic, strong) NSLock *flowIDMapLock; @property (nonatomic, strong) NSLock *flowIDMapLock;
// Used by RCTDevMenu
@property (nonatomic, copy) NSString *bridgeDescription;
+ (instancetype)currentBridge; + (instancetype)currentBridge;
+ (void)setCurrentBridge:(RCTBridge *)bridge; + (void)setCurrentBridge:(RCTBridge *)bridge;

View File

@ -72,6 +72,30 @@ typedef NS_ENUM(NSUInteger, RCTBridgeFields) {
RCTBridgeFieldCallID, RCTBridgeFieldCallID,
}; };
namespace {
class GetDescAdapter : public JSExecutorFactory {
public:
GetDescAdapter(RCTCxxBridge *bridge, std::shared_ptr<JSExecutorFactory> factory)
: bridge_(bridge)
, factory_(factory) {}
std::unique_ptr<JSExecutor> createJSExecutor(
std::shared_ptr<ExecutorDelegate> delegate,
std::shared_ptr<MessageQueueThread> jsQueue) override {
auto ret = factory_->createJSExecutor(delegate, jsQueue);
bridge_.bridgeDescription =
[NSString stringWithFormat:@"RCTCxxBridge %s",
ret->getDescription().c_str()];
return std::move(ret);
}
private:
RCTCxxBridge *bridge_;
std::shared_ptr<JSExecutorFactory> factory_;
};
}
static bool isRAMBundle(NSData *script) { static bool isRAMBundle(NSData *script) {
BundleHeader header; BundleHeader header;
[script getBytes:&header length:sizeof(header)]; [script getBytes:&header length:sizeof(header)];
@ -154,6 +178,7 @@ struct RCTInstanceCallback : public InstanceCallback {
@synthesize loading = _loading; @synthesize loading = _loading;
@synthesize valid = _valid; @synthesize valid = _valid;
@synthesize performanceLogger = _performanceLogger; @synthesize performanceLogger = _performanceLogger;
@synthesize bridgeDescription = _bridgeDescription;
+ (void)initialize + (void)initialize
{ {
@ -491,6 +516,10 @@ struct RCTInstanceCallback : public InstanceCallback {
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"-[RCTCxxBridge initializeBridge:]", nil); RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"-[RCTCxxBridge initializeBridge:]", nil);
// This can only be false if the bridge was invalidated before startup completed // This can only be false if the bridge was invalidated before startup completed
if (_reactInstance) { if (_reactInstance) {
#if RCT_DEV
executorFactory = std::make_shared<GetDescAdapter>(self, executorFactory);
#endif
// This is async, but any calls into JS are blocked by the m_syncReady CV in Instance // This is async, but any calls into JS are blocked by the m_syncReady CV in Instance
_reactInstance->initializeBridge( _reactInstance->initializeBridge(
std::unique_ptr<RCTInstanceCallback>(new RCTInstanceCallback(self)), std::unique_ptr<RCTInstanceCallback>(new RCTInstanceCallback(self)),

View File

@ -117,6 +117,10 @@ public:
callback:m_errorBlock]; callback:m_errorBlock];
} }
virtual std::string getDescription() override {
return [NSStringFromClass([m_jse class]) UTF8String];
}
private: private:
id<RCTJavaScriptExecutor> m_jse; id<RCTJavaScriptExecutor> m_jse;
RCTJavaScriptCompleteBlock m_errorBlock; RCTJavaScriptCompleteBlock m_errorBlock;

View File

@ -9,6 +9,7 @@
#import "RCTDevMenu.h" #import "RCTDevMenu.h"
#import "RCTBridge+Private.h"
#import "RCTDevSettings.h" #import "RCTDevSettings.h"
#import "RCTKeyCommands.h" #import "RCTKeyCommands.h"
#import "RCTLog.h" #import "RCTLog.h"
@ -259,7 +260,11 @@ RCT_EXPORT_METHOD(show)
return; return;
} }
NSString *title = [NSString stringWithFormat:@"React Native: Development (%@)", [_bridge class]]; NSString *desc = _bridge.bridgeDescription;
if (desc.length == 0) {
desc = NSStringFromClass([_bridge class]);
}
NSString *title = [NSString stringWithFormat:@"React Native: Development (%@)", desc];
// On larger devices we don't have an anchor point for the action sheet // On larger devices we don't have an anchor point for the action sheet
UIAlertControllerStyle style = [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone ? UIAlertControllerStyleActionSheet : UIAlertControllerStyleAlert; UIAlertControllerStyle style = [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone ? UIAlertControllerStyleActionSheet : UIAlertControllerStyleAlert;
_actionSheet = [UIAlertController alertControllerWithTitle:title _actionSheet = [UIAlertController alertControllerWithTitle:title

View File

@ -114,4 +114,8 @@ void ProxyExecutor::setGlobalVariable(std::string propName,
jni::make_jstring(jsonValue->c_str()).get()); jni::make_jstring(jsonValue->c_str()).get());
} }
std::string ProxyExecutor::getDescription() {
return "Chrome";
}
} } } }

View File

@ -47,6 +47,7 @@ public:
virtual void setGlobalVariable( virtual void setGlobalVariable(
std::string propName, std::string propName,
std::unique_ptr<const JSBigString> jsonValue) override; std::unique_ptr<const JSBigString> jsonValue) override;
virtual std::string getDescription() override;
private: private:
jni::global_ref<jobject> m_executor; jni::global_ref<jobject> m_executor;

View File

@ -509,6 +509,18 @@ void JSCExecutor::setGlobalVariable(std::string propName, std::unique_ptr<const
} }
} }
std::string JSCExecutor::getDescription() {
#if defined(__APPLE__)
if (isCustomJSCPtr(m_context)) {
return "Custom JSC";
} else {
return "System JSC";
}
#else
return "JSC";
#endif
}
String JSCExecutor::adoptString(std::unique_ptr<const JSBigString> script) { String JSCExecutor::adoptString(std::unique_ptr<const JSBigString> script) {
#if defined(WITH_FBJSCEXTENSIONS) #if defined(WITH_FBJSCEXTENSIONS)
const JSBigString* string = script.release(); const JSBigString* string = script.release();

View File

@ -88,6 +88,8 @@ public:
std::string propName, std::string propName,
std::unique_ptr<const JSBigString> jsonValue) override; std::unique_ptr<const JSBigString> jsonValue) override;
virtual std::string getDescription() override;
virtual void* getJavaScriptContext() override; virtual void* getJavaScriptContext() override;
#ifdef WITH_JSC_MEMORY_PRESSURE #ifdef WITH_JSC_MEMORY_PRESSURE

View File

@ -73,6 +73,13 @@ public:
return nullptr; return nullptr;
} }
/**
* The description is displayed in the dev menu, if there is one in
* this build. There is a default, but if this method returns a
* non-empty string, it will be used instead.
*/
virtual std::string getDescription() = 0;
virtual void handleMemoryPressure(int pressureLevel) {} virtual void handleMemoryPressure(int pressureLevel) {}
virtual void destroy() {} virtual void destroy() {}