Skip to content

Commit

Permalink
Add structured clone tests for errors
Browse files Browse the repository at this point in the history
This is tests for spec changes.
 - whatwg/html#4665
 - whatwg/webidl#732
  • Loading branch information
yutakahirano authored and natechapin committed Aug 23, 2019
1 parent 6232022 commit 7b44ad5
Showing 1 changed file with 218 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,224 @@
assert_throws('DATA_CLONE_ERR', function() {worker.postMessage(document)});
});
t.done();
}
},
function() {
var t = async_test("Empty Error objects can be cloned");
t.id = 27;
worker.onmessage = t.step_func_done(function(e) {
assert_equals(Object.getPrototypeOf(e.data), Error.prototype, "Checking prototype");
assert_equals(e.data.constructor, Error, "Checking constructor");
assert_equals(e.data.name, "Error", "Checking name");
assert_false(e.data.hasOwnProperty("message"), "Checking message");
assert_equals(e.data.foo, undefined, "Checking custom property");
});
t.step(function() {
const error = Error();
assert_false(error.hasOwnProperty("message"), "Checking message on the source realm");
worker.postMessage(error);
});
},
function() {
var t = async_test("Error objects can be cloned");
t.id = 28;
worker.onmessage = t.step_func_done(function(e) {
assert_equals(Object.getPrototypeOf(e.data), Error.prototype, "Checking prototype");
assert_equals(e.data.constructor, Error, "Checking constructor");
assert_equals(e.data.name, "Error", "Checking name");
assert_equals(e.data.message, "some message", "Checking message");
assert_equals(e.data.foo, undefined, "Checking custom property");
});
t.step(function() {
const error = Error("some message");
error.foo = "bar";
worker.postMessage(error);
});
},
function() {
var t = async_test("EvalError objects can be cloned");
t.id = 29;
worker.onmessage = t.step_func_done(function(e) {
assert_equals(Object.getPrototypeOf(e.data), EvalError.prototype, "Checking prototype");
assert_equals(e.data.constructor, EvalError, "Checking constructor");
assert_equals(e.data.name, "EvalError", "Checking name");
assert_equals(e.data.message, "some message", "Checking message");
assert_equals(e.data.foo, undefined, "Checking custom property");
});
t.step(function() {
const error = EvalError("some message");
error.foo = "bar";
worker.postMessage(error);
});
},
function() {
var t = async_test("RangeError objects can be cloned");
t.id = 30;
worker.onmessage = t.step_func_done(function(e) {
assert_equals(Object.getPrototypeOf(e.data), RangeError.prototype, "Checking prototype");
assert_equals(e.data.constructor, RangeError, "Checking constructor");
assert_equals(e.data.name, "RangeError", "Checking name");
assert_equals(e.data.message, "some message", "Checking message");
assert_equals(e.data.foo, undefined, "Checking custom property");
});
t.step(function() {
const error = RangeError("some message");
error.foo = "bar";
worker.postMessage(error);
});
},
function() {
var t = async_test("ReferenceError objects can be cloned");
t.id = 31;
worker.onmessage = t.step_func_done(function(e) {
assert_equals(Object.getPrototypeOf(e.data), ReferenceError.prototype, "Checking prototype");
assert_equals(e.data.constructor, ReferenceError, "Checking constructor");
assert_equals(e.data.name, "ReferenceError", "Checking name");
assert_equals(e.data.message, "some message", "Checking message");
assert_equals(e.data.foo, undefined, "Checking custom property");
});
t.step(function() {
const error = ReferenceError("some message");
error.foo = "bar";
worker.postMessage(error);
});
},
function() {
var t = async_test("SyntaxError objects can be cloned");
t.id = 32;
worker.onmessage = t.step_func_done(function(e) {
assert_equals(Object.getPrototypeOf(e.data), SyntaxError.prototype, "Checking prototype");
assert_equals(e.data.constructor, SyntaxError, "Checking constructor");
assert_equals(e.data.name, "SyntaxError", "Checking name");
assert_equals(e.data.message, "some message", "Checking message");
assert_equals(e.data.foo, undefined, "Checking custom property");
});
t.step(function() {
const error = SyntaxError("some message");
error.foo = "bar";
worker.postMessage(error);
});
},
function() {
var t = async_test("TypeError objects can be cloned");
t.id = 33;
worker.onmessage = t.step_func_done(function(e) {
assert_equals(Object.getPrototypeOf(e.data), TypeError.prototype, "Checking prototype");
assert_equals(e.data.constructor, TypeError, "Checking constructor");
assert_equals(e.data.name, "TypeError", "Checking name");
assert_equals(e.data.message, "some message", "Checking message");
assert_equals(e.data.foo, undefined, "Checking custom property");
});
t.step(function() {
const error = TypeError("some message");
error.foo = "bar";
worker.postMessage(error);
});
},
function() {
var t = async_test("URIError objects can be cloned");
t.id = 34;
worker.onmessage = t.step_func_done(function(e) {
assert_equals(Object.getPrototypeOf(e.data), URIError.prototype, "Checking prototype");
assert_equals(e.data.constructor, URIError, "Checking constructor");
assert_equals(e.data.name, "URIError", "Checking name");
assert_equals(e.data.message, "some message", "Checking message");
assert_equals(e.data.foo, undefined, "Checking custom property");
});
t.step(function() {
const error = URIError("some message");
error.foo = "bar";
worker.postMessage(error);
});
},
function() {
var t = async_test("Cloning a modified Error");
t.id = 35;
worker.onmessage = t.step_func_done(function(e) {
assert_equals(Object.getPrototypeOf(e.data), SyntaxError.prototype, "Checking prototype");
assert_equals(e.data.constructor, SyntaxError, "Checking constructor");
assert_equals(e.data.name, "SyntaxError", "Checking name");
assert_equals(e.data.message, "another message", "Checking message");
assert_equals(e.data.foo, undefined, "Checking custom property");
});
t.step(function() {
const error = URIError("some message");
Object.setPrototypeOf(error, SyntaxError.prototype);
error.message = {toString: () => "another message" }
error.constructor = RangeError;
error.name = "TypeError";
error.foo = "bar";
worker.postMessage(error);
});
},
function() {
var t = async_test("Error.message: getter is ignored when cloning");
t.id = 36;
worker.onmessage = t.step_func_done(function(e) {
assert_equals(Object.getPrototypeOf(e.data), Error.prototype, "Checking prototype");
assert_equals(e.data.constructor, Error, "Checking constructor");
assert_equals(e.data.name, "Error", "Checking name");
assert_false(e.data.hasOwnProperty("message"), "Checking message");
assert_equals(e.data.foo, undefined, "Checking custom property");
});
t.step(function() {
const error = Error();
Object.defineProperty(error, "message", { get: () => "hello" });
assert_equals(error.message, "hello", "Checking message on the source realm");
worker.postMessage(error);
});
},
function() {
var t = async_test("Error.message: undefined property is stringified");
t.id = 37;
worker.onmessage = t.step_func_done(function(e) {
assert_equals(Object.getPrototypeOf(e.data), Error.prototype, "Checking prototype");
assert_equals(e.data.constructor, Error, "Checking constructor");
assert_equals(e.data.name, "Error", "Checking name");
assert_equals(e.data.message, "undefined", "Checking message");
assert_equals(e.data.foo, undefined, "Checking custom property");
});
t.step(function() {
const error = Error();
error.message = undefined;
assert_equals(error.message, undefined, "Checking message on the source realm");
worker.postMessage(error);
});
},
function() {
var t = async_test("DOMException objects can be cloned");
t.id = 38;
worker.onmessage = t.step_func_done(function(e) {
assert_equals(Object.getPrototypeOf(e.data), DOMException.prototype, "Checking prototype");
assert_equals(e.data.constructor, DOMException, "Checking constructor");
assert_equals(e.data.name, "IndexSizeError", "Checking name");
assert_equals(e.data.message, "some message", "Checking message");
assert_equals(e.data.code, DOMException.INDEX_SIZE_ERR, "Checking code");
assert_equals(e.data.foo, undefined, "Checking custom property");
});
t.step(function() {
const error = new DOMException("some message", "IndexSizeError");
worker.postMessage(error);
});
},
function() {
var t = async_test("DOMException objects created by the UA can be cloned");
t.id = 39;
worker.onmessage = t.step_func_done(function(e) {
assert_equals(Object.getPrototypeOf(e.data), DOMException.prototype, "Checking prototype");
assert_equals(e.data.constructor, DOMException, "Checking constructor");
assert_equals(e.data.code, DOMException.DATA_CLONE_ERR, "Checking code");
assert_equals(e.data.name, "DataCloneError", "Checking name");
});
t.step(function() {
try {
worker.postMessage(window);
} catch (error) {
worker.postMessage(error);
return;
}
assert_unreached("Window must not be clonable");
});
},
];
}, {explicit_done:true});

Expand Down

0 comments on commit 7b44ad5

Please sign in to comment.