summaryrefslogtreecommitdiffstats
path: root/dom/base/test/worker_postMessages.js
blob: 968ec209a2323ec2f56020d6c9bf2138da7e8410 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function test_workers() {
  onmessage = function(e) {
    postMessage(e.data, e.ports);
  }
}

function test_broadcastChannel() {
  var bc = new BroadcastChannel('postMessagesTest_inWorkers');
  bc.onmessage = function(e) {
    postMessage(e.data);
  }
}

function test_messagePort(port) {
  port.onmessage = function(e) {
    postMessage(e.data, e.ports);
  }
}

onmessage = function(e) {
  if (e.data == 'workers') {
    test_workers();
    postMessage('ok');
  } else if (e.data == 'broadcastChannel') {
    test_broadcastChannel();
    postMessage('ok');
  } else if (e.data == 'messagePort') {
    test_messagePort(e.ports[0]);
    postMessage('ok');
  } else {
    postMessage('ko');
  }
}