Skip to content

Commit 7e4b8ff

Browse files
mhorowitzfacebook-github-bot
authored andcommitted
Support passing native modules to JSContext
Reviewed By: amnn Differential Revision: D4561036 fbshipit-source-id: b096a222103e895b14cba1ec5b2bb6e72dd72c37
1 parent bacee5a commit 7e4b8ff

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

ReactCommon/cxxreact/BUCK

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ if THIS_IS_FBANDROID:
5555
# `initOnJSVMThread` to be called before the platform-specific hooks
5656
# have been properly initialised. Bad Times(TM).
5757
# -- @ashokmenon (2017/01/03)
58-
'//java/com/facebook/java2js:jni',
5958
react_native_target('jni/xreact/jni:jni'),
6059
react_native_xplat_target('cxxreact/...'),
6160
],

ReactCommon/cxxreact/Instance.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "Instance.h"
44

5+
#include "CxxMessageQueue.h"
56
#include "Executor.h"
67
#include "MethodCall.h"
78
#include "RecoverableError.h"
@@ -36,6 +37,15 @@ void Instance::initializeBridge(
3637
std::shared_ptr<ModuleRegistry> moduleRegistry) {
3738
callback_ = std::move(callback);
3839

40+
if (!nativeQueue) {
41+
// TODO pass down a thread/queue from java, instead of creating our own.
42+
43+
auto queue = std::make_unique<CxxMessageQueue>();
44+
std::thread t(queue->getUnregisteredRunLoop());
45+
t.detach();
46+
nativeQueue = std::move(queue);
47+
}
48+
3949
jsQueue->runOnQueueSync(
4050
[this, &jsef, moduleRegistry, jsQueue,
4151
nativeQueue=folly::makeMoveWrapper(std::move(nativeQueue))] () mutable {

ReactCommon/cxxreact/NativeToJsBridge.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,13 @@ NativeToJsBridge::NativeToJsBridge(
9595
std::shared_ptr<InstanceCallback> callback)
9696
: m_destroyed(std::make_shared<bool>(false))
9797
, m_mainExecutorToken(callback->createExecutorToken())
98-
, m_delegate(
99-
std::make_shared<JsToNativeBridge>(
100-
this, registry, std::move(nativeQueue), callback)) {
98+
, m_delegate(registry
99+
? std::make_shared<JsToNativeBridge>(
100+
this, registry, std::move(nativeQueue), callback)
101+
: nullptr) {
102+
if (!m_delegate) {
103+
nativeQueue->quitSynchronous();
104+
}
101105
std::unique_ptr<JSExecutor> mainExecutor =
102106
jsExecutorFactory->createJSExecutor(m_delegate, jsQueue);
103107
// cached to avoid locked map lookup in the common case
@@ -314,7 +318,9 @@ ExecutorToken NativeToJsBridge::getTokenForExecutor(JSExecutor& executor) {
314318
}
315319

316320
void NativeToJsBridge::destroy() {
317-
m_delegate->quitQueueSynchronous();
321+
if (m_delegate) {
322+
m_delegate->quitQueueSynchronous();
323+
}
318324
auto* executorMessageQueueThread = getMessageQueueThread(m_mainExecutorToken);
319325
// All calls made through runOnExecutorQueue have an early exit if
320326
// m_destroyed is true. Setting this before the runOnQueueSync will cause

0 commit comments

Comments
 (0)