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 378789 500e3282b566bfda4db95ab2526c10f8b2bdcff4
parent 378788 f3257085d3c4be6c83eb616d29f70b816638983e
child 378790 fd1a80b2522dae0c0aa61d0e7338ea79f9a9ac9a
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmaja_zf, test-only
bugs1336214
milestone53.0a2
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
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],
+]);