Bug 1284232 - Convert internal error list to a set; r?automatedtester draft
authorAndreas Tolfsen <ato@mozilla.com>
Fri, 08 Jul 2016 14:00:56 +0100
changeset 385463 c74b57859f12749904c44a326e3431744ef911fd
parent 385462 78a68e53c82d9e9d3477125a014c9ef888d43ca3
child 524936 972431d47b3de19f1eff27567708ce36eab2589f
push id22510
push userbmo:ato@mozilla.com
push dateFri, 08 Jul 2016 13:34:06 +0000
reviewersautomatedtester
bugs1284232
milestone50.0a1
Bug 1284232 - Convert internal error list to a set; r?automatedtester MozReview-Commit-ID: THj6qxvUus
testing/marionette/error.js
--- a/testing/marionette/error.js
+++ b/testing/marionette/error.js
@@ -1,17 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 const {interfaces: Ci, utils: Cu} = Components;
 
-const ERRORS = [
+const ERRORS = new Set([
   "ElementNotAccessibleError",
   "ElementNotVisibleError",
   "InvalidArgumentError",
   "InvalidElementStateError",
   "InvalidSelectorError",
   "InvalidSessionIdError",
   "JavaScriptError",
   "NoAlertOpenError",
@@ -22,30 +22,30 @@ const ERRORS = [
   "SessionNotCreatedError",
   "StaleElementReferenceError",
   "TimeoutError",
   "UnableToSetCookieError",
   "UnknownCommandError",
   "UnknownError",
   "UnsupportedOperationError",
   "WebDriverError",
-];
+]);
 
 const BUILTIN_ERRORS = new Set([
   "Error",
   "EvalError",
   "InternalError",
   "RangeError",
   "ReferenceError",
   "SyntaxError",
   "TypeError",
   "URIError",
 ]);
 
-this.EXPORTED_SYMBOLS = ["error"].concat(ERRORS);
+this.EXPORTED_SYMBOLS = ["error"].concat(Array.from(ERRORS));
 
 this.error = {};
 
 /**
  * Checks if obj is an instance of the Error prototype in a safe manner.
  * Prefer using this over using instanceof since the Error prototype
  * isn't unique across browsers, and XPCOM nsIException's are special
  * snowflakes.
@@ -71,17 +71,17 @@ error.isError = function(val) {
   }
 };
 
 /**
  * Checks if obj is an object in the WebDriverError prototypal chain.
  */
 error.isWebDriverError = function(obj) {
   return error.isError(obj) &&
-      ("name" in obj && ERRORS.indexOf(obj.name) >= 0);
+      ("name" in obj && ERRORS.has(obj.name));
 };
 
 /**
  * Wraps an Error prototype in a WebDriverError.  If the given error is
  * already a WebDriverError, this is effectively a no-op.
  */
 error.wrap = function(err) {
   if (error.isWebDriverError(err)) {