mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 10:00:54 +00: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 --HG-- extra : histedit_source : c35a686b6b9cea4ae50d0d63223f4cdde6f6e4a2 extra : rebase_source : 4aad87845982cc81fec375ae9f63223a58003aec extra : commitid : 825ScXhXQSy extra : source : 1f5e37f8e44641e5434d8393f307f2ea4e80cdc6 extra : intermediate-source : dc6460e0f336c151be27bd124935b52361ea9557
This commit is contained in:
parent
4b2e6ac6c6
commit
993e7e8a4e
@ -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