Fri, 16 Jan 2015 18:13:44 +0100
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 | <!DOCTYPE HTML> |
michael@0 | 6 | <html> |
michael@0 | 7 | <meta charset="utf-8"> |
michael@0 | 8 | <body> |
michael@0 | 9 | <script type="text/javascript"> |
michael@0 | 10 | var worker; |
michael@0 | 11 | |
michael@0 | 12 | function start(workerCount, messageCallback) { |
michael@0 | 13 | var seenWindowError; |
michael@0 | 14 | window.onerror = function(message, filename, lineno) { |
michael@0 | 15 | if (!seenWindowError) { |
michael@0 | 16 | seenWindowError = true; |
michael@0 | 17 | messageCallback({ |
michael@0 | 18 | type: "window", |
michael@0 | 19 | data: { message: message, filename: filename, lineno: lineno } |
michael@0 | 20 | }); |
michael@0 | 21 | return true; |
michael@0 | 22 | } |
michael@0 | 23 | }; |
michael@0 | 24 | |
michael@0 | 25 | worker = new Worker("errorPropagation_worker.js"); |
michael@0 | 26 | |
michael@0 | 27 | worker.onmessage = function(event) { |
michael@0 | 28 | messageCallback(event.data); |
michael@0 | 29 | }; |
michael@0 | 30 | |
michael@0 | 31 | var seenWorkerError; |
michael@0 | 32 | worker.onerror = function(event) { |
michael@0 | 33 | if (!seenWorkerError) { |
michael@0 | 34 | seenWorkerError = true; |
michael@0 | 35 | messageCallback({ |
michael@0 | 36 | type: "worker", |
michael@0 | 37 | data: { |
michael@0 | 38 | message: event.message, |
michael@0 | 39 | filename: event.filename, |
michael@0 | 40 | lineno: event.lineno |
michael@0 | 41 | } |
michael@0 | 42 | }); |
michael@0 | 43 | event.preventDefault(); |
michael@0 | 44 | } |
michael@0 | 45 | }; |
michael@0 | 46 | |
michael@0 | 47 | worker.postMessage(workerCount); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | function stop() { |
michael@0 | 51 | worker.terminate(); |
michael@0 | 52 | } |
michael@0 | 53 | </script> |
michael@0 | 54 | </body> |
michael@0 | 55 | </html> |