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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 }
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/fast/events/window-onerror-01-expected.txt » ('j') | Source/core/dom/ErrorEvent.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698