Permalink
Browse files

Load Indexed RAM format on android

Reviewed By: javache

Differential Revision: D4268243

fbshipit-source-id: fc969cfc69810d0477c926ffc79c23584fcbd7eb
  • Loading branch information...
davidaurelio authored and Facebook Github Bot committed Dec 5, 2016
1 parent fb39069 commit f9f32eb426b5385e199ef6e1d2b610dfe20e60e7
@@ -14,6 +14,8 @@
#include <jni/LocalReference.h>
#include <cxxreact/Instance.h>
+#include <cxxreact/JSBundleType.h>
+#include <cxxreact/JSIndexedRAMBundle.h>
#include <cxxreact/MethodCall.h>
#include <cxxreact/ModuleRegistry.h>
@@ -174,10 +176,32 @@ void CatalystInstanceImpl::loadScriptFromAssets(jobject assetManager,
}
}
+bool CatalystInstanceImpl::isIndexedRAMBundle(const char *sourcePath) {
+ std::ifstream bundle_stream(sourcePath, std::ios_base::in);
+ if (!bundle_stream) {
+ return false;
+ }
+ BundleHeader header;
+ bundle_stream.read(reinterpret_cast<char *>(&header), sizeof(header));
+ bundle_stream.close();
+ return parseTypeFromHeader(header) == ScriptTag::RAMBundle;
+}
+
void CatalystInstanceImpl::loadScriptFromFile(jni::alias_ref<jstring> fileName,
const std::string& sourceURL) {
- return instance_->loadScriptFromFile(fileName ? fileName->toStdString() : "",
- sourceURL);
+
+ std::string file = fileName ? fileName->toStdString() : "";
+
+ if (isIndexedRAMBundle(file.c_str())) {
+ auto bundle = folly::make_unique<JSIndexedRAMBundle>(file.c_str());
+ auto startupScript = bundle->getStartupCode();
+ instance_->loadUnbundle(
+ std::move(bundle),
+ std::move(startupScript),
+ sourceURL);
+ } else {
+ instance_->loadScriptFromFile(file, sourceURL);
+ }
}
void CatalystInstanceImpl::loadScriptFromOptimizedBundle(const std::string& bundlePath,
@@ -40,6 +40,8 @@ class CatalystInstanceImpl : public jni::HybridClass<CatalystInstanceImpl> {
CatalystInstanceImpl();
+ static bool isIndexedRAMBundle(const char *sourcePath);
+
void initializeBridge(
jni::alias_ref<ReactCallback::javaobject> callback,
// This executor is actually a factory holder.
@@ -9,13 +9,15 @@ LOCAL_SRC_FILES := \
Executor.cpp \
Instance.cpp \
JSCExecutor.cpp \
+ JSBundleType.cpp \
JSCLegacyProfiler.cpp \
JSCLegacyTracing.cpp \
JSCMemory.cpp \
JSCNativeModules.cpp \
JSCPerfStats.cpp \
JSCTracing.cpp \
JSCWebWorker.cpp \
+ JSIndexedRAMBundle.cpp \
MethodCall.cpp \
ModuleRegistry.cpp \
NativeToJsBridge.cpp \

0 comments on commit f9f32eb

Please sign in to comment.