summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/fetch/nested_worker_wrapper.js
blob: 1a14cf06d9a87cfd29c87e5294680e0010aba3a8 (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
function getScriptUrl() {
  return new URL(location.href).searchParams.get("script");
}

// Hold the nested worker alive until this parent worker closes.
var worker;

addEventListener("message", function nestedWorkerWrapperOnMessage(evt) {
  removeEventListener("message", nestedWorkerWrapperOnMessage);

  worker = new Worker("worker_wrapper.js?script=" + getScriptUrl());

  worker.addEventListener("message", function (evt) {
    self.postMessage({
      context: "NestedWorker",
      type: evt.data.type,
      status: evt.data.status,
      msg: evt.data.msg,
    });
  });

  worker.addEventListener("error", function (evt) {
    self.postMessage({
      context: "NestedWorker",
      type: "status",
      status: false,
      msg: "Nested worker error: " + evt.message,
    });
  });

  worker.postMessage(evt.data);
});