Skip to content

Commit

Permalink
Bug 1603802 [wpt PR 20771] - Add/update tests for cross-realm Error s…
Browse files Browse the repository at this point in the history
…erialization, a=testonly

Automatic update from web-platform-tests
Add/update tests for cross-realm Error serialization

Follows whatwg/html#5150.
--

wpt-commits: 9882946dd9fcf7251387c2bfc778331b7ae85846
wpt-pr: 20771
  • Loading branch information
domenic authored and moz-wptsync-bot committed Jan 9, 2020
1 parent 37adf8e commit c972c20
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Helper that posts its parent a TypeError</title>

<script>
window.doIt = () => {
parent.postMessage(new TypeError("!!"), "*");
};
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Structured cloning of Error objects: extra tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<!-- Most tests are in the general framework in structuredclone_0.html.
This contains specialty tests that don't fit into that framework. -->

<body>

<script>
"use strict";
test(t => {
const exceptionToThrow = new Error("throw me!");

const badError = new Error();
Object.defineProperty(badError, "name", { get() { throw exceptionToThrow; } });

const worker = new Worker("./resources/echo-worker.js");
t.add_cleanup(() => worker.terminate());

assert_throws_exactly(exceptionToThrow, () => {
worker.postMessage(badError);
});
}, "Throwing name getter fails serialization");

// https://bugs.chromium.org/p/chromium/issues/detail?id=1030086
// https://github.com/whatwg/html/pull/5150
async_test(t => {
window.onmessage = t.step_func_done(e => {
assert_equals(e.data.name, "TypeError");
});

const iframe = document.createElement("iframe");
iframe.onload = () => {
if (iframe.contentWindow.location === "about:blank") {
return;
}

iframe.contentWindow.doIt();
};
iframe.src = "resources/post-parent-type-error.html";
document.body.append(iframe);
}, "Errors sent across realms should preserve their type");
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -498,12 +498,12 @@
});
},
function() {
var t = async_test("URIError objects from other realms are treated as Error");
var t = async_test("URIError objects from other realms are treated as URIError");
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(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");
});
Expand All @@ -520,9 +520,9 @@
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(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, "another message", "Checking message");
assert_equals(e.data.foo, undefined, "Checking custom property");
});
Expand Down

0 comments on commit c972c20

Please sign in to comment.