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,