OLD | NEW |
(Empty) | |
| 1 function stripURL(url) { |
| 2 return url ? url.match( /[^\/]+\/?$/ )[0] : url; |
| 3 } |
| 4 |
| 5 function throwException(message) { |
| 6 throw new Error(message ? message : "An exception"); |
| 7 } |
| 8 |
| 9 var errorsSeen = 0; |
| 10 function dumpOnErrorArgumentValuesAndReturn(returnValue, callback) { |
| 11 window.onerror = function (message, url, line, column) { |
| 12 debug("window.onerror: \"" + message + "\" at " + stripURL(url) + " (Lin
e: " + line + ", Column: " + column + ")"); |
| 13 |
| 14 if (callback) |
| 15 callback(++errorsSeen); |
| 16 if (returnValue) |
| 17 debug("Returning 'true': the error should not be reported in the con
sole as an unhandled exception."); |
| 18 else |
| 19 debug("Returning 'false': the error should be reported in the consol
e as an unhandled exception."); |
| 20 return returnValue; |
| 21 }; |
| 22 } |
| 23 |
| 24 function dumpErrorEventAndAllowDefault(callback) { |
| 25 window.addEventListener('error', function (e) { |
| 26 dumpErrorEvent(e) |
| 27 debug("Not calling e.preventDefault(): the error should be reported in t
he console as an unhandled exception."); |
| 28 if (callback) |
| 29 callback(++errorsSeen); |
| 30 }); |
| 31 } |
| 32 |
| 33 function dumpErrorEventAndPreventDefault(callback) { |
| 34 window.addEventListener('error', function (e) { |
| 35 dumpErrorEvent(e); |
| 36 debug("Calling e.preventDefault(): the error should not be reported in t
he console as an unhandled exception."); |
| 37 e.preventDefault(); |
| 38 if (callback) |
| 39 callback(++errorsSeen); |
| 40 }); |
| 41 } |
| 42 |
| 43 var eventPassedToTheErrorListener = null; |
| 44 var eventCurrentTarget = null; |
| 45 function dumpErrorEvent(e) { |
| 46 debug("Handling '" + e.type + "' event (phase " + e.eventPhase + "): \"" + e
.message + "\" at " + stripURL(e.filename) + ":" + e.lineno); |
| 47 |
| 48 eventPassedToTheErrorListener = e; |
| 49 eventCurrentTarget = e.currentTarget; |
| 50 shouldBe('eventPassedToTheErrorListener', 'window.event'); |
| 51 shouldBe('eventCurrentTarget', 'window'); |
| 52 eventPassedToTheErrorListener = null; |
| 53 eventCurrentTarget = null; |
| 54 } |
OLD | NEW |