summaryrefslogtreecommitdiffstats
path: root/dom/workers/test/errorwarning_worker.js
blob: 1c372104c8e927356e4abd365a0f673a4966a7e3 (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
/**
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

function errorHandler() {
  postMessage({ type: 'error' });
}

onmessage = function(event) {
  if (event.data.errors) {
    try {
      // This is an error:
      postMessage({ type: 'ignore', value: b.aaa });
    } catch(e) {
      errorHandler();
    }
  } else {
    var a = {};
    // This is a warning:
    postMessage({ type: 'ignore', value: a.foo });
  }

  if (event.data.loop != 0) {
    var worker = new Worker('errorwarning_worker.js');
    worker.onerror = errorHandler;
    worker.postMessage({ loop: event.data.loop - 1, errors: event.data.errors });

    worker.onmessage = function(e) {
      postMessage(e.data);
    }

  } else {
    postMessage({ type: 'finish' });
  }
}

onerror = errorHandler;
onerror = onerror;
if (!onerror || onerror != onerror) {
  throw "onerror wasn't set properly";
}