Skip to content

Commit

Permalink
Bug 1555596 [wpt PR 17095] - Add structured clone tests for errors, a…
Browse files Browse the repository at this point in the history
…=testonly

Automatic update from web-platform-tests
Add structured clone tests for errors

This is tests for spec changes.
 - whatwg/html#4665
 - whatwg/webidl#732

--
Add tests for cloning from another realm

--
Test some stuff before cloning

--

wpt-commits: 1b4fbe0c7049d89fd805dc157f68d82616f5d203, efc79eef01ffa65273ff01736d989ff5fa79f18d, 84af6c875d378944b39d895acdcfc170736b2d3d
wpt-pr: 17095

UltraBlame original commit: 696cf52f476f2f644137d19d9b9c4ec4dc400731
  • Loading branch information
marco-c committed Oct 4, 2019
1 parent a3aeb2d commit 8247a37
Showing 1 changed file with 238 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</head>
<body>
<div id="log"></div>
<iframe></iframe>

<script type="text/javascript">
var worker;
Expand Down Expand Up @@ -367,7 +368,243 @@
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("URIError objects from other realms are treated as Error");
t.id = 35;
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 = frames[0].URIError("some message");
assert_equals(Object.getPrototypeOf(error), frames[0].prototype, "Checking prototype before cloning");
assert_equals(error.constructor, frames[0].URIError, "Checking constructor before cloning");
assert_equals(error.name, "URIError", "Checking name before cloning");
error.foo = "bar";
worker.postMessage(error);
});
},
function() {
var t = async_test("Cloning a modified Error");
t.id = 36;
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 = 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_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 = 38;
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 = 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.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 = 40;
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 8247a37

Please sign in to comment.