errorwarning_worker.js 929 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * Any copyright is dedicated to the Public Domain.
  3. * http://creativecommons.org/publicdomain/zero/1.0/
  4. */
  5. function errorHandler() {
  6. postMessage({ type: 'error' });
  7. }
  8. onmessage = function(event) {
  9. if (event.data.errors) {
  10. try {
  11. // This is an error:
  12. postMessage({ type: 'ignore', value: b.aaa });
  13. } catch(e) {
  14. errorHandler();
  15. }
  16. } else {
  17. var a = {};
  18. // This is a warning:
  19. postMessage({ type: 'ignore', value: a.foo });
  20. }
  21. if (event.data.loop != 0) {
  22. var worker = new Worker('errorwarning_worker.js');
  23. worker.onerror = errorHandler;
  24. worker.postMessage({ loop: event.data.loop - 1, errors: event.data.errors });
  25. worker.onmessage = function(e) {
  26. postMessage(e.data);
  27. }
  28. } else {
  29. postMessage({ type: 'finish' });
  30. }
  31. }
  32. onerror = errorHandler;
  33. onerror = onerror;
  34. if (!onerror || onerror != onerror) {
  35. throw "onerror wasn't set properly";
  36. }