Web Inspector: Remove recompileAllJSFunctions timer in ScriptDebugServer
[WebKit-https.git] / LayoutTests / inspector-protocol / debugger / setPauseOnExceptions-uncaught.html
1 <html>
2 <head>
3 <script src="../../http/tests/inspector-protocol/resources/protocol-test.js"></script>
4 <script src="resources/exception.js"></script>
5 <script>
6 function test()
7 {
8     var expectPause = false;
9
10     var statementsWithoutExceptions = [
11         "1+1;",
12         "noException();",
13         "catchNested(noException, 7);"
14     ];
15
16     var statementsWithCaughtExceptions = [
17         "try{ ({}).a.b.c.d } catch (e) { console.log('caught inline: ' + JSON.stringify(e)); }",
18         "catchNested(exceptionBasic, 1);",
19         "catchNested(exceptionDOM, 2);",
20         "catchNested(exceptionInHostFunction, 3);",
21         "catchNested(throwString, 10);",
22         "catchNested(throwParam, 5, new Error('error message'));"
23     ];
24
25     var currentUncaughtExceptionStatement = 0;
26     var statementsWithUncaughtExceptions = [
27         "({}).a.b.c.d;",
28         "exceptionBasic();",
29         "exceptionDOM();",
30         "exceptionInHostFunction();",
31         "throwString();",
32         "throwParam({x:1});",
33         "throwParam(new Error('error message'));"
34     ];
35
36     // FIXME: <https://webkit.org/b/121108> Web Inspector gets paused twice when there is an exception in host function
37     var extraPauses = 1;
38
39     function evaluateStatements(list, callback)
40     {
41         for (var i = 0; i < list.length; ++i) {
42             var statement = list[i];
43             var last = i === list.length - 1;
44             var responseCallback = last ? function() { setTimeout(callback, 10); } : function(){};
45             InspectorTest.sendCommand("Runtime.evaluate", {expression: "setTimeout(function() { " + statement + " }, 0);"}, responseCallback);
46         }
47     }
48
49     function evaluateExpectedNoPauses(callback)
50     {
51         var statements = statementsWithoutExceptions.concat(statementsWithCaughtExceptions);
52         evaluateStatements(statements, function() {
53             InspectorTest.log("PASS - did not pause on non-exception statements or caught exception statements");
54             callback();
55         });
56     }
57
58     function triggerNextUncaughtException()
59     {
60         // Evaluate statement and expect to pause.
61         if (currentUncaughtExceptionStatement < statementsWithUncaughtExceptions.length) {
62             var statement = statementsWithUncaughtExceptions[currentUncaughtExceptionStatement++];
63             InspectorTest.sendCommand("Runtime.evaluate", {expression: "setTimeout(function() { " + statement + " }, 0);"});
64             return;
65         }
66
67         // FIXME: <https://webkit.org/b/121108> Web Inspector gets paused twice when there is an exception in host function
68         if (extraPauses-- > 0)
69             return;
70
71         // Done evaluating statements to pause. Evaluate some more we do not expect to pause.
72         InspectorTest.log("PASS - paused for each uncaught exception");
73         expectPause = false;
74         evaluateExpectedNoPauses(function() {
75             InspectorTest.log("PASS");
76             InspectorTest.completeTest();
77         });
78     }
79
80
81     InspectorTest.sendCommand("Debugger.enable", {});
82     InspectorTest.sendCommand("Debugger.setPauseOnExceptions", {state: "uncaught"}, function(responseObject) {
83         InspectorTest.checkForError(responseObject);
84         InspectorTest.log("Debugger.setPauseOnExceptions - uncaught");
85         evaluateExpectedNoPauses(function() {
86             expectPause = true;
87             triggerNextUncaughtException();
88         });
89     });
90
91     InspectorTest.eventHandler["Debugger.paused"] = function(messageObject)
92     {
93         InspectorTest.log("Paused!");
94
95         if (!expectPause) {
96             InspectorTest.log("FAIL - debugger paused when we did not expect to");
97             InspectorTest.completeTest();
98             return;
99         }
100
101         InspectorTest.sendCommand("Debugger.resume", {});
102     }
103
104     InspectorTest.eventHandler["Debugger.resumed"] = function(messageObject)
105     {
106         InspectorTest.log("Resumed");
107         triggerNextUncaughtException();
108     }
109 }
110 </script>
111 </head>
112 <body onload="runTest()">
113 <p>Debugger.setPauseOnExceptions uncaught</p>
114 </body>
115 </html>