Bug 1284232 - Convert internal error list to a set; r?automatedtester
MozReview-Commit-ID: THj6qxvUus
--- 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)) {