Commit 67fb55f3 authored by Ian Moody's avatar Ian Moody
Browse files

Bug 1536653 - browser/ automated ESLint no-throw-literal fixes. r=Gijs

Result of running:
$ mach eslint -funix browser/ | 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/D24110

--HG--
extra : moz-landing-system : lando
parent 4bb3237b
......@@ -272,7 +272,7 @@ class ContextMenuChild extends ActorChild {
if (!href || !href.match(/\S/)) {
// Without this we try to save as the current doc,
// for example, HTML case also throws if empty
throw "Empty href";
throw new Error("Empty href");
}
return this._makeURLAbsolute(this.context.link.baseURI, href);
......@@ -375,7 +375,7 @@ class ContextMenuChild extends ActorChild {
}
if (urls.length != 1) {
throw "found multiple URLs";
throw new Error("found multiple URLs");
}
return urls[0];
......
......@@ -5141,7 +5141,7 @@ var XULBrowserWindow = {
this._lastLocationForEvent = spec;
if (typeof(aIsSimulated) != "boolean" && typeof(aIsSimulated) != "undefined") {
throw "onContentBlockingEvent: aIsSimulated receieved an unexpected type";
throw new Error("onContentBlockingEvent: aIsSimulated receieved an unexpected type");
}
ContentBlocking.onContentBlockingEvent(this._event, aWebProgress, aIsSimulated);
......@@ -8393,7 +8393,7 @@ TabModalPromptBox.prototype = {
get browser() {
let browser = this._weakBrowserRef.get();
if (!browser) {
throw "Stale promptbox! The associated browser is gone.";
throw new Error("Stale promptbox! The associated browser is gone.");
}
return browser;
},
......
......@@ -24,7 +24,7 @@ function pageInfoTreeView(treeid, copycol) {
}
pageInfoTreeView.prototype = {
set rowCount(c) { throw "rowCount is a readonly property"; },
set rowCount(c) { throw new Error("rowCount is a readonly property"); },
get rowCount() { return this.rows; },
setTree(tree) {
......
......@@ -16,5 +16,5 @@ function test() {
}
}
throw "couldn't find the content window";
throw new Error("couldn't find the content window");
}
......@@ -61,7 +61,7 @@ add_task(async function() {
ok(checked, idstring + " should be selected");
break;
default:
throw "data-state attribute is missing or has invalid value";
throw new Error("data-state attribute is missing or has invalid value");
}
});
return contentValidLinks;
......
......@@ -151,7 +151,7 @@ function test() {
// From browser/base/content/test/general/bug792715.sjs, we should never send a
// cookie because we are making only 2 requests: one in public mode, and
// one in private mode.
throw "We should never send a cookie in this test";
throw new Error("We should never send a cookie in this test");
} catch (ex) {
if (ex.result == Cr.NS_ERROR_NOT_AVAILABLE) {
info("onModifyRequest caught NOTAVAIL" + ex);
......
......@@ -2069,7 +2069,7 @@ var CustomizableUIInternal = {
try {
gSavedState = JSON.parse(state);
if (typeof gSavedState != "object" || gSavedState === null) {
throw "Invalid saved state";
throw new Error("Invalid saved state");
}
} catch (e) {
Services.prefs.clearUserPref(kPrefCustomizationState);
......
......@@ -827,10 +827,10 @@ const PanelUI = {
let notificationEl = getNotificationFromElement(event.originalTarget);
if (!notificationEl)
throw "PanelUI._onNotificationButtonEvent: couldn't find notification element";
throw new Error("PanelUI._onNotificationButtonEvent: couldn't find notification element");
if (!notificationEl.notification)
throw "PanelUI._onNotificationButtonEvent: couldn't find notification";
throw new Error("PanelUI._onNotificationButtonEvent: couldn't find notification");
let notification = notificationEl.notification;
......@@ -844,7 +844,7 @@ const PanelUI = {
_onBannerItemSelected(event) {
let target = event.originalTarget;
if (!target.notification)
throw "menucommand target has no associated action/notification";
throw new Error("menucommand target has no associated action/notification");
event.stopPropagation();
AppMenuNotifications.callMainAction(window, target.notification, false);
......
......@@ -884,7 +884,7 @@ var Policies = {
try {
defaultEngine = Services.search.getEngineByName(param.Default);
if (!defaultEngine) {
throw "No engine by that name could be found";
throw new Error("No engine by that name could be found");
}
} catch (ex) {
log.error(`Search engine lookup failed when attempting to set ` +
......
......@@ -370,7 +370,7 @@ PlacesViewBase.prototype = {
this._domNodes.set(aPlacesNode, popup);
} else {
throw "Unexpected node";
throw new Error("Unexpected node");
}
element.setAttribute("label", PlacesUIUtils.getBestTitle(aPlacesNode));
......@@ -1028,7 +1028,7 @@ PlacesToolbar.prototype = {
this._onPopupHidden(aEvent);
break;
default:
throw "Trying to handle unexpected event.";
throw new Error("Trying to handle unexpected event.");
}
},
......@@ -1994,7 +1994,7 @@ this.PlacesPanelview = class extends PlacesViewBase {
element = document.createXULElement("toolbarseparator");
} else {
if (type != Ci.nsINavHistoryResultNode.RESULT_TYPE_URI)
throw "Unexpected node";
throw new Error("Unexpected node");
element = document.createXULElement("toolbarbutton");
element.classList.add("subviewbutton", "subviewbutton-iconic", "bookmark-item");
......
......@@ -758,7 +758,7 @@ var PlacesSearchBox = {
break;
}
default:
throw "Invalid filterCollection on search";
throw new Error("Invalid filterCollection on search");
}
// Update the details panel
......@@ -880,7 +880,7 @@ var PlacesQueryBuilder = {
filterCollection = "downloads";
break;
default:
throw "Invalid search scope";
throw new Error("Invalid search scope");
}
// Update the search box. Re-search if there's an active search.
......
......@@ -149,11 +149,11 @@ let gContainersManager = {
let name = document.getElementById("name").value;
if (!this.icons.includes(icon)) {
throw "Internal error. The icon value doesn't match.";
throw new Error("Internal error. The icon value doesn't match.");
}
if (!this.colors.includes(color)) {
throw "Internal error. The color value doesn't match.";
throw new Error("Internal error. The color value doesn't match.");
}
if (this.userContextId) {
......
......@@ -2444,7 +2444,7 @@ var gMainPane = {
let downloadsDir = await Downloads.getSystemDownloadsDirectory();
return new FileUtils.File(downloadsDir);
}
throw "ASSERTION FAILED: folder type should be 'Desktop' or 'Downloads'";
throw new Error("ASSERTION FAILED: folder type should be 'Desktop' or 'Downloads'");
},
/**
......
......@@ -31,7 +31,7 @@ var gCategoryInits = new Map();
function init_category_if_required(category) {
let categoryInfo = gCategoryInits.get(category);
if (!categoryInfo) {
throw "Unknown in-content prefs category! Can't init " + category;
throw new Error("Unknown in-content prefs category! Can't init " + category);
}
if (categoryInfo.inited) {
return null;
......
......@@ -220,7 +220,7 @@ var gPermissionManager = {
let uri = Services.io.newURI(input_url);
let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
if (principal.origin.startsWith("moz-nullprincipal:")) {
throw "Null principal";
throw new Error("Null principal");
}
principals.push(principal);
} catch (ex) {
......
......@@ -43,7 +43,7 @@ async function withHttpServer(details = { scheme: "http", host: "localhost", por
details.port = server.identity.primaryPort;
server.identity.setPrimary(details.scheme, details.host, details.port);
} catch (ex) {
throw ("We can't launch our http server successfully. " + ex);
throw new Error("We can't launch our http server successfully. " + ex);
}
Assert.ok(server.identity.has(details.scheme, details.host, details.port),
`${url} is listening.`);
......
......@@ -164,7 +164,7 @@ this.FirefoxMonitor = {
} else {
// Something is very strange if we reach this line, so we throw
// in order to prevent init from completing and burst the stack.
throw "Cannot find fxmonitor chrome.manifest for registering translated strings";
throw new Error("Cannot find fxmonitor chrome.manifest for registering translated strings");
}
},
......
......@@ -223,7 +223,7 @@ var Sanitizer = {
startDate = endDate - 86400000000; // 24*60*60*1000000
break;
default:
throw "Invalid time span for clear private data: " + ts;
throw new Error("Invalid time span for clear private data: " + ts);
}
return [startDate, endDate];
},
......
......@@ -521,7 +521,7 @@ var SitePermissions = {
}
if (state == this.ALLOW_COOKIES_FOR_SESSION && permissionID != "cookie") {
throw "ALLOW_COOKIES_FOR_SESSION can only be set on the cookie permission";
throw new Error("ALLOW_COOKIES_FOR_SESSION can only be set on the cookie permission");
}
// Save temporary permissions.
......@@ -535,11 +535,11 @@ var SitePermissions = {
// a more fine-grained TemporaryPermissions that temporarily blocks for the
// entire browser, but temporarily allows only for specific frames.
if (state != this.BLOCK) {
throw "'Block' is the only permission we can save temporarily on a browser";
throw new Error("'Block' is the only permission we can save temporarily on a browser");
}
if (!browser) {
throw "TEMPORARY scoped permissions require a browser object";
throw new Error("TEMPORARY scoped permissions require a browser object");
}
TemporaryPermissions.set(browser, permissionID, state);
......
......@@ -223,7 +223,7 @@ var TestRunner = {
**/
_findBoundingBox(selectors, windowType) {
if (!selectors.length) {
throw "No selectors specified.";
throw new Error("No selectors specified.");
}
// Set window type, default "navigator:browser"
......@@ -253,7 +253,7 @@ var TestRunner = {
}
if (!element) {
throw `No element for '${selector}' found.`;
throw new Error(`No element for '${selector}' found.`);
}
// Calculate box region, convert to Rect
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment