Initial implementation of multiple RAM bundles registry
Differential Revision: D5850963 fbshipit-source-id: e1bd6d74953872d38e73a20f6d054905a7e4c80c
This commit is contained in:
parent
da2ea2601b
commit
2f952fbaac
|
@ -1105,6 +1105,10 @@
|
|||
C6827DF71EF17CCC00D66BEF /* RCTJSEnvironment.h in Headers */ = {isa = PBXBuildFile; fileRef = C6827DF51EF17CCC00D66BEF /* RCTJSEnvironment.h */; };
|
||||
C6827DFB1EF1800E00D66BEF /* RCTJSEnvironment.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = C6827DF51EF17CCC00D66BEF /* RCTJSEnvironment.h */; };
|
||||
C6827DFC1EF1801B00D66BEF /* RCTJSEnvironment.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = C6827DF51EF17CCC00D66BEF /* RCTJSEnvironment.h */; };
|
||||
C6D3801A1F71D76100621378 /* RAMBundleRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = C6D380181F71D75B00621378 /* RAMBundleRegistry.h */; };
|
||||
C6D3801B1F71D76200621378 /* RAMBundleRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = C6D380181F71D75B00621378 /* RAMBundleRegistry.h */; };
|
||||
C6D3801C1F71D76700621378 /* RAMBundleRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C6D380191F71D75B00621378 /* RAMBundleRegistry.cpp */; };
|
||||
C6D3801D1F71D76800621378 /* RAMBundleRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C6D380191F71D75B00621378 /* RAMBundleRegistry.cpp */; };
|
||||
CF2731C01E7B8DE40044CA4F /* RCTDeviceInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = CF2731BE1E7B8DE40044CA4F /* RCTDeviceInfo.h */; };
|
||||
CF2731C11E7B8DE40044CA4F /* RCTDeviceInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = CF2731BF1E7B8DE40044CA4F /* RCTDeviceInfo.m */; };
|
||||
CF2731C21E7B8DEF0044CA4F /* RCTDeviceInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = CF2731BE1E7B8DE40044CA4F /* RCTDeviceInfo.h */; };
|
||||
|
@ -2095,6 +2099,8 @@
|
|||
C6194AAB1EF156280034D062 /* RCTPackagerConnectionConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTPackagerConnectionConfig.h; sourceTree = "<group>"; };
|
||||
C654505D1F3BD9280090799B /* RCTManagedPointer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTManagedPointer.h; sourceTree = "<group>"; };
|
||||
C6827DF51EF17CCC00D66BEF /* RCTJSEnvironment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTJSEnvironment.h; sourceTree = "<group>"; };
|
||||
C6D380181F71D75B00621378 /* RAMBundleRegistry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RAMBundleRegistry.h; sourceTree = "<group>"; };
|
||||
C6D380191F71D75B00621378 /* RAMBundleRegistry.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RAMBundleRegistry.cpp; sourceTree = "<group>"; };
|
||||
CF2731BE1E7B8DE40044CA4F /* RCTDeviceInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTDeviceInfo.h; sourceTree = "<group>"; };
|
||||
CF2731BF1E7B8DE40044CA4F /* RCTDeviceInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTDeviceInfo.m; sourceTree = "<group>"; };
|
||||
E3BBC8EB1ADE6F47001BBD81 /* RCTTextDecorationLineType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTTextDecorationLineType.h; sourceTree = "<group>"; };
|
||||
|
@ -2775,6 +2781,8 @@
|
|||
AC70D2EE1DE48AC5002E6351 /* oss-compat-util.h */,
|
||||
3D92B0D11E03699D0018521A /* Platform.cpp */,
|
||||
3D92B0D21E03699D0018521A /* Platform.h */,
|
||||
C6D380191F71D75B00621378 /* RAMBundleRegistry.cpp */,
|
||||
C6D380181F71D75B00621378 /* RAMBundleRegistry.h */,
|
||||
3D7454791E54757500E74ADD /* RecoverableError.h */,
|
||||
3D92B0D31E03699D0018521A /* SampleCxxModule.cpp */,
|
||||
3D92B0D41E03699D0018521A /* SampleCxxModule.h */,
|
||||
|
@ -2979,6 +2987,7 @@
|
|||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
3D74547E1E54759A00E74ADD /* JSModulesUnbundle.h in Headers */,
|
||||
C6D3801B1F71D76200621378 /* RAMBundleRegistry.h in Headers */,
|
||||
27595AD51E575C7800CCE2B1 /* NativeToJsBridge.h in Headers */,
|
||||
27595AC41E575C7800CCE2B1 /* Instance.h in Headers */,
|
||||
27595AD11E575C7800CCE2B1 /* MessageQueueThread.h in Headers */,
|
||||
|
@ -3067,6 +3076,7 @@
|
|||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
3D74547F1E54759E00E74ADD /* JSModulesUnbundle.h in Headers */,
|
||||
C6D3801A1F71D76100621378 /* RAMBundleRegistry.h in Headers */,
|
||||
27595ABA1E575C7800CCE2B1 /* NativeToJsBridge.h in Headers */,
|
||||
27595AA91E575C7800CCE2B1 /* Instance.h in Headers */,
|
||||
27595AB61E575C7800CCE2B1 /* MessageQueueThread.h in Headers */,
|
||||
|
@ -3944,6 +3954,7 @@
|
|||
3DC159E51E83E1E9007B1282 /* JSBigString.cpp in Sources */,
|
||||
13F8877B1E29726200C3C7A1 /* JSIndexedRAMBundle.cpp in Sources */,
|
||||
13F8877D1E29726200C3C7A1 /* ModuleRegistry.cpp in Sources */,
|
||||
C6D3801C1F71D76700621378 /* RAMBundleRegistry.cpp in Sources */,
|
||||
13F8876E1E29726200C3C7A1 /* CxxNativeModule.cpp in Sources */,
|
||||
13F887721E29726200C3C7A1 /* JSCExecutor.cpp in Sources */,
|
||||
13F887741E29726200C3C7A1 /* JSCLegacyTracing.cpp in Sources */,
|
||||
|
@ -3968,6 +3979,7 @@
|
|||
3DC159E61E83E1FA007B1282 /* JSBigString.cpp in Sources */,
|
||||
13F8878E1E29726300C3C7A1 /* JSIndexedRAMBundle.cpp in Sources */,
|
||||
13F887901E29726300C3C7A1 /* ModuleRegistry.cpp in Sources */,
|
||||
C6D3801D1F71D76800621378 /* RAMBundleRegistry.cpp in Sources */,
|
||||
13F887851E29726300C3C7A1 /* JSCExecutor.cpp in Sources */,
|
||||
13F887871E29726300C3C7A1 /* JSCLegacyTracing.cpp in Sources */,
|
||||
13F8878A1E29726300C3C7A1 /* JSCPerfStats.cpp in Sources */,
|
||||
|
|
|
@ -22,6 +22,7 @@ LOCAL_SRC_FILES := \
|
|||
ModuleRegistry.cpp \
|
||||
NativeToJsBridge.cpp \
|
||||
Platform.cpp \
|
||||
RAMBundleRegistry.cpp \
|
||||
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/..
|
||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "JSModulesUnbundle.h"
|
||||
#include "ModuleRegistry.h"
|
||||
#include "Platform.h"
|
||||
#include "RAMBundleRegistry.h"
|
||||
#include "RecoverableError.h"
|
||||
#include "SystraceSection.h"
|
||||
|
||||
|
@ -354,10 +355,10 @@ void JSCExecutor::loadApplicationScript(std::unique_ptr<const JSBigString> scrip
|
|||
}
|
||||
|
||||
void JSCExecutor::setJSModulesUnbundle(std::unique_ptr<JSModulesUnbundle> unbundle) {
|
||||
if (!m_unbundle) {
|
||||
if (!m_bundleRegistry) {
|
||||
installNativeHook<&JSCExecutor::nativeRequire>("nativeRequire");
|
||||
}
|
||||
m_unbundle = std::move(unbundle);
|
||||
m_bundleRegistry = folly::make_unique<RAMBundleRegistry>(std::move(unbundle));
|
||||
}
|
||||
|
||||
void JSCExecutor::bindBridge() throw(JSException) {
|
||||
|
@ -550,8 +551,8 @@ void JSCExecutor::flushQueueImmediate(Value&& queue) {
|
|||
m_delegate->callNativeModules(*this, folly::parseJson(queueStr), false);
|
||||
}
|
||||
|
||||
void JSCExecutor::loadModule(uint32_t moduleId) {
|
||||
auto module = m_unbundle->getModule(moduleId);
|
||||
void JSCExecutor::loadModule(uint32_t bundleId, uint32_t moduleId) {
|
||||
auto module = m_bundleRegistry->getModule(bundleId, moduleId);
|
||||
auto sourceUrl = String::createExpectingAscii(m_context, module.name);
|
||||
auto source = String::createExpectingAscii(m_context, module.code);
|
||||
evaluateScript(m_context, source, sourceUrl);
|
||||
|
@ -574,9 +575,10 @@ JSValueRef JSCExecutor::getNativeModule(JSObjectRef object, JSStringRef property
|
|||
JSValueRef JSCExecutor::nativeRequire(
|
||||
size_t argumentCount,
|
||||
const JSValueRef arguments[]) {
|
||||
uint32_t moduleId = parseNativeRequireParameters(m_context, arguments, argumentCount).second;
|
||||
uint32_t bundleId, moduleId;
|
||||
std::tie(bundleId, moduleId) = parseNativeRequireParameters(m_context, arguments, argumentCount);
|
||||
ReactMarker::logMarker(ReactMarker::NATIVE_REQUIRE_START);
|
||||
loadModule(moduleId);
|
||||
loadModule(bundleId, moduleId);
|
||||
ReactMarker::logMarker(ReactMarker::NATIVE_REQUIRE_STOP);
|
||||
return Value::makeUndefined(m_context);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <cxxreact/JSCNativeModules.h>
|
||||
#include <cxxreact/JSExecutor.h>
|
||||
|
@ -24,6 +23,7 @@ namespace facebook {
|
|||
namespace react {
|
||||
|
||||
class MessageQueueThread;
|
||||
class RAMBundleRegistry;
|
||||
|
||||
class RN_EXPORT JSCExecutorFactory : public JSExecutorFactory {
|
||||
public:
|
||||
|
@ -106,7 +106,7 @@ private:
|
|||
std::shared_ptr<ExecutorDelegate> m_delegate;
|
||||
std::shared_ptr<bool> m_isDestroyed = std::shared_ptr<bool>(new bool(false));
|
||||
std::shared_ptr<MessageQueueThread> m_messageQueueThread;
|
||||
std::unique_ptr<JSModulesUnbundle> m_unbundle;
|
||||
std::unique_ptr<RAMBundleRegistry> m_bundleRegistry;
|
||||
JSCNativeModules m_nativeModules;
|
||||
folly::dynamic m_jscConfig;
|
||||
std::once_flag m_bindFlag;
|
||||
|
@ -125,7 +125,7 @@ private:
|
|||
void callNativeModules(Value&&);
|
||||
void flush();
|
||||
void flushQueueImmediate(Value&&);
|
||||
void loadModule(uint32_t moduleId);
|
||||
void loadModule(uint32_t bundleId, uint32_t moduleId);
|
||||
|
||||
String adoptString(std::unique_ptr<const JSBigString>);
|
||||
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
#include "RAMBundleRegistry.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
constexpr uint32_t RAMBundleRegistry::MAIN_BUNDLE_ID;
|
||||
|
||||
RAMBundleRegistry::RAMBundleRegistry(std::unique_ptr<JSModulesUnbundle> mainBundle) {
|
||||
m_bundles.emplace(MAIN_BUNDLE_ID, std::move(mainBundle));
|
||||
}
|
||||
|
||||
JSModulesUnbundle::Module RAMBundleRegistry::getModule(uint32_t bundleId, uint32_t moduleId) {
|
||||
return getBundle(bundleId)->getModule(moduleId);
|
||||
}
|
||||
|
||||
JSModulesUnbundle *RAMBundleRegistry::getBundle(uint32_t bundleId) const {
|
||||
return m_bundles.at(bundleId).get();
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
|
||||
#include <cxxreact/JSModulesUnbundle.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
class RAMBundleRegistry {
|
||||
public:
|
||||
constexpr static uint32_t MAIN_BUNDLE_ID = 0;
|
||||
|
||||
explicit RAMBundleRegistry(std::unique_ptr<JSModulesUnbundle> mainBundle);
|
||||
JSModulesUnbundle::Module getModule(uint32_t bundleId, uint32_t moduleId);
|
||||
private:
|
||||
JSModulesUnbundle *getBundle(uint32_t bundleId) const;
|
||||
|
||||
std::unordered_map<uint32_t, std::unique_ptr<JSModulesUnbundle>> m_bundles;
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
Loading…
Reference in New Issue