| OLD | NEW |
| 1 function stripURL(url) { | 1 function stripURL(url) { |
| 2 return url ? url.match( /[^\/]+\/?$/ )[0] : url; | 2 return url ? url.match( /[^\/]+\/?$/ )[0] : url; |
| 3 } | 3 } |
| 4 | 4 |
| 5 function throwException(message) { | 5 function throwException(message) { |
| 6 throw new Error(message ? message : "An exception"); | 6 throw new Error(message ? message : "An exception"); |
| 7 } | 7 } |
| 8 | 8 |
| 9 var errorsSeen = 0; | 9 var errorsSeen = 0; |
| 10 function dumpOnErrorArgumentValuesAndReturn(returnValue, callback) { | 10 function dumpOnErrorArgumentValuesAndReturn(returnValue, callback) { |
| 11 window.onerror = function (message, url, line, column) { | 11 window.onerror = function (message, url, line, column, error) { |
| 12 debug("window.onerror: \"" + message + "\" at " + stripURL(url) + " (Lin
e: " + line + ", Column: " + column + ")"); | 12 debug("window.onerror: \"" + message + "\" at " + stripURL(url) + " (Lin
e: " + line + ", Column: " + column + ")"); |
| 13 if (error) |
| 14 debug(stripStackURLs(error.stack)); |
| 13 | 15 |
| 14 if (callback) | 16 if (callback) |
| 15 callback(++errorsSeen); | 17 callback(++errorsSeen); |
| 16 if (returnValue) | 18 if (returnValue) |
| 17 debug("Returning 'true': the error should not be reported in the con
sole as an unhandled exception."); | 19 debug("Returning 'true': the error should not be reported in the con
sole as an unhandled exception."); |
| 18 else | 20 else |
| 19 debug("Returning 'false': the error should be reported in the consol
e as an unhandled exception."); | 21 debug("Returning 'false': the error should be reported in the consol
e as an unhandled exception."); |
| 20 return returnValue; | 22 return returnValue; |
| 21 }; | 23 }; |
| 22 } | 24 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 37 e.preventDefault(); | 39 e.preventDefault(); |
| 38 if (callback) | 40 if (callback) |
| 39 callback(++errorsSeen); | 41 callback(++errorsSeen); |
| 40 }); | 42 }); |
| 41 } | 43 } |
| 42 | 44 |
| 43 var eventPassedToTheErrorListener = null; | 45 var eventPassedToTheErrorListener = null; |
| 44 var eventCurrentTarget = null; | 46 var eventCurrentTarget = null; |
| 45 function dumpErrorEvent(e) { | 47 function dumpErrorEvent(e) { |
| 46 debug("Handling '" + e.type + "' event (phase " + e.eventPhase + "): \"" + e
.message + "\" at " + stripURL(e.filename) + ":" + e.lineno); | 48 debug("Handling '" + e.type + "' event (phase " + e.eventPhase + "): \"" + e
.message + "\" at " + stripURL(e.filename) + ":" + e.lineno); |
| 49 if (e.error) |
| 50 debug(stripStackURLs(e.error.stack)); |
| 47 | 51 |
| 48 eventPassedToTheErrorListener = e; | 52 eventPassedToTheErrorListener = e; |
| 49 eventCurrentTarget = e.currentTarget; | 53 eventCurrentTarget = e.currentTarget; |
| 50 shouldBe('eventPassedToTheErrorListener', 'window.event'); | 54 shouldBe('eventPassedToTheErrorListener', 'window.event'); |
| 51 shouldBe('eventCurrentTarget', 'window'); | 55 shouldBe('eventCurrentTarget', 'window'); |
| 52 eventPassedToTheErrorListener = null; | 56 eventPassedToTheErrorListener = null; |
| 53 eventCurrentTarget = null; | 57 eventCurrentTarget = null; |
| 54 } | 58 } |
| 59 |
| 60 function stripStackURLs(stackTrace) { |
| 61 var text = stackTrace + "\n\n"; |
| 62 stackTrace = stackTrace.split("\n"); |
| 63 var length = Math.min(stackTrace.length, 100); |
| 64 for (var i = 0; i < length; i++) { |
| 65 text += stackTrace[i].replace(/at ((?:eval at \()?[a-zA-Z\.]+ )?\(?.+\/(
[^\/]+):(\d+):(\d+)\)?/, "at $1$2:$3:$4") + "\n"; |
| 66 } |
| 67 return text; |
| 68 } |
| OLD | NEW |