Try/catch exceptions in JSCExecutor for debugging crash

Reviewed By: lexs

Differential Revision: D2982534

fb-gh-sync-id: 4eda4116cd60e2e46771ecddefc1d27eee761762
shipit-source-id: 4eda4116cd60e2e46771ecddefc1d27eee761762
This commit is contained in:
Andy Street 2016-02-26 10:57:55 -08:00 committed by Facebook Github Bot 0
parent 4b98511a3e
commit f99579adaa
4 changed files with 26 additions and 10 deletions

View File

@ -126,13 +126,17 @@ JSCExecutor::JSCExecutor(
}
JSCExecutor::~JSCExecutor() {
*m_isDestroyed = true;
if (m_messageQueueThread->isOnThread()) {
terminateOnJSVMThread();
} else {
m_messageQueueThread->runOnQueueSync([this] () {
try {
*m_isDestroyed = true;
if (m_messageQueueThread->isOnThread()) {
terminateOnJSVMThread();
});
} else {
m_messageQueueThread->runOnQueueSync([this] () {
terminateOnJSVMThread();
});
}
} catch (...) {
Exceptions::handleUncaughtException();
}
}

View File

@ -20,10 +20,14 @@ LoadScriptFromAssets loadScriptFromAssets;
namespace PerfLogging {
InstallNativeHooks installNativeHooks;
}
};
namespace JSLogging {
JSCNativeHook nativeHook = nullptr;
}
};
namespace Exceptions {
HandleUncaughtException handleUncaughtException;
};
} }

View File

@ -34,7 +34,7 @@ extern LoadScriptFromAssets loadScriptFromAssets;
namespace PerfLogging {
using InstallNativeHooks = std::function<void(JSGlobalContextRef)>;
extern InstallNativeHooks installNativeHooks;
}
};
namespace JSLogging {
using JSCNativeHook = JSValueRef (*) (
@ -44,6 +44,11 @@ namespace JSLogging {
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception);
extern JSCNativeHook nativeHook;
}
};
namespace Exceptions {
using HandleUncaughtException = std::function<void()>;
extern HandleUncaughtException handleUncaughtException;
};
} }

View File

@ -865,6 +865,9 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
return std::unique_ptr<MessageQueueThread>(
JMessageQueueThread::currentMessageQueueThread().release());
};
Exceptions::handleUncaughtException = [] () {
translatePendingCppExceptionToJavaException();
};
PerfLogging::installNativeHooks = addNativePerfLoggingHooks;
JSLogging::nativeHook = nativeLoggingHook;