Bug 1409852 - Assert.throws should support `throw null`;r?mdeboer
MozReview-Commit-ID: HxxrvzZn9Aq
--- a/testing/modules/Assert.jsm
+++ b/testing/modules/Assert.jsm
@@ -303,17 +303,17 @@ proto.strictEqual = function strictEqual
* @param message (optional)
* (string) Short explanation of the expected result
*/
proto.notStrictEqual = function notStrictEqual(actual, expected, message) {
this.report(actual === expected, actual, expected, message, "!==");
};
function expectedException(actual, expected) {
- if (!actual || !expected) {
+ if (!expected) {
return false;
}
if (instanceOf(expected, "RegExp")) {
return expected.test(actual);
// We need to guard against the right hand parameter of "instanceof" lacking
// the "prototype" property, which is true of arrow functions in particular.
} else if (!(typeof expected === "function" && !expected.prototype) &&
@@ -353,26 +353,29 @@ function expectedException(actual, expec
proto.throws = function(block, expected, message) {
let actual;
if (typeof expected === "string") {
message = expected;
expected = null;
}
+ var has_thrown;
try {
block();
+ has_thrown = false;
} catch (e) {
+ has_thrown = true;
actual = e;
}
message = (expected && expected.name ? " (" + expected.name + ")." : ".") +
(message ? " " + message : ".");
- if (!actual) {
+ if (!has_thrown) {
this.report(true, actual, expected, "Missing expected exception" + message);
}
if ((actual && expected && !expectedException(actual, expected))) {
throw actual;
}
this.report(false, expected, expected, message);