8
8
#include < folly/json.h>
9
9
#include < folly/Memory.h>
10
10
#include < folly/MoveWrapper.h>
11
+ #include < glog/logging.h>
11
12
12
13
#include " Instance.h"
13
14
#include " JSBigString.h"
@@ -99,16 +100,22 @@ void NativeToJsBridge::loadApplication(
99
100
std::unique_ptr<const JSBigString> startupScript,
100
101
std::string startupScriptSourceURL) {
101
102
runOnExecutorQueue (
102
- [bundleRegistryWrap=folly::makeMoveWrapper (std::move (bundleRegistry)),
103
+ [this ,
104
+ bundleRegistryWrap=folly::makeMoveWrapper (std::move (bundleRegistry)),
103
105
startupScript=folly::makeMoveWrapper (std::move (startupScript)),
104
106
startupScriptSourceURL=std::move (startupScriptSourceURL)]
105
107
(JSExecutor* executor) mutable {
106
108
auto bundleRegistry = bundleRegistryWrap.move ();
107
109
if (bundleRegistry) {
108
110
executor->setBundleRegistry (std::move (bundleRegistry));
109
111
}
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
+ }
112
119
});
113
120
}
114
121
@@ -119,8 +126,13 @@ void NativeToJsBridge::loadApplicationSync(
119
126
if (bundleRegistry) {
120
127
m_executor->setBundleRegistry (std::move (bundleRegistry));
121
128
}
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
+ }
124
136
}
125
137
126
138
void NativeToJsBridge::callFunction (
@@ -136,8 +148,13 @@ void NativeToJsBridge::callFunction(
136
148
systraceCookie);
137
149
#endif
138
150
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]
140
152
(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
+
141
158
#ifdef WITH_FBSYSTRACE
142
159
FbSystraceAsyncFlow::end (
143
160
TRACE_TAG_REACT_CXX_BRIDGE,
@@ -162,8 +179,12 @@ void NativeToJsBridge::invokeCallback(double callbackId, folly::dynamic&& argume
162
179
systraceCookie);
163
180
#endif
164
181
165
- runOnExecutorQueue ([callbackId, arguments = std::move (arguments), systraceCookie]
182
+ runOnExecutorQueue ([this , callbackId, arguments = std::move (arguments), systraceCookie]
166
183
(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
+ }
167
188
#ifdef WITH_FBSYSTRACE
168
189
FbSystraceAsyncFlow::end (
169
190
TRACE_TAG_REACT_CXX_BRIDGE,
0 commit comments