Initial implementation of multiple RAM bundles registry

Differential Revision: D5850963

fbshipit-source-id: e1bd6d74953872d38e73a20f6d054905a7e4c80c
This commit is contained in:
Alex Dvornikov
2017-09-21 08:34:44 -07:00
committed by Facebook Github Bot
parent da2ea2601b
commit 2f952fbaac
6 changed files with 75 additions and 9 deletions

View File

@@ -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);
}