summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/general/worker_child.js
blob: fa340fc6525acc7c09913060ab92f0f53df87a55 (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
let timeStampCodes;
let worker = new Worker("worker_grandchild.js");

function listenToParent(event) {
  self.removeEventListener("message", listenToParent);
  timeStampCodes = event.data;

  let timeStamps = [];
  for (let timeStampCode of timeStampCodes) {
    timeStamps.push(eval(timeStampCode));
  }
  // Send the timeStamps to the parent.
  postMessage(timeStamps);

  // Tell the grandchild to start.
  worker.postMessage(timeStampCodes);
}

// The worker grandchild will send results back.
function listenToChild(event) {
  worker.removeEventListener("message", listenToChild);
  // Pass the results to the parent.
  postMessage(event.data);
  worker.terminate();
}

worker.addEventListener("message", listenToChild);
self.addEventListener("message", listenToParent);