Expose ModuleRegistry on ExecutorDelegate

Differential Revision: D3944588

fbshipit-source-id: f8450a6735e1f6283c3bfe9d2ce883327172621c
This commit is contained in:
Pieter De Baets 2016-10-03 05:07:41 -07:00 коммит произвёл Facebook Github Bot
Родитель 6d175f2c25
Коммит d7d89172c2
5 изменённых файлов: 15 добавлений и 18 удалений

Просмотреть файл

@ -7,6 +7,7 @@
#include <fb/fbjni.h> #include <fb/fbjni.h>
#include <cxxreact/ExecutorToken.h> #include <cxxreact/ExecutorToken.h>
#include <cxxreact/noncopyable.h>
using namespace facebook::jni; using namespace facebook::jni;

Просмотреть файл

@ -10,6 +10,7 @@
#include <folly/Memory.h> #include <folly/Memory.h>
#include <cxxreact/SystraceSection.h> #include <cxxreact/SystraceSection.h>
#include <cxxreact/ModuleRegistry.h>
namespace facebook { namespace facebook {
namespace react { namespace react {
@ -41,11 +42,12 @@ ProxyExecutor::ProxyExecutor(jni::global_ref<jobject>&& executorInstance,
, m_delegate(delegate) { , m_delegate(delegate) {
folly::dynamic nativeModuleConfig = folly::dynamic::array; folly::dynamic nativeModuleConfig = folly::dynamic::array;
auto moduleRegistry = delegate->getModuleRegistry();
{ {
SystraceSection s("collectNativeModuleDescriptions"); SystraceSection s("collectNativeModuleDescriptions");
for (const auto& name : delegate->moduleNames()) { for (const auto& name : moduleRegistry->moduleNames()) {
nativeModuleConfig.push_back(delegate->getModuleConfig(name)); nativeModuleConfig.push_back(moduleRegistry->getConfig(name));
} }
} }

Просмотреть файл

@ -11,8 +11,6 @@
#include <folly/dynamic.h> #include <folly/dynamic.h>
#include "JSModulesUnbundle.h"
namespace facebook { namespace facebook {
namespace react { namespace react {
@ -27,7 +25,9 @@ enum {
}; };
class JSExecutor; class JSExecutor;
class JSModulesUnbundle;
class MessageQueueThread; class MessageQueueThread;
class ModuleRegistry;
struct MethodCallResult { struct MethodCallResult {
folly::dynamic result; folly::dynamic result;
@ -44,8 +44,8 @@ class ExecutorDelegate {
std::shared_ptr<MessageQueueThread> queue) = 0; std::shared_ptr<MessageQueueThread> queue) = 0;
virtual std::unique_ptr<JSExecutor> unregisterExecutor(JSExecutor& executor) = 0; virtual std::unique_ptr<JSExecutor> unregisterExecutor(JSExecutor& executor) = 0;
virtual std::vector<std::string> moduleNames() = 0; virtual std::shared_ptr<ModuleRegistry> getModuleRegistry() = 0;
virtual folly::dynamic getModuleConfig(const std::string& name) = 0;
virtual void callNativeModules( virtual void callNativeModules(
JSExecutor& executor, folly::dynamic&& calls, bool isEndOfBatch) = 0; JSExecutor& executor, folly::dynamic&& calls, bool isEndOfBatch) = 0;
virtual MethodCallResult callSerializableNativeHook( virtual MethodCallResult callSerializableNativeHook(

Просмотреть файл

@ -20,8 +20,9 @@
#include "Platform.h" #include "Platform.h"
#include "SystraceSection.h" #include "SystraceSection.h"
#include "Value.h" #include "Value.h"
#include "JSCSamplingProfiler.h" #include "JSCSamplingProfiler.h"
#include "JSModulesUnbundle.h"
#include "ModuleRegistry.h"
#if defined(WITH_JSC_EXTRA_TRACING) || DEBUG #if defined(WITH_JSC_EXTRA_TRACING) || DEBUG
#include "JSCTracing.h" #include "JSCTracing.h"
@ -117,7 +118,7 @@ JSCExecutor::JSCExecutor(std::shared_ptr<ExecutorDelegate> delegate,
{ {
SystraceSection s("collectNativeModuleNames"); SystraceSection s("collectNativeModuleNames");
for (auto& name : delegate->moduleNames()) { for (auto& name : delegate->getModuleRegistry()->moduleNames()) {
nativeModuleConfig.push_back(folly::dynamic::array(std::move(name))); 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(); 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); return Value::fromDynamic(m_context, config);
} }

Просмотреть файл

@ -41,15 +41,8 @@ public:
return m_nativeToJs->unregisterExecutor(executor); return m_nativeToJs->unregisterExecutor(executor);
} }
std::vector<std::string> moduleNames() override { std::shared_ptr<ModuleRegistry> getModuleRegistry() override {
// If this turns out to be too expensive to run on the js thread, return m_registry;
// 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);
} }
void callNativeModules( void callNativeModules(