From 15cd98b7826b92edd5289868ae728db80c0eeaa9 Mon Sep 17 00:00:00 2001 From: Ben Nham Date: Mon, 18 Dec 2017 13:19:37 -0800 Subject: [PATCH] add isInspectable property Reviewed By: Hypuk Differential Revision: D6578736 fbshipit-source-id: a4229c3766125ff55cff50a49893b2385f9c8a6a --- React/Base/RCTBatchedBridge.mm | 6 ++++++ React/Base/RCTBridge+Private.h | 6 ++++++ React/CxxBridge/RCTCxxBridge.mm | 4 ++++ ReactCommon/cxxreact/Instance.cpp | 4 ++++ ReactCommon/cxxreact/Instance.h | 1 + ReactCommon/cxxreact/NativeToJsBridge.cpp | 4 ++++ ReactCommon/cxxreact/NativeToJsBridge.h | 1 + 7 files changed, 26 insertions(+) diff --git a/React/Base/RCTBatchedBridge.mm b/React/Base/RCTBatchedBridge.mm index f989d939a..1a7273cc6 100644 --- a/React/Base/RCTBatchedBridge.mm +++ b/React/Base/RCTBatchedBridge.mm @@ -1094,4 +1094,10 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR } } +#pragma mark - Inspector + +- (BOOL)isInspectable { + return NO; +} + @end diff --git a/React/Base/RCTBridge+Private.h b/React/Base/RCTBridge+Private.h index 343d998db..dc7d0b5ab 100644 --- a/React/Base/RCTBridge+Private.h +++ b/React/Base/RCTBridge+Private.h @@ -168,6 +168,12 @@ RCT_EXTERN void RCTVerifyAllModulesExported(NSArray *extraModules); @end +@interface RCTBridge (Inspector) + +@property (nonatomic, readonly, getter=isInspectable) BOOL inspectable; + +@end + @interface RCTBatchedBridge : RCTBridge @property (nonatomic, weak, readonly) RCTBridge *parentBridge; diff --git a/React/CxxBridge/RCTCxxBridge.mm b/React/CxxBridge/RCTCxxBridge.mm index 1cb78175e..74eef66ed 100644 --- a/React/CxxBridge/RCTCxxBridge.mm +++ b/React/CxxBridge/RCTCxxBridge.mm @@ -194,6 +194,10 @@ struct RCTInstanceCallback : public InstanceCallback { return (JSGlobalContextRef)(self->_reactInstance ? self->_reactInstance->getJavaScriptContext() : nullptr); } +- (BOOL)isInspectable { + return self->_reactInstance->isInspectable(); +} + - (instancetype)initWithParentBridge:(RCTBridge *)bridge { RCTAssertParam(bridge); diff --git a/ReactCommon/cxxreact/Instance.cpp b/ReactCommon/cxxreact/Instance.cpp index 01ead3731..c3fd8cf60 100644 --- a/ReactCommon/cxxreact/Instance.cpp +++ b/ReactCommon/cxxreact/Instance.cpp @@ -143,6 +143,10 @@ void *Instance::getJavaScriptContext() { : nullptr; } +bool Instance::isInspectable() { + return nativeToJsBridge_ ? nativeToJsBridge_->isInspectable() : false; +} + void Instance::callJSFunction(std::string &&module, std::string &&method, folly::dynamic &¶ms) { callback_->incrementPendingJSCalls(); diff --git a/ReactCommon/cxxreact/Instance.h b/ReactCommon/cxxreact/Instance.h index d04bcb356..bcd0bea39 100644 --- a/ReactCommon/cxxreact/Instance.h +++ b/ReactCommon/cxxreact/Instance.h @@ -55,6 +55,7 @@ public: void setGlobalVariable(std::string propName, std::unique_ptr jsonValue); void *getJavaScriptContext(); + bool isInspectable(); void callJSFunction(std::string &&module, std::string &&method, folly::dynamic &¶ms); void callJSCallback(uint64_t callbackId, folly::dynamic &¶ms); diff --git a/ReactCommon/cxxreact/NativeToJsBridge.cpp b/ReactCommon/cxxreact/NativeToJsBridge.cpp index 51bad86f7..f8ae2856e 100644 --- a/ReactCommon/cxxreact/NativeToJsBridge.cpp +++ b/ReactCommon/cxxreact/NativeToJsBridge.cpp @@ -190,6 +190,10 @@ void* NativeToJsBridge::getJavaScriptContext() { return m_executor->getJavaScriptContext(); } +bool NativeToJsBridge::isInspectable() { + return m_executor->isInspectable(); +} + #ifdef WITH_JSC_MEMORY_PRESSURE void NativeToJsBridge::handleMemoryPressure(int pressureLevel) { runOnExecutorQueue([=] (JSExecutor* executor) { diff --git a/ReactCommon/cxxreact/NativeToJsBridge.h b/ReactCommon/cxxreact/NativeToJsBridge.h index 093707f2e..586766e38 100644 --- a/ReactCommon/cxxreact/NativeToJsBridge.h +++ b/ReactCommon/cxxreact/NativeToJsBridge.h @@ -101,6 +101,7 @@ public: void registerBundle(uint32_t bundleId, const std::string& bundlePath); void setGlobalVariable(std::string propName, std::unique_ptr jsonValue); void* getJavaScriptContext(); + bool isInspectable(); #ifdef WITH_JSC_MEMORY_PRESSURE void handleMemoryPressure(int pressureLevel);