Skip to content

Commit

Permalink
Remove RAMBundleRegistry subclasses
Browse files Browse the repository at this point in the history
Differential Revision: D6262247

fbshipit-source-id: 708f919e34f1706d9aca19a34ad8ea506e9f8d8b
  • Loading branch information
fromcelticpark authored and facebook-github-bot committed Nov 8, 2017
1 parent b0193b0 commit 6ecae73
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 131 deletions.
6 changes: 3 additions & 3 deletions React/CxxBridge/RCTCxxBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
#import <cxxreact/JSBundleType.h>
#import <cxxreact/JSCExecutor.h>
#import <cxxreact/JSIndexedRAMBundle.h>
#include <cxxreact/JSIndexedRAMBundleRegistry.h>
#import <cxxreact/Platform.h>
#import <cxxreact/RAMBundleRegistry.h>
#import <jschelpers/Value.h>

#import "NSDataBigString.h"
Expand Down Expand Up @@ -1152,8 +1152,8 @@ - (void)executeApplicationScript:(NSData *)script
? [[self.delegate jsSegmentsDirectory].path stringByAppendingString:@"/"]
: nil;
auto registry = jsSegmentsDirectory != nil
? std::make_unique<JSIndexedRAMBundleRegistry>(std::move(ramBundle), jsSegmentsDirectory.UTF8String)
: std::make_unique<RAMBundleRegistry>(std::move(ramBundle));
? RAMBundleRegistry::multipleBundlesRegistry(std::move(ramBundle), JSIndexedRAMBundle::buildFactory(jsSegmentsDirectory.UTF8String))
: RAMBundleRegistry::singleBundleRegistry(std::move(ramBundle));
self->_reactInstance->loadRAMBundle(std::move(registry), std::move(scriptStr),
sourceUrlStr.UTF8String, !async);
}
Expand Down
16 changes: 0 additions & 16 deletions React/React.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,6 @@
597633371F4E021D005BE8A4 /* RCTShadowView+Internal.m in Sources */ = {isa = PBXBuildFile; fileRef = 597633341F4E021D005BE8A4 /* RCTShadowView+Internal.m */; };
597633381F4E021D005BE8A4 /* RCTShadowView+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 597633351F4E021D005BE8A4 /* RCTShadowView+Internal.h */; };
597633391F4E021D005BE8A4 /* RCTShadowView+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 597633351F4E021D005BE8A4 /* RCTShadowView+Internal.h */; };
598FD1911F816998006C54CB /* JSIndexedRAMBundleRegistry.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = C6D3801E1F71D91600621378 /* JSIndexedRAMBundleRegistry.h */; };
598FD1921F816A2A006C54CB /* RAMBundleRegistry.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = C6D380181F71D75B00621378 /* RAMBundleRegistry.h */; };
598FD1931F817284006C54CB /* PrivateDataBase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9936F3351F5F2F480010BF04 /* PrivateDataBase.cpp */; };
598FD1941F8172A9006C54CB /* PrivateDataBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 9936F3361F5F2F480010BF04 /* PrivateDataBase.h */; };
Expand Down Expand Up @@ -1158,7 +1157,6 @@
C654505E1F3BD9280090799B /* RCTManagedPointer.h in Headers */ = {isa = PBXBuildFile; fileRef = C654505D1F3BD9280090799B /* RCTManagedPointer.h */; };
C654505F1F3BD9280090799B /* RCTManagedPointer.h in Headers */ = {isa = PBXBuildFile; fileRef = C654505D1F3BD9280090799B /* RCTManagedPointer.h */; };
C669D8981F72E3DE006748EB /* RAMBundleRegistry.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = C6D380181F71D75B00621378 /* RAMBundleRegistry.h */; };
C669D8B91F72E4B7006748EB /* JSIndexedRAMBundleRegistry.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = C6D3801E1F71D91600621378 /* JSIndexedRAMBundleRegistry.h */; };
C6827DF61EF17CCC00D66BEF /* RCTJSEnvironment.h in Headers */ = {isa = PBXBuildFile; fileRef = C6827DF51EF17CCC00D66BEF /* RCTJSEnvironment.h */; };
C6827DF71EF17CCC00D66BEF /* RCTJSEnvironment.h in Headers */ = {isa = PBXBuildFile; fileRef = C6827DF51EF17CCC00D66BEF /* RCTJSEnvironment.h */; };
C6827DFB1EF1800E00D66BEF /* RCTJSEnvironment.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = C6827DF51EF17CCC00D66BEF /* RCTJSEnvironment.h */; };
Expand All @@ -1167,10 +1165,6 @@
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 */; };
C6D380201F71D91D00621378 /* JSIndexedRAMBundleRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = C6D3801E1F71D91600621378 /* JSIndexedRAMBundleRegistry.h */; };
C6D380211F71D91E00621378 /* JSIndexedRAMBundleRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = C6D3801E1F71D91600621378 /* JSIndexedRAMBundleRegistry.h */; };
C6D380221F71D92300621378 /* JSIndexedRAMBundleRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C6D3801F1F71D91600621378 /* JSIndexedRAMBundleRegistry.cpp */; };
C6D380231F71D92400621378 /* JSIndexedRAMBundleRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C6D3801F1F71D91600621378 /* JSIndexedRAMBundleRegistry.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 */; };
Expand Down Expand Up @@ -1455,7 +1449,6 @@
dstSubfolderSpec = 16;
files = (
598FD1921F816A2A006C54CB /* RAMBundleRegistry.h in Copy Headers */,
598FD1911F816998006C54CB /* JSIndexedRAMBundleRegistry.h in Copy Headers */,
3DA9823B1E5B1053004F2374 /* CxxModule.h in Copy Headers */,
3DA9823C1E5B1053004F2374 /* CxxNativeModule.h in Copy Headers */,
3DA9823D1E5B1053004F2374 /* JSExecutor.h in Copy Headers */,
Expand Down Expand Up @@ -1674,7 +1667,6 @@
dstPath = include/cxxreact;
dstSubfolderSpec = 16;
files = (
C669D8B91F72E4B7006748EB /* JSIndexedRAMBundleRegistry.h in Copy Headers */,
C669D8981F72E3DE006748EB /* RAMBundleRegistry.h in Copy Headers */,
3DA981A01E5B0E34004F2374 /* CxxModule.h in Copy Headers */,
3DA981A11E5B0E34004F2374 /* CxxNativeModule.h in Copy Headers */,
Expand Down Expand Up @@ -2194,8 +2186,6 @@
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>"; };
C6D3801E1F71D91600621378 /* JSIndexedRAMBundleRegistry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSIndexedRAMBundleRegistry.h; sourceTree = "<group>"; };
C6D3801F1F71D91600621378 /* JSIndexedRAMBundleRegistry.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSIndexedRAMBundleRegistry.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>"; };
Expand Down Expand Up @@ -2905,8 +2895,6 @@
3D92B0AB1E03699D0018521A /* JSExecutor.h */,
3D92B0C61E03699D0018521A /* JSIndexedRAMBundle.cpp */,
3D92B0C71E03699D0018521A /* JSIndexedRAMBundle.h */,
C6D3801F1F71D91600621378 /* JSIndexedRAMBundleRegistry.cpp */,
C6D3801E1F71D91600621378 /* JSIndexedRAMBundleRegistry.h */,
3D92B0C81E03699D0018521A /* JSModulesUnbundle.h */,
3D92B0C91E03699D0018521A /* MessageQueueThread.h */,
3D92B0CA1E03699D0018521A /* MethodCall.cpp */,
Expand Down Expand Up @@ -3154,7 +3142,6 @@
27595AC61E575C7800CCE2B1 /* JsArgumentHelpers.h in Headers */,
27595AD71E575C7800CCE2B1 /* SampleCxxModule.h in Headers */,
27595AD21E575C7800CCE2B1 /* MethodCall.h in Headers */,
C6D380211F71D91E00621378 /* JSIndexedRAMBundleRegistry.h in Headers */,
3D3030221DF8294C00D6DDAE /* JSBundleType.h in Headers */,
27595ACA1E575C7800CCE2B1 /* JSCMemory.h in Headers */,
3D74547D1E54758900E74ADD /* JSBigString.h in Headers */,
Expand Down Expand Up @@ -3244,7 +3231,6 @@
27595AAB1E575C7800CCE2B1 /* JsArgumentHelpers.h in Headers */,
27595ABC1E575C7800CCE2B1 /* SampleCxxModule.h in Headers */,
27595AB71E575C7800CCE2B1 /* MethodCall.h in Headers */,
C6D380201F71D91D00621378 /* JSIndexedRAMBundleRegistry.h in Headers */,
3D3CD9471DE5FC7800167DC4 /* oss-compat-util.h in Headers */,
27595AAF1E575C7800CCE2B1 /* JSCMemory.h in Headers */,
3D74547C1E54758900E74ADD /* JSBigString.h in Headers */,
Expand Down Expand Up @@ -4133,7 +4119,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
C6D380221F71D92300621378 /* JSIndexedRAMBundleRegistry.cpp in Sources */,
3DC159E51E83E1E9007B1282 /* JSBigString.cpp in Sources */,
13F8877B1E29726200C3C7A1 /* JSIndexedRAMBundle.cpp in Sources */,
13F8877D1E29726200C3C7A1 /* ModuleRegistry.cpp in Sources */,
Expand All @@ -4159,7 +4144,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
C6D380231F71D92400621378 /* JSIndexedRAMBundleRegistry.cpp in Sources */,
3DC159E61E83E1FA007B1282 /* JSBigString.cpp in Sources */,
13F8878E1E29726300C3C7A1 /* JSIndexedRAMBundle.cpp in Sources */,
13F887901E29726300C3C7A1 /* ModuleRegistry.cpp in Sources */,
Expand Down
1 change: 0 additions & 1 deletion ReactAndroid/src/main/jni/react/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ LOCAL_SRC_FILES := \
JSLoader.cpp \
JSLogging.cpp \
JniJSModulesUnbundle.cpp \
JniRAMBundleRegistry.cpp \
MethodInvoker.cpp \
ModuleRegistryBuilder.cpp \
NativeArray.cpp \
Expand Down
22 changes: 14 additions & 8 deletions ReactAndroid/src/main/jni/react/jni/CatalystInstanceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
#include <cxxreact/JSBigString.h>
#include <cxxreact/JSBundleType.h>
#include <cxxreact/JSIndexedRAMBundle.h>
#include <cxxreact/JSIndexedRAMBundleRegistry.h>
#include <cxxreact/MethodCall.h>
#include <cxxreact/RecoverableError.h>
#include <cxxreact/ModuleRegistry.h>
#include <cxxreact/RecoverableError.h>
#include <cxxreact/RAMBundleRegistry.h>
#include <fb/log.h>
#include <folly/dynamic.h>
#include <folly/Memory.h>
Expand All @@ -22,9 +22,8 @@

#include "CxxModuleWrapper.h"
#include "JavaScriptExecutorHolder.h"
#include "JniJSModulesUnbundle.h"
#include "JniRAMBundleRegistry.h"
#include "JNativeRunnable.h"
#include "JniJSModulesUnbundle.h"
#include "NativeArray.h"

using namespace facebook::jni;
Expand Down Expand Up @@ -193,9 +192,7 @@ void CatalystInstanceImpl::jniLoadScriptFromAssets(
auto script = loadScriptFromAssets(manager, sourceURL);
if (JniJSModulesUnbundle::isUnbundle(manager, sourceURL)) {
auto bundle = JniJSModulesUnbundle::fromEntryFile(manager, sourceURL);
auto registry = jsSegmentsDirectory_.empty()
? folly::make_unique<RAMBundleRegistry>(std::move(bundle))
: folly::make_unique<JniRAMBundleRegistry>(std::move(bundle), manager, sourceURL);
auto registry = RAMBundleRegistry::singleBundleRegistry(std::move(bundle));
instance_->loadRAMBundle(
std::move(registry),
std::move(script),
Expand All @@ -211,7 +208,16 @@ void CatalystInstanceImpl::jniLoadScriptFromFile(const std::string& fileName,
const std::string& sourceURL,
bool loadSynchronously) {
if (Instance::isIndexedRAMBundle(fileName.c_str())) {
instance_->loadRAMBundleFromFile(fileName, sourceURL, loadSynchronously);
auto bundle = folly::make_unique<JSIndexedRAMBundle>(fileName.c_str());
auto script = bundle->getStartupCode();
auto registry = jsSegmentsDirectory_.empty()
? RAMBundleRegistry::singleBundleRegistry(std::move(bundle))
: RAMBundleRegistry::multipleBundlesRegistry(std::move(bundle), JSIndexedRAMBundle::buildFactory(jsSegmentsDirectory_));
instance_->loadRAMBundle(
std::move(registry),
std::move(script),
sourceURL,
loadSynchronously);
} else {
std::unique_ptr<const JSBigFileString> script;
RecoverableError::runRethrowingAsRecoverable<std::system_error>(
Expand Down
24 changes: 0 additions & 24 deletions ReactAndroid/src/main/jni/react/jni/JniRAMBundleRegistry.cpp

This file was deleted.

21 changes: 0 additions & 21 deletions ReactAndroid/src/main/jni/react/jni/JniRAMBundleRegistry.h

This file was deleted.

1 change: 0 additions & 1 deletion ReactCommon/cxxreact/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ LOCAL_SRC_FILES := \
JSCTracing.cpp \
JSCUtils.cpp \
JSIndexedRAMBundle.cpp \
JSIndexedRAMBundleRegistry.cpp \
MethodCall.cpp \
ModuleRegistry.cpp \
NativeToJsBridge.cpp \
Expand Down
1 change: 0 additions & 1 deletion ReactCommon/cxxreact/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ CXXREACT_PUBLIC_HEADERS = [
"JSCExecutor.h",
"JSCNativeModules.h",
"JSIndexedRAMBundle.h",
"JSIndexedRAMBundleRegistry.h",
"JSModulesUnbundle.h",
"MessageQueueThread.h",
"MethodCall.h",
Expand Down
2 changes: 1 addition & 1 deletion ReactCommon/cxxreact/Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void Instance::loadRAMBundleFromFile(const std::string& sourcePath,
bool loadSynchronously) {
auto bundle = folly::make_unique<JSIndexedRAMBundle>(sourcePath.c_str());
auto startupScript = bundle->getStartupCode();
auto registry = folly::make_unique<RAMBundleRegistry>(std::move(bundle));
auto registry = RAMBundleRegistry::singleBundleRegistry(std::move(bundle));
loadRAMBundle(
std::move(registry),
std::move(startupScript),
Expand Down
9 changes: 9 additions & 0 deletions ReactCommon/cxxreact/JSIndexedRAMBundle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@

#include "JSIndexedRAMBundle.h"

#include <folly/Memory.h>

#include "oss-compat-util.h"

namespace facebook {
namespace react {

std::function<std::unique_ptr<JSModulesUnbundle>(uint32_t)> JSIndexedRAMBundle::buildFactory(const std::string& baseDirectoryPath) {
return [baseDirectoryPath](uint32_t index){
std::string bundlePathById = baseDirectoryPath + toString(index) + ".jsbundle";
return folly::make_unique<JSIndexedRAMBundle>(bundlePathById.c_str());
};
}

JSIndexedRAMBundle::JSIndexedRAMBundle(const char *sourcePath) :
m_bundle (sourcePath, std::ios_base::in) {
if (!m_bundle) {
Expand Down
2 changes: 2 additions & 0 deletions ReactCommon/cxxreact/JSIndexedRAMBundle.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace react {

class RN_EXPORT JSIndexedRAMBundle : public JSModulesUnbundle {
public:
static std::function<std::unique_ptr<JSModulesUnbundle>(uint32_t)> buildFactory(const std::string& baseDirectoryPath);

// Throws std::runtime_error on failure.
JSIndexedRAMBundle(const char *sourceURL);

Expand Down
22 changes: 0 additions & 22 deletions ReactCommon/cxxreact/JSIndexedRAMBundleRegistry.cpp

This file was deleted.

25 changes: 0 additions & 25 deletions ReactCommon/cxxreact/JSIndexedRAMBundleRegistry.h

This file was deleted.

19 changes: 17 additions & 2 deletions ReactCommon/cxxreact/RAMBundleRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,35 @@

#include "RAMBundleRegistry.h"

#include <folly/Memory.h>

#include <libgen.h>

namespace facebook {
namespace react {

constexpr uint32_t RAMBundleRegistry::MAIN_BUNDLE_ID;

RAMBundleRegistry::RAMBundleRegistry(std::unique_ptr<JSModulesUnbundle> mainBundle) {
std::unique_ptr<RAMBundleRegistry> RAMBundleRegistry::singleBundleRegistry(std::unique_ptr<JSModulesUnbundle> mainBundle) {
RAMBundleRegistry *registry = new RAMBundleRegistry(std::move(mainBundle));
return std::unique_ptr<RAMBundleRegistry>(registry);
}

std::unique_ptr<RAMBundleRegistry> RAMBundleRegistry::multipleBundlesRegistry(std::unique_ptr<JSModulesUnbundle> mainBundle, std::function<std::unique_ptr<JSModulesUnbundle>(uint32_t)> factory) {
RAMBundleRegistry *registry = new RAMBundleRegistry(std::move(mainBundle), std::move(factory));
return std::unique_ptr<RAMBundleRegistry>(registry);
}

RAMBundleRegistry::RAMBundleRegistry(std::unique_ptr<JSModulesUnbundle> mainBundle, std::function<std::unique_ptr<JSModulesUnbundle>(uint32_t)> factory): m_factory(factory) {
m_bundles.emplace(MAIN_BUNDLE_ID, std::move(mainBundle));
}

JSModulesUnbundle::Module RAMBundleRegistry::getModule(uint32_t bundleId, uint32_t moduleId) {
if (m_bundles.find(bundleId) == m_bundles.end()) {
m_bundles.emplace(bundleId, this->bundleById(bundleId));
if (!m_factory) {
throw std::runtime_error("You need to register factory function in order to support multiple RAM bundles.");
}
m_bundles.emplace(bundleId, m_factory(bundleId));
}

return getBundle(bundleId)->getModule(moduleId);
Expand Down
Loading

0 comments on commit 6ecae73

Please sign in to comment.