Hook up ShadowChicken to the debugger to show tail deleted frames
[WebKit-https.git] / LayoutTests / inspector / debugger / tail-recursion.html
1 <!doctype html>
2 <html>
3 <head>
4 <script type="text/javascript" src="../../http/tests/inspector/resources/inspector-test.js"></script>
5 <script type="text/javascript" src="../../http/tests/inspector/debugger/debugger-test.js"></script>
6 <script type="text/javascript" src="./resources/tail-recursion.js"></script>
7 <script>
8
9 function test()
10 {
11     var scriptObject;
12
13     function startTest() {
14         InspectorTest.log("Starting Test");
15         // 0 based indices.
16         var testInfos = [{line : 3, column : 8}, {line : 4, column : 8}];
17         for (let testInfo of testInfos) {
18             let location = scriptObject.createSourceCodeLocation(testInfo.line, testInfo.column);
19             let breakpoint = new WebInspector.Breakpoint(location);
20             WebInspector.debuggerManager.addBreakpoint(breakpoint);
21         }
22         InspectorTest.evaluateInPage("startRecurse()");
23     }
24
25     let numBreakpointHits = 0;
26     WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.CallFramesDidChange, function(event) {
27         var activeCallFrame = WebInspector.debuggerManager.activeCallFrame;
28
29         if (!activeCallFrame)
30             return;
31
32         numBreakpointHits++;
33         var stopLocation = "line: " + activeCallFrame.sourceCodeLocation.lineNumber + ", column: " + activeCallFrame.sourceCodeLocation.columnNumber;
34
35         InspectorTest.log("\n\n------------------------------------");
36         InspectorTest.log("Hit breakpoint at " + stopLocation);
37         InspectorTest.log("numBreakpointHits: " + numBreakpointHits);
38         const numFramesToInspect = 50;
39         InspectorTest.log("Going to look at the top " + numFramesToInspect + " frames.");
40         InspectorTest.log("------------------------------------");
41
42         InspectorTest.assert(WebInspector.debuggerManager.callFrames.length > numFramesToInspect); // We just look at top 50. This isn't a precise number. But it gets at the gist of the debugging experience.
43         for (let i = 0; i < numFramesToInspect; i++) {
44             let callFrame = WebInspector.debuggerManager.callFrames[i];
45             InspectorTest.assert(callFrame.functionName === "recurse");
46             let topScope = callFrame.scopeChain[0];
47
48             if (i > 0)
49                 InspectorTest.assert(callFrame.isTailDeleted);
50             else
51                 InspectorTest.assert(!callFrame.isTailDeleted);
52
53             topScope.objects[0].getAllPropertyDescriptors(function(properties) {
54                 let found = false;
55                 for (let propertyDescriptor of properties) {
56                     if (propertyDescriptor.name === 'i') {
57                         found = true;
58                         InspectorTest.log("Looking at frame number: " + i);
59                         InspectorTest.log("    variable 'i': " + JSON.stringify(propertyDescriptor.value));
60                         InspectorTest.assert(propertyDescriptor.value.type === 'number');
61                         if (numBreakpointHits === 2 && i === 0)
62                             InspectorTest.assert(propertyDescriptor.value.value === i + 1); // this tests the i++ inside tail-recurse.js
63                         else
64                             InspectorTest.assert(propertyDescriptor.value.value === i);
65                     }
66                 }
67                 InspectorTest.assert(found);
68             });
69         }
70
71         WebInspector.debuggerManager.resume();
72     });
73
74     WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.Resumed, function(event) {
75         InspectorTest.log("Tests done");
76         InspectorTest.completeTest();
77     });
78
79     WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.ScriptAdded, function(event) {
80         eventScriptObject = event.data.script;
81         
82         if (/tail-recursion\.js$/.test(eventScriptObject.url)) {
83             scriptObject = eventScriptObject;
84             startTest();
85             return;
86         }
87
88     });
89
90     InspectorTest.reloadPage();
91 }
92 </script>
93 </head>
94 <body onload="runTest()">
95     <p>Testing that we keep around tail deleted frames in the inspector. </p>
96 </body>
97 </html>