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.

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

mercurial