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 | var seenScopeError; |
michael@0 | 6 | onerror = function(message, filename, lineno) { |
michael@0 | 7 | if (!seenScopeError) { |
michael@0 | 8 | seenScopeError = true; |
michael@0 | 9 | postMessage({ |
michael@0 | 10 | type: "scope", |
michael@0 | 11 | data: { message: message, filename: filename, lineno: lineno } |
michael@0 | 12 | }); |
michael@0 | 13 | return true; |
michael@0 | 14 | } |
michael@0 | 15 | }; |
michael@0 | 16 | |
michael@0 | 17 | onmessage = function(event) { |
michael@0 | 18 | var workerId = parseInt(event.data); |
michael@0 | 19 | |
michael@0 | 20 | if (workerId > 1) { |
michael@0 | 21 | var worker = new Worker("errorPropagation_worker.js"); |
michael@0 | 22 | |
michael@0 | 23 | worker.onmessage = function(event) { |
michael@0 | 24 | postMessage(event.data); |
michael@0 | 25 | }; |
michael@0 | 26 | |
michael@0 | 27 | var seenWorkerError; |
michael@0 | 28 | worker.onerror = function(event) { |
michael@0 | 29 | if (!seenWorkerError) { |
michael@0 | 30 | seenWorkerError = true; |
michael@0 | 31 | postMessage({ |
michael@0 | 32 | type: "worker", |
michael@0 | 33 | data: { |
michael@0 | 34 | message: event.message, |
michael@0 | 35 | filename: event.filename, |
michael@0 | 36 | lineno: event.lineno |
michael@0 | 37 | } |
michael@0 | 38 | }); |
michael@0 | 39 | event.preventDefault(); |
michael@0 | 40 | } |
michael@0 | 41 | }; |
michael@0 | 42 | |
michael@0 | 43 | worker.postMessage(workerId - 1); |
michael@0 | 44 | return; |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | var interval = setInterval(function() { |
michael@0 | 48 | throw new Error("expectedError"); |
michael@0 | 49 | }, 100); |
michael@0 | 50 | }; |