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