Bug 667155 - Ensure uncaught exceptions do cause test failures in plain mochitests. r=ted

This commit is contained in:
Cameron McCormack 2011-06-27 11:05:02 +12:00
parent d94e1ef1e9
commit 8d48f55b96

View File

@ -790,21 +790,22 @@ var isDeeply = SimpleTest.isDeeply;
var gOldOnError = window.onerror;
window.onerror = function simpletestOnerror(errorMsg, url, lineNumber) {
var funcIdentifier = "[SimpleTest/SimpleTest.js, window.onerror]";
var isPlainMochitest = window.location.protocol != "chrome:";
// Log the message.
// XXX Chrome mochitests sometimes trigger this window.onerror handler,
// but there are a number of uncaught JS exceptions from those tests
// currently, so we can't log them as errors just yet. For now, when
// parentRunner is null, just dump it so that the error is visible but
// not in a plain mochitest, just dump it so that the error is visible but
// doesn't cause a test failure. See bug 652494.
function logInfo(message) {
if (parentRunner) {
SimpleTest._logInfo(funcIdentifier, message);
function logError(message) {
if (isPlainMochitest) {
SimpleTest.ok(false, funcIdentifier, message);
} else {
dump(funcIdentifier + " " + message);
}
}
logInfo("An error occurred: " + errorMsg + " at " + url + ":" + lineNumber);
logError("An error occurred: " + errorMsg + " at " + url + ":" + lineNumber);
// There is no Components.stack.caller to log. (See bug 511888.)
// Call previous handler.
@ -814,10 +815,10 @@ window.onerror = function simpletestOnerror(errorMsg, url, lineNumber) {
gOldOnError(errorMsg, url, lineNumber);
} catch (e) {
// Log the error.
logInfo("Exception thrown by gOldOnError(): " + e);
logError("Exception thrown by gOldOnError(): " + e);
// Log its stack.
if (e.stack) {
logInfo("JavaScript error stack:\n" + e.stack);
logError("JavaScript error stack:\n" + e.stack);
}
}
}