summaryrefslogtreecommitdiffstats
path: root/dom/workers/test/errorPropagation_iframe.html
blob: c5f6884875c0083351d5362a6cf74d6195518316 (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
<!--
  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: message, filename: filename, lineno: lineno }
            });
            return true;
          }
        };

        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>