Permalink
Browse files

Fixing a race condition that may be caused by the reloadable executor.

Reviewed By: javache

Differential Revision: D5139379

fbshipit-source-id: 24aa820caacfe3780d0e5a2f5868cdc46cefc3fb
  • Loading branch information...
Dan Caspi authored and facebook-github-bot committed Jun 6, 2017
1 parent 699a0be commit 63ffa7c2f6035efb4fa3c6f5437372965be31fb0
Showing with 14 additions and 8 deletions.
  1. +14 −8 ReactCommon/cxxreact/JSCExecutor.cpp
@@ -79,11 +79,13 @@ inline JSObjectCallAsFunctionCallback exceptionWrapMethod() {
JSValueRef *exception) {
try {
auto executor = Object::getGlobalObject(ctx).getPrivate<JSCExecutor>();
return (executor->*method)(argumentCount, arguments);
if (executor && executor->getJavaScriptContext()) { // Executor not invalidated
return (executor->*method)(argumentCount, arguments);
}
} catch (...) {
*exception = translatePendingCppExceptionToJSError(ctx, function);
return Value::makeUndefined(ctx);
}
return Value::makeUndefined(ctx);
}
};
@@ -100,11 +102,13 @@ inline JSObjectGetPropertyCallback exceptionWrapMethod() {
JSValueRef *exception) {
try {
auto executor = Object::getGlobalObject(ctx).getPrivate<JSCExecutor>();
return (executor->*method)(object, propertyName);
if (executor && executor->getJavaScriptContext()) { // Executor not invalidated
return (executor->*method)(object, propertyName);
}
} catch (...) {
*exception = translatePendingCppExceptionToJSError(ctx, object);
return Value::makeUndefined(ctx);
}
return Value::makeUndefined(ctx);
}
};
@@ -256,17 +260,19 @@ void JSCExecutor::initOnJSVMThread() throw(JSException) {
}
void JSCExecutor::terminateOnJSVMThread() {
JSGlobalContextRef context = m_context;
m_context = nullptr;
Object::getGlobalObject(context).setPrivate(nullptr);
m_nativeModules.reset();
#ifdef WITH_INSPECTOR
if (canUseInspector(m_context)) {
if (canUseInspector(context)) {
IInspector* pInspector = JSC_JSInspectorGetInstance(true);
pInspector->unregisterGlobalContext(m_context);
pInspector->unregisterGlobalContext(context);
}
#endif
JSC_JSGlobalContextRelease(m_context);
m_context = nullptr;
JSC_JSGlobalContextRelease(context);
}
#ifdef WITH_FBJSCEXTENSIONS

0 comments on commit 63ffa7c

Please sign in to comment.