Bug 1336214 - Use static lookup of errors; r?maja_zf draft
authorAndreas Tolfsen <ato@mozilla.com>
Fri, 10 Feb 2017 18:33:37 +0000
changeset 483019 a2f2016c9284aff30cf450dfa53939b46792fdd0
parent 483018 0b850460ec5d6cc38484432201bbceeb16bf81cf
child 483020 9617b5cb0bd2806f178b843f2e96fb42695c739c
child 483021 0045ef2da1a397f047cf2a9779f807e59a75fa48
push id45193
push userbmo:ato@mozilla.com
push dateMon, 13 Feb 2017 16:42:48 +0000
reviewersmaja_zf
bugs1336214
milestone54.0a1
Bug 1336214 - Use static lookup of errors; r?maja_zf To avoid errors from being needlessly constructed on starting the Marionette server, this changes testing/marionette/error.js to use a static lookup table for error status codes. This also provides some added security since individual custom errors may have specific constructor logic that would cause an error to throw an error if the correct arguments were not provided, and we cannot guarantee that we provide the right ones generically when loading in the error module. MozReview-Commit-ID: 1sejpNzsjJp
testing/marionette/error.js
--- a/testing/marionette/error.js
+++ b/testing/marionette/error.js
@@ -394,16 +394,31 @@ UnknownError.prototype = Object.create(W
 
 this.UnsupportedOperationError = function (msg) {
   WebDriverError.call(this, msg);
   this.name = "UnsupportedOperationError";
   this.status = "unsupported operation";
 };
 UnsupportedOperationError.prototype = Object.create(WebDriverError.prototype);
 
-const nameLookup = new Map();
-const statusLookup = new Map();
-for (let s of ERRORS) {
-  let cls = this[s];
-  let inst = new cls();
-  nameLookup.set(inst.name, cls);
-  statusLookup.set(inst.status, cls);
-};
+const STATUSES = new Map([
+  ["element not accessible", ElementNotAccessibleError],
+  ["element not visible", ElementNotVisibleError],
+  ["insecure certificate", InsecureCertificateError],
+  ["invalid argument", InvalidArgumentError],
+  ["invalid element state", InvalidElementStateError],
+  ["invalid selector", InvalidSelectorError],
+  ["invalid session id", InvalidSessionIDError],
+  ["javascript error", JavaScriptError],
+  ["no alert open", NoAlertOpenError],
+  ["no such element", NoSuchElementError],
+  ["no such frame", NoSuchFrameError],
+  ["no such window", NoSuchWindowError],
+  ["script timeout", ScriptTimeoutError],
+  ["session not created", SessionNotCreatedError],
+  ["stale element reference", StaleElementReferenceError],
+  ["timeout", TimeoutError],
+  ["unable to set cookie", UnableToSetCookieError],
+  ["unknown command", UnknownCommandError],
+  ["unknown error", UnknownError],
+  ["unsupported operation", UnsupportedOperationError],
+  ["webdriver error", WebDriverError],
+]);