chromium/third_party/blink/web_tests/external/wpt/workers/semantics/structured-clone/dedicated.html

<!doctype html>
<title>structured clone to dedicated 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([`
        onmessage = ev => postMessage(ev.data, ev.data.transfer);
      `], {type: 'text/javascript'});
      this.blobURL = URL.createObjectURL(blob);
      this.worker = new Worker(this.blobURL);
    },
    structuredClone(data, transfer) {
      return new Promise(resolve => {
        this.worker.addEventListener('message', function f(ev) {
          this.worker.removeEventListener('message', f);
          resolve(ev.data.data);
        }.bind(this));
        this.worker.postMessage({data, transfer}, transfer);
      });
    },
    teardown() {
      this.worker.terminate();
      URL.revokeObjectURL(this.blobURL);
    }
  });
</script>