Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / debugger / function-details.html
1 <html>
2 <head>
3 <script src="../../http/tests/inspector/inspector-test.js"></script>
4 <script src="../../http/tests/inspector/debugger-test.js"></script>
5
6 <script>  function firstLineFunction()
7
8 {
9 }
10
11    function notFirstLineFunction()
12
13 {
14 }
15
16 var obj = {
17     m: function() {}
18 }
19
20 function functionWithDisplayName() {}
21 functionWithDisplayName.displayName = "user-friendly name";
22
23 function functionWithDisplayNameGetter() {}
24 functionWithDisplayNameGetter.__defineGetter__("displayName", function() { return "FAIL_should_not_execute"; });
25
26 var smallClosure = (function(p) { return function() { return p; }; })("Capybara");
27
28 var bigClosure = (function(p) {
29     var o = {
30        e: 7,
31        f: 5,
32        get u() { return 3; },
33        set v(value) { }
34     };
35     with (o) {
36         try {
37             throw Error("Test");
38         } catch (ex) {
39             return function() {
40                 return String(p) + String(ex) + u + e;
41             };
42         }
43     }
44 })({});
45
46 function test()
47 {
48     function dumpFunctionDetails(details)
49     {
50         InspectorTest.addResult("Function details: ");
51         InspectorTest.addResult("lineNumber: " + details.location.lineNumber);
52         InspectorTest.addResult("columnNumber: " + details.location.columnNumber);
53         InspectorTest.addResult("scriptId is valid: " + !!details.location.scriptId);
54         InspectorTest.addResult("functionName: " + details.functionName);
55     }
56
57     function dumpFunctionNoScopes()
58     {
59         InspectorTest.addResult("scopeChain: n/a");
60     }
61
62     function dumpFunctionScope(pos, type, propertyDescriptors)
63     {
64         var variables;
65         if (type == "global") {
66             variables = "<global object properties omitted>";
67         } else {
68             var varArray = [];
69             for (var i = 0; i < propertyDescriptors.length; i++) {
70                 var d = propertyDescriptors[i];
71                 var valueStr;
72                 if (d.value) {
73                     if (d.value.value)
74                         valueStr = JSON.stringify(d.value.value);
75                     else
76                         valueStr = "<no string representation>";
77                 } else {
78                     valueStr = "<no value>";
79                 }
80                 varArray.push(d.name + ": " + valueStr);
81             }
82             varArray.sort();
83             variables = varArray.join();
84         }
85         InspectorTest.addResult("scopeChain #" + pos + ": " + type + "; " + variables);
86     }
87
88     function loadAndDumpScopeObjects(scopeChain, end) {
89         function loadScopeObject(pos, next) {
90             if (pos >= scopeChain.length) {
91                 next();
92                 return;
93             }
94             var scopeJson = scopeChain[pos];
95             RuntimeAgent.getProperties(scopeJson.object.objectId, true, didGetProperties);
96
97             function didGetProperties(error, propertyDescriptors) {
98                 dumpFunctionScope(pos, scopeJson.type, propertyDescriptors);
99                 loadScopeObject(pos + 1, next);
100             }
101         }
102
103         if (scopeChain) {
104             loadScopeObject(0, end);
105         } else {
106             dumpFunctionNoScopes();
107             end();
108         }
109     }
110
111     function performStandardTestCase(pageExpression, next) {
112         InspectorTest.evaluateInPage(pageExpression, didEvaluate);
113
114         function didEvaluate(remote)
115         {
116             InspectorTest.addResult(pageExpression + " type = " + remote.type);
117             DebuggerAgent.getFunctionDetails(remote.objectId, didGetDetails);
118         }
119         function didGetDetails(error, response)
120         {
121             dumpFunctionDetails(response);
122             loadAndDumpScopeObjects(response.scopeChain, next);
123         }
124     }
125
126     InspectorTest.runDebuggerTestSuite([
127         function testGetFirstLineFunctionDetails(next)
128         {
129             performStandardTestCase("firstLineFunction", next);
130         },
131         function testGetNonFirstLineFunctionDetails(next)
132         {
133             performStandardTestCase("notFirstLineFunction", next);
134         },
135         function testGetDetailsOfFunctionWithInferredName(next)
136         {
137             performStandardTestCase("obj.m", next);
138         },
139         function testGetDetailsOfFunctionWithDisplayName(next)
140         {
141             performStandardTestCase("functionWithDisplayName", next);
142         },
143         function testGetDetailsOfFunctionWithDisplayNameGetter(next)
144         {
145             performStandardTestCase("functionWithDisplayNameGetter", next);
146         },
147         function testSmallClosure(next)
148         {
149             performStandardTestCase("smallClosure", next);
150         },
151         function testBigClosure(next)
152         {
153             performStandardTestCase("bigClosure", next);
154         }
155     ]);
156 };
157
158 </script>
159
160 </head>
161
162 <body onload="runTest()">
163 <p>Tests that Debugger.getFunctionDetails command returns correct location.
164 <a href="https://bugs.webkit.org/show_bug.cgi?id=71808">Bug 71808</a>
165 </p>
166
167 </body>
168 </html>