WorkerDebugger.console_debugger.js 955 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict"
  2. function ok(a, msg) {
  3. postMessage(JSON.stringify({ type: 'status', what: !!a, msg: msg }));
  4. }
  5. function is(a, b, msg) {
  6. ok(a === b, msg);
  7. }
  8. function finish() {
  9. postMessage(JSON.stringify({ type: 'finish' }));
  10. }
  11. function magic() {
  12. console.log("Hello from the debugger script!");
  13. var foo = retrieveConsoleEvents();
  14. ok(Array.isArray(foo), "We received an array.");
  15. ok(foo.length >= 2, "At least 2 messages.");
  16. is(foo[0].arguments[0], "Can you see this console message?", "First message ok.");
  17. is(foo[1].arguments[0], "Can you see this second console message?", "Second message ok.");
  18. setConsoleEventHandler(function(consoleData) {
  19. is(consoleData.arguments[0], "Random message.", "Random message ok!");
  20. // The consoleEventHandler can be null.
  21. setConsoleEventHandler(null);
  22. finish();
  23. });
  24. }
  25. this.onmessage = function (event) {
  26. switch (event.data) {
  27. case "do magic":
  28. magic();
  29. break;
  30. }
  31. };