diff --git a/ReactCommon/cxxreact/NativeToJsBridge.cpp b/ReactCommon/cxxreact/NativeToJsBridge.cpp index 27c54a3739c..2c3893e87e6 100644 --- a/ReactCommon/cxxreact/NativeToJsBridge.cpp +++ b/ReactCommon/cxxreact/NativeToJsBridge.cpp @@ -84,14 +84,15 @@ private: }; NativeToJsBridge::NativeToJsBridge( - JSExecutorFactory* jsExecutorFactory, + JSExecutorFactory *jsExecutorFactory, std::shared_ptr registry, std::shared_ptr jsQueue, std::shared_ptr callback) - : m_destroyed(std::make_shared(false)) - , m_delegate(std::make_shared(registry, callback)) - , m_executor(jsExecutorFactory->createJSExecutor(m_delegate, jsQueue)) - , m_executorMessageQueueThread(std::move(jsQueue)) {} + : m_destroyed(std::make_shared(false)), + m_delegate(std::make_shared(registry, callback)), + m_executor(jsExecutorFactory->createJSExecutor(m_delegate, jsQueue)), + m_executorMessageQueueThread(std::move(jsQueue)), + m_inspectable(m_executor->isInspectable()) {} // This must be called on the same thread on which the constructor was called. NativeToJsBridge::~NativeToJsBridge() { @@ -225,7 +226,7 @@ void* NativeToJsBridge::getJavaScriptContext() { } bool NativeToJsBridge::isInspectable() { - return m_executor->isInspectable(); + return m_inspectable; } bool NativeToJsBridge::isBatchActive() { diff --git a/ReactCommon/cxxreact/NativeToJsBridge.h b/ReactCommon/cxxreact/NativeToJsBridge.h index c80114230e8..bf5746a0e7f 100644 --- a/ReactCommon/cxxreact/NativeToJsBridge.h +++ b/ReactCommon/cxxreact/NativeToJsBridge.h @@ -96,6 +96,11 @@ private: std::unique_ptr m_executor; std::shared_ptr m_executorMessageQueueThread; + // Memoize this on the JS thread, so that it can be inspected from + // any thread later. This assumes inspectability doesn't change for + // a JSExecutor instance, which is true for all existing implementations. + bool m_inspectable; + // Keep track of whether the JS bundle containing the application logic causes // exception when evaluated initially. If so, more calls to JS will very // likely fail as well, so this flag can help prevent them.