Bug 1237961 - Assert.throws raises a TypeError exception when the "expected" parameter is an arrow function. r=mikedeboer
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Fri, 20 Jan 2017 15:38:56 +0100
changeset 377648 96d7d786f56b1ed6ae15c153014ea8cefcb406e2
parent 377647 46225906354e6a74c04c15cce5243d82daf2f092
child 377649 e91f28eb9a8831d1988350a8cd9e4c41d2b637d4
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs1237961
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1237961 - Assert.throws raises a TypeError exception when the "expected" parameter is an arrow function. r=mikedeboer MozReview-Commit-ID: CyhD00Uwbwj
testing/modules/Assert.jsm
testing/modules/tests/xpcshell/test_assert.js
--- 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(" "));
     }