From 24f3add0103c8d6b243200892cbd35a487500ad1 Mon Sep 17 00:00:00 2001 From: Ashok Menon Date: Tue, 10 Jan 2017 07:04:52 -0800 Subject: [PATCH] Use JSExecutor's file-based Loading API in NativeToJsBridge and Instance Reviewed By: javache Differential Revision: D4320773 fbshipit-source-id: fa46728ba0d45818737b32952efbfae7bc8ef9f1 --- ReactCommon/cxxreact/Instance.cpp | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/ReactCommon/cxxreact/Instance.cpp b/ReactCommon/cxxreact/Instance.cpp index 04beb1206..9840973c6 100644 --- a/ReactCommon/cxxreact/Instance.cpp +++ b/ReactCommon/cxxreact/Instance.cpp @@ -4,6 +4,7 @@ #include "Executor.h" #include "MethodCall.h" +#include "RecoverableError.h" #include "SystraceSection.h" #include @@ -13,13 +14,14 @@ #include #include -#include #include #include namespace facebook { namespace react { +using namespace detail; + Instance::~Instance() { if (nativeToJsBridge_) { nativeToJsBridge_->destroy(); @@ -66,24 +68,17 @@ void Instance::loadScriptFromStringSync(std::unique_ptr strin void Instance::loadScriptFromFile(const std::string& filename, const std::string& sourceURL) { - // TODO mhorowitz: ReactMarker around file read - std::unique_ptr buf; - { - SystraceSection s("reactbridge_xplat_loadScriptFromFile", - "fileName", filename); + 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 script; + RecoverableError::runRethrowingAsRecoverable( + [&filename, &script]() { + script = JSBigFileString::fromPath(filename); + }); - loadScriptFromString(std::move(buf), sourceURL); + nativeToJsBridge_->loadApplication(nullptr, std::move(script), sourceURL); } void Instance::loadScriptFromOptimizedBundle(std::string bundlePath,