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