diff --git a/testing/marionette/error.js b/testing/marionette/error.js index fb00c40b2b19..66f9f6128810 100644 --- a/testing/marionette/error.js +++ b/testing/marionette/error.js @@ -6,7 +6,7 @@ const {interfaces: Ci, utils: Cu} = Components; -const errors = [ +const ERRORS = [ "ElementNotAccessibleError", "ElementNotVisibleError", "InvalidArgumentError", @@ -29,10 +29,21 @@ const errors = [ "WebDriverError", ]; -this.EXPORTED_SYMBOLS = ["error"].concat(errors); +this.EXPORTED_SYMBOLS = ["error"].concat(ERRORS); this.error = {}; +error.BuiltinErrors = { + Error: 0, + EvalError: 1, + InternalError: 2, + RangeError: 3, + ReferenceError: 4, + SyntaxError: 5, + TypeError: 6, + URIError: 7, +}; + /** * Checks if obj is an instance of the Error prototype in a safe manner. * Prefer using this over using instanceof since the Error prototype @@ -50,7 +61,7 @@ error.isError = function(val) { } else if (val instanceof Ci.nsIException) { return true; } else { - return Object.getPrototypeOf(val) == "Error"; + return Object.getPrototypeOf(val) in error.BuiltinErrors; } }; @@ -59,7 +70,7 @@ error.isError = function(val) { */ error.isWebDriverError = function(obj) { return error.isError(obj) && - ("name" in obj && errors.indexOf(obj.name) >= 0); + ("name" in obj && ERRORS.indexOf(obj.name) >= 0); }; /** @@ -328,7 +339,7 @@ UnsupportedOperationError.prototype = Object.create(WebDriverError.prototype); const nameLookup = new Map(); const statusLookup = new Map(); -for (let s of errors) { +for (let s of ERRORS) { let cls = this[s]; let inst = new cls(); nameLookup.set(inst.name, cls); diff --git a/testing/marionette/test_error.js b/testing/marionette/test_error.js index 2ee7c18996bd..9b65d6242bf1 100644 --- a/testing/marionette/test_error.js +++ b/testing/marionette/test_error.js @@ -14,6 +14,19 @@ function notok(condition) { ok(!(condition)); } +add_test(function test_BuiltinErrors() { + ok("Error" in error.BuiltinErrors); + ok("EvalError" in error.BuiltinErrors); + ok("InternalError" in error.BuiltinErrors); + ok("RangeError" in error.BuiltinErrors); + ok("ReferenceError" in error.BuiltinErrors); + ok("SyntaxError" in error.BuiltinErrors); + ok("TypeError" in error.BuiltinErrors); + ok("URIError" in error.BuiltinErrors); + + run_next_test(); +}); + add_test(function test_isError() { notok(error.isError(null)); notok(error.isError([])); @@ -21,6 +34,13 @@ add_test(function test_isError() { ok(error.isError(new Components.Exception())); ok(error.isError(new Error())); + ok(error.isError(new EvalError())); + ok(error.isError(new InternalError())); + ok(error.isError(new RangeError())); + ok(error.isError(new ReferenceError())); + ok(error.isError(new SyntaxError())); + ok(error.isError(new TypeError())); + ok(error.isError(new URIError())); ok(error.isError(new WebDriverError())); ok(error.isError(new InvalidArgumentError())); @@ -30,6 +50,13 @@ add_test(function test_isError() { add_test(function test_isWebDriverError() { notok(error.isWebDriverError(new Components.Exception())); notok(error.isWebDriverError(new Error())); + notok(error.isWebDriverError(new EvalError())); + notok(error.isWebDriverError(new InternalError())); + notok(error.isWebDriverError(new RangeError())); + notok(error.isWebDriverError(new ReferenceError())); + notok(error.isWebDriverError(new SyntaxError())); + notok(error.isWebDriverError(new TypeError())); + notok(error.isWebDriverError(new URIError())); ok(error.isWebDriverError(new WebDriverError())); ok(error.isWebDriverError(new InvalidArgumentError()));