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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
<html>
<head>
<script type="text/javascript" src="../../http/tests/inspector-protocol/resources/protocol-test.js"></script>
<script>
function test()
{
// A general-purpose engine for sending a sequence of protocol commands.
// The clients provide requests and response handlers, while the engine catches
// errors and makes sure that once there's nothing to do completeTest() is called.
// @param step is an object with command, params and callback fields
function runRequestSeries(step)
{
processStep(step);
function processStep(s)
{
try {
processStepOrFail(s);
} catch (e) {
InspectorTest.log(e.stack);
InspectorTest.completeTest();
}
}
function processStepOrFail(s)
{
if (!s) {
InspectorTest.completeTest();
return;
}
if (!s.command) {
// A simple loopback step.
var next = s.callback();
processStep(next);
return;
}
var innerCallback = function(response)
{
if ("error" in response) {
InspectorTest.log(response.error.message);
InspectorTest.completeTest();
return;
}
var next;
try {
next = s.callback(response.result);
} catch (e) {
InspectorTest.log(e.stack);
InspectorTest.completeTest();
return;
}
processStep(next);
}
InspectorTest.sendCommand(s.command, s.params, innerCallback);
}
}
var firstStep = { callback: callbackStart5 };
runRequestSeries(firstStep);
// 'Object5' section -- check properties of '5' wrapped as object (has an internal property).
function callbackStart5()
{
// Create an wrapper object with additional property.
var expression = "(function(){var r = Object(5); r.foo = 'cat';return r;})()";
return { command: "Runtime.evaluate", params: {expression: expression}, callback: callbackEval5 };
}
function callbackEval5(result)
{
var id = result.result.objectId;
if (id === undefined)
throw new Error("objectId is expected");
return {
command: "Runtime.getProperties", params: {objectId: id, ownProperties: true}, callback: callbackProperties5
};
}
function callbackProperties5(result)
{
logGetPropertiesResult("Object(5)", result);
return { callback: callbackStartNotOwn };
}
// 'Not own' section -- check all properties of the object, including ones from it prototype chain.
function callbackStartNotOwn()
{
// Create an wrapper object with additional property.
var expression = "({ a: 2, set b() {}, get b() {return 5;}, __proto__: { a: 3, c: 4, get d() {return 6;} }})";
return { command: "Runtime.evaluate", params: {expression: expression}, callback: callbackEvalNotOwn };
}
function callbackEvalNotOwn(result)
{
var id = result.result.objectId;
if (id === undefined)
throw new Error("objectId is expected");
return {
command: "Runtime.getProperties", params: {objectId: id, ownProperties: false}, callback: callbackPropertiesNotOwn
};
}
function callbackPropertiesNotOwn(result)
{
logGetPropertiesResult("Not own properties", result);
return { callback: callbackStartAccessorsOnly };
}
// 'Accessors only' section -- check only accessor properties of the object.
function callbackStartAccessorsOnly()
{
// Create an wrapper object with additional property.
var expression = "({ a: 2, set b() {}, get b() {return 5;}, c: 'c', set d(){} })";
return { command: "Runtime.evaluate", params: {expression: expression}, callback: callbackEvalAccessorsOnly };
}
function callbackEvalAccessorsOnly(result)
{
var id = result.result.objectId;
if (id === undefined)
throw new Error("objectId is expected");
return {
command: "Runtime.getProperties", params: {objectId: id, ownProperties: true, accessorPropertiesOnly: true}, callback: callbackPropertiesAccessorsOnly
};
}
function callbackPropertiesAccessorsOnly(result)
{
logGetPropertiesResult("Accessor only properties", result);
return { callback: callbackStartArray };
}
// 'Array' section -- check properties of an array.
function callbackStartArray()
{
var expression = "['red', 'green', 'blue']";
return { command: "Runtime.evaluate", params: {expression: expression}, callback: callbackEvalArray };
}
function callbackEvalArray(result)
{
var id = result.result.objectId;
if (id === undefined)
throw new Error("objectId is expected");
return {
command: "Runtime.getProperties", params: {objectId: id, ownProperties: true}, callback: callbackPropertiesArray
};
}
function callbackPropertiesArray(result)
{
logGetPropertiesResult("array", result);
return { callback: callbackStartBound };
}
// 'Bound' section -- check properties of a bound function (has a bunch of internal properties).
function callbackStartBound()
{
var expression = "Number.bind({}, 5)";
return { command: "Runtime.evaluate", params: {expression: expression}, callback: callbackEvalBound };
}
function callbackEvalBound(result)
{
var id = result.result.objectId;
if (id === undefined)
throw new Error("objectId is expected");
return {
command: "Runtime.getProperties", params: {objectId: id, ownProperties: true}, callback: callbackPropertiesBound
};
}
function callbackPropertiesBound(result)
{
logGetPropertiesResult("Bound function", result);
return; // End of test
}
// A helper function that dumps object properties and internal properties in sorted order.
function logGetPropertiesResult(title, protocolResult)
{
function hasGetterSetter(property, fieldName)
{
var v = property[fieldName];
if (!v)
return false;
return v.type !== "undefined"
}
InspectorTest.log("Properties of " + title);
var propertyArray = protocolResult.result;
propertyArray.sort(NamedThingComparator);
for (var i = 0; i < propertyArray.length; i++) {
var p = propertyArray[i];
var v = p.value;
var own = p.isOwn ? "own" : "inherited";
if (v)
InspectorTest.log(" " + p.name + " " + own + " " + v.type + " " + v.value );
else
InspectorTest.log(" " + p.name + " " + own + " no value" +
(hasGetterSetter(p, "get") ? ", getter" : "") + (hasGetterSetter(p, "set") ? ", setter" : ""));
}
var internalPropertyArray = protocolResult.internalProperties;
if (internalPropertyArray) {
InspectorTest.log("Internal properties");
internalPropertyArray.sort(NamedThingComparator);
for (var i = 0; i < internalPropertyArray.length; i++) {
var p = internalPropertyArray[i];
var v = p.value;
InspectorTest.log(" " + p.name + " " + v.type + " " + v.value);
}
}
function NamedThingComparator(o1, o2)
{
return o1.name === o2.name ? 0 : (o1.name < o2.name ? -1 : 1);
}
}
}
</script>
</head>
<body onLoad="runTest();">
</body>
</html>
|