Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional test for cloning of error stacks #17159

Merged
merged 3 commits into from
Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<link rel="author" title="Domenic Denicola" href="mailto:[email protected]">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script src="resources/test-sab.js"></script>

<div id="log"></div>
Expand All @@ -13,9 +14,10 @@
"use strict";

async_test(t => {
const testId = token();
const sab = new SharedArrayBuffer(1);
window.addEventListener("message", t.step_func(({ data }) => {
if (data.testId !== 1) {
if (data.testId !== testId) {
return;
}

Expand All @@ -24,29 +26,31 @@
t.done();
}));

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

async_test(t => {
const testId = token();
const sab = new SharedArrayBuffer();
const worker = new Worker("resources/echo-worker.js");
const worker = new Worker("../resources/echo-worker.js");

worker.addEventListener("message", t.step_func(({ data }) => {
if (data.testId !== 2) {
if (data.testId !== testId) {
return;
}

assert_not_equals(data.sab, sab);
t.done();
}));

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

async_test(t => {
const testId = token();
const sab = new SharedArrayBuffer();
window.addEventListener("message", t.step_func(({ data }) => {
if (data.testId !== 3) {
if (data.testId !== testId) {
return;
}

Expand All @@ -56,9 +60,9 @@

const iframe = document.createElement("iframe");
iframe.onload = t.step_func(() => {
iframe.contentWindow.postMessage({ testId: 3, sab }, "*");
iframe.contentWindow.postMessage({ testId, sab }, "*");
});
iframe.src = "resources/echo-iframe.html";
iframe.src = "../resources/echo-iframe.html";
document.body.appendChild(iframe);
}, "postMessaging to an iframe and back does not give back the same SharedArrayBuffer");
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

test(() => {
const sab = new SharedArrayBuffer();
const worker = new Worker("resources/echo-worker.js");
const worker = new Worker("../resources/echo-worker.js");
assert_throws("DataCloneError", () => worker.postMessage(sab, [sab]));
assert_throws("DataCloneError", () => worker.postMessage("test", [sab]));
}, "Trying to transfer a SharedArrayBuffer to a worker throws");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// META: script=/common/utils.js

// .stack properties on errors are unspecified, but are present in most
// browsers, most of the time. https://github.com/tc39/proposal-error-stacks/ tracks standardizing them.
// Tests will pass automatically if the .stack property isn't present.

stackTests(() => {
return new Error('some message');
}, 'page-created Error');

stackTests(() => {
return new DOMException('InvalidStateError', 'some message');
}, 'page-created DOMException');

stackTests(() => {
try {
Object.defineProperty();
} catch (e) {
return e;
}
}, 'JS-engine-created TypeError');

stackTests(() => {
try {
HTMLParagraphElement.prototype.align;
} catch (e) {
return e;
}
}, 'web API-created TypeError');

stackTests(() => {
try {
document.createElement('');
} catch (e) {
return e;
}
}, 'web API-created DOMException');

function stackTests(errorFactory, description) {
async_test(t => {
const error = errorFactory();
const originalStack = error.stack;

if (!originalStack) {
t.done();
return;
}

const worker = new Worker('resources/echo-worker.js');
worker.onmessage = t.step_func_done(e => {
assert_equals(e.data.stack, originalStack);
});

worker.postMessage(error);
}, description + ' (worker)');

async_test(t => {
const thisTestId = token();

const error = errorFactory();
const originalStack = error.stack;

if (!originalStack) {
t.done();
return;
}

const iframe = document.createElement('iframe');
window.addEventListener('message', t.step_func(e => {
if (e.data.testId === thisTestId) {
assert_equals(e.data.error.stack, originalStack);
t.done();
}
}));

iframe.onload = t.step_func(() => {
iframe.contentWindow.postMessage({ error, testId: thisTestId }, "*");
});

const crossSiteEchoIFrame = new URL('resources/echo-iframe.html', location.href);
crossSiteEchoIFrame.hostname = '{{hosts[alt][www1]}}';
iframe.src = crossSiteEchoIFrame;
document.body.append(iframe);
}, description + ' (cross-site iframe)');
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
//the worker is used for each test in sequence
//worker's callback will be set for each test
//worker's internal onmessage echoes the data back to this thread through postMessage
worker = new Worker("./echo.js");
worker = new Worker("./resources/echo-worker.js");
testCollection = [
function() {
var t = async_test("Primitive BigInt is cloned");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//the worker is used for each test in sequence
//worker's callback will be set for each test
//worker's internal onmessage echoes the data back to this thread through postMessage
worker = new Worker("./echo.js");
worker = new Worker("./resources/echo-worker.js");
testCollection = [
function() {
var t = async_test("Primitive string is cloned");
Expand Down