OLD | NEW |
---|---|
(Empty) | |
1 if (window.testRunner) | |
do-not-use
2013/07/23 14:46:09
Would becomes optional if we used js-test-pre.js
| |
2 testRunner.dumpAsText(); | |
3 | |
4 var output; | |
5 | |
6 function log(message) { | |
do-not-use
2013/07/23 14:46:09
Any reason we are not using js-test-pre.js? We cou
Mike West
2013/07/23 14:51:54
I thought about it, and decided that the advantage
| |
7 if (!output) { | |
8 output = document.createElement('pre') | |
9 document.body.appendChild(output); | |
10 } | |
11 | |
12 output.appendChild(document.createTextNode(message + "\n")); | |
13 } | |
14 | |
15 function stripURL(url) { | |
16 return url ? url.match( /[^\/]+\/?$/ )[0] : url; | |
17 } | |
18 | |
19 function throwException(message) { | |
20 throw new Error(message ? message : "An exception"); | |
21 } | |
22 | |
23 function DumpOnErrorArgumentValuesAndReturn(returnValue, callback) { | |
24 window.onerror = function (message, url, line, column) { | |
25 log("window.onerror: \"" + message + "\" at " + stripURL(url) + " (" + l ine + ", " + column + ")"); | |
26 if (callback) | |
27 callback(); | |
28 if (returnValue) | |
29 log("- Returning 'true': the error should not be reported in the con sole as an unhandled exception."); | |
30 else | |
31 log("- Returning 'false': the error should be reported in the consol e as an unhandled exception."); | |
32 return returnValue; | |
33 }; | |
34 } | |
35 | |
36 function DumpErrorEventAndAllowDefault(callback) { | |
37 window.addEventListener('error', function (e) { | |
38 DumpErrorEvent(e) | |
39 log("- Not calling e.preventDefault(): the error should be reported in t he console as an unhandled exception."); | |
40 if (callback) | |
41 callback(); | |
42 }); | |
43 } | |
44 | |
45 function DumpErrorEventAndPreventDefault(callback) { | |
46 window.addEventListener('error', function (e) { | |
47 DumpErrorEvent(e); | |
48 log("- Calling e.preventDefault(): the error should not be reported in t he console as an unhandled exception."); | |
49 e.preventDefault(); | |
50 if (callback) | |
51 callback(); | |
52 }); | |
53 } | |
54 | |
55 function DumpErrorEvent(e) { | |
56 log("Handling '" + e.type + "' event (phase " + e.eventPhase + "): \"" + e.m essage + "\" at " + stripURL(e.filename) + ":" + e.lineno); | |
57 | |
58 log("PASS: event passed to the listener is the same as 'window.event': " + ( window.event === e)); | |
59 log("PASS: 'currentTarget' is the global object: " + (e.currentTarget === wi ndow)); | |
60 } | |
OLD | NEW |