From d7d89172c2f0905b1e5bad4540b4b53eab03fb3a Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Mon, 3 Oct 2016 05:07:41 -0700 Subject: [PATCH] Expose ModuleRegistry on ExecutorDelegate Differential Revision: D3944588 fbshipit-source-id: f8450a6735e1f6283c3bfe9d2ce883327172621c --- ReactAndroid/src/main/jni/xreact/jni/JExecutorToken.h | 1 + .../src/main/jni/xreact/jni/ProxyExecutor.cpp | 6 ++++-- ReactCommon/cxxreact/Executor.h | 8 ++++---- ReactCommon/cxxreact/JSCExecutor.cpp | 7 ++++--- ReactCommon/cxxreact/NativeToJsBridge.cpp | 11 ++--------- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/ReactAndroid/src/main/jni/xreact/jni/JExecutorToken.h b/ReactAndroid/src/main/jni/xreact/jni/JExecutorToken.h index 0505801ea5d..0277ea09860 100644 --- a/ReactAndroid/src/main/jni/xreact/jni/JExecutorToken.h +++ b/ReactAndroid/src/main/jni/xreact/jni/JExecutorToken.h @@ -7,6 +7,7 @@ #include #include +#include using namespace facebook::jni; diff --git a/ReactAndroid/src/main/jni/xreact/jni/ProxyExecutor.cpp b/ReactAndroid/src/main/jni/xreact/jni/ProxyExecutor.cpp index 342ca474936..20d8d6ee263 100644 --- a/ReactAndroid/src/main/jni/xreact/jni/ProxyExecutor.cpp +++ b/ReactAndroid/src/main/jni/xreact/jni/ProxyExecutor.cpp @@ -10,6 +10,7 @@ #include #include +#include namespace facebook { namespace react { @@ -41,11 +42,12 @@ ProxyExecutor::ProxyExecutor(jni::global_ref&& executorInstance, , m_delegate(delegate) { folly::dynamic nativeModuleConfig = folly::dynamic::array; + auto moduleRegistry = delegate->getModuleRegistry(); { SystraceSection s("collectNativeModuleDescriptions"); - for (const auto& name : delegate->moduleNames()) { - nativeModuleConfig.push_back(delegate->getModuleConfig(name)); + for (const auto& name : moduleRegistry->moduleNames()) { + nativeModuleConfig.push_back(moduleRegistry->getConfig(name)); } } diff --git a/ReactCommon/cxxreact/Executor.h b/ReactCommon/cxxreact/Executor.h index 017ff748bce..1ffaf54c017 100644 --- a/ReactCommon/cxxreact/Executor.h +++ b/ReactCommon/cxxreact/Executor.h @@ -11,8 +11,6 @@ #include -#include "JSModulesUnbundle.h" - namespace facebook { namespace react { @@ -27,7 +25,9 @@ enum { }; class JSExecutor; +class JSModulesUnbundle; class MessageQueueThread; +class ModuleRegistry; struct MethodCallResult { folly::dynamic result; @@ -44,8 +44,8 @@ class ExecutorDelegate { std::shared_ptr queue) = 0; virtual std::unique_ptr unregisterExecutor(JSExecutor& executor) = 0; - virtual std::vector moduleNames() = 0; - virtual folly::dynamic getModuleConfig(const std::string& name) = 0; + virtual std::shared_ptr getModuleRegistry() = 0; + virtual void callNativeModules( JSExecutor& executor, folly::dynamic&& calls, bool isEndOfBatch) = 0; virtual MethodCallResult callSerializableNativeHook( diff --git a/ReactCommon/cxxreact/JSCExecutor.cpp b/ReactCommon/cxxreact/JSCExecutor.cpp index 79df03c754d..7d7046ae705 100644 --- a/ReactCommon/cxxreact/JSCExecutor.cpp +++ b/ReactCommon/cxxreact/JSCExecutor.cpp @@ -20,8 +20,9 @@ #include "Platform.h" #include "SystraceSection.h" #include "Value.h" - #include "JSCSamplingProfiler.h" +#include "JSModulesUnbundle.h" +#include "ModuleRegistry.h" #if defined(WITH_JSC_EXTRA_TRACING) || DEBUG #include "JSCTracing.h" @@ -117,7 +118,7 @@ JSCExecutor::JSCExecutor(std::shared_ptr delegate, { SystraceSection s("collectNativeModuleNames"); - for (auto& name : delegate->moduleNames()) { + for (auto& name : delegate->getModuleRegistry()->moduleNames()) { nativeModuleConfig.push_back(folly::dynamic::array(std::move(name))); } } @@ -687,7 +688,7 @@ JSValueRef JSCExecutor::nativeRequireModuleConfig( } std::string moduleName = Value(m_context, arguments[0]).toString().str(); - folly::dynamic config = m_delegate->getModuleConfig(moduleName); + folly::dynamic config = m_delegate->getModuleRegistry()->getConfig(moduleName); return Value::fromDynamic(m_context, config); } diff --git a/ReactCommon/cxxreact/NativeToJsBridge.cpp b/ReactCommon/cxxreact/NativeToJsBridge.cpp index ad7ce7b2812..1e3084843c1 100644 --- a/ReactCommon/cxxreact/NativeToJsBridge.cpp +++ b/ReactCommon/cxxreact/NativeToJsBridge.cpp @@ -41,15 +41,8 @@ public: return m_nativeToJs->unregisterExecutor(executor); } - std::vector moduleNames() override { - // If this turns out to be too expensive to run on the js thread, - // we can compute it in the ctor, and just return std::move() it - // here. - return m_registry->moduleNames(); - } - - folly::dynamic getModuleConfig(const std::string& name) override { - return m_registry->getConfig(name); + std::shared_ptr getModuleRegistry() override { + return m_registry; } void callNativeModules(