WorkerDebugger.console_debugger.js (1058B)
1 "use strict"; 2 3 /* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */ 4 5 function ok(a, msg) { 6 postMessage(JSON.stringify({ type: "status", what: !!a, msg })); 7 } 8 9 function is(a, b, msg) { 10 ok(a === b, msg); 11 } 12 13 function finish() { 14 postMessage(JSON.stringify({ type: "finish" })); 15 } 16 17 function magic() { 18 console.log("Hello from the debugger script!"); 19 20 var foo = retrieveConsoleEvents(); 21 ok(Array.isArray(foo), "We received an array."); 22 ok(foo.length >= 2, "At least 2 messages."); 23 24 is( 25 foo[0].arguments[0], 26 "Can you see this console message?", 27 "First message ok." 28 ); 29 is( 30 foo[1].arguments[0], 31 "Can you see this second console message?", 32 "Second message ok." 33 ); 34 35 setConsoleEventHandler(function (consoleData) { 36 is(consoleData.arguments[0], "Random message.", "Random message ok!"); 37 38 // The consoleEventHandler can be null. 39 setConsoleEventHandler(null); 40 41 finish(); 42 }); 43 } 44 45 this.onmessage = function (event) { 46 switch (event.data) { 47 case "do magic": 48 magic(); 49 break; 50 } 51 };