Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Unified Diff: LayoutTests/fast/events/resources/onerror-test.js

Issue 20351002: Add 'error' parameter to 'window.onerror' handlers. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Constructor. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: LayoutTests/fast/events/resources/onerror-test.js
diff --git a/LayoutTests/fast/events/resources/onerror-test.js b/LayoutTests/fast/events/resources/onerror-test.js
index 1016aa201081576947532187954f43b99b8fbb74..b63a8aeae452e7e18be4443be8cb2183a9c75993 100644
--- a/LayoutTests/fast/events/resources/onerror-test.js
+++ b/LayoutTests/fast/events/resources/onerror-test.js
@@ -8,15 +8,19 @@ function throwException(message) {
var errorsSeen = 0;
function dumpOnErrorArgumentValuesAndReturn(returnValue, callback) {
- window.onerror = function (message, url, line, column) {
+ window.onerror = function (message, url, line, column, error) {
debug("window.onerror: \"" + message + "\" at " + stripURL(url) + " (Line: " + line + ", Column: " + column + ")");
+ if (error)
+ debug(stripStackURLs(error.stack));
+ else
+ debug("No stack trace.");
if (callback)
callback(++errorsSeen);
if (returnValue)
- debug("Returning 'true': the error should not be reported in the console as an unhandled exception.");
+ debug("Returning 'true': the error should not be reported in the console as an unhandled exception.\n\n\n");
else
- debug("Returning 'false': the error should be reported in the console as an unhandled exception.");
+ debug("Returning 'false': the error should be reported in the console as an unhandled exception.\n\n\n");
return returnValue;
};
}
@@ -24,7 +28,7 @@ function dumpOnErrorArgumentValuesAndReturn(returnValue, callback) {
function dumpErrorEventAndAllowDefault(callback) {
window.addEventListener('error', function (e) {
dumpErrorEvent(e)
- debug("Not calling e.preventDefault(): the error should be reported in the console as an unhandled exception.");
+ debug("Not calling e.preventDefault(): the error should be reported in the console as an unhandled exception.\n\n\n");
if (callback)
callback(++errorsSeen);
});
@@ -33,7 +37,7 @@ function dumpErrorEventAndAllowDefault(callback) {
function dumpErrorEventAndPreventDefault(callback) {
window.addEventListener('error', function (e) {
dumpErrorEvent(e);
- debug("Calling e.preventDefault(): the error should not be reported in the console as an unhandled exception.");
+ debug("Calling e.preventDefault(): the error should not be reported in the console as an unhandled exception.\n\n\n");
e.preventDefault();
if (callback)
callback(++errorsSeen);
@@ -44,6 +48,10 @@ var eventPassedToTheErrorListener = null;
var eventCurrentTarget = null;
function dumpErrorEvent(e) {
debug("Handling '" + e.type + "' event (phase " + e.eventPhase + "): \"" + e.message + "\" at " + stripURL(e.filename) + ":" + e.lineno);
+ if (e.error)
+ debug(stripStackURLs(e.error.stack));
+ else
+ debug("No stack trace.");
eventPassedToTheErrorListener = e;
eventCurrentTarget = e.currentTarget;
@@ -52,3 +60,13 @@ function dumpErrorEvent(e) {
eventPassedToTheErrorListener = null;
eventCurrentTarget = null;
}
+
+function stripStackURLs(stackTrace) {
+ stackTrace = stackTrace.split("\n");
+ var length = Math.min(stackTrace.length, 100);
+ var text = "Stack Trace:\n";
+ for (var i = 0; i < length; i++) {
+ text += stackTrace[i].replace(/at ((?:eval at \()?[a-zA-Z\.]+ )?\(?.+\/([^\/]+):(\d+):(\d+)\)?/, "at $1$2:$3:$4") + "\n";
+ }
+ return text;
+}

Powered by Google App Engine
This is Rietveld 408576698