Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 11 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /workers/semantics/structured-clone/shared.html - WPT Dashboard Interop Dashboard
<!doctype html>
<title>structured clone to shared worker</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src=/common/sab.js></script>
<script src=/html/webappapis/structured-clone/structured-clone-battery-of-tests.js></script>
<script src=/html/webappapis/structured-clone/structured-clone-battery-of-tests-with-transferables.js></script>
<script src=/html/webappapis/structured-clone/structured-clone-battery-of-tests-harness.js></script>
<div id=log></div>
<script>
runStructuredCloneBatteryOfTests({
setup() {
const blob = new Blob([`
onconnect = ev => {
const port = ev.ports[0];
port.onmessage = ev => port.postMessage(ev.data, ev.data.transfer);
};
`], {type: 'text/javascript'});
this.blobURL = URL.createObjectURL(blob);
this.worker = new SharedWorker(this.blobURL);
this.port = this.worker.port;
},
structuredClone(data, transfer) {
return new Promise(resolve => {
this.port.addEventListener('message', function f(ev) {
this.port.removeEventListener('message', f);
resolve(ev.data.data);
}.bind(this));
this.port.start();
this.port.postMessage({data, transfer}, transfer);
});
},
teardown() {
URL.revokeObjectURL(this.blobURL);
}
});
</script>