Support passing native modules to JSContext

Reviewed By: amnn

Differential Revision: D4561036

fbshipit-source-id: b096a222103e895b14cba1ec5b2bb6e72dd72c37
This commit is contained in:
Marc Horowitz 2017-03-14 15:28:49 -07:00 committed by Facebook Github Bot
parent bacee5ad56
commit 7e4b8ff000
3 changed files with 20 additions and 5 deletions

View File

@ -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/...'),
],

View File

@ -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> 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<CxxMessageQueue>();
std::thread t(queue->getUnregisteredRunLoop());
t.detach();
nativeQueue = std::move(queue);
}
jsQueue->runOnQueueSync(
[this, &jsef, moduleRegistry, jsQueue,
nativeQueue=folly::makeMoveWrapper(std::move(nativeQueue))] () mutable {

View File

@ -95,9 +95,13 @@ NativeToJsBridge::NativeToJsBridge(
std::shared_ptr<InstanceCallback> callback)
: m_destroyed(std::make_shared<bool>(false))
, m_mainExecutorToken(callback->createExecutorToken())
, m_delegate(
std::make_shared<JsToNativeBridge>(
this, registry, std::move(nativeQueue), callback)) {
, m_delegate(registry
? std::make_shared<JsToNativeBridge>(
this, registry, std::move(nativeQueue), callback)
: nullptr) {
if (!m_delegate) {
nativeQueue->quitSynchronous();
}
std::unique_ptr<JSExecutor> 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