Skip to content

Commit 63ffa7c

Browse files
dcaspifacebook-github-bot
authored andcommitted
Fixing a race condition that may be caused by the reloadable executor.
Reviewed By: javache Differential Revision: D5139379 fbshipit-source-id: 24aa820caacfe3780d0e5a2f5868cdc46cefc3fb
1 parent 699a0be commit 63ffa7c

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

ReactCommon/cxxreact/JSCExecutor.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ inline JSObjectCallAsFunctionCallback exceptionWrapMethod() {
7979
JSValueRef *exception) {
8080
try {
8181
auto executor = Object::getGlobalObject(ctx).getPrivate<JSCExecutor>();
82-
return (executor->*method)(argumentCount, arguments);
82+
if (executor && executor->getJavaScriptContext()) { // Executor not invalidated
83+
return (executor->*method)(argumentCount, arguments);
84+
}
8385
} catch (...) {
8486
*exception = translatePendingCppExceptionToJSError(ctx, function);
85-
return Value::makeUndefined(ctx);
8687
}
88+
return Value::makeUndefined(ctx);
8789
}
8890
};
8991

@@ -100,11 +102,13 @@ inline JSObjectGetPropertyCallback exceptionWrapMethod() {
100102
JSValueRef *exception) {
101103
try {
102104
auto executor = Object::getGlobalObject(ctx).getPrivate<JSCExecutor>();
103-
return (executor->*method)(object, propertyName);
105+
if (executor && executor->getJavaScriptContext()) { // Executor not invalidated
106+
return (executor->*method)(object, propertyName);
107+
}
104108
} catch (...) {
105109
*exception = translatePendingCppExceptionToJSError(ctx, object);
106-
return Value::makeUndefined(ctx);
107110
}
111+
return Value::makeUndefined(ctx);
108112
}
109113
};
110114

@@ -256,17 +260,19 @@ void JSCExecutor::initOnJSVMThread() throw(JSException) {
256260
}
257261

258262
void JSCExecutor::terminateOnJSVMThread() {
263+
JSGlobalContextRef context = m_context;
264+
m_context = nullptr;
265+
Object::getGlobalObject(context).setPrivate(nullptr);
259266
m_nativeModules.reset();
260267

261268
#ifdef WITH_INSPECTOR
262-
if (canUseInspector(m_context)) {
269+
if (canUseInspector(context)) {
263270
IInspector* pInspector = JSC_JSInspectorGetInstance(true);
264-
pInspector->unregisterGlobalContext(m_context);
271+
pInspector->unregisterGlobalContext(context);
265272
}
266273
#endif
267274

268-
JSC_JSGlobalContextRelease(m_context);
269-
m_context = nullptr;
275+
JSC_JSGlobalContextRelease(context);
270276
}
271277

272278
#ifdef WITH_FBJSCEXTENSIONS

0 commit comments

Comments
 (0)