diff --git a/ReactCommon/cxxreact/BUCK b/ReactCommon/cxxreact/BUCK index 45496978a..c82d6a876 100644 --- a/ReactCommon/cxxreact/BUCK +++ b/ReactCommon/cxxreact/BUCK @@ -55,7 +55,6 @@ if THIS_IS_FBANDROID: # `initOnJSVMThread` to be called before the platform-specific hooks # have been properly initialised. Bad Times(TM). # -- @ashokmenon (2017/01/03) - '//java/com/facebook/java2js:jni', react_native_target('jni/xreact/jni:jni'), react_native_xplat_target('cxxreact/...'), ], diff --git a/ReactCommon/cxxreact/Instance.cpp b/ReactCommon/cxxreact/Instance.cpp index c67395843..12a9dbe1e 100644 --- a/ReactCommon/cxxreact/Instance.cpp +++ b/ReactCommon/cxxreact/Instance.cpp @@ -2,6 +2,7 @@ #include "Instance.h" +#include "CxxMessageQueue.h" #include "Executor.h" #include "MethodCall.h" #include "RecoverableError.h" @@ -36,6 +37,15 @@ void Instance::initializeBridge( std::shared_ptr moduleRegistry) { callback_ = std::move(callback); + if (!nativeQueue) { + // TODO pass down a thread/queue from java, instead of creating our own. + + auto queue = std::make_unique(); + std::thread t(queue->getUnregisteredRunLoop()); + t.detach(); + nativeQueue = std::move(queue); + } + jsQueue->runOnQueueSync( [this, &jsef, moduleRegistry, jsQueue, nativeQueue=folly::makeMoveWrapper(std::move(nativeQueue))] () mutable { diff --git a/ReactCommon/cxxreact/NativeToJsBridge.cpp b/ReactCommon/cxxreact/NativeToJsBridge.cpp index 347d5ad9e..56a71adfd 100644 --- a/ReactCommon/cxxreact/NativeToJsBridge.cpp +++ b/ReactCommon/cxxreact/NativeToJsBridge.cpp @@ -95,9 +95,13 @@ NativeToJsBridge::NativeToJsBridge( std::shared_ptr callback) : m_destroyed(std::make_shared(false)) , m_mainExecutorToken(callback->createExecutorToken()) - , m_delegate( - std::make_shared( - this, registry, std::move(nativeQueue), callback)) { + , m_delegate(registry + ? std::make_shared( + this, registry, std::move(nativeQueue), callback) + : nullptr) { + if (!m_delegate) { + nativeQueue->quitSynchronous(); + } std::unique_ptr mainExecutor = jsExecutorFactory->createJSExecutor(m_delegate, jsQueue); // cached to avoid locked map lookup in the common case @@ -314,7 +318,9 @@ ExecutorToken NativeToJsBridge::getTokenForExecutor(JSExecutor& executor) { } void NativeToJsBridge::destroy() { - m_delegate->quitQueueSynchronous(); + if (m_delegate) { + m_delegate->quitQueueSynchronous(); + } auto* executorMessageQueueThread = getMessageQueueThread(m_mainExecutorToken); // All calls made through runOnExecutorQueue have an early exit if // m_destroyed is true. Setting this before the runOnQueueSync will cause