Web Inspector: Save Console Evaluations into Command Line variables $1-$99 ($n)
[WebKit-https.git] / LayoutTests / inspector / debugger / command-line-api-exception-nested-catch.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 function triggerException()
8 {
9     // We expect uncaught exceptions, so avoid logs for them.
10     window.onerror = function(){};
11     setTimeout(nestedCatchBlocks, 0);
12 }
13
14 function test()
15 {
16     WebInspector.debuggerManager.allExceptionsBreakpoint.disabled = false;
17
18     function dumpCommandLineAPIValue(prefix) {
19         WebInspector.runtimeManager.evaluateInInspectedWindow("$exception", "test", true, true, false, false, false, function(result, wasThrown) {
20             InspectorTest.log(prefix + ": $exception => " + result.description);
21         });
22     }
23
24     function checkIfExceptionValueMatchesVariable(varName) {
25         WebInspector.runtimeManager.evaluateInInspectedWindow("$exception === " + varName, "test", true, true, false, false, false, function(result, wasThrown) {
26             InspectorTest.log("  CATCH: $exception === " + varName + " ? " + result.description);
27         });
28     }
29
30     var done = false;
31     var phase = 0;
32
33     WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.CallFramesDidChange, function(event) {
34         if (done)
35             return;
36
37         phase++;
38
39         // Skip past the first pause to the second pause.
40         if (phase === 1) {
41             dumpCommandLineAPIValue("OUTER 1");
42             WebInspector.debuggerManager.resume();
43             return;
44         }
45
46         // Paused on the exception in the inner try, step over to get into the inner catch.
47         if (phase === 2) {
48             dumpCommandLineAPIValue("INNER 1");
49             WebInspector.debuggerManager.stepOver();
50             return;
51         }
52
53         // Paused in the inner catch, verify $exception is "inner exception".
54         if (phase === 3) {
55             dumpCommandLineAPIValue("INNER 2");
56             checkIfExceptionValueMatchesVariable("e2");
57             WebInspector.debuggerManager.stepOver();
58             return;
59         }
60         
61         // Stepped into the outer catch, verify $exception is "outer exception".
62         if (phase === 4) {
63             dumpCommandLineAPIValue("OUTER 2");
64             checkIfExceptionValueMatchesVariable("e1");
65             WebInspector.debuggerManager.resume();
66             return;
67         }
68     });
69
70     WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.Resumed, function(event) {
71         done = true;
72         dumpCommandLineAPIValue("AFTER  ");
73         InspectorTest.completeTest();
74     });
75
76     dumpCommandLineAPIValue("BEFORE ");
77     InspectorTest.evaluateInPage("triggerException()");
78 }
79 </script>
80 </head>
81 <body onload="runTest()">
82     <p>Checks that <code>$exception</code> is the value of the current exception, even in nested catch blocks.</p>
83 </body>
84 </html>