Bug 1336214 - Use static lookup of errors. r=maja_zf, a=test-only
authorAndreas Tolfsen <ato@mozilla.com>
Fri, 10 Feb 2017 18:33:37 +0000
changeset 376505 500e3282b566bfda4db95ab2526c10f8b2bdcff4
parent 376504 f3257085d3c4be6c83eb616d29f70b816638983e
child 376506 fd1a80b2522dae0c0aa61d0e7338ea79f9a9ac9a
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmaja_zf, test-only
Bug 1336214 - Use static lookup of errors. r=maja_zf, a=test-only 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
--- 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],