Web Inspector: Provide $exception in the console for the thrown exception value
[WebKit-https.git] / LayoutTests / inspector / debugger / command-line-api-exception.html
1 <!doctype html>
2 <html>
3 <head>
4 <script type="text/javascript" src="../../http/tests/inspector/inspector-test.js"></script>
5 <script type="text/javascript" src="./resources/exceptions.js"></script>
6 <script>
7 var exceptionIndex = 0;
8 var exceptionCausers = [
9     triggerUncaughtTypeException,
10     triggerUncaughtReferenceException,
11     triggerUncaughtSyntaxException,
12     triggerUncaughtDOMException,
13     throwString,
14     throwNumber,
15     throwNull,
16     throwObject,
17     throwNode,
18     function() { catcher(triggerUncaughtTypeException); },
19     function() { catcher(throwString); },
20     function() { catcher(throwObject); },
21 ];
22
23
24 function triggerNextException()
25 {
26     // We expect uncaught exceptions, so avoid logs for them.
27     window.onerror = function(){};
28
29     setTimeout(function() {
30         exceptionCausers[exceptionIndex++]();
31     }, 0);
32 }
33
34 function test()
35 {
36     WebInspector.debuggerManager.allExceptionsBreakpoint.disabled = false;
37
38     function triggerNextException() {
39         InspectorTest.evaluateInPage("triggerNextException()");
40     }
41
42     function dumpCommandLineAPIValue(prefix) {
43         WebInspector.runtimeManager.evaluateInInspectedWindow("$exception", "test", true, true, false, function(result, wasThrown) {
44             InspectorTest.log(prefix + ": $exception => " + result.description);
45         });
46     }
47
48     function checkIfExceptionValueMatchesCatchVariable() {
49         WebInspector.runtimeManager.evaluateInInspectedWindow("$exception === e", "test", true, true, false, function(result, wasThrown) {
50             InspectorTest.log("STEPPED OUT TO CATCH BLOCK: $exception === e ? " + result.description);
51         });
52     }
53
54     var pauses = 0;
55     var stepping = false;
56     var done = false;
57     const pointWhereExpectionsAreBeingCaught = 9;
58     const expectedPauses = 12;
59
60     WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.CallFramesDidChange, function(event) {
61         if (done)
62             return;
63
64         if (!stepping) {
65             dumpCommandLineAPIValue("PAUSE #" + (++pauses));
66             if (pauses > pointWhereExpectionsAreBeingCaught) {
67                 WebInspector.debuggerManager.stepOut();
68                 stepping = true;
69                 return;
70             }
71         } else {
72             checkIfExceptionValueMatchesCatchVariable();
73             stepping = false;
74         }
75
76         WebInspector.debuggerManager.resume();
77
78         if (pauses !== expectedPauses) {
79             triggerNextException();
80             return;
81         }
82     });
83
84     WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.Resumed, function(event) {
85         done = true;
86         dumpCommandLineAPIValue("AFTER");
87         InspectorTest.completeTest();
88     });
89
90     dumpCommandLineAPIValue("BEFORE");
91     triggerNextException();
92 }
93 </script>
94 </head>
95 <body onload="runTest()">
96     <p>Checks that <code>$exception</code> is available and accurate in evaluations when paused on an exception.</p>
97 </body>
98 </html>