Bug 1538766 - mobile/ automated ESLint no-throw-literal fixes. r=petru
authorIan Moody <moz-ian@perix.co.uk>
Tue, 26 Mar 2019 08:29:37 +0000
changeset 466121 2596c01bd847e7a4ff0eabaea3ad7dda2024cf65
parent 466120 a20d8267e39f2523a003dfd61237e9845cc765b9
child 466122 1b85204856e2a90335fb54b1e8176bd5c81e1b62
push id81456
push userncsoregi@mozilla.com
push dateTue, 26 Mar 2019 16:56:06 +0000
treeherderautoland@1b85204856e2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspetru
bugs1538766
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 1538766 - mobile/ automated ESLint no-throw-literal fixes. r=petru Result of running: $ mach eslint -funix mobile/ | sed -Ee 's/:.+//' - | xargs sed -E \ -e 's/throw ((["`])[^"]+\2);/throw new Error(\1);/g' \ -e 's/throw ((["`])[^"]+\2 \+ [^ ";]+);/throw new Error(\1);/g' \ -e 's/throw \(/throw new Error(/g' -i Differential Revision: https://phabricator.services.mozilla.com/D24731
mobile/android/components/LoginManagerPrompter.js
mobile/android/components/NSSDialogService.js
mobile/android/components/PromptService.js
mobile/android/components/SessionStore.js
mobile/android/components/geckoview/GeckoViewPermission.js
mobile/android/components/geckoview/GeckoViewPrompt.js
mobile/android/modules/DownloadNotifications.jsm
mobile/android/modules/Home.jsm
mobile/android/modules/Notifications.jsm
mobile/android/modules/PageActions.jsm
mobile/android/modules/SharedPreferences.jsm
mobile/android/modules/WebrtcUI.jsm
--- a/mobile/android/components/LoginManagerPrompter.js
+++ b/mobile/android/components/LoginManagerPrompter.js
@@ -43,17 +43,17 @@ LoginManagerPrompter.prototype = {
   get _strBundle() {
     if (!this.__strBundle) {
       this.__strBundle = {
         pwmgr: Services.strings.createBundle("chrome://browser/locale/passwordmgr.properties"),
         brand: Services.strings.createBundle("chrome://branding/locale/brand.properties"),
       };
 
       if (!this.__strBundle)
-        throw "String bundle for Login Manager not present!";
+        throw new Error("String bundle for Login Manager not present!");
     }
 
     return this.__strBundle;
   },
 
   __ellipsis: null,
   get _ellipsis() {
   if (!this.__ellipsis) {
--- a/mobile/android/components/NSSDialogService.js
+++ b/mobile/android/components/NSSDialogService.js
@@ -104,17 +104,17 @@ NSSDialogs.prototype = {
       if (response.trustEmail) aTrust.value |= Ci.nsIX509CertDB.TRUSTED_EMAIL;
       return true;
     }
   },
 
   setPKCS12FilePassword: function(aCtx, aPassword) {
     // this dialog is never shown in Fennec; in Desktop it is shown while backing up a personal
     // certificate to a file via Preferences->Advanced->Encryption->View Certificates->Your Certificates
-    throw "Unimplemented";
+    throw new Error("Unimplemented");
   },
 
   getPKCS12FilePassword: function(aCtx, aPassword) {
     let prompt = this.getPrompt(this.getString("pkcs12.getpassword.title"),
                                 this.getString("pkcs12.getpassword.message"),
                                 [ this.getString("nssdialogs.ok.label"),
                                   this.getString("nssdialogs.cancel.label"),
                                 ], aCtx).addPassword({id: "pw"});
--- a/mobile/android/components/PromptService.js
+++ b/mobile/android/components/PromptService.js
@@ -714,21 +714,21 @@ var PromptUtils = {
   },
 
   getAuthTarget: function pu_getAuthTarget(aChannel, aAuthInfo) {
     let hostname, realm;
     // If our proxy is demanding authentication, don't use the
     // channel's actual destination.
     if (aAuthInfo.flags & Ci.nsIAuthInformation.AUTH_PROXY) {
         if (!(aChannel instanceof Ci.nsIProxiedChannel))
-          throw "proxy auth needs nsIProxiedChannel";
+          throw new Error("proxy auth needs nsIProxiedChannel");
 
       let info = aChannel.proxyInfo;
       if (!info)
-        throw "proxy auth needs nsIProxyInfo";
+        throw new Error("proxy auth needs nsIProxyInfo");
 
       // Proxies don't have a scheme, but we'll use "moz-proxy://"
       // so that it's more obvious what the login is for.
       let idnService = Cc["@mozilla.org/network/idn-service;1"].getService(Ci.nsIIDNService);
       hostname = "moz-proxy://" + idnService.convertUTF8toACE(info.host) + ":" + info.port;
       realm = aAuthInfo.realm;
       if (!realm)
         realm = hostname;
--- a/mobile/android/components/SessionStore.js
+++ b/mobile/android/components/SessionStore.js
@@ -1417,22 +1417,22 @@ SessionStore.prototype = {
     return this._getCurrentState();
   },
 
   _restoreWindow(aData) {
     let state;
     try {
       state = JSON.parse(aData);
     } catch (e) {
-      throw "Invalid session JSON: " + aData;
+      throw new Error("Invalid session JSON: " + aData);
     }
 
     // To do a restore, we must have at least one window with one tab
     if (!state || state.windows.length == 0 || !state.windows[0].tabs || state.windows[0].tabs.length == 0) {
-      throw "Invalid session JSON: " + aData;
+      throw new Error("Invalid session JSON: " + aData);
     }
 
     let window = Services.wm.getMostRecentWindow("navigator:browser");
     let tabs = state.windows[0].tabs;
 
     for (let i = 0; i < tabs.length; i++) {
       let tabData = tabs[i];
 
@@ -1486,25 +1486,25 @@ SessionStore.prototype = {
       return 0; // not a browser window, or not otherwise tracked by SS.
     }
 
     return this._windows[aWindow.__SSID].closedTabs.length;
   },
 
   getClosedTabs(aWindow) {
     if (!aWindow.__SSID) {
-      throw (Components.returnCode = Cr.NS_ERROR_INVALID_ARG);
+      throw new Error(Components.returnCode = Cr.NS_ERROR_INVALID_ARG);
     }
 
     return this._windows[aWindow.__SSID].closedTabs;
   },
 
   undoCloseTab(aWindow, aCloseTabData) {
     if (!aWindow.__SSID) {
-      throw (Components.returnCode = Cr.NS_ERROR_INVALID_ARG);
+      throw new Error(Components.returnCode = Cr.NS_ERROR_INVALID_ARG);
     }
 
     // If the tab data is in the closedTabs array, remove it.
     if (aCloseTabData.tabId) {
       let tabId = [aCloseTabData.tabId];
       this._removeClosedTabs(aWindow, tabId);
     }
 
@@ -1557,17 +1557,17 @@ SessionStore.prototype = {
 
   _sendClosedTabsToJava(aWindow) {
     // If the app is shutting down, we don't need to do anything.
     if (this._loadState <= STATE_QUITTING) {
       return;
     }
 
     if (!aWindow.__SSID) {
-      throw (Components.returnCode = Cr.NS_ERROR_INVALID_ARG);
+      throw new Error(Components.returnCode = Cr.NS_ERROR_INVALID_ARG);
     }
 
     let closedTabs = this._windows[aWindow.__SSID].closedTabs;
     let isPrivate = PrivateBrowsingUtils.isBrowserPrivate(aWindow.BrowserApp.selectedBrowser);
 
     let tabs = closedTabs
       .filter(tab => tab.isPrivate == isPrivate)
       .map(function(tab) {
--- a/mobile/android/components/geckoview/GeckoViewPermission.js
+++ b/mobile/android/components/geckoview/GeckoViewPermission.js
@@ -113,19 +113,19 @@ GeckoViewPermission.prototype = {
           id: device.id,
           rawId: device.rawId,
           name: device.name,
           mediaSource: device.mediaSource,
         };
       });
 
       if (constraints.video && !sources.some(source => source.type === "videoinput")) {
-        throw "no video source";
+        throw new Error("no video source");
       } else if (constraints.audio && !sources.some(source => source.type === "audioinput")) {
-        throw "no audio source";
+        throw new Error("no audio source");
       }
 
       let dispatcher = GeckoViewUtils.getDispatcherForWindow(win);
       let uri = win.document.documentURIObject;
       return dispatcher.sendRequestForResult({
         type: "GeckoView:MediaPermission",
         uri: uri.displaySpec,
         video: constraints.video ? sources.filter(source => source.type === "videoinput") : null,
--- a/mobile/android/components/geckoview/GeckoViewPrompt.js
+++ b/mobile/android/components/geckoview/GeckoViewPrompt.js
@@ -755,21 +755,21 @@ PromptDelegate.prototype = {
     return text;
   },
 
   _getAuthTarget: function(aChannel, aAuthInfo) {
     // If our proxy is demanding authentication, don't use the
     // channel's actual destination.
     if (aAuthInfo.flags & Ci.nsIAuthInformation.AUTH_PROXY) {
       if (!(aChannel instanceof Ci.nsIProxiedChannel)) {
-        throw "proxy auth needs nsIProxiedChannel";
+        throw new Error("proxy auth needs nsIProxiedChannel");
       }
       let info = aChannel.proxyInfo;
       if (!info) {
-        throw "proxy auth needs nsIProxyInfo";
+        throw new Error("proxy auth needs nsIProxyInfo");
       }
       // Proxies don't have a scheme, but we'll use "moz-proxy://"
       // so that it's more obvious what the login is for.
       let idnService = Cc["@mozilla.org/network/idn-service;1"].getService(Ci.nsIIDNService);
       let hostname = "moz-proxy://" + idnService.convertUTF8toACE(info.host) + ":" + info.port;
       let realm = aAuthInfo.realm;
       if (!realm) {
         realm = hostname;
--- a/mobile/android/modules/DownloadNotifications.jsm
+++ b/mobile/android/modules/DownloadNotifications.jsm
@@ -127,17 +127,17 @@ var DownloadNotifications = {
       .then((downloads) => {
         for (let download of downloads) {
           let cookie2 = getCookieFromDownload(download);
           if (cookie2 === cookie) {
             return download;
           }
         }
 
-        throw "Couldn't find download for " + cookie;
+        throw new Error("Couldn't find download for " + cookie);
       });
   },
 
   onCancel: function(cookie) {
     // TODO: I'm not sure what we do here...
   },
 
   showInAboutDownloads: function(download) {
--- a/mobile/android/modules/Home.jsm
+++ b/mobile/android/modules/Home.jsm
@@ -15,17 +15,17 @@ const {EventDispatcher} = ChromeUtils.im
 const PREFS_PANEL_AUTH_PREFIX = "home_panels_auth_";
 
 // Default weight for a banner message.
 const DEFAULT_WEIGHT = 100;
 
 // See bug 915424
 function resolveGeckoURI(aURI) {
   if (!aURI)
-    throw "Can't resolve an empty uri";
+    throw new Error("Can't resolve an empty uri");
 
   if (aURI.startsWith("chrome://")) {
     let registry = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIChromeRegistry);
     return registry.convertChromeURL(Services.io.newURI(aURI)).spec;
   } else if (aURI.startsWith("resource://")) {
     let handler = Services.io.getProtocolHandler("resource").QueryInterface(Ci.nsIResProtocolHandler);
     return handler.resolveURI(Services.io.newURI(aURI));
   }
@@ -163,17 +163,17 @@ var HomeBanner = (function() {
 
     /**
      * Removes a banner message from the rotation.
      *
      * @param id The id of the message to remove.
      */
     remove: function(id) {
       if (!(id in _messages)) {
-        throw "Home.banner: Can't remove message that doesn't exist: id = " + id;
+        throw new Error("Home.banner: Can't remove message that doesn't exist: id = " + id);
       }
 
       delete _messages[id];
 
       // If there are no more messages, remove the observers.
       if (Object.keys(_messages).length == 0) {
         EventDispatcher.instance.unregisterListener(this, [
           "HomeBanner:Click",
@@ -215,20 +215,20 @@ var HomePanels = (function() {
       });
     },
 
     "HomePanels:Authenticate": function handlePanelsAuthenticate(data) {
       // Generate panel options to get auth handler.
       let id = data.id;
       let options = _registeredPanels[id]();
       if (!options.auth) {
-        throw "Home.panels: Invalid auth for panel.id = " + id;
+        throw new Error("Home.panels: Invalid auth for panel.id = " + id);
       }
       if (!options.auth.authenticate || typeof options.auth.authenticate !== "function") {
-        throw "Home.panels: Invalid auth authenticate function: panel.id = " + this.id;
+        throw new Error("Home.panels: Invalid auth authenticate function: panel.id = " + this.id);
       }
       options.auth.authenticate();
     },
 
     "HomePanels:RefreshView": function handlePanelsRefreshView(data) {
       let options = _registeredPanels[data.panelId]();
       let view = options.views[data.viewIndex];
 
@@ -249,31 +249,31 @@ var HomePanels = (function() {
       let id = data.id;
       _assertPanelExists(id);
 
       let options = _registeredPanels[id]();
       if (!options.oninstall) {
         return;
       }
       if (typeof options.oninstall !== "function") {
-        throw "Home.panels: Invalid oninstall function: panel.id = " + this.id;
+        throw new Error("Home.panels: Invalid oninstall function: panel.id = " + this.id);
       }
       options.oninstall();
     },
 
     "HomePanels:Uninstalled": function handlePanelsUninstalled(data) {
       let id = data.id;
       _assertPanelExists(id);
 
       let options = _registeredPanels[id]();
       if (!options.onuninstall) {
         return;
       }
       if (typeof options.onuninstall !== "function") {
-        throw "Home.panels: Invalid onuninstall function: panel.id = " + this.id;
+        throw new Error("Home.panels: Invalid onuninstall function: panel.id = " + this.id);
       }
       options.onuninstall();
     },
   };
 
   // Holds the current set of registered panels that can be
   // installed, updated, uninstalled, or unregistered. It maps
   // panel ids with the functions that dynamically generate
@@ -309,17 +309,17 @@ var HomePanels = (function() {
   function Panel(id, options) {
     this.id = id;
     this.title = options.title;
     this.layout = options.layout;
     this.views = options.views;
     this.default = !!options.default;
 
     if (!this.id || !this.title) {
-      throw "Home.panels: Can't create a home panel without an id and title!";
+      throw new Error("Home.panels: Can't create a home panel without an id and title!");
     }
 
     if (!this.layout) {
       // Use FRAME layout by default
       this.layout = Layout.FRAME;
     } else if (!_valueExists(Layout, this.layout)) {
       throw "Home.panels: Invalid layout for panel: panel.id = " + this.id + ", panel.layout =" + this.layout;
     }
@@ -354,20 +354,20 @@ var HomePanels = (function() {
 
       if (view.onrefresh) {
         view.refreshEnabled = true;
       }
     }
 
     if (options.auth) {
       if (!options.auth.messageText) {
-        throw "Home.panels: Invalid auth messageText: panel.id = " + this.id;
+        throw new Error("Home.panels: Invalid auth messageText: panel.id = " + this.id);
       }
       if (!options.auth.buttonText) {
-        throw "Home.panels: Invalid auth buttonText: panel.id = " + this.id;
+        throw new Error("Home.panels: Invalid auth buttonText: panel.id = " + this.id);
       }
 
       this.authConfig = {
         messageText: options.auth.messageText,
         buttonText: options.auth.buttonText,
       };
 
       // Include optional image URL if it is specified.
@@ -393,34 +393,34 @@ var HomePanels = (function() {
         return true;
       }
     }
     return false;
   };
 
   let _assertPanelExists = function(id) {
     if (!(id in _registeredPanels)) {
-      throw "Home.panels: Panel doesn't exist: id = " + id;
+      throw new Error("Home.panels: Panel doesn't exist: id = " + id);
     }
   };
 
   return Object.freeze({
     Layout: Layout,
     View: View,
     Item: Item,
     ItemHandler: ItemHandler,
 
     register: function(id, optionsCallback) {
       // Bail if the panel already exists
       if (id in _registeredPanels) {
-        throw "Home.panels: Panel already exists: id = " + id;
+        throw new Error("Home.panels: Panel already exists: id = " + id);
       }
 
       if (!optionsCallback || typeof optionsCallback !== "function") {
-        throw "Home.panels: Panel callback must be a function: id = " + id;
+        throw new Error("Home.panels: Panel callback must be a function: id = " + id);
       }
 
       _registeredPanels[id] = optionsCallback;
     },
 
     unregister: function(id) {
       _assertPanelExists(id);
 
--- a/mobile/android/modules/Notifications.jsm
+++ b/mobile/android/modules/Notifications.jsm
@@ -17,34 +17,34 @@ function Notification(aId, aOptions) {
   this.fillWithOptions(aOptions);
 }
 
 Notification.prototype = {
   fillWithOptions: function(aOptions) {
     if ("icon" in aOptions && aOptions.icon != null)
       this._icon = aOptions.icon;
     else
-      throw "Notification icon is mandatory";
+      throw new Error("Notification icon is mandatory");
 
     if ("title" in aOptions && aOptions.title != null)
       this._title = aOptions.title;
     else
-      throw "Notification title is mandatory";
+      throw new Error("Notification title is mandatory");
 
     if ("message" in aOptions && aOptions.message != null)
       this._message = aOptions.message;
     else
       this._message = null;
 
     if ("priority" in aOptions && aOptions.priority != null)
       this._priority = aOptions.priority;
 
     if ("buttons" in aOptions && aOptions.buttons != null) {
       if (aOptions.buttons.length > 3)
-        throw "Too many buttons provided. The max number is 3";
+        throw new Error("Too many buttons provided. The max number is 3");
 
       this._buttons = {};
       for (let i = 0; i < aOptions.buttons.length; i++) {
         let button_id = aOptions.buttons[i].buttonId;
         this._buttons[button_id] = aOptions.buttons[i];
       }
     } else {
       this._buttons = null;
@@ -179,17 +179,17 @@ var Notifications = {
     notification.show();
 
     return id;
   },
 
   update: function notif_update(aId, aOptions) {
     let notification = _notificationsMap[aId];
     if (!notification)
-      throw "Unknown notification id";
+      throw new Error("Unknown notification id");
     notification.fillWithOptions(aOptions);
     notification.show();
   },
 
   cancel: function notif_cancel(aId) {
     let notification = _notificationsMap[aId];
     if (notification)
       notification.cancel();
--- a/mobile/android/modules/PageActions.jsm
+++ b/mobile/android/modules/PageActions.jsm
@@ -13,17 +13,17 @@ XPCOMUtils.defineLazyServiceGetter(this,
                                    "nsIUUIDGenerator");
 
 var EXPORTED_SYMBOLS = ["PageActions"];
 
 // Copied from browser.js
 // TODO: We should move this method to a common importable location
 function resolveGeckoURI(aURI) {
   if (!aURI)
-    throw "Can't resolve an empty uri";
+    throw new Error("Can't resolve an empty uri");
 
   if (aURI.startsWith("chrome://")) {
     let registry = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIChromeRegistry);
     return registry.convertChromeURL(Services.io.newURI(aURI)).spec;
   } else if (aURI.startsWith("resource://")) {
     let handler = Services.io.getProtocolHandler("resource").QueryInterface(Ci.nsIResProtocolHandler);
     return handler.resolveURI(Services.io.newURI(aURI));
   }
--- a/mobile/android/modules/SharedPreferences.jsm
+++ b/mobile/android/modules/SharedPreferences.jsm
@@ -56,17 +56,17 @@ var SharedPreferences = {
  *   - profileName {String} (optional, only valid when using Scope.PROFILE)
  */
 function SharedPreferencesImpl(options = {}) {
   if (!(this instanceof SharedPreferencesImpl)) {
     return new SharedPreferencesImpl(options);
   }
 
   if (options.scope == null || options.scope == undefined) {
-    throw "Shared Preferences must specifiy a scope.";
+    throw new Error("Shared Preferences must specifiy a scope.");
   }
 
   this._scope = options.scope;
   this._profileName = options.profileName;
   this._branch = options.branch;
   this._observers = {};
 }
 
--- a/mobile/android/modules/WebrtcUI.jsm
+++ b/mobile/android/modules/WebrtcUI.jsm
@@ -111,17 +111,17 @@ var WebrtcUI = {
       } else if (cameraActive) {
         notificationOptions.message = Strings.browser.GetStringFromName("getUserMedia.sharingCamera.message2");
         notificationOptions.icon = "drawable:alert_camera";
       } else if (audioActive) {
         notificationOptions.message = Strings.browser.GetStringFromName("getUserMedia.sharingMicrophone.message2");
         notificationOptions.icon = "drawable:alert_mic";
       } else {
         // somethings wrong. lets throw
-        throw "Couldn't find any cameras or microphones being used";
+        throw new Error("Couldn't find any cameras or microphones being used");
       }
 
       if (this._notificationId)
           Notifications.update(this._notificationId, notificationOptions);
       else
         this._notificationId = Notifications.create(notificationOptions);
       if (count > 1)
         msg.count = count;