dom/workers/test/console_worker.js

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

     1 /**
     2  * Any copyright is dedicated to the Public Domain.
     3  * http://creativecommons.org/publicdomain/zero/1.0/
     4  */
     6 onmessage = function(event) {
     7   // TEST: does console exist?
     8   postMessage({event: 'console exists', status: !!console, last : false});
    10   postMessage({event: 'trace without function', status: true, last : false});
    12   for (var i = 0; i < 10; ++i) {
    13     console.what('1', 123, 321);
    14   }
    16   for (var i = 0; i < 10; ++i) {
    17     console.log(i, i, i);
    18   }
    20   function trace1() {
    21     function trace2() {
    22       function trace3() {
    23         console.trace("trace " + i);
    24       }
    25       trace3();
    26     }
    27     trace2();
    28   }
    29   trace1();
    31   foobar585956c = function(a) {
    32     console.trace();
    33     return a+"c";
    34   };
    36   function foobar585956b(a) {
    37     return foobar585956c(a+"b");
    38   }
    40   function foobar585956a(omg) {
    41     return foobar585956b(omg + "a");
    42   }
    44   function foobar646025(omg) {
    45     console.log(omg, "o", "d");
    46   }
    48   function startTimer(timer) {
    49     console.time(timer);
    50   }
    52   function stopTimer(timer) {
    53     console.timeEnd(timer);
    54   }
    56   function testGroups() {
    57     console.groupCollapsed("a", "group");
    58     console.group("b", "group");
    59     console.groupEnd("b", "group");
    60   }
    62   foobar585956a('omg');
    63   foobar646025('omg');
    64   testGroups();
    65   startTimer('foo');
    66   setTimeout(function() {
    67     stopTimer('foo');
    68     nextSteps(event);
    69   }, 10);
    70 }
    72 function nextSteps(event) {
    74   function namelessTimer() {
    75     console.time();
    76     console.timeEnd();
    77   }
    79   namelessTimer();
    81   var str = "Test Message."
    82   console.foobar(str); // if this throws, we don't execute following funcs
    83   console.log(str);
    84   console.info(str);
    85   console.warn(str);
    86   console.error(str);
    87   console.exception(str);
    88   console.assert(true, str);
    89   console.assert(false, str);
    90   console.profile(str);
    91   console.profileEnd(str);
    92   postMessage({event: '4 messages', status: true, last : false});
    94   // Recursive:
    95   if (event.data == true) {
    96     var worker = new Worker('console_worker.js');
    97     worker.onmessage = function(event) {
    98       postMessage(event.data);
    99     }
   100     worker.postMessage(false);
   101   } else {
   102     postMessage({event: 'bye bye', status: true, last : true});
   103   }
   104 }

mercurial