Bug 1245153 - error.isError must recognise built-in Error prototypes; r=automatedtester

Due to a previous programming error, error.isError only recognised
the base Error prototype.  It must also test for the other built-in
prototypes, such as TypeError et al.

--HG--
extra : commitid : F50Xhg2Q86e
extra : rebase_source : 3f757bf9667763718d54fcb6912156bcdcd9e787
extra : histedit_source : 77fd0e6b6471b18528c27954e6348f93fc520d64
This commit is contained in:
Andreas Tolfsen 2016-02-03 18:41:37 +00:00
Родитель 02246b8b4e
Коммит 1a77effa7d
2 изменённых файлов: 43 добавлений и 5 удалений

Просмотреть файл

@ -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);

Просмотреть файл

@ -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()));