Configure JSExector with BundleRegistry instead of JSModulesUnbundle.
Differential Revision: D5850968 fbshipit-source-id: e5e7ad92c2347c2641551fcf820f061ffde5fed6
This commit is contained in:
parent
2f952fbaac
commit
79821917fa
|
@ -36,6 +36,7 @@
|
|||
#import <cxxreact/JSCExecutor.h>
|
||||
#import <cxxreact/JSIndexedRAMBundle.h>
|
||||
#import <cxxreact/Platform.h>
|
||||
#import <cxxreact/RAMBundleRegistry.h>
|
||||
#import <jschelpers/Value.h>
|
||||
|
||||
#import "NSDataBigString.h"
|
||||
|
@ -1184,8 +1185,9 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR
|
|||
[self->_performanceLogger markStopForTag:RCTPLRAMBundleLoad];
|
||||
[self->_performanceLogger setValue:scriptStr->size() forTag:RCTPLRAMStartupCodeSize];
|
||||
if (self->_reactInstance) {
|
||||
self->_reactInstance->loadUnbundle(std::move(ramBundle), std::move(scriptStr),
|
||||
sourceUrlStr.UTF8String, !async);
|
||||
auto registry = std::make_unique<RAMBundleRegistry>(std::move(ramBundle));
|
||||
self->_reactInstance->loadRAMBundle(std::move(registry), std::move(scriptStr),
|
||||
sourceUrlStr.UTF8String, !async);
|
||||
}
|
||||
} else if (self->_reactInstance) {
|
||||
self->_reactInstance->loadScriptFromString(std::make_unique<NSDataBigString>(script),
|
||||
|
|
|
@ -91,8 +91,8 @@ public:
|
|||
}];
|
||||
}
|
||||
|
||||
void setJSModulesUnbundle(std::unique_ptr<JSModulesUnbundle>) override {
|
||||
RCTAssert(NO, @"Unbundle is not supported in RCTObjcExecutor");
|
||||
void setBundleRegistry(std::unique_ptr<RAMBundleRegistry>) override {
|
||||
RCTAssert(NO, @"RAM bundles are not supported in RCTObjcExecutor");
|
||||
}
|
||||
|
||||
void callFunction(const std::string &module, const std::string &method,
|
||||
|
|
|
@ -1101,6 +1101,7 @@
|
|||
C6194AB11EF156280034D062 /* RCTPackagerConnectionConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = C6194AAB1EF156280034D062 /* RCTPackagerConnectionConfig.h */; };
|
||||
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 */; };
|
||||
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 */; };
|
||||
|
@ -1608,6 +1609,7 @@
|
|||
dstPath = include/cxxreact;
|
||||
dstSubfolderSpec = 16;
|
||||
files = (
|
||||
C669D8981F72E3DE006748EB /* RAMBundleRegistry.h in Copy Headers */,
|
||||
3DA981A01E5B0E34004F2374 /* CxxModule.h in Copy Headers */,
|
||||
3DA981A11E5B0E34004F2374 /* CxxNativeModule.h in Copy Headers */,
|
||||
3DA981A21E5B0E34004F2374 /* JSExecutor.h in Copy Headers */,
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <cxxreact/MethodCall.h>
|
||||
#include <cxxreact/RecoverableError.h>
|
||||
#include <cxxreact/ModuleRegistry.h>
|
||||
#include <cxxreact/RAMBundleRegistry.h>
|
||||
#include <fb/log.h>
|
||||
#include <folly/dynamic.h>
|
||||
#include <folly/Memory.h>
|
||||
|
@ -185,8 +186,10 @@ void CatalystInstanceImpl::jniLoadScriptFromAssets(
|
|||
auto manager = extractAssetManager(assetManager);
|
||||
auto script = loadScriptFromAssets(manager, sourceURL);
|
||||
if (JniJSModulesUnbundle::isUnbundle(manager, sourceURL)) {
|
||||
instance_->loadUnbundle(
|
||||
folly::make_unique<JniJSModulesUnbundle>(manager, sourceURL),
|
||||
auto bundle = folly::make_unique<JniJSModulesUnbundle>(manager, sourceURL);
|
||||
auto registry = folly::make_unique<RAMBundleRegistry>(std::move(bundle));
|
||||
instance_->loadRAMBundle(
|
||||
std::move(registry),
|
||||
std::move(script),
|
||||
sourceURL,
|
||||
loadSynchronously);
|
||||
|
@ -214,8 +217,9 @@ void CatalystInstanceImpl::jniLoadScriptFromFile(const std::string& fileName,
|
|||
if (isIndexedRAMBundle(zFileName)) {
|
||||
auto bundle = folly::make_unique<JSIndexedRAMBundle>(zFileName);
|
||||
auto startupScript = bundle->getStartupCode();
|
||||
instance_->loadUnbundle(
|
||||
std::move(bundle),
|
||||
auto registry = folly::make_unique<RAMBundleRegistry>(std::move(bundle));
|
||||
instance_->loadRAMBundle(
|
||||
std::move(registry),
|
||||
std::move(startupScript),
|
||||
sourceURL,
|
||||
loadSynchronously);
|
||||
|
|
|
@ -84,10 +84,10 @@ void ProxyExecutor::loadApplicationScript(
|
|||
// we launch the application.
|
||||
}
|
||||
|
||||
void ProxyExecutor::setJSModulesUnbundle(std::unique_ptr<JSModulesUnbundle>) {
|
||||
void ProxyExecutor::setBundleRegistry(std::unique_ptr<RAMBundleRegistry>) {
|
||||
jni::throwNewJavaException(
|
||||
"java/lang/UnsupportedOperationException",
|
||||
"Loading application unbundles is not supported for proxy executors");
|
||||
"Loading application RAM bundles is not supported for proxy executors");
|
||||
}
|
||||
|
||||
void ProxyExecutor::callFunction(const std::string& moduleId, const std::string& methodId, const folly::dynamic& arguments) {
|
||||
|
|
|
@ -35,8 +35,8 @@ public:
|
|||
virtual void loadApplicationScript(
|
||||
std::unique_ptr<const JSBigString> script,
|
||||
std::string sourceURL) override;
|
||||
virtual void setJSModulesUnbundle(
|
||||
std::unique_ptr<JSModulesUnbundle> bundle) override;
|
||||
virtual void setBundleRegistry(
|
||||
std::unique_ptr<RAMBundleRegistry> bundle) override;
|
||||
virtual void callFunction(
|
||||
const std::string& moduleId,
|
||||
const std::string& methodId,
|
||||
|
|
|
@ -87,6 +87,7 @@ CXXREACT_PUBLIC_HEADERS = [
|
|||
"NativeModule.h",
|
||||
"NativeToJsBridge.h",
|
||||
"Platform.h",
|
||||
"RAMBundleRegistry.h",
|
||||
"RecoverableError.h",
|
||||
"SharedProxyCxxModule.h",
|
||||
"SystraceSection.h",
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
|
||||
#include "JSBigString.h"
|
||||
#include "JSExecutor.h"
|
||||
#include "JSModulesUnbundle.h"
|
||||
#include "MessageQueueThread.h"
|
||||
#include "MethodCall.h"
|
||||
#include "NativeToJsBridge.h"
|
||||
#include "RAMBundleRegistry.h"
|
||||
#include "RecoverableError.h"
|
||||
#include "SystraceSection.h"
|
||||
|
||||
|
@ -50,17 +50,17 @@ void Instance::initializeBridge(
|
|||
CHECK(nativeToJsBridge_);
|
||||
}
|
||||
|
||||
void Instance::loadApplication(std::unique_ptr<JSModulesUnbundle> unbundle,
|
||||
void Instance::loadApplication(std::unique_ptr<RAMBundleRegistry> bundleRegistry,
|
||||
std::unique_ptr<const JSBigString> string,
|
||||
std::string sourceURL) {
|
||||
callback_->incrementPendingJSCalls();
|
||||
SystraceSection s("Instance::loadApplication", "sourceURL",
|
||||
sourceURL);
|
||||
nativeToJsBridge_->loadApplication(std::move(unbundle), std::move(string),
|
||||
nativeToJsBridge_->loadApplication(std::move(bundleRegistry), std::move(string),
|
||||
std::move(sourceURL));
|
||||
}
|
||||
|
||||
void Instance::loadApplicationSync(std::unique_ptr<JSModulesUnbundle> unbundle,
|
||||
void Instance::loadApplicationSync(std::unique_ptr<RAMBundleRegistry> bundleRegistry,
|
||||
std::unique_ptr<const JSBigString> string,
|
||||
std::string sourceURL) {
|
||||
std::unique_lock<std::mutex> lock(m_syncMutex);
|
||||
|
@ -68,7 +68,7 @@ void Instance::loadApplicationSync(std::unique_ptr<JSModulesUnbundle> unbundle,
|
|||
|
||||
SystraceSection s("Instance::loadApplicationSync", "sourceURL",
|
||||
sourceURL);
|
||||
nativeToJsBridge_->loadApplicationSync(std::move(unbundle), std::move(string),
|
||||
nativeToJsBridge_->loadApplicationSync(std::move(bundleRegistry), std::move(string),
|
||||
std::move(sourceURL));
|
||||
}
|
||||
|
||||
|
@ -91,15 +91,15 @@ void Instance::loadScriptFromString(std::unique_ptr<const JSBigString> string,
|
|||
}
|
||||
}
|
||||
|
||||
void Instance::loadUnbundle(std::unique_ptr<JSModulesUnbundle> unbundle,
|
||||
std::unique_ptr<const JSBigString> startupScript,
|
||||
std::string startupScriptSourceURL,
|
||||
bool loadSynchronously) {
|
||||
void Instance::loadRAMBundle(std::unique_ptr<RAMBundleRegistry> bundleRegistry,
|
||||
std::unique_ptr<const JSBigString> startupScript,
|
||||
std::string startupScriptSourceURL,
|
||||
bool loadSynchronously) {
|
||||
if (loadSynchronously) {
|
||||
loadApplicationSync(std::move(unbundle), std::move(startupScript),
|
||||
loadApplicationSync(std::move(bundleRegistry), std::move(startupScript),
|
||||
std::move(startupScriptSourceURL));
|
||||
} else {
|
||||
loadApplication(std::move(unbundle), std::move(startupScript),
|
||||
loadApplication(std::move(bundleRegistry), std::move(startupScript),
|
||||
std::move(startupScriptSourceURL));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,9 +21,9 @@ namespace react {
|
|||
|
||||
class JSBigString;
|
||||
class JSExecutorFactory;
|
||||
class JSModulesUnbundle;
|
||||
class MessageQueueThread;
|
||||
class ModuleRegistry;
|
||||
class RAMBundleRegistry;
|
||||
|
||||
struct InstanceCallback {
|
||||
virtual ~InstanceCallback() {}
|
||||
|
@ -44,9 +44,9 @@ public:
|
|||
|
||||
void loadScriptFromString(std::unique_ptr<const JSBigString> string,
|
||||
std::string sourceURL, bool loadSynchronously);
|
||||
void loadUnbundle(std::unique_ptr<JSModulesUnbundle> unbundle,
|
||||
std::unique_ptr<const JSBigString> startupScript,
|
||||
std::string startupScriptSourceURL, bool loadSynchronously);
|
||||
void loadRAMBundle(std::unique_ptr<RAMBundleRegistry> bundleRegistry,
|
||||
std::unique_ptr<const JSBigString> startupScript,
|
||||
std::string startupScriptSourceURL, bool loadSynchronously);
|
||||
bool supportsProfiling();
|
||||
void setGlobalVariable(std::string propName,
|
||||
std::unique_ptr<const JSBigString> jsonValue);
|
||||
|
@ -73,10 +73,10 @@ public:
|
|||
|
||||
private:
|
||||
void callNativeModules(folly::dynamic &&calls, bool isEndOfBatch);
|
||||
void loadApplication(std::unique_ptr<JSModulesUnbundle> unbundle,
|
||||
void loadApplication(std::unique_ptr<RAMBundleRegistry> bundleRegistry,
|
||||
std::unique_ptr<const JSBigString> startupScript,
|
||||
std::string startupScriptSourceURL);
|
||||
void loadApplicationSync(std::unique_ptr<JSModulesUnbundle> unbundle,
|
||||
void loadApplicationSync(std::unique_ptr<RAMBundleRegistry> bundleRegistry,
|
||||
std::unique_ptr<const JSBigString> startupScript,
|
||||
std::string startupScriptSourceURL);
|
||||
|
||||
|
|
|
@ -354,11 +354,11 @@ void JSCExecutor::loadApplicationScript(std::unique_ptr<const JSBigString> scrip
|
|||
ReactMarker::logTaggedMarker(ReactMarker::RUN_JS_BUNDLE_STOP, scriptName.c_str());
|
||||
}
|
||||
|
||||
void JSCExecutor::setJSModulesUnbundle(std::unique_ptr<JSModulesUnbundle> unbundle) {
|
||||
void JSCExecutor::setBundleRegistry(std::unique_ptr<RAMBundleRegistry> bundleRegistry) {
|
||||
if (!m_bundleRegistry) {
|
||||
installNativeHook<&JSCExecutor::nativeRequire>("nativeRequire");
|
||||
}
|
||||
m_bundleRegistry = folly::make_unique<RAMBundleRegistry>(std::move(unbundle));
|
||||
m_bundleRegistry = std::move(bundleRegistry);
|
||||
}
|
||||
|
||||
void JSCExecutor::bindBridge() throw(JSException) {
|
||||
|
|
|
@ -65,8 +65,7 @@ public:
|
|||
std::unique_ptr<const JSBigString> script,
|
||||
std::string sourceURL) override;
|
||||
|
||||
virtual void setJSModulesUnbundle(
|
||||
std::unique_ptr<JSModulesUnbundle> unbundle) override;
|
||||
virtual void setBundleRegistry(std::unique_ptr<RAMBundleRegistry> bundleRegistry) override;
|
||||
|
||||
virtual void callFunction(
|
||||
const std::string& moduleId,
|
||||
|
|
|
@ -16,6 +16,7 @@ class JSExecutor;
|
|||
class JSModulesUnbundle;
|
||||
class MessageQueueThread;
|
||||
class ModuleRegistry;
|
||||
class RAMBundleRegistry;
|
||||
|
||||
// This interface describes the delegate interface required by
|
||||
// Executor implementations to call from JS into native code.
|
||||
|
@ -48,9 +49,9 @@ public:
|
|||
std::string sourceURL) = 0;
|
||||
|
||||
/**
|
||||
* Add an application "unbundle" file
|
||||
* Add an application "RAM" bundle registry
|
||||
*/
|
||||
virtual void setJSModulesUnbundle(std::unique_ptr<JSModulesUnbundle> bundle) = 0;
|
||||
virtual void setBundleRegistry(std::unique_ptr<RAMBundleRegistry> bundleRegistry) = 0;
|
||||
|
||||
/**
|
||||
* Executes BatchedBridge.callFunctionReturnFlushedQueue with the module ID,
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
#include "JSBigString.h"
|
||||
#include "SystraceSection.h"
|
||||
#include "MethodCall.h"
|
||||
#include "JSModulesUnbundle.h"
|
||||
#include "MessageQueueThread.h"
|
||||
#include "RAMBundleRegistry.h"
|
||||
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
#include <fbsystrace.h>
|
||||
|
@ -91,17 +91,17 @@ NativeToJsBridge::~NativeToJsBridge() {
|
|||
}
|
||||
|
||||
void NativeToJsBridge::loadApplication(
|
||||
std::unique_ptr<JSModulesUnbundle> unbundle,
|
||||
std::unique_ptr<RAMBundleRegistry> bundleRegistry,
|
||||
std::unique_ptr<const JSBigString> startupScript,
|
||||
std::string startupScriptSourceURL) {
|
||||
runOnExecutorQueue(
|
||||
[unbundleWrap=folly::makeMoveWrapper(std::move(unbundle)),
|
||||
[bundleRegistryWrap=folly::makeMoveWrapper(std::move(bundleRegistry)),
|
||||
startupScript=folly::makeMoveWrapper(std::move(startupScript)),
|
||||
startupScriptSourceURL=std::move(startupScriptSourceURL)]
|
||||
(JSExecutor* executor) mutable {
|
||||
auto unbundle = unbundleWrap.move();
|
||||
if (unbundle) {
|
||||
executor->setJSModulesUnbundle(std::move(unbundle));
|
||||
auto bundleRegistry = bundleRegistryWrap.move();
|
||||
if (bundleRegistry) {
|
||||
executor->setBundleRegistry(std::move(bundleRegistry));
|
||||
}
|
||||
executor->loadApplicationScript(std::move(*startupScript),
|
||||
std::move(startupScriptSourceURL));
|
||||
|
@ -109,11 +109,11 @@ void NativeToJsBridge::loadApplication(
|
|||
}
|
||||
|
||||
void NativeToJsBridge::loadApplicationSync(
|
||||
std::unique_ptr<JSModulesUnbundle> unbundle,
|
||||
std::unique_ptr<RAMBundleRegistry> bundleRegistry,
|
||||
std::unique_ptr<const JSBigString> startupScript,
|
||||
std::string startupScriptSourceURL) {
|
||||
if (unbundle) {
|
||||
m_executor->setJSModulesUnbundle(std::move(unbundle));
|
||||
if (bundleRegistry) {
|
||||
m_executor->setBundleRegistry(std::move(bundleRegistry));
|
||||
}
|
||||
m_executor->loadApplicationScript(std::move(startupScript),
|
||||
std::move(startupScriptSourceURL));
|
||||
|
|
|
@ -18,10 +18,10 @@ namespace facebook {
|
|||
namespace react {
|
||||
|
||||
struct InstanceCallback;
|
||||
class JSModulesUnbundle;
|
||||
class JsToNativeBridge;
|
||||
class MessageQueueThread;
|
||||
class ModuleRegistry;
|
||||
class RAMBundleRegistry;
|
||||
|
||||
// This class manages calls from native code to JS. It also manages
|
||||
// executors and their threads. All functions here can be called from
|
||||
|
@ -85,16 +85,16 @@ public:
|
|||
}
|
||||
|
||||
/**
|
||||
* Starts the JS application. If unbundle is non-null, then it is
|
||||
* Starts the JS application. If bundleRegistry is non-null, then it is
|
||||
* used to fetch JavaScript modules as individual scripts.
|
||||
* Otherwise, the script is assumed to include all the modules.
|
||||
*/
|
||||
void loadApplication(
|
||||
std::unique_ptr<JSModulesUnbundle> unbundle,
|
||||
std::unique_ptr<RAMBundleRegistry> bundleRegistry,
|
||||
std::unique_ptr<const JSBigString> startupCode,
|
||||
std::string sourceURL);
|
||||
void loadApplicationSync(
|
||||
std::unique_ptr<JSModulesUnbundle> unbundle,
|
||||
std::unique_ptr<RAMBundleRegistry> bundleRegistry,
|
||||
std::unique_ptr<const JSBigString> startupCode,
|
||||
std::string sourceURL);
|
||||
|
||||
|
|
|
@ -12,6 +12,10 @@ RAMBundleRegistry::RAMBundleRegistry(std::unique_ptr<JSModulesUnbundle> mainBund
|
|||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
return getBundle(bundleId)->getModule(moduleId);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,16 +8,25 @@
|
|||
#include <utility>
|
||||
|
||||
#include <cxxreact/JSModulesUnbundle.h>
|
||||
#include <jschelpers/noncopyable.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
class RAMBundleRegistry {
|
||||
class RAMBundleRegistry : noncopyable {
|
||||
public:
|
||||
constexpr static uint32_t MAIN_BUNDLE_ID = 0;
|
||||
|
||||
explicit RAMBundleRegistry(std::unique_ptr<JSModulesUnbundle> mainBundle);
|
||||
RAMBundleRegistry(RAMBundleRegistry&&) = default;
|
||||
RAMBundleRegistry& operator=(RAMBundleRegistry&&) = default;
|
||||
|
||||
JSModulesUnbundle::Module getModule(uint32_t bundleId, uint32_t moduleId);
|
||||
virtual ~RAMBundleRegistry() {};
|
||||
protected:
|
||||
virtual std::unique_ptr<JSModulesUnbundle> bundleById(uint32_t index) const {
|
||||
throw std::runtime_error("Please, override this method in a subclass to support multiple RAM bundles.");
|
||||
}
|
||||
private:
|
||||
JSModulesUnbundle *getBundle(uint32_t bundleId) const;
|
||||
|
||||
|
|
Loading…
Reference in New Issue