Bug 1537776 - dom/ automated ESLint no-throw-literal fixes. r=asuth,mccr8

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ian Moody 2019-03-25 16:03:38 +00:00
Родитель 3e2a03dd32
Коммит fe4fab15e3
13 изменённых файлов: 41 добавлений и 41 удалений

Просмотреть файл

@ -26,9 +26,9 @@ var f2Main = f2(this, null, i32.buffer);
if (this.jsFuns)
ok(jsFuns.isAsmJSFunction(f2Main), "f2.main is an asm.js function");
if (f2Main(4) !== 6)
throw "f2Main(4)";
throw new Error("f2Main(4)");
if (f2Main(100) !== 4950)
throw "f2.main(100)";
throw new Error("f2.main(100)");
var sum = (((i32.length - 1) * i32.length) / 2);
if (f2Main(i32.length) !== sum)
throw "f2.main(" + i32.length + ")";
@ -70,7 +70,7 @@ if (this.jsFuns)
begin = Date.now();
lastSum = 0;
if (f3Main() !== lastSum)
throw "f3.main()";
throw new Error("f3.main()");
if (!this.jsFuns)
postMessage("ok");

Просмотреть файл

@ -48,7 +48,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=929236
SimpleTest.finish();
break;
default:
throw "huh?";
throw new Error("huh?");
}
}

Просмотреть файл

@ -53,7 +53,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=944821
finishedCount++;
if (finishedCount < 1 || finishedCount > 2 * N) {
throw "Huh?!";
throw new Error("Huh?!");
} else if (finishedCount == N) {
for (let i = 0; i < N; i++)
evalAsync(codes[i]);

Просмотреть файл

@ -56,7 +56,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=941830
document.body.appendChild(script);
break;
default:
throw "Huh?";
throw new Error("Huh?");
}
};

Просмотреть файл

@ -54,30 +54,30 @@ async function testCreateTonsOfFD() {
try {
cached_response_array = await Promise.all(promise_array);
} catch (e) {
throw ("Fail to open tons of files with error: " + e);
throw new Error("Fail to open tons of files with error: " + e);
}
if (cached_response_array.length != number_of_fd) {
throw ("Fail to cache.match the cached responses");
throw new Error("Fail to cache.match the cached responses");
}
info("Stage C: Consume the cached body");
for (let i = 0; i < number_of_fd; ++i) {
if (!cached_response_array[i]) {
// Reduce the checking message.
throw ("The cached response doesn't exist");
throw new Error("The cached response doesn't exist");
}
let bodyText = "";
try {
bodyText = await cached_response_array[i].text();
} catch (e) {
throw ("Fail to consume the cached response's body with error: " + e);
throw new Error("Fail to consume the cached response's body with error: " + e);
}
if (bodyText != body) {
// Reduce the checking message.
throw ("The cached body doeen't be the same as original one");
throw new Error("The cached body doeen't be the same as original one");
}
}

Просмотреть файл

@ -49,7 +49,7 @@ TestArray.addTest(
var that = this;
var alg = {
get name() {
throw "Oh no, no name!";
throw new Error("Oh no, no name!");
},
};
@ -70,14 +70,14 @@ TestArray.addTest(
function doExport(x) {
if (!hasKeyFields(x)) {
throw "Invalid key; missing field(s)";
throw new Error("Invalid key; missing field(s)");
} else if ((x.algorithm.name != alg) ||
(x.algorithm.length != 8 * tv.raw.length) ||
(x.type != "secret") ||
(!x.extractable) ||
(x.usages.length != 1) ||
(x.usages[0] != "encrypt")) {
throw "Invalid key: incorrect key data";
throw new Error("Invalid key: incorrect key data");
}
return crypto.subtle.exportKey("raw", x);
}
@ -136,7 +136,7 @@ TestArray.addTest(
function doExport(x) {
if (!hasKeyFields(x)) {
throw "Invalid key; missing field(s)";
throw new Error("Invalid key; missing field(s)");
} else if ((x.algorithm.name != alg.name) ||
(x.algorithm.hash.name != alg.hash) ||
(x.algorithm.modulusLength != 512) ||
@ -145,7 +145,7 @@ TestArray.addTest(
(!x.extractable) ||
(x.usages.length != 1) ||
(x.usages[0] != "sign")) {
throw "Invalid key: incorrect key data";
throw new Error("Invalid key: incorrect key data");
}
return crypto.subtle.exportKey("pkcs8", x);
}
@ -183,7 +183,7 @@ TestArray.addTest(
function doExport(x) {
if (!hasKeyFields(x)) {
throw "Invalid key; missing field(s)";
throw new Error("Invalid key; missing field(s)");
} else if ((x.algorithm.name != alg.name) ||
(x.algorithm.modulusLength != 1024) ||
(x.algorithm.publicExponent.byteLength != 3) ||
@ -191,7 +191,7 @@ TestArray.addTest(
(!x.extractable) ||
(x.usages.length != 1) ||
(x.usages[0] != "verify")) {
throw "Invalid key: incorrect key data";
throw new Error("Invalid key: incorrect key data");
}
return crypto.subtle.exportKey("spki", x);
}

Просмотреть файл

@ -72,7 +72,7 @@ TestArray.addTest(
.then(function(x) {
// Deriving less bytes works.
if (x.byteLength != 2) {
throw "should have derived two bytes";
throw new Error("should have derived two bytes");
}
})
// Deriving more than the curve yields doesn't.
@ -257,7 +257,7 @@ TestArray.addTest(
(tp.crv != x.crv) &&
(tp.x != x.x) &&
(tp.y != x.y)) {
throw "exported public key doesn't match";
throw new Error("exported public key doesn't match");
}
}, error(that))
.then(doExportPriv, error(that))
@ -341,12 +341,12 @@ TestArray.addTest(
return crypto.subtle.deriveKey({ name: "ECDH", public: pubKey }, privKey, algDerived, false, ["sign", "verify"])
.then(function(x) {
if (!hasKeyFields(x)) {
throw "Invalid key; missing field(s)";
throw new Error("Invalid key; missing field(s)");
}
// 512 bit is the default for HMAC-SHA1.
if (x.algorithm.length != 512) {
throw "Invalid key; incorrect length";
throw new Error("Invalid key; incorrect length");
}
return x;
@ -395,7 +395,7 @@ TestArray.addTest(
return derived.then(function(x) {
if (!util.memcmp(x, tv.ecdh_p256.spki)) {
throw "exported key is invalid";
throw new Error("exported key is invalid");
}
if (keys.length) {

Просмотреть файл

@ -73,7 +73,7 @@ TestArray.addTest(
function doDerive(x) {
if (!hasKeyFields(x)) {
throw "Invalid key; missing field(s)";
throw new Error("Invalid key; missing field(s)");
}
var algo = {
@ -101,7 +101,7 @@ TestArray.addTest(
function doDerive(x) {
if (!hasKeyFields(x)) {
throw "Invalid key; missing field(s)";
throw new Error("Invalid key; missing field(s)");
}
var algo = {
@ -130,7 +130,7 @@ TestArray.addTest(
function doDerive(x) {
if (!hasKeyFields(x)) {
throw "Invalid key; missing field(s)";
throw new Error("Invalid key; missing field(s)");
}
var algo = {
@ -148,11 +148,11 @@ TestArray.addTest(
return crypto.subtle.deriveKey(algo, x, algDerived, false, ["sign", "verify"])
.then(function(y) {
if (!hasKeyFields(y)) {
throw "Invalid key; missing field(s)";
throw new Error("Invalid key; missing field(s)");
}
if (y.algorithm.length != 512) {
throw "Invalid key; incorrect length";
throw new Error("Invalid key; incorrect length");
}
return y;
@ -214,7 +214,7 @@ TestArray.addTest(
function doDerive(x) {
if (!hasKeyFields(x)) {
throw "Invalid key; missing field(s)";
throw new Error("Invalid key; missing field(s)");
}
var algo = {
@ -243,7 +243,7 @@ TestArray.addTest(
function doDerive(x) {
if (!hasKeyFields(x)) {
throw "Invalid key; missing field(s)";
throw new Error("Invalid key; missing field(s)");
}
var algo = {
@ -272,7 +272,7 @@ TestArray.addTest(
function doDerive(x) {
if (!hasKeyFields(x)) {
throw "Invalid key; missing field(s)";
throw new Error("Invalid key; missing field(s)");
}
var deriveAlg = {

Просмотреть файл

@ -62,7 +62,7 @@
let transaction = request.transaction;
transaction.oncomplete = unexpectedSuccessHandler;
transaction.onabort = grabEventAndContinueHandler;
throw "STOP";
throw new Error("STOP");
};
let event = yield undefined;
@ -106,7 +106,7 @@
request = objectStore.add({}, 1);
request.onsuccess = function(event) {
throw "foo";
throw new Error("foo");
};
event = yield undefined;
@ -155,7 +155,7 @@
request.onsuccess = unexpectedSuccessHandler;
request.onerror = function(event) {
event.preventDefault();
throw "STOP";
throw new Error("STOP");
};
event = yield undefined;

Просмотреть файл

@ -45,7 +45,7 @@
function dummyWorkerScript() {
/* eslint-env worker */
onmessage = function(event) {
throw ("Shouldn't be called!");
throw new Error("Shouldn't be called!");
};
}

Просмотреть файл

@ -188,22 +188,22 @@ function compareKeys(k1, k2) {
function addPermission(permission, url)
{
throw "addPermission";
throw new Error("addPermission");
}
function removePermission(permission, url)
{
throw "removePermission";
throw new Error("removePermission");
}
function allowIndexedDB(url)
{
throw "allowIndexedDB";
throw new Error("allowIndexedDB");
}
function disallowIndexedDB(url)
{
throw "disallowIndexedDB";
throw new Error("disallowIndexedDB");
}
function enableExperimental()

Просмотреть файл

@ -115,7 +115,7 @@ async function testSteps() {
}
default: {
throw ("Unknown type: " + type);
throw new Error("Unknown type: " + type);
}
}

Просмотреть файл

@ -55,7 +55,7 @@ function nativeVerticalWheelEventMsg() {
case "mac": return 0; // value is unused, can be anything
case "linux": return 4; // value is unused, pass GDK_SCROLL_SMOOTH anyway
}
throw "Native wheel events not supported on platform " + getPlatform();
throw new Error("Native wheel events not supported on platform " + getPlatform());
}
/**