OLD | NEW |
| (Empty) |
1 // Copyright 2016 the V8 project authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // A general-purpose engine for sending a sequence of protocol commands. | |
6 // The clients provide requests and response handlers, while the engine catches | |
7 // errors and makes sure that once there's nothing to do completeTest() is calle
d. | |
8 // @param step is an object with command, params and callback fields | |
9 function runRequestSeries(step) | |
10 { | |
11 processStep(step); | |
12 | |
13 function processStep(s) | |
14 { | |
15 try { | |
16 processStepOrFail(s); | |
17 } catch (e) { | |
18 InspectorTest.log(e.stack); | |
19 InspectorTest.completeTest(); | |
20 } | |
21 } | |
22 | |
23 function processStepOrFail(s) | |
24 { | |
25 if (!s) { | |
26 InspectorTest.completeTest(); | |
27 return; | |
28 } | |
29 if (!s.command) { | |
30 // A simple loopback step. | |
31 var next = s.callback(); | |
32 processStep(next); | |
33 return; | |
34 } | |
35 | |
36 var innerCallback = function(response) | |
37 { | |
38 if ("error" in response) { | |
39 InspectorTest.log(response.error.message); | |
40 InspectorTest.completeTest(); | |
41 return; | |
42 } | |
43 var next; | |
44 try { | |
45 next = s.callback(response.result); | |
46 } catch (e) { | |
47 InspectorTest.log(e.stack); | |
48 InspectorTest.completeTest(); | |
49 return; | |
50 } | |
51 processStep(next); | |
52 } | |
53 InspectorTest.sendCommand(s.command, s.params, innerCallback); | |
54 } | |
55 } | |
56 | |
57 var firstStep = { callback: callbackStart5 }; | |
58 | |
59 runRequestSeries(firstStep); | |
60 | |
61 // 'Object5' section -- check properties of '5' wrapped as object (has an inter
nal property). | |
62 | |
63 function callbackStart5() | |
64 { | |
65 // Create an wrapper object with additional property. | |
66 var expression = "(function(){var r = Object(5); r.foo = 'cat';return r;})()"; | |
67 | |
68 return { command: "Runtime.evaluate", params: {expression: expression}, callba
ck: callbackEval5 }; | |
69 } | |
70 function callbackEval5(result) | |
71 { | |
72 var id = result.result.objectId; | |
73 if (id === undefined) | |
74 throw new Error("objectId is expected"); | |
75 return { | |
76 command: "Runtime.getProperties", params: {objectId: id, ownProperties: true
}, callback: callbackProperties5 | |
77 }; | |
78 } | |
79 function callbackProperties5(result) | |
80 { | |
81 logGetPropertiesResult("Object(5)", result); | |
82 return { callback: callbackStartNotOwn }; | |
83 } | |
84 | |
85 | |
86 // 'Not own' section -- check all properties of the object, including ones from
it prototype chain. | |
87 | |
88 function callbackStartNotOwn() | |
89 { | |
90 // Create an wrapper object with additional property. | |
91 var expression = "({ a: 2, set b(_) {}, get b() {return 5;}, __proto__: { a: 3
, c: 4, get d() {return 6;} }})"; | |
92 | |
93 return { command: "Runtime.evaluate", params: {expression: expression}, callba
ck: callbackEvalNotOwn }; | |
94 } | |
95 function callbackEvalNotOwn(result) | |
96 { | |
97 var id = result.result.objectId; | |
98 if (id === undefined) | |
99 throw new Error("objectId is expected"); | |
100 return { | |
101 command: "Runtime.getProperties", params: {objectId: id, ownProperties: fals
e}, callback: callbackPropertiesNotOwn | |
102 }; | |
103 } | |
104 function callbackPropertiesNotOwn(result) | |
105 { | |
106 logGetPropertiesResult("Not own properties", result); | |
107 return { callback: callbackStartAccessorsOnly }; | |
108 } | |
109 | |
110 | |
111 // 'Accessors only' section -- check only accessor properties of the object. | |
112 | |
113 function callbackStartAccessorsOnly() | |
114 { | |
115 // Create an wrapper object with additional property. | |
116 var expression = "({ a: 2, set b(_) {}, get b() {return 5;}, c: 'c', set d(_){
} })"; | |
117 | |
118 return { command: "Runtime.evaluate", params: {expression: expression}, callba
ck: callbackEvalAccessorsOnly }; | |
119 } | |
120 function callbackEvalAccessorsOnly(result) | |
121 { | |
122 var id = result.result.objectId; | |
123 if (id === undefined) | |
124 throw new Error("objectId is expected"); | |
125 return { | |
126 command: "Runtime.getProperties", params: {objectId: id, ownProperties: true
, accessorPropertiesOnly: true}, callback: callbackPropertiesAccessorsOnly | |
127 }; | |
128 } | |
129 function callbackPropertiesAccessorsOnly(result) | |
130 { | |
131 logGetPropertiesResult("Accessor only properties", result); | |
132 return { callback: callbackStartArray }; | |
133 } | |
134 | |
135 | |
136 // 'Array' section -- check properties of an array. | |
137 | |
138 function callbackStartArray() | |
139 { | |
140 var expression = "['red', 'green', 'blue']"; | |
141 return { command: "Runtime.evaluate", params: {expression: expression}, callba
ck: callbackEvalArray }; | |
142 } | |
143 function callbackEvalArray(result) | |
144 { | |
145 var id = result.result.objectId; | |
146 if (id === undefined) | |
147 throw new Error("objectId is expected"); | |
148 return { | |
149 command: "Runtime.getProperties", params: {objectId: id, ownProperties: true
}, callback: callbackPropertiesArray | |
150 }; | |
151 } | |
152 function callbackPropertiesArray(result) | |
153 { | |
154 logGetPropertiesResult("array", result); | |
155 return { callback: callbackStartBound }; | |
156 } | |
157 | |
158 | |
159 // 'Bound' section -- check properties of a bound function (has a bunch of inter
nal properties). | |
160 | |
161 function callbackStartBound() | |
162 { | |
163 var expression = "Number.bind({}, 5)"; | |
164 return { command: "Runtime.evaluate", params: {expression: expression}, callba
ck: callbackEvalBound }; | |
165 } | |
166 function callbackEvalBound(result) | |
167 { | |
168 var id = result.result.objectId; | |
169 if (id === undefined) | |
170 throw new Error("objectId is expected"); | |
171 return { | |
172 command: "Runtime.getProperties", params: {objectId: id, ownProperties: true
}, callback: callbackPropertiesBound | |
173 }; | |
174 } | |
175 function callbackPropertiesBound(result) | |
176 { | |
177 logGetPropertiesResult("Bound function", result); | |
178 return; // End of test | |
179 } | |
180 | |
181 // A helper function that dumps object properties and internal properties in sor
ted order. | |
182 function logGetPropertiesResult(title, protocolResult) | |
183 { | |
184 function hasGetterSetter(property, fieldName) | |
185 { | |
186 var v = property[fieldName]; | |
187 if (!v) | |
188 return false; | |
189 return v.type !== "undefined" | |
190 } | |
191 | |
192 InspectorTest.log("Properties of " + title); | |
193 var propertyArray = protocolResult.result; | |
194 propertyArray.sort(NamedThingComparator); | |
195 for (var i = 0; i < propertyArray.length; i++) { | |
196 var p = propertyArray[i]; | |
197 var v = p.value; | |
198 var own = p.isOwn ? "own" : "inherited"; | |
199 if (v) | |
200 InspectorTest.log(" " + p.name + " " + own + " " + v.type + " " + v.value
); | |
201 else | |
202 InspectorTest.log(" " + p.name + " " + own + " no value" + | |
203 (hasGetterSetter(p, "get") ? ", getter" : "") + (hasGetterSetter(p, "set
") ? ", setter" : "")); | |
204 } | |
205 var internalPropertyArray = protocolResult.internalProperties; | |
206 if (internalPropertyArray) { | |
207 InspectorTest.log("Internal properties"); | |
208 internalPropertyArray.sort(NamedThingComparator); | |
209 for (var i = 0; i < internalPropertyArray.length; i++) { | |
210 var p = internalPropertyArray[i]; | |
211 var v = p.value; | |
212 InspectorTest.log(" " + p.name + " " + v.type + " " + v.value); | |
213 } | |
214 } | |
215 | |
216 function NamedThingComparator(o1, o2) | |
217 { | |
218 return o1.name === o2.name ? 0 : (o1.name < o2.name ? -1 : 1); | |
219 } | |
220 } | |
OLD | NEW |