Bug 1237961 - Assert.throws raises a TypeError exception when the "expected" parameter is an arrow function. r=mikedeboer
MozReview-Commit-ID: CyhD00Uwbwj
--- a/testing/modules/Assert.jsm
+++ b/testing/modules/Assert.jsm
@@ -309,17 +309,20 @@ proto.notStrictEqual = function notStric
function expectedException(actual, expected) {
if (!actual || !expected) {
return false;
}
if (instanceOf(expected, "RegExp")) {
return expected.test(actual);
- } else if (actual instanceof expected) {
+ // 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) &&
+ actual instanceof expected) {
return true;
} else if (expected.call({}, actual) === true) {
return true;
}
return false;
}
--- a/testing/modules/tests/xpcshell/test_assert.js
+++ b/testing/modules/tests/xpcshell/test_assert.js
@@ -203,16 +203,22 @@ function run_test() {
assert.throws(makeBlock(thrower, TypeError), /test/);
// use a fn to validate error object
assert.throws(makeBlock(thrower, TypeError), function(err) {
if ((err instanceof TypeError) && /test/.test(err)) {
return true;
}
});
+ // do the same with an arrow function
+ assert.throws(makeBlock(thrower, TypeError), err => {
+ if ((err instanceof TypeError) && /test/.test(err)) {
+ return true;
+ }
+ });
function testAssertionMessage(actual, expected) {
try {
assert.equal(actual, "");
} catch (e) {
assert.equal(e.toString(),
["AssertionError:", expected, "==", '""'].join(" "));
}