Bug 1544284 - toolkit/ manual ESLint no-throw-literal fixes. r=Standard8
authorIan Moody <moz-ian@perix.co.uk>
Tue, 16 Apr 2019 19:30:27 +0000
changeset 469811 64a7117d226073ad5d41bc3fd2935ceed45a2efe
parent 469810 5e262e96eac73a03f7b7c6b7a0a42bf90b7670af
child 469812 331387fa113c0e34e5405a558161f7f0512a9973
push id35883
push userbtara@mozilla.com
push dateWed, 17 Apr 2019 21:47:29 +0000
treeherdermozilla-central@02b89c29412b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8
bugs1544284
milestone68.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 1544284 - toolkit/ manual ESLint no-throw-literal fixes. r=Standard8 Includes an otherwise-automated change to test_jsctypes.js that required an expectation change in test_ctypes.xul. Differential Revision: https://phabricator.services.mozilla.com/D27449
.eslintrc.js
toolkit/components/ctypes/tests/chrome/test_ctypes.xul
toolkit/components/ctypes/tests/unit/test_jsctypes.js
toolkit/components/downloads/DownloadCore.jsm
toolkit/content/contentAreaUtils.js
toolkit/content/tests/widgets/test_videocontrols_jsdisabled.html
toolkit/modules/BrowserUtils.jsm
toolkit/modules/GMPInstallManager.jsm
toolkit/modules/Http.jsm
toolkit/modules/tests/xpcshell/test_EventEmitter.js
toolkit/modules/tests/xpcshell/test_Http.js
toolkit/modules/tests/xpcshell/test_Promise.js
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -82,29 +82,16 @@ module.exports = {
     // TODO: Bug 1515949. Enable no-undef for gfx/
     "files": "gfx/layers/apz/test/mochitest/**",
     "rules": {
       "no-undef": "off",
     }
   }, {
     // TODO: Bug 1246594. Empty this list once the rule has landed for all dirs
     "files": [
-      "toolkit/components/aboutmemory/content/aboutMemory.js",
-      "toolkit/components/captivedetect/test/unit/test_multiple_requests.js",
-      "toolkit/components/cleardata/ServiceWorkerCleanUp.jsm",
-      "toolkit/components/ctypes/**",
-      "toolkit/components/downloads/**",
-      "toolkit/components/places/tests/**",
-      "toolkit/components/processsingleton/MainProcessSingleton.jsm",
-      "toolkit/components/prompts/**",
-      "toolkit/components/search/SearchService.jsm",
-      "toolkit/components/telemetry/app/TelemetryEnvironment.jsm",
-      "toolkit/content/**",
-      "toolkit/modules/**",
-      "toolkit/mozapps/**",
       "tools/leak-gauge/leak-gauge.html",
       "xpcom/tests/unit/test_iniParser.js",
     ],
     "rules": {
       "no-throw-literal": "off",
     }
   }, {
     ...removeOverrides(xpcshellTestConfig),
--- a/toolkit/components/ctypes/tests/chrome/test_ctypes.xul
+++ b/toolkit/components/ctypes/tests/chrome/test_ctypes.xul
@@ -77,18 +77,18 @@
 
       var worker = new ChromeWorker("ctypes_worker.js");
       worker.onmessage = function(event) {
         is(event.data, "Done!", "Wrong message!");
         cleanupLibs(dir);
         SimpleTest.finish();
       }
       worker.onerror = function(event) {
-        if (event.message == "uncaught exception: 7.5 million years for that?" ||
-            event.message == "uncaught exception: Just following orders, sir!") {
+        if (event.message == "Error: 7.5 million years for that?" ||
+            event.message == "Error: Just following orders, sir!") {
           // We throw those on purpose in the worker, so ignore them.
           event.preventDefault();
           return;
         }
         ok(false, "Worker had an error: " + event.message);
         worker.terminate();
         cleanupLibs(dir);
         SimpleTest.finish();
--- a/toolkit/components/ctypes/tests/unit/test_jsctypes.js
+++ b/toolkit/components/ctypes/tests/unit/test_jsctypes.js
@@ -2556,17 +2556,17 @@ function run_closure_tests(library) {
   }
 }
 
 function run_single_closure_tests(library, abi, suffix) {
   let b = 23;
 
   function closure_fn(i) {
     if (i == 42)
-      throw "7.5 million years for that?";
+      throw new Error("7.5 million years for that?");
     return "a" in this ? i + this.a : i + b;
   }
 
   Assert.equal(closure_fn(7), 7 + b);
   let thisobj = { a: 5 };
   Assert.equal(closure_fn.call(thisobj, 7), 7 + thisobj.a);
 
   // Construct a closure, and call it ourselves.
@@ -2590,17 +2590,17 @@ function run_single_closure_tests(librar
   Assert.equal(test_closure(42, closure3), 54);
 
   // Check what happens when the return type is bigger than a word.
   var fn_64_t = ctypes.FunctionType(ctypes.default_abi, ctypes.uint64_t, [ctypes.bool]).ptr;
   var bignum1 = ctypes.UInt64.join(0xDEADBEEF, 0xBADF00D);
   var bignum2 = ctypes.UInt64.join(0xDEFEC8ED, 0xD15EA5E);
   function closure_fn_64(fail) {
     if (fail)
-      throw "Just following orders, sir!";
+      throw new Error("Just following orders, sir!");
     return bignum1;
   }
   var closure64 = fn_64_t(closure_fn_64, null, bignum2);
   Assert.equal(ctypes.UInt64.compare(closure64(false), bignum1), 0);
   Assert.equal(ctypes.UInt64.compare(closure64(true), bignum2), 0);
 
   // Test a callback that returns void (see bug 682504).
   var fn_v_t = ctypes.FunctionType(ctypes.default_abi, ctypes.void_t, []).ptr;
--- a/toolkit/components/downloads/DownloadCore.jsm
+++ b/toolkit/components/downloads/DownloadCore.jsm
@@ -422,17 +422,17 @@ this.Download.prototype = {
           throw new DownloadError({ becauseBlockedByRuntimePermissions: true });
         }
 
         // We should check if we have been canceled in the meantime, after all
         // the previous asynchronous operations have been executed and just
         // before we call the "execute" method of the saver.
         if (this._promiseCanceled) {
           // The exception will become a cancellation in the "catch" block.
-          throw undefined;
+          throw new Error(undefined);
         }
 
         // Execute the actual download through the saver object.
         this._saverExecuting = true;
         try {
           await this.saver.execute(DS_setProgressBytes.bind(this),
                                    DS_setProperties.bind(this));
         } catch (ex) {
--- a/toolkit/content/contentAreaUtils.js
+++ b/toolkit/content/contentAreaUtils.js
@@ -851,17 +851,17 @@ function appendFiltersForContentType(aFi
       bundleName   = "WebPageXMLOnlyFilter";
       filterString = "*.xml";
       break;
     }
   }
 
   if (!bundleName) {
     if (aSaveMode != SAVEMODE_FILEONLY)
-      throw "Invalid save mode for type '" + aContentType + "'";
+      throw new Error(`Invalid save mode for type '${aContentType}'`);
 
     var mimeInfo = getMIMEInfoForType(aContentType, aFileExtension);
     if (mimeInfo) {
       var extString = "";
       for (var extension of mimeInfo.getFileExtensions()) {
         if (extString)
           extString += "; "; // If adding more than one extension,
                                 // separate by semi-colon
--- a/toolkit/content/tests/widgets/test_videocontrols_jsdisabled.html
+++ b/toolkit/content/tests/widgets/test_videocontrols_jsdisabled.html
@@ -29,17 +29,17 @@ function runTest(event) {
       is(video.paused, true, "checking video play state");
       win.close();
 
       SimpleTest.finish();
       break;
 
     default:
       ok(false, "unexpected test #" + testnum + " w/ event " + event.type);
-      throw "unexpected test #" + testnum + " w/ event " + event.type;
+      throw new Error(`unexpected test #${testnum} w/ event ${event.type}`);
   }
 
   testnum++;
 }
 
 SpecialPowers.pushPrefEnv({"set": [["javascript.enabled", false]]}, startTest);
 
 var testnum = 1;
--- a/toolkit/modules/BrowserUtils.jsm
+++ b/toolkit/modules/BrowserUtils.jsm
@@ -69,17 +69,17 @@ var BrowserUtils = {
       else
         secMan.checkLoadURIStrWithPrincipal(aPrincipal, aURL, aFlags);
     } catch (e) {
       let principalStr = "";
       try {
         principalStr = " from " + aPrincipal.URI.spec;
       } catch (e2) { }
 
-      throw "Load of " + aURL + principalStr + " denied.";
+      throw new Error(`Load of ${aURL + principalStr} denied.`);
     }
   },
 
   /**
    * Return or create a principal with the codebase of one, and the originAttributes
    * of an existing principal (e.g. on a docshell, where the originAttributes ought
    * not to change, that is, we should keep the userContextId, privateBrowsingId,
    * etc. the same when changing the principal).
--- a/toolkit/modules/GMPInstallManager.jsm
+++ b/toolkit/modules/GMPInstallManager.jsm
@@ -256,16 +256,17 @@ GMPInstallManager.prototype = {
           failureEncountered = true;
           installResults.push({
             id:     addon.id,
             result: "failed",
           });
         }
       }
       if (failureEncountered) {
+        // eslint-disable-next-line no-throw-literal
         throw {status:  "failed",
                results: installResults};
       }
       return {status:  "succeeded",
               results: installResults};
     } catch (e) {
       log.error("Could not check for addons", e);
       throw e;
--- a/toolkit/modules/Http.jsm
+++ b/toolkit/modules/Http.jsm
@@ -57,17 +57,17 @@ function httpRequest(aUrl, aOptions) {
     try {
       let target = aRequest.target;
       if (aOptions.logger)
         aOptions.logger.debug("Received response: " + target.responseText);
       if (target.status < 200 || target.status >= 300) {
         let errorText = target.responseText;
         if (!errorText || /<(ht|\?x)ml\b/i.test(errorText))
           errorText = target.statusText;
-        throw target.status + " - " + errorText;
+        throw new Error(target.status + " - " + errorText);
       }
       if (aOptions.onLoad)
         aOptions.onLoad(target.responseText, this);
     } catch (e) {
       if (aOptions.onError)
         aOptions.onError(e, aRequest.target.responseText, this);
     }
   };
--- a/toolkit/modules/tests/xpcshell/test_EventEmitter.js
+++ b/toolkit/modules/tests/xpcshell/test_EventEmitter.js
@@ -49,16 +49,17 @@ function testEmitter(emitter) {
     emitter.emit("onlyonce");
 
     testThrowingExceptionInListener();
   }
 
   function testThrowingExceptionInListener() {
     function throwListener() {
       emitter.off("throw-exception");
+      // eslint-disable-next-line no-throw-literal
       throw {
         toString: () => "foo",
         stack: "bar",
       };
     }
 
     emitter.on("throw-exception", throwListener);
     emitter.emit("throw-exception");
--- a/toolkit/modules/tests/xpcshell/test_Http.js
+++ b/toolkit/modules/tests/xpcshell/test_Http.js
@@ -86,17 +86,17 @@ add_test(function test_errorCallback() {
   do_test_pending();
   let options = {
     onSuccess(aResponse) {
       Assert.ok(false);
       do_test_finished();
       run_next_test();
     },
     onError(e, aResponse) {
-      Assert.equal(e, "404 - Not Found");
+      Assert.equal(e.message, "404 - Not Found");
       do_test_finished();
       run_next_test();
     },
   };
   httpRequest(kBaseUrl + "/failure", options);
 });
 
 add_test(function test_PostData() {
--- a/toolkit/modules/tests/xpcshell/test_Promise.js
+++ b/toolkit/modules/tests/xpcshell/test_Promise.js
@@ -710,25 +710,25 @@ tests.push(
     );
   }));
 
 // Test that throwing from the iterable passed to Promise.all() rejects the
 // promise returned by Promise.all()
 tests.push(
   make_promise_test(function all_iterable_throws(test) {
     function* iterable() {
-      throw 1;
+      throw new Error(1);
     }
 
     return Promise.all(iterable()).then(
       function onResolve() {
         do_throw("all() unexpectedly resolved");
       },
       function onReject(reason) {
-        Assert.equal(reason, 1, "all() rejects when the iterator throws");
+        Assert.equal(reason.message, 1, "all() rejects when the iterator throws");
       }
     );
   }));
 
 // Test that Promise.race() resolves with the first available resolution value
 tests.push(
   make_promise_test(function race_resolve(test) {
     let p1 = Promise.resolve(1);
@@ -795,25 +795,25 @@ tests.push(
     );
   }));
 
 // Test that throwing from the iterable passed to Promise.race() rejects the
 // promise returned by Promise.race()
 tests.push(
   make_promise_test(function race_iterable_throws(test) {
     function* iterable() {
-      throw 1;
+      throw new Error(1);
     }
 
     return Promise.race(iterable()).then(
       function onResolve() {
         do_throw("race() unexpectedly resolved");
       },
       function onReject(reason) {
-        Assert.equal(reason, 1, "race() rejects when the iterator throws");
+        Assert.equal(reason.message, 1, "race() rejects when the iterator throws");
       }
     );
   }));
 
 // Test that rejecting one of the promises passed to Promise.race() rejects the
 // promise returned by Promise.race()
 tests.push(
   make_promise_test(function race_reject(test) {
@@ -881,17 +881,17 @@ tests.push(
       function onReject(reason) {
         Assert.equal(reason, 1, "Executor rejected with correct value");
       }
     );
 
     // throw from the executor, causing a rejection
     let throwPromise = new Promise(
       function executor() {
-        throw 1;
+        throw 1; // eslint-disable-line no-throw-literal
       }
     ).then(
       function onResolve() {
         do_throw("Throwing inside an executor should not resolve the promise");
       },
       function onReject(reason) {
         Assert.equal(reason, 1, "Executor rejected with correct value");
       }