Skip to content

Commit

Permalink
Fix timers not firing when running in JS debugger
Browse files Browse the repository at this point in the history
Reviewed By: mhorowitz

Differential Revision: D5227125

fbshipit-source-id: 3dadb3f2e2fd088853537c09cc019d7be6319444
  • Loading branch information
javache authored and facebook-github-bot committed Jun 13, 2017
1 parent 96d3be1 commit 6482538
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions React/CxxBridge/RCTObjcExecutor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -32,26 +33,31 @@

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) {
m_errorBlock(error);
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);
Expand Down Expand Up @@ -120,7 +126,8 @@ virtual void stopProfiler(const std::string &titleString,
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;
};

Expand All @@ -135,7 +142,7 @@ virtual void stopProfiler(const std::string &titleString,
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));
}

}
Expand Down

0 comments on commit 6482538

Please sign in to comment.