summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/resources/broadcastchannel-iframe.html
blob: 02b9bcbbe8827e590e10f70e2a2f4576a7a8ca0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<!DOCTYPE html>
<meta charset="utf-8">
<title>A test page that messes with a given SharedArrayBuffer sent from a BroadcastChannel</title>

<script>
"use strict";
const query = new URLSearchParams(location.search);
const channel = new BroadcastChannel(query.get("channel"));
const i = Number(query.get("index"));

channel.onmessage = e => {
  const sab = e.data.sab;
  if (sab === undefined) {
    // We only care about "broadcasts" from the window
    return;
  }

  const view = new Uint8Array(sab);
  view[i] = i + 1;
  channel.postMessage({ i });
};
</script>