Differential Revision: D3887878

fbshipit-source-id: 212fc3188f059d7378ecd61bb5e31fc87a857e8a
This commit is contained in:
Michał Gregorczyk 2016-09-29 09:08:28 -07:00 коммит произвёл Facebook Github Bot
Родитель aa36adb116
Коммит b1fdac47b5
2 изменённых файлов: 38 добавлений и 17 удалений

Просмотреть файл

@ -18,10 +18,12 @@ namespace react {
#define UNPACKED_JS_SOURCE_PATH_SUFFIX "/bundle.js"
#define UNPACKED_META_PATH_SUFFIX "/bundle.meta"
#define UNPACKED_BYTECODE_SUFFIX "/bundle.bytecode"
enum {
UNPACKED_JS_SOURCE = (1 << 0),
UNPACKED_BC_CACHE = (1 << 1),
UNPACKED_BYTECODE = (1 << 2),
};
class JSExecutor;

Просмотреть файл

@ -9,9 +9,11 @@
#include <string>
#include <glog/logging.h>
#include <folly/json.h>
#include <folly/Exception.h>
#include <folly/Memory.h>
#include <folly/String.h>
#include <folly/Conv.h>
#include <fcntl.h>
#include <sys/time.h>
#include "FollySupport.h"
@ -260,30 +262,47 @@ void JSCExecutor::loadApplicationScript(
SystraceSection s("JSCExecutor::loadApplicationScript",
"sourceURL", sourceURL);
if ((flags & UNPACKED_JS_SOURCE) == 0) {
throw std::runtime_error("Optimized bundle with no unpacked js source");
}
folly::throwOnFail<std::runtime_error>(
(flags & UNPACKED_JS_SOURCE) || (flags & UNPACKED_BYTECODE),
"Optimized bundle with no unpacked source or bytecode");
String jsSourceURL(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);
folly::checkUnixError(fd, "Couldn't open compiled bundle");
SCOPE_EXIT { close(fd); };
auto length = lseek(fd, 0, SEEK_END);
folly::checkUnixError(length, "Couldn't seek to the end of compiled bundle");
sourceCode = JSCreateCompiledSourceCode(fd, length, jsSourceURL);
} else {
auto jsScriptBigString = JSBigMmapString::fromOptimizedBundle(bundlePath);
if (jsScriptBigString->encoding() != JSBigMmapString::Encoding::Ascii) {
LOG(WARNING) << "Bundle is not ASCII encoded - falling back to the slow path";
return loadApplicationScript(std::move(jsScriptBigString), sourceURL);
}
ReactMarker::logMarker("RUN_JS_BUNDLE_START");
if (flags & UNPACKED_BC_CACHE) {
configureJSCBCCache(m_context, bundlePath);
}
String jsSourceURL(sourceURL.c_str());
JSSourceCodeRef sourceCode = JSCreateSourceCode(
sourceCode = JSCreateSourceCode(
jsScriptBigString->fd(),
jsScriptBigString->size(),
jsSourceURL,
jsScriptBigString->hash(),
true);
SCOPE_EXIT { JSReleaseSourceCode(sourceCode); };
}
ReactMarker::logMarker("RUN_JS_BUNDLE_START");
evaluateSourceCode(m_context, sourceCode, jsSourceURL);