diff --git a/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/CatalystInstanceImpl.java b/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/CatalystInstanceImpl.java index 6ab0fe0e4..14e5b774b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/CatalystInstanceImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/CatalystInstanceImpl.java @@ -208,15 +208,9 @@ public class CatalystInstanceImpl implements CatalystInstance { jniLoadScriptFromFile(fileName, sourceURL); } - /* package */ void loadScriptFromOptimizedBundle(String path, String sourceURL, int flags) { - mSourceURL = sourceURL; - jniLoadScriptFromOptimizedBundle(path, sourceURL, flags); - } - private native void jniSetSourceURL(String sourceURL); private native void jniLoadScriptFromAssets(AssetManager assetManager, String assetURL); private native void jniLoadScriptFromFile(String fileName, String sourceURL); - private native void jniLoadScriptFromOptimizedBundle(String path, String sourceURL, int flags); @Override public void runJSBundle() { diff --git a/ReactAndroid/src/main/jni/xreact/jni/CatalystInstanceImpl.cpp b/ReactAndroid/src/main/jni/xreact/jni/CatalystInstanceImpl.cpp index 592602a36..77cd311d3 100644 --- a/ReactAndroid/src/main/jni/xreact/jni/CatalystInstanceImpl.cpp +++ b/ReactAndroid/src/main/jni/xreact/jni/CatalystInstanceImpl.cpp @@ -105,8 +105,6 @@ void CatalystInstanceImpl::registerNatives() { makeNativeMethod("jniSetSourceURL", CatalystInstanceImpl::jniSetSourceURL), makeNativeMethod("jniLoadScriptFromAssets", CatalystInstanceImpl::jniLoadScriptFromAssets), makeNativeMethod("jniLoadScriptFromFile", CatalystInstanceImpl::jniLoadScriptFromFile), - makeNativeMethod("jniLoadScriptFromOptimizedBundle", - CatalystInstanceImpl::jniLoadScriptFromOptimizedBundle), makeNativeMethod("jniCallJSFunction", CatalystInstanceImpl::jniCallJSFunction), makeNativeMethod("jniCallJSCallback", CatalystInstanceImpl::jniCallJSCallback), makeNativeMethod("getMainExecutorToken", CatalystInstanceImpl::getMainExecutorToken), @@ -217,14 +215,6 @@ void CatalystInstanceImpl::jniLoadScriptFromFile(const std::string& fileName, } } -void CatalystInstanceImpl::jniLoadScriptFromOptimizedBundle(const std::string& bundlePath, - const std::string& sourceURL, - jint flags) { - return instance_->loadScriptFromOptimizedBundle(std::move(bundlePath), - std::move(sourceURL), - flags); -} - void CatalystInstanceImpl::jniCallJSFunction( JExecutorToken* token, std::string module, std::string method, NativeArray* arguments) { // We want to share the C++ code, and on iOS, modules pass module/method diff --git a/ReactAndroid/src/main/jni/xreact/jni/CatalystInstanceImpl.h b/ReactAndroid/src/main/jni/xreact/jni/CatalystInstanceImpl.h index 941f62fb0..61e07b9c6 100644 --- a/ReactAndroid/src/main/jni/xreact/jni/CatalystInstanceImpl.h +++ b/ReactAndroid/src/main/jni/xreact/jni/CatalystInstanceImpl.h @@ -57,7 +57,6 @@ class CatalystInstanceImpl : public jni::HybridClass { void jniLoadScriptFromAssets(jni::alias_ref assetManager, const std::string& assetURL); void jniLoadScriptFromFile(const std::string& fileName, const std::string& sourceURL); - void jniLoadScriptFromOptimizedBundle(const std::string& bundlePath, const std::string& sourceURL, jint flags); void jniCallJSFunction(JExecutorToken* token, std::string module, std::string method, NativeArray* arguments); void jniCallJSCallback(JExecutorToken* token, jint callbackId, NativeArray* arguments); local_ref getMainExecutorToken(); diff --git a/ReactCommon/cxxreact/Executor.cpp b/ReactCommon/cxxreact/Executor.cpp deleted file mode 100644 index 63110f748..000000000 --- a/ReactCommon/cxxreact/Executor.cpp +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#include "Executor.h" - -#include -#include -#include -#include -#include - -#include -#include - -namespace facebook { -namespace react { - -void JSExecutor::loadApplicationScript(std::string bundlePath, std::string sourceURL, int flags) { - if ((flags & UNPACKED_JS_SOURCE) == 0) { - throw std::runtime_error("No unpacked js source file"); - } - return loadApplicationScript( - JSBigOptimizedBundleString::fromOptimizedBundle(bundlePath), - std::move(sourceURL)); -} - -std::unique_ptr JSBigFileString::fromPath(const std::string& sourceURL) { - int fd = ::open(sourceURL.c_str(), O_RDONLY); - folly::checkUnixError(fd, "Could not open file", sourceURL); - SCOPE_EXIT { CHECK(::close(fd) == 0); }; - - struct stat fileInfo; - folly::checkUnixError(::fstat(fd, &fileInfo), "fstat on bundle failed."); - - return folly::make_unique(fd, fileInfo.st_size); -} - -static JSBigOptimizedBundleString::Encoding encodingFromByte(uint8_t byte) { - switch (byte) { - case 0: - return JSBigOptimizedBundleString::Encoding::Unknown; - case 1: - return JSBigOptimizedBundleString::Encoding::Ascii; - case 2: - return JSBigOptimizedBundleString::Encoding::Utf8; - case 3: - return JSBigOptimizedBundleString::Encoding::Utf16; - default: - throw std::invalid_argument("Unknown bundle encoding"); - } -} - -std::unique_ptr JSBigOptimizedBundleString::fromOptimizedBundle( - const std::string& bundlePath) { - uint8_t sha1[20]; - uint8_t encoding; - struct stat fileInfo; - int fd = -1; - SCOPE_EXIT { CHECK(fd == -1 || ::close(fd) == 0); }; - - { - auto metaPath = bundlePath + UNPACKED_META_PATH_SUFFIX; - std::ifstream metaFile; - metaFile.exceptions(std::ifstream::eofbit | std::ifstream::failbit | std::ifstream::badbit); - metaFile.open(metaPath, std::ifstream::in | std::ifstream::binary); - metaFile.read(reinterpret_cast(sha1), sizeof(sha1)); - metaFile.read(reinterpret_cast(&encoding), sizeof(encoding)); - } - - { - auto sourcePath = bundlePath + UNPACKED_JS_SOURCE_PATH_SUFFIX; - fd = ::open(sourcePath.c_str(), O_RDONLY); - folly::checkUnixError(fd, "could not open js bundle file."); - } - - folly::checkUnixError(::fstat(fd, &fileInfo), "fstat on js bundle failed."); - - return folly::make_unique( - fd, - fileInfo.st_size, - sha1, - encodingFromByte(encoding)); -} - -} // namespace react -} // namespace facebook diff --git a/ReactCommon/cxxreact/Executor.h b/ReactCommon/cxxreact/Executor.h index a2aa450ab..b3d91af2d 100644 --- a/ReactCommon/cxxreact/Executor.h +++ b/ReactCommon/cxxreact/Executor.h @@ -66,11 +66,6 @@ public: virtual void loadApplicationScript(std::unique_ptr script, std::string sourceURL) = 0; - /** - * Execute an application script optimized bundle in the JS context. - */ - virtual void loadApplicationScript(std::string bundlePath, std::string source, int flags); - /** * Add an application "unbundle" file */ diff --git a/ReactCommon/cxxreact/Instance.cpp b/ReactCommon/cxxreact/Instance.cpp index fafa07914..c67395843 100644 --- a/ReactCommon/cxxreact/Instance.cpp +++ b/ReactCommon/cxxreact/Instance.cpp @@ -90,16 +90,6 @@ void Instance::loadScriptFromFile(const std::string& filename, nativeToJsBridge_->loadApplication(nullptr, std::move(script), sourceURL); } -void Instance::loadScriptFromOptimizedBundle(std::string bundlePath, - std::string sourceURL, - int flags) { - SystraceSection s("reactbridge_xplat_loadScriptFromOptimizedBundle", - "bundlePath", bundlePath); - nativeToJsBridge_->loadOptimizedApplicationScript(std::move(bundlePath), - std::move(sourceURL), - flags); -} - void Instance::loadUnbundle(std::unique_ptr unbundle, std::unique_ptr startupScript, std::string startupScriptSourceURL) { diff --git a/ReactCommon/cxxreact/Instance.h b/ReactCommon/cxxreact/Instance.h index 385d22e3d..4b8da4f26 100644 --- a/ReactCommon/cxxreact/Instance.h +++ b/ReactCommon/cxxreact/Instance.h @@ -39,7 +39,6 @@ class Instance { void loadScriptFromString(std::unique_ptr string, std::string sourceURL); void loadScriptFromStringSync(std::unique_ptr string, std::string sourceURL); void loadScriptFromFile(const std::string& filename, const std::string& sourceURL); - void loadScriptFromOptimizedBundle(std::string bundlePath, std::string sourceURL, int flags); void loadUnbundle( std::unique_ptr unbundle, std::unique_ptr startupScript, diff --git a/ReactCommon/cxxreact/JSBigString.cpp b/ReactCommon/cxxreact/JSBigString.cpp new file mode 100644 index 000000000..69ed3a461 --- /dev/null +++ b/ReactCommon/cxxreact/JSBigString.cpp @@ -0,0 +1,27 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#include "JSBigString.h" + +#include +#include +#include + +#include +#include + +namespace facebook { +namespace react { + +std::unique_ptr JSBigFileString::fromPath(const std::string& sourceURL) { + int fd = ::open(sourceURL.c_str(), O_RDONLY); + folly::checkUnixError(fd, "Could not open file", sourceURL); + SCOPE_EXIT { CHECK(::close(fd) == 0); }; + + struct stat fileInfo; + folly::checkUnixError(::fstat(fd, &fileInfo), "fstat on bundle failed."); + + return folly::make_unique(fd, fileInfo.st_size); +} + +} // namespace react +} // namespace facebook diff --git a/ReactCommon/cxxreact/JSBigString.h b/ReactCommon/cxxreact/JSBigString.h index 63cc981a3..c6b8ce497 100644 --- a/ReactCommon/cxxreact/JSBigString.h +++ b/ReactCommon/cxxreact/JSBigString.h @@ -165,71 +165,4 @@ private: mutable const char *m_data; // Pointer to the mmaped region. }; -class JSBigOptimizedBundleString : public JSBigString { -public: - enum class Encoding { - Unknown, - Ascii, - Utf8, - Utf16, - }; - - JSBigOptimizedBundleString(int fd, size_t size, const uint8_t sha1[20], Encoding encoding) : - m_fd(-1), - m_size(size), - m_encoding(encoding), - m_str(nullptr) - { - folly::checkUnixError( - m_fd = dup(fd), - "Could not duplicate file descriptor"); - - memcpy(m_hash, sha1, 20); - } - - ~JSBigOptimizedBundleString() { - if (m_str) { - CHECK(munmap((void *)m_str, m_size) != -1); - } - close(m_fd); - } - - bool isAscii() const override { - return m_encoding == Encoding::Ascii; - } - - const char* c_str() const override { - if (!m_str) { - m_str = (const char *)mmap(0, m_size, PROT_READ, MAP_SHARED, m_fd, 0); - CHECK(m_str != MAP_FAILED); - } - return m_str; - } - - size_t size() const override { - return m_size; - } - - int fd() const { - return m_fd; - } - - const uint8_t* hash() const { - return m_hash; - } - - Encoding encoding() const { - return m_encoding; - } - - static std::unique_ptr fromOptimizedBundle(const std::string& bundlePath); - -private: - int m_fd; - size_t m_size; - uint8_t m_hash[20]; - Encoding m_encoding; - mutable const char *m_str; -}; - } } diff --git a/ReactCommon/cxxreact/JSCExecutor.cpp b/ReactCommon/cxxreact/JSCExecutor.cpp index 812423bf0..d44145769 100644 --- a/ReactCommon/cxxreact/JSCExecutor.cpp +++ b/ReactCommon/cxxreact/JSCExecutor.cpp @@ -343,65 +343,6 @@ static const char* explainLoadSourceStatus(JSLoadSourceStatus status) { } #endif -#ifdef WITH_FBJSCEXTENSIONS -void JSCExecutor::loadApplicationScript( - std::string bundlePath, - std::string sourceURL, - int flags) { - SystraceSection s("JSCExecutor::loadApplicationScript", - "sourceURL", sourceURL); - - if (!(flags & (UNPACKED_JS_SOURCE | UNPACKED_BYTECODE))) { - throw RecoverableError("Optimized bundle with no unpacked source or bytecode"); - } - - String jsSourceURL(m_context, sourceURL.c_str()); - JSSourceCodeRef sourceCode = nullptr; - SCOPE_EXIT { - if (sourceCode) { - JSReleaseSourceCode(sourceCode); - } - }; - - if (flags & UNPACKED_BYTECODE) { - int fd = open((bundlePath + UNPACKED_BYTECODE_SUFFIX).c_str(), O_RDONLY); - RecoverableError::runRethrowingAsRecoverable([fd]() { - folly::checkUnixError(fd, "Couldn't open compiled bundle"); - }); - SCOPE_EXIT { close(fd); }; - - JSLoadSourceStatus jsStatus; - sourceCode = JSCreateCompiledSourceCode(fd, jsSourceURL, &jsStatus); - - if (!sourceCode) { - throw RecoverableError(explainLoadSourceStatus(jsStatus)); - } - } else { - auto jsScriptBigString = JSBigOptimizedBundleString::fromOptimizedBundle(bundlePath); - if (!jsScriptBigString->isAscii()) { - LOG(WARNING) << "Bundle is not ASCII encoded - falling back to the slow path"; - return loadApplicationScript(std::move(jsScriptBigString), sourceURL); - } - - sourceCode = JSCreateSourceCode( - jsScriptBigString->fd(), - jsSourceURL, - jsScriptBigString->hash(), - true); - } - - ReactMarker::logMarker("RUN_JS_BUNDLE_START"); - - evaluateSourceCode(m_context, sourceCode, jsSourceURL); - - bindBridge(); - - flush(); - ReactMarker::logMarker("CREATE_REACT_CONTEXT_END"); - ReactMarker::logMarker("RUN_JS_BUNDLE_END"); -} -#endif - void JSCExecutor::loadApplicationScript(std::unique_ptr script, std::string sourceURL) { SystraceSection s("JSCExecutor::loadApplicationScript", "sourceURL", sourceURL); diff --git a/ReactCommon/cxxreact/JSCExecutor.h b/ReactCommon/cxxreact/JSCExecutor.h index 7ea8cfa57..3fbb03504 100644 --- a/ReactCommon/cxxreact/JSCExecutor.h +++ b/ReactCommon/cxxreact/JSCExecutor.h @@ -62,13 +62,6 @@ public: std::unique_ptr script, std::string sourceURL) override; -#ifdef WITH_FBJSCEXTENSIONS - virtual void loadApplicationScript( - std::string bundlePath, - std::string sourceURL, - int flags) override; -#endif - virtual void setJSModulesUnbundle( std::unique_ptr unbundle) override; diff --git a/ReactCommon/cxxreact/NativeToJsBridge.cpp b/ReactCommon/cxxreact/NativeToJsBridge.cpp index 1e3084843..347d5ad9e 100644 --- a/ReactCommon/cxxreact/NativeToJsBridge.cpp +++ b/ReactCommon/cxxreact/NativeToJsBridge.cpp @@ -111,20 +111,6 @@ NativeToJsBridge::~NativeToJsBridge() { "NativeToJsBridge::destroy() must be called before deallocating the NativeToJsBridge!"; } -void NativeToJsBridge::loadOptimizedApplicationScript( - std::string bundlePath, - std::string sourceURL, - int flags) { - runOnExecutorQueue( - m_mainExecutorToken, - [bundlePath=std::move(bundlePath), - sourceURL=std::move(sourceURL), - flags=flags] - (JSExecutor* executor) { - executor->loadApplicationScript(std::move(bundlePath), std::move(sourceURL), flags); - }); -} - void NativeToJsBridge::loadApplication( std::unique_ptr unbundle, std::unique_ptr startupScript, diff --git a/ReactCommon/cxxreact/NativeToJsBridge.h b/ReactCommon/cxxreact/NativeToJsBridge.h index a5ad50914..70ef620b8 100644 --- a/ReactCommon/cxxreact/NativeToJsBridge.h +++ b/ReactCommon/cxxreact/NativeToJsBridge.h @@ -123,12 +123,6 @@ public: std::unique_ptr startupCode, std::string sourceURL); - /** - * Similar to loading a "bundle", but instead of passing js source this method accepts - * path to a directory containing files prepared for particular JSExecutor. - */ - void loadOptimizedApplicationScript(std::string bundlePath, std::string sourceURL, int flags); - void setGlobalVariable(std::string propName, std::unique_ptr jsonValue); void* getJavaScriptContext(); bool supportsProfiling();