chromium/third_party/blink/web_tests/external/wpt/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/resources/sharedworker-failure.js

let state = "send-sw-failure"
onconnect = initialE => {
  let port = initialE.source;
  port.postMessage(state)
  port.onmessage = e => {
    if(state === "" && e.data === "send-window-failure") {
      port.postMessage(new SharedArrayBuffer())
    } else {
      port.postMessage("failure")
    }
  }
  port.onmessageerror = e => {
    if(state === "send-sw-failure") {
      port.postMessage("send-sw-failure-success")
      state = ""
    }
  }
}