summaryrefslogtreecommitdiffstats
path: root/toolkit/components/aboutperformance/tests/browser/workers.html
blob: 29bb895ae2f8723c9f405d708af48e765d576d39 (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
34
35
36
37
38
39
40
41
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>
    Main frame for test browser_aboutperformance.js
  </title>
</head>
<body>

<p>
fib(<span id="n">?</span>) = <span id="result">?</span>
</p>

</body>
<script>
  var result = document.querySelector('#result');
  var span_n = document.querySelector('#n');
  var worker = new Worker("workers_script.js");
  var n = 1;

  var wait = new Promise(ready => {
    worker.onmessage = function(event) {
      result.textContent = event.data;
      span_n.textContent = n;
      console.log(`Got: fib($n) = $result\n`);
      n++;
      ready();
      // Keep looping to keep the worker as "High energy use"
      worker.postMessage(n);
    };
  });

  worker.postMessage(n);

  window.waitForTestReady = async () => {
    await wait;
  };

</script>
</html>