Commit 21aefc6b authored by Ian Moody's avatar Ian Moody
Browse files

Bug 1539177 - netwerk/ automated ESLint no-throw-literal fixes. r=kershaw

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

--HG--
extra : moz-landing-system : lando
parent 17422d41
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ WellKnownOpportunisticUtils.prototype = {
      let obj = JSON.parse(aJSON.toLowerCase());
      let ports = obj[aOrigin.toLowerCase()]["tls-ports"];
      if (!ports.includes(aAlternatePort)) {
        throw "invalid port";
        throw new Error("invalid port");
      }
      this.lifetime = obj[aOrigin.toLowerCase()].lifetime;
      this.mixed = obj[aOrigin.toLowerCase()]["mixed-scheme"];
+3 −3
Original line number Diff line number Diff line
@@ -1593,7 +1593,7 @@ RequestReader.prototype =
    try {
      metadata._httpVersion = new nsHttpVersion(match[1]);
      if (!metadata._httpVersion.atLeast(nsHttpVersion.HTTP_1_0))
        throw "unsupported HTTP version";
        throw new Error("unsupported HTTP version");
    } catch (e) {
      // we support HTTP/1.0 and HTTP/1.1 only
      throw HTTP_501;
@@ -4431,7 +4431,7 @@ function htmlEscape(str) {
function nsHttpVersion(versionString) {
  var matches = /^(\d+)\.(\d+)$/.exec(versionString);
  if (!matches)
    throw "Not a valid HTTP version!";
    throw new Error("Not a valid HTTP version!");

  /** The major version number of this, as a number. */
  this.major = parseInt(matches[1], 10);
@@ -4441,7 +4441,7 @@ function nsHttpVersion(versionString) {

  if (isNaN(this.major) || isNaN(this.minor) ||
      this.major < 0 || this.minor < 0)
    throw "Not a valid HTTP version!";
    throw new Error("Not a valid HTTP version!");
}
nsHttpVersion.prototype =
{
+3 −3
Original line number Diff line number Diff line
@@ -351,15 +351,15 @@ function runHttpTests(testArray, done) {
 */
function RawTest(host, port, data, responseCheck) {
  if (0 > port || 65535 < port || port % 1 !== 0)
    throw "bad port";
    throw new Error("bad port");
  if (!(data instanceof Array))
    data = [data];
  if (data.length <= 0)
    throw "bad data length";
    throw new Error("bad data length");

  // eslint-disable-next-line no-control-regex
  if (!data.every(function(v) { return /^[\x00-\xff]*$/.test(v); }))
    throw "bad data contained non-byte-valued character";
    throw new Error("bad data contained non-byte-valued character");

  this.host = host;
  this.port = port;
+1 −1
Original line number Diff line number Diff line
@@ -71,6 +71,6 @@ function register400Handler(ch) {

// /throws/exception (and also a 404 and 400 error handler)
function throwsException(metadata, response) {
  throw "this shouldn't cause an exit...";
  throw new Error("this shouldn't cause an exit...");
  do_throw("Not reached!"); // eslint-disable-line no-unreachable
}
+3 −3
Original line number Diff line number Diff line
@@ -105,7 +105,7 @@ function testGetHeader() {

  try {
    headers.getHeader(":");
    throw "Failed to throw for invalid header";
    throw new Error("Failed to throw for invalid header");
  } catch (e) {
    if (e.result !== Cr.NS_ERROR_INVALID_ARG)
      do_throw("headers.getHeader(':') must throw invalid arg");
@@ -113,7 +113,7 @@ function testGetHeader() {

  try {
    headers.getHeader("valid");
    throw "header doesn't exist";
    throw new Error("header doesn't exist");
  } catch (e) {
    if (e.result !== Cr.NS_ERROR_NOT_AVAILABLE)
      do_throw("shouldn't be a header named 'valid' in headers!");
@@ -158,7 +158,7 @@ function testHasHeader() {

  try {
    headers.hasHeader(":");
    throw "failed to throw";
    throw new Error("failed to throw");
  } catch (e) {
    if (e.result !== Cr.NS_ERROR_INVALID_ARG)
      do_throw(".hasHeader for an invalid name should throw");
Loading