summaryrefslogtreecommitdiffstats
path: root/dom/workers/test/errorPropagation_iframe.html
blob: cbaed1778f1087964dc9b6084b8dee62c6d66cec (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!--
  Any copyright is dedicated to the Public Domain.
  http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
  <meta charset="utf-8">
  <body>
    <script type="text/javascript">
      var worker;

      function start(workerCount, messageCallback) {
        var seenWindowError;
        window.onerror = function(message, filename, lineno) {
          if (!seenWindowError) {
            seenWindowError = true;
            messageCallback({
              type: "window",
              data: { message, filename, lineno }
            });
            return true;
          }
          return undefined;
        };

        worker = new Worker("errorPropagation_worker.js");

        worker.onmessage = function(event) {
          messageCallback(event.data);
        };

        var seenWorkerError;
        worker.onerror = function(event) {
          if (!seenWorkerError) {
            seenWorkerError = true;
            messageCallback({
              type: "worker",
              data: {
                message: event.message,
                filename: event.filename,
                lineno: event.lineno
              }
            });
            event.preventDefault();
          }
        };

        worker.postMessage(workerCount);
      }

      function stop() {
        worker.terminate();
      }
    </script>
  </body>
</html>