Use JSExecutor's file-based Loading API in NativeToJsBridge and Instance

Reviewed By: javache

Differential Revision: D4320773

fbshipit-source-id: fa46728ba0d45818737b32952efbfae7bc8ef9f1
This commit is contained in:
Ashok Menon 2017-01-10 07:04:52 -08:00 committed by Facebook Github Bot
parent 8819bef56b
commit 24f3add010
1 changed files with 12 additions and 17 deletions

View File

@ -4,6 +4,7 @@
#include "Executor.h"
#include "MethodCall.h"
#include "RecoverableError.h"
#include "SystraceSection.h"
#include <folly/json.h>
@ -13,13 +14,14 @@
#include <glog/logging.h>
#include <condition_variable>
#include <fstream>
#include <mutex>
#include <string>
namespace facebook {
namespace react {
using namespace detail;
Instance::~Instance() {
if (nativeToJsBridge_) {
nativeToJsBridge_->destroy();
@ -66,24 +68,17 @@ void Instance::loadScriptFromStringSync(std::unique_ptr<const JSBigString> strin
void Instance::loadScriptFromFile(const std::string& filename,
const std::string& sourceURL) {
// TODO mhorowitz: ReactMarker around file read
std::unique_ptr<JSBigBufferString> buf;
{
callback_->incrementPendingJSCalls();
SystraceSection s("reactbridge_xplat_loadScriptFromFile",
"fileName", filename);
std::ifstream jsfile(filename);
if (!jsfile) {
LOG(ERROR) << "Unable to load script from file" << filename;
} else {
jsfile.seekg(0, std::ios::end);
buf.reset(new JSBigBufferString(jsfile.tellg()));
jsfile.seekg(0, std::ios::beg);
jsfile.read(buf->data(), buf->size());
}
}
std::unique_ptr<const JSBigFileString> script;
RecoverableError::runRethrowingAsRecoverable<std::system_error>(
[&filename, &script]() {
script = JSBigFileString::fromPath(filename);
});
loadScriptFromString(std::move(buf), sourceURL);
nativeToJsBridge_->loadApplication(nullptr, std::move(script), sourceURL);
}
void Instance::loadScriptFromOptimizedBundle(std::string bundlePath,