Fix timers not firing when running in JS debugger

Reviewed By: mhorowitz

Differential Revision: D5227125

fbshipit-source-id: 3dadb3f2e2fd088853537c09cc019d7be6319444
This commit is contained in:
Pieter De Baets 2017-06-13 09:30:36 -07:00 committed by Facebook Github Bot
parent 96d3be18bf
commit 64825389df
1 changed files with 14 additions and 7 deletions

View File

@ -16,6 +16,7 @@
#import <React/RCTProfile.h>
#import <React/RCTUtils.h>
#import <cxxreact/Executor.h>
#import <cxxreact/MessageQueueThread.h>
#import <cxxreact/ModuleRegistry.h>
#import <folly/json.h>
@ -32,11 +33,14 @@ public:
class RCTObjcExecutor : public JSExecutor {
public:
RCTObjcExecutor(id<RCTJavaScriptExecutor> jse, RCTJavaScriptCompleteBlock errorBlock,
std::shared_ptr<facebook::react::ExecutorDelegate> delegate)
RCTObjcExecutor(id<RCTJavaScriptExecutor> jse,
RCTJavaScriptCompleteBlock errorBlock,
std::shared_ptr<MessageQueueThread> jsThread,
std::shared_ptr<ExecutorDelegate> delegate)
: m_jse(jse)
, m_errorBlock(errorBlock)
, m_delegate(delegate)
, m_jsThread(std::move(jsThread))
, m_delegate(std::move(delegate))
{
m_jsCallback = ^(id json, NSError *error) {
if (error) {
@ -44,14 +48,16 @@ public:
return;
}
m_delegate->callNativeModules(*this, [RCTConvert folly_dynamic:json], true);
m_jsThread->runOnQueue([this, json]{
m_delegate->callNativeModules(*this, [RCTConvert folly_dynamic:json], true);
});
};
// Synchronously initialize the executor
[jse setUp];
folly::dynamic nativeModuleConfig = folly::dynamic::array;
auto moduleRegistry = delegate->getModuleRegistry();
auto moduleRegistry = m_delegate->getModuleRegistry();
for (const auto &name : moduleRegistry->moduleNames()) {
auto config = moduleRegistry->getConfig(name);
nativeModuleConfig.push_back(config ? config->config : nullptr);
@ -120,7 +126,8 @@ public:
private:
id<RCTJavaScriptExecutor> m_jse;
RCTJavaScriptCompleteBlock m_errorBlock;
std::shared_ptr<facebook::react::ExecutorDelegate> m_delegate;
std::shared_ptr<ExecutorDelegate> m_delegate;
std::shared_ptr<MessageQueueThread> m_jsThread;
RCTJavaScriptCallback m_jsCallback;
};
@ -135,7 +142,7 @@ std::unique_ptr<JSExecutor> RCTObjcExecutorFactory::createJSExecutor(
std::shared_ptr<ExecutorDelegate> delegate,
std::shared_ptr<MessageQueueThread> jsQueue) {
return std::unique_ptr<JSExecutor>(
new RCTObjcExecutor(m_jse, m_errorBlock, delegate));
new RCTObjcExecutor(m_jse, m_errorBlock, jsQueue, delegate));
}
}