88#include < folly/json.h>
99#include < folly/Memory.h>
1010#include < folly/MoveWrapper.h>
11+ #include < glog/logging.h>
1112
1213#include " Instance.h"
1314#include " JSBigString.h"
@@ -99,16 +100,22 @@ void NativeToJsBridge::loadApplication(
99100 std::unique_ptr<const JSBigString> startupScript,
100101 std::string startupScriptSourceURL) {
101102 runOnExecutorQueue (
102- [bundleRegistryWrap=folly::makeMoveWrapper (std::move (bundleRegistry)),
103+ [this ,
104+ bundleRegistryWrap=folly::makeMoveWrapper (std::move (bundleRegistry)),
103105 startupScript=folly::makeMoveWrapper (std::move (startupScript)),
104106 startupScriptSourceURL=std::move (startupScriptSourceURL)]
105107 (JSExecutor* executor) mutable {
106108 auto bundleRegistry = bundleRegistryWrap.move ();
107109 if (bundleRegistry) {
108110 executor->setBundleRegistry (std::move (bundleRegistry));
109111 }
110- executor->loadApplicationScript (std::move (*startupScript),
111- std::move (startupScriptSourceURL));
112+ try {
113+ executor->loadApplicationScript (std::move (*startupScript),
114+ std::move (startupScriptSourceURL));
115+ } catch (...) {
116+ m_applicationScriptHasFailure = true ;
117+ throw ;
118+ }
112119 });
113120}
114121
@@ -119,8 +126,13 @@ void NativeToJsBridge::loadApplicationSync(
119126 if (bundleRegistry) {
120127 m_executor->setBundleRegistry (std::move (bundleRegistry));
121128 }
122- m_executor->loadApplicationScript (std::move (startupScript),
123- std::move (startupScriptSourceURL));
129+ try {
130+ m_executor->loadApplicationScript (std::move (startupScript),
131+ std::move (startupScriptSourceURL));
132+ } catch (...) {
133+ m_applicationScriptHasFailure = true ;
134+ throw ;
135+ }
124136}
125137
126138void NativeToJsBridge::callFunction (
@@ -136,8 +148,13 @@ void NativeToJsBridge::callFunction(
136148 systraceCookie);
137149 #endif
138150
139- runOnExecutorQueue ([module = std::move (module ), method = std::move (method), arguments = std::move (arguments), systraceCookie]
151+ runOnExecutorQueue ([this , module = std::move (module ), method = std::move (method), arguments = std::move (arguments), systraceCookie]
140152 (JSExecutor* executor) {
153+ if (m_applicationScriptHasFailure) {
154+ LOG (ERROR) << " Attempting to call JS function on a bad application bundle: " << module .c_str () << " ." << method.c_str () << " ()" ;
155+ throw std::runtime_error (" Attempting to call JS function on a bad application bundle: " + module + " ." + method + " ()" );
156+ }
157+
141158 #ifdef WITH_FBSYSTRACE
142159 FbSystraceAsyncFlow::end (
143160 TRACE_TAG_REACT_CXX_BRIDGE,
@@ -162,8 +179,12 @@ void NativeToJsBridge::invokeCallback(double callbackId, folly::dynamic&& argume
162179 systraceCookie);
163180 #endif
164181
165- runOnExecutorQueue ([callbackId, arguments = std::move (arguments), systraceCookie]
182+ runOnExecutorQueue ([this , callbackId, arguments = std::move (arguments), systraceCookie]
166183 (JSExecutor* executor) {
184+ if (m_applicationScriptHasFailure) {
185+ LOG (ERROR) << " Attempting to call JS callback on a bad application bundle: " << callbackId;
186+ throw std::runtime_error (" Attempting to invoke JS callback on a bad application bundle." );
187+ }
167188 #ifdef WITH_FBSYSTRACE
168189 FbSystraceAsyncFlow::end (
169190 TRACE_TAG_REACT_CXX_BRIDGE,
0 commit comments