Make isInspectable safe to call from any thread

Summary: The bridge was not properly isolating isInspectable onto the JS thread.

Reviewed By: fkgozali

Differential Revision: D14991970

fbshipit-source-id: 92a06c90bade8f92bfa81fa3b7dfb23b17db6117
This commit is contained in:
Marc Horowitz 2019-04-17 21:17:51 -07:00 коммит произвёл Facebook Github Bot
Родитель 1149d85b9f
Коммит 0735873fbc
2 изменённых файлов: 12 добавлений и 6 удалений

Просмотреть файл

@ -84,14 +84,15 @@ private:
};
NativeToJsBridge::NativeToJsBridge(
JSExecutorFactory* jsExecutorFactory,
JSExecutorFactory *jsExecutorFactory,
std::shared_ptr<ModuleRegistry> registry,
std::shared_ptr<MessageQueueThread> jsQueue,
std::shared_ptr<InstanceCallback> callback)
: m_destroyed(std::make_shared<bool>(false))
, m_delegate(std::make_shared<JsToNativeBridge>(registry, callback))
, m_executor(jsExecutorFactory->createJSExecutor(m_delegate, jsQueue))
, m_executorMessageQueueThread(std::move(jsQueue)) {}
: m_destroyed(std::make_shared<bool>(false)),
m_delegate(std::make_shared<JsToNativeBridge>(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() {

Просмотреть файл

@ -96,6 +96,11 @@ private:
std::unique_ptr<JSExecutor> m_executor;
std::shared_ptr<MessageQueueThread> 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.