Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 4aee476

Browse files
domenicjgraham
authored andcommitted
Bug 1556663 [wpt PR 17159] - Add optional test for cloning of error stacks, a=testonly
Automatic update from web-platform-tests Add optional test for cloning of error stacks Supplements web-platform-tests/wpt#17095. Follows whatwg/html#4665 and whatwg/webidl#732. -- wpt-commits: 1da6bed5d8c4c38200383b86928b7be68bfb87da wpt-pr: 17159 --HG-- rename : testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/resources/echo-iframe.html => testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/resources/echo-iframe.html rename : testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/resources/echo-worker.js => testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/resources/echo-worker.js
1 parent 5c6faf8 commit 4aee476

File tree

8 files changed

+100
-12
lines changed

8 files changed

+100
-12
lines changed

testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/echo.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/identity-not-preserved.html

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<link rel="author" title="Domenic Denicola" href="mailto:[email protected]">
66
<script src="/resources/testharness.js"></script>
77
<script src="/resources/testharnessreport.js"></script>
8+
<script src="/common/utils.js"></script>
89
<script src="resources/test-sab.js"></script>
910

1011
<div id="log"></div>
@@ -13,9 +14,10 @@
1314
"use strict";
1415

1516
async_test(t => {
17+
const testId = token();
1618
const sab = new SharedArrayBuffer(1);
1719
window.addEventListener("message", t.step_func(({ data }) => {
18-
if (data.testId !== 1) {
20+
if (data.testId !== testId) {
1921
return;
2022
}
2123

@@ -24,29 +26,31 @@
2426
t.done();
2527
}));
2628

27-
window.postMessage({ sab, testId: 1 }, "*");
29+
window.postMessage({ testId, sab }, "*");
2830
}, "postMessaging to this window does not give back the same SharedArrayBuffer (but does use the same backing block)");
2931

3032
async_test(t => {
33+
const testId = token();
3134
const sab = new SharedArrayBuffer();
32-
const worker = new Worker("resources/echo-worker.js");
35+
const worker = new Worker("../resources/echo-worker.js");
3336

3437
worker.addEventListener("message", t.step_func(({ data }) => {
35-
if (data.testId !== 2) {
38+
if (data.testId !== testId) {
3639
return;
3740
}
3841

3942
assert_not_equals(data.sab, sab);
4043
t.done();
4144
}));
4245

43-
worker.postMessage({ testId: 2, sab });
46+
worker.postMessage({ testId, sab });
4447
}, "postMessaging to a worker and back does not give back the same SharedArrayBuffer");
4548

4649
async_test(t => {
50+
const testId = token();
4751
const sab = new SharedArrayBuffer();
4852
window.addEventListener("message", t.step_func(({ data }) => {
49-
if (data.testId !== 3) {
53+
if (data.testId !== testId) {
5054
return;
5155
}
5256

@@ -56,9 +60,9 @@
5660

5761
const iframe = document.createElement("iframe");
5862
iframe.onload = t.step_func(() => {
59-
iframe.contentWindow.postMessage({ testId: 3, sab }, "*");
63+
iframe.contentWindow.postMessage({ testId, sab }, "*");
6064
});
61-
iframe.src = "resources/echo-iframe.html";
65+
iframe.src = "../resources/echo-iframe.html";
6266
document.body.appendChild(iframe);
6367
}, "postMessaging to an iframe and back does not give back the same SharedArrayBuffer");
6468
</script>

testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/no-transferring.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
test(() => {
1919
const sab = new SharedArrayBuffer();
20-
const worker = new Worker("resources/echo-worker.js");
20+
const worker = new Worker("../resources/echo-worker.js");
2121
assert_throws("DataCloneError", () => worker.postMessage(sab, [sab]));
2222
assert_throws("DataCloneError", () => worker.postMessage("test", [sab]));
2323
}, "Trying to transfer a SharedArrayBuffer to a worker throws");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// META: script=/common/utils.js
2+
3+
// .stack properties on errors are unspecified, but are present in most
4+
// browsers, most of the time. https://github.com/tc39/proposal-error-stacks/ tracks standardizing them.
5+
// Tests will pass automatically if the .stack property isn't present.
6+
7+
stackTests(() => {
8+
return new Error('some message');
9+
}, 'page-created Error');
10+
11+
stackTests(() => {
12+
return new DOMException('InvalidStateError', 'some message');
13+
}, 'page-created DOMException');
14+
15+
stackTests(() => {
16+
try {
17+
Object.defineProperty();
18+
} catch (e) {
19+
return e;
20+
}
21+
}, 'JS-engine-created TypeError');
22+
23+
stackTests(() => {
24+
try {
25+
HTMLParagraphElement.prototype.align;
26+
} catch (e) {
27+
return e;
28+
}
29+
}, 'web API-created TypeError');
30+
31+
stackTests(() => {
32+
try {
33+
document.createElement('');
34+
} catch (e) {
35+
return e;
36+
}
37+
}, 'web API-created DOMException');
38+
39+
function stackTests(errorFactory, description) {
40+
async_test(t => {
41+
const error = errorFactory();
42+
const originalStack = error.stack;
43+
44+
if (!originalStack) {
45+
t.done();
46+
return;
47+
}
48+
49+
const worker = new Worker('resources/echo-worker.js');
50+
worker.onmessage = t.step_func_done(e => {
51+
assert_equals(e.data.stack, originalStack);
52+
});
53+
54+
worker.postMessage(error);
55+
}, description + ' (worker)');
56+
57+
async_test(t => {
58+
const thisTestId = token();
59+
60+
const error = errorFactory();
61+
const originalStack = error.stack;
62+
63+
if (!originalStack) {
64+
t.done();
65+
return;
66+
}
67+
68+
const iframe = document.createElement('iframe');
69+
window.addEventListener('message', t.step_func(e => {
70+
if (e.data.testId === thisTestId) {
71+
assert_equals(e.data.error.stack, originalStack);
72+
t.done();
73+
}
74+
}));
75+
76+
iframe.onload = t.step_func(() => {
77+
iframe.contentWindow.postMessage({ error, testId: thisTestId }, "*");
78+
});
79+
80+
const crossSiteEchoIFrame = new URL('resources/echo-iframe.html', location.href);
81+
crossSiteEchoIFrame.hostname = '{{hosts[alt][www1]}}';
82+
iframe.src = crossSiteEchoIFrame;
83+
document.body.append(iframe);
84+
}, description + ' (cross-site iframe)');
85+
}

testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/structured_clone_bigint.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
//the worker is used for each test in sequence
2424
//worker's callback will be set for each test
2525
//worker's internal onmessage echoes the data back to this thread through postMessage
26-
worker = new Worker("./echo.js");
26+
worker = new Worker("./resources/echo-worker.js");
2727
testCollection = [
2828
function() {
2929
var t = async_test("Primitive BigInt is cloned");

testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/structuredclone_0.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//the worker is used for each test in sequence
1919
//worker's callback will be set for each test
2020
//worker's internal onmessage echoes the data back to this thread through postMessage
21-
worker = new Worker("./echo.js");
21+
worker = new Worker("./resources/echo-worker.js");
2222
testCollection = [
2323
function() {
2424
var t = async_test("Primitive string is cloned");

0 commit comments

Comments
 (0)