OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium 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 /** | |
6 * @param {*} data | |
7 * @param {*} key | |
8 * @param {T} value | |
9 * @return {T} | |
10 * @template T | |
11 */ | |
12 WebInspector.storeTo = function(data, key, value) | |
pfeldman
2015/08/27 01:21:32
This should go to utilities.js as a separate patch
| |
13 { | |
14 data[key] = value; | |
15 return value; | |
16 } | |
17 | |
18 /** | |
19 * @param {!WebInspector.CallFunctionResult} result | |
20 * @return {!Promise<!WebInspector.RemoteObject>} | |
21 */ | |
22 WebInspector.assertCallFunctionResult = function(result) | |
pfeldman
2015/08/27 01:21:32
This seems too specific and needs to be next to th
| |
23 { | |
24 if (result.wasThrown || !result.object) | |
25 return Promise.reject(new Error("Function was thrown")); | |
26 return Promise.resolve(result.object); | |
27 } | |
28 | |
29 /** | |
30 * @suppressReceiverCheck | |
31 * @return {T} | |
32 * @this {T} | |
33 * @template T | |
34 */ | |
35 WebInspector.identity = function() | |
pfeldman
2015/08/27 01:21:32
This is weird!
| |
36 { | |
37 return this; | |
38 } | |
39 | |
40 /** | |
41 * @constructor | |
42 * @param {!WebInspector.RemoteObject} object | |
43 */ | |
44 WebInspector.RemoteArray = function(object) | |
pfeldman
2015/08/27 01:21:32
These could go into RemoteObject.js, lets land it
| |
45 { | |
46 this._object = object; | |
47 } | |
48 | |
49 /** | |
50 * @param {?WebInspector.RemoteObject} object | |
51 * @return {!Promise<!WebInspector.RemoteArray>} | |
52 */ | |
53 WebInspector.RemoteArray.createPromise = function(object) | |
pfeldman
2015/08/27 01:21:32
This does not need to be a promise, there is no as
| |
54 { | |
55 if (!object || object.subtype !== "array") | |
56 return Promise.reject(new Error("Object is empty or not an array")); | |
57 return Promise.resolve(new WebInspector.RemoteArray(object)); | |
58 } | |
59 | |
60 WebInspector.RemoteArray.prototype = { | |
61 /** | |
62 * @param {number} idx | |
63 * @return {!Promise<!WebInspector.CallFunctionResult>} | |
64 */ | |
65 at: function(idx) | |
pfeldman
2015/08/27 01:21:32
no abbreviations in Blink.
| |
66 { | |
67 return this._object.callFunctionPromise(at, [WebInspector.RemoteObject.t oCallArgument(idx)]); | |
68 | |
69 /** | |
70 * @suppressReceiverCheck | |
71 * @param {number} idx | |
72 * @return {*} | |
73 * @this {!Object} | |
74 */ | |
75 function at(idx) | |
76 { | |
77 return this[idx]; | |
78 } | |
79 }, | |
80 | |
81 /** | |
82 * @return {number} | |
83 */ | |
84 length: function() | |
85 { | |
86 return this._object.arrayLength(); | |
87 } | |
88 } | |
89 | |
90 /** | |
91 * @constructor | |
92 * @param {!WebInspector.RemoteObject} object | |
93 */ | |
94 WebInspector.RemoteFunction = function(object) | |
95 { | |
96 this._object = object; | |
97 } | |
98 | |
99 /** | |
100 * @param {?WebInspector.RemoteObject} object | |
101 * @return {!Promise<!WebInspector.RemoteFunction>} | |
102 */ | |
103 WebInspector.RemoteFunction.createPromise = function(object) | |
104 { | |
105 if (!object || object.type !== "function") | |
106 return Promise.reject(new Error("Object is empty or not a function")); | |
107 return Promise.resolve(new WebInspector.RemoteFunction(object)); | |
pfeldman
2015/08/27 01:21:32
ditto
| |
108 } | |
109 | |
110 WebInspector.RemoteFunction.prototype = { | |
111 /** | |
112 * @return {!Promise<!WebInspector.RemoteObject>} | |
113 */ | |
114 targetFunction: function() | |
115 { | |
116 return this._object.getOwnPropertiesPromise().then(findTargetFunction.bi nd(this)); | |
117 | |
118 /** | |
119 * @param {!{properties: ?Array<!WebInspector.RemoteObjectProperty>, int ernalProperties: ?Array<!WebInspector.RemoteObjectProperty>}} ownProperties | |
120 * @return {!WebInspector.RemoteObject} | |
121 * @this {WebInspector.RemoteFunction} | |
122 */ | |
123 function findTargetFunction(ownProperties) | |
124 { | |
125 if (!ownProperties.internalProperties) | |
126 return this._object; | |
127 var internalProperties = ownProperties.internalProperties; | |
128 for (var i = 0; i < internalProperties.length; ++i) { | |
129 if (internalProperties[i].name === "[[TargetFunction]]") | |
130 return internalProperties[i].value; | |
131 } | |
132 return this._object; | |
133 } | |
134 } | |
135 } | |
136 | |
137 /** | |
138 * @constructor | |
139 * @param {!WebInspector.RemoteObject} object | |
140 */ | |
141 WebInspector.RemoteSet = function(object) | |
pfeldman
2015/08/27 01:21:32
Why do you need a writable wrapper like this?
| |
142 { | |
143 this._object = object; | |
144 } | |
145 | |
146 /** | |
147 * @param {!Array<!WebInspector.RemoteObject>} array | |
148 * @return {!Promise<!WebInspector.RemoteSet>} | |
149 * @this {WebInspector.RemoteObject} | |
150 */ | |
151 WebInspector.RemoteSet.createFromArrayPromise = function(array) | |
152 { | |
153 return WebInspector.RemoteSet.createEmptyPromise.call(this).then(addArray); | |
154 /** | |
155 * @param {!WebInspector.RemoteSet} remoteSet | |
156 * @return {!Promise<!WebInspector.RemoteSet>} | |
157 */ | |
158 function addArray(remoteSet) | |
159 { | |
160 var promise = Promise.resolve(remoteSet); | |
161 for (var i = 0; i < array.length; ++i) | |
162 promise = promise.then(WebInspector.RemoteSet.prototype.add.bind(rem oteSet, array[i])); | |
163 return promise; | |
164 } | |
165 } | |
166 | |
167 /** | |
168 * @return {!Promise<!WebInspector.RemoteSet>} | |
169 * @this {WebInspector.RemoteObject} | |
170 */ | |
171 WebInspector.RemoteSet.createEmptyPromise = function() | |
172 { | |
173 return this.callFunctionPromise(emptySet, undefined) | |
174 .then(WebInspector.assertCallFunctionResult) | |
175 .then(createRemoteSet); | |
176 | |
177 /** | |
178 * @return {!Set} | |
179 */ | |
180 function emptySet() | |
181 { | |
182 return new Set(); | |
183 } | |
184 | |
185 /** | |
186 * @param {!WebInspector.RemoteObject} object | |
187 * @return {!WebInspector.RemoteSet} | |
188 */ | |
189 function createRemoteSet(object) | |
190 { | |
191 return new WebInspector.RemoteSet(object); | |
192 } | |
193 } | |
194 | |
195 WebInspector.RemoteSet.prototype = | |
196 { | |
197 /** | |
198 * @param {!WebInspector.RemoteObject} object | |
199 * @return {!Promise<!WebInspector.RemoteSet>} | |
200 */ | |
201 add: function(object) | |
202 { | |
203 return this._object.callFunctionPromise(add, [WebInspector.RemoteObject. toCallArgument(object)]) | |
204 .then(returnThis.bind(this)); | |
205 | |
206 /** | |
207 * @suppressReceiverCheck | |
208 * @param {!Object} object | |
209 * @return {!Set} | |
210 * @this {Set} | |
211 */ | |
212 function add(object) | |
213 { | |
214 this.add(object); | |
215 return this; | |
216 } | |
217 | |
218 /** | |
219 * @return {!T} | |
220 * @this {T} | |
221 * @template T | |
222 */ | |
223 function returnThis() | |
224 { | |
225 return this; | |
226 } | |
227 }, | |
228 | |
229 /** | |
230 * @param {!WebInspector.RemoteObject} object | |
231 * @return {!Promise<boolean>} | |
232 */ | |
233 has: function(object) | |
234 { | |
235 return /** @type {!Promise<boolean>} */(this._object.callFunctionJSONPro mise(has, [WebInspector.RemoteObject.toCallArgument(object)])); | |
236 | |
237 /** | |
238 * @suppressReceiverCheck | |
239 * @param {!Object} object | |
240 * @return {boolean} | |
241 * @this {Set} | |
242 */ | |
243 function has(object) | |
244 { | |
245 return this.has(object); | |
246 } | |
247 } | |
248 } | |
OLD | NEW |