Bug 1406150 - Always throw exceptions by using 'new'. draft
authorHenrik Skupin <mail@hskupin.info>
Fri, 06 Oct 2017 14:07:13 +0200
changeset 676048 72a8c933e7bcf2106f4bf6f7aabd49cb0b1cc9e5
parent 675508 53bbdaaa2b8c1819061be26101b075c081b23260
child 734831 b4fdbaf749e7142b25d08b29df35bf999cc74d5b
push id83373
push userbmo:hskupin@gmail.com
push dateFri, 06 Oct 2017 14:06:45 +0000
bugs1406150
milestone58.0a1
Bug 1406150 - Always throw exceptions by using 'new'. MozReview-Commit-ID: GmI1PuSQwWU
testing/marionette/driver.js
testing/marionette/navigate.js
testing/marionette/packets.js
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -195,33 +195,33 @@ Object.defineProperty(GeckoDriver.protot
       case Context.CHROME:
         let chromeWin = this.getCurrentWindow();
         return new URL(chromeWin.location.href);
 
       case Context.CONTENT:
         return new URL(this.curBrowser.currentURI.spec);
 
       default:
-        throw TypeError(`Unknown context: ${this.context}`);
+        throw new TypeError(`Unknown context: ${this.context}`);
     }
   },
 });
 
 Object.defineProperty(GeckoDriver.prototype, "title", {
   get() {
     switch (this.context) {
       case Context.CHROME:
         let chromeWin = this.getCurrentWindow();
         return chromeWin.document.documentElement.getAttribute("title");
 
       case Context.CONTENT:
         return this.curBrowser.currentTitle;
 
       default:
-        throw TypeError(`Unknown context: ${this.context}`);
+        throw new TypeError(`Unknown context: ${this.context}`);
     }
   },
 });
 
 Object.defineProperty(GeckoDriver.prototype, "proxy", {
   get() {
     return this.capabilities.get("proxy");
   },
@@ -2696,17 +2696,17 @@ GeckoDriver.prototype.deleteCookie = fun
   let {hostname, pathname} = this.currentURL;
   let candidateName = assert.string(cmd.parameters.name);
   for (let toDelete of cookie.iter(hostname, pathname)) {
     if (toDelete.name === candidateName) {
       return cookie.remove(toDelete);
     }
   }
 
-  throw UnknownError("Unable to find cookie");
+  throw new UnknownError("Unable to find cookie");
 };
 
 /**
  * Close the currently selected tab/window.
  *
  * With multiple open tabs present the currently selected tab will
  * be closed.  Otherwise the window itself will be closed. If it is the
  * last window currently open, the window will not be closed to prevent
@@ -3311,17 +3311,17 @@ GeckoDriver.prototype.quit = async funct
 
 GeckoDriver.prototype.installAddon = function(cmd) {
   assert.firefox();
 
   let path = cmd.parameters.path;
   let temp = cmd.parameters.temporary || false;
   if (typeof path == "undefined" || typeof path != "string" ||
       typeof temp != "boolean") {
-    throw InvalidArgumentError();
+    throw new InvalidArgumentError();
   }
 
   return addon.install(path, temp);
 };
 
 GeckoDriver.prototype.uninstallAddon = function(cmd) {
   assert.firefox();
 
--- a/testing/marionette/navigate.js
+++ b/testing/marionette/navigate.js
@@ -27,17 +27,17 @@ this.navigate = {};
  *
  * @throws TypeError
  *     If <code>current</code> is not defined, or any of
  *     <code>current</code> or <code>future</code>  are invalid URLs.
  */
 navigate.isLoadEventExpected = function(current, future = undefined) {
   // assume we will go somewhere exciting
   if (typeof current == "undefined") {
-    throw TypeError("Expected at least one URL");
+    throw new TypeError("Expected at least one URL");
   }
 
   // Assume we will go somewhere exciting
   if (typeof future == "undefined") {
     return true;
   }
 
   let cur = new URL(current);
--- a/testing/marionette/packets.js
+++ b/testing/marionette/packets.js
@@ -80,18 +80,18 @@ Packet.fromHeader = function(header, tra
 Packet.prototype = {
 
   get length() {
     return this._length;
   },
 
   set length(length) {
     if (length > PACKET_LENGTH_MAX) {
-      throw Error("Packet length " + length + " exceeds the max length of " +
-                  PACKET_LENGTH_MAX);
+      throw new Error("Packet length " + length +
+                      " exceeds the max length of " + PACKET_LENGTH_MAX);
     }
     this._length = length;
   },
 
   destroy() {
     this._transport = null;
   },
 };