mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1245153 - Add error.wrap to wrap Error prototypes; r=automatedtester
Generally, Error prototypes that are not based on WebDriverError must be wrapped so that they can be serialised across the AsyncMessageChannel. MozReview-Commit-ID: EtkpEOBhrST
This commit is contained in:
parent
735298b4f8
commit
0be76c7b3b
@ -73,6 +73,17 @@ error.isWebDriverError = function(obj) {
|
||||
("name" in obj && ERRORS.indexOf(obj.name) >= 0);
|
||||
};
|
||||
|
||||
/**
|
||||
* Wraps an Error prototype in a WebDriverError. If the given error is
|
||||
* already a WebDriverError, this is effectively a no-op.
|
||||
*/
|
||||
error.wrap = function(err) {
|
||||
if (error.isWebDriverError(err)) {
|
||||
return err;
|
||||
}
|
||||
return new WebDriverError(`${err.name}: ${err.message}`, err.stack);
|
||||
};
|
||||
|
||||
/**
|
||||
* Unhandled error reporter. Dumps the error and its stacktrace to console,
|
||||
* and reports error to the Browser Console.
|
||||
@ -151,11 +162,12 @@ error.fromJson = function(json) {
|
||||
* It should not be used directly, as it does not correspond to a real
|
||||
* error in the specification.
|
||||
*/
|
||||
this.WebDriverError = function(msg) {
|
||||
this.WebDriverError = function(msg, stack = undefined) {
|
||||
Error.call(this, msg);
|
||||
this.name = "WebDriverError";
|
||||
this.message = msg;
|
||||
this.status = "webdriver error";
|
||||
this.stack = stack;
|
||||
};
|
||||
WebDriverError.prototype = Object.create(Error.prototype);
|
||||
|
||||
|
@ -64,6 +64,21 @@ add_test(function test_isWebDriverError() {
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
add_test(function test_wrap() {
|
||||
equal(error.wrap(new WebDriverError()).name, "WebDriverError");
|
||||
equal(error.wrap(new InvalidArgumentError()).name, "InvalidArgumentError");
|
||||
equal(error.wrap(new Error()).name, "WebDriverError");
|
||||
equal(error.wrap(new EvalError()).name, "WebDriverError");
|
||||
equal(error.wrap(new InternalError()).name, "WebDriverError");
|
||||
equal(error.wrap(new RangeError()).name, "WebDriverError");
|
||||
equal(error.wrap(new ReferenceError()).name, "WebDriverError");
|
||||
equal(error.wrap(new SyntaxError()).name, "WebDriverError");
|
||||
equal(error.wrap(new TypeError()).name, "WebDriverError");
|
||||
equal(error.wrap(new URIError()).name, "WebDriverError");
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
add_test(function test_stringify() {
|
||||
equal("<unprintable error>", error.stringify());
|
||||
equal("<unprintable error>", error.stringify("foo"));
|
||||
|
Loading…
Reference in New Issue
Block a user