summaryrefslogtreecommitdiffstats
path: root/dom/workers/test/console_worker.js
blob: 811dc12bae29a07c3bce4814aba5c1a8bf984d7a (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

onmessage = function (event) {
  // TEST: does console exist?
  postMessage({ event: "console exists", status: !!console, last: false });

  postMessage({
    event: "console is the same object",
    // eslint-disable-next-line no-self-compare
    status: console === console,
    last: false,
  });

  postMessage({ event: "trace without function", status: true, last: false });

  for (var i = 0; i < 10; ++i) {
    console.log(i, i, i);
  }

  function trace1() {
    function trace2() {
      function trace3() {
        console.trace("trace " + i);
      }
      trace3();
    }
    trace2();
  }
  trace1();

  foobar585956c = function (a) {
    console.trace();
    return a + "c";
  };

  function foobar585956b(a) {
    return foobar585956c(a + "b");
  }

  function foobar585956a(omg) {
    return foobar585956b(omg + "a");
  }

  function foobar646025(omg) {
    console.log(omg, "o", "d");
  }

  function startTimer(timer) {
    console.time(timer);
  }

  function stopTimer(timer) {
    console.timeEnd(timer);
  }

  function timeStamp(label) {
    console.timeStamp(label);
  }

  function testGroups() {
    console.groupCollapsed("a", "group");
    console.group("b", "group");
    console.groupEnd();
  }

  foobar585956a("omg");
  foobar646025("omg");
  timeStamp();
  timeStamp("foo");
  testGroups();
  startTimer("foo");
  setTimeout(function () {
    stopTimer("foo");
    nextSteps(event);
  }, 10);
};

function nextSteps(event) {
  function namelessTimer() {
    console.time();
    console.timeEnd();
  }

  namelessTimer();

  var str = "Test Message.";
  console.log(str);
  console.info(str);
  console.warn(str);
  console.error(str);
  console.exception(str);
  console.assert(true, str);
  console.assert(false, str);
  console.profile(str);
  console.profileEnd(str);
  console.timeStamp();
  console.clear();
  postMessage({ event: "4 messages", status: true, last: false });

  // Recursive:
  if (event.data == true) {
    var worker = new Worker("console_worker.js");
    worker.onmessage = function (msg) {
      postMessage(msg.data);
    };
    worker.postMessage(false);
  } else {
    postMessage({ event: "bye bye", status: true, last: true });
  }
}