summaryrefslogtreecommitdiffstats
path: root/dom/workers/test/csp_worker.js
blob: 63b3adeaf36120a2caa6f2a4abdc1731987ef4fe (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
/**
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */
onmessage = function(event) {
  if (event.data.do == "eval") {
    var res;
    try {
      res = eval("40+2");
    }
    catch(ex) {
      res = ex+"";
    }
    postMessage(res);
  }
  else if (event.data.do == "nest") {
    var worker = new Worker(event.data.uri);
    if (--event.data.level) {
      worker.postMessage(event.data);
    }
    else {
      worker.postMessage({ do: "eval" });
    }
    worker.onmessage = (e) => {
      postMessage(e.data);
    }
  }
}