OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 10 matching lines...) Expand all Loading... | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 /** | |
32 * @typedef {{object: ?WebInspector.RemoteObject, wasThrown: (boolean|undefined) }} | |
33 */ | |
34 WebInspector.CallFunctionResult; | |
35 | |
31 /** | 36 /** |
32 * This may not be an interface due to "instanceof WebInspector.RemoteObject" ch ecks in the code. | 37 * This may not be an interface due to "instanceof WebInspector.RemoteObject" ch ecks in the code. |
33 * | 38 * |
34 * @constructor | 39 * @constructor |
35 */ | 40 */ |
36 WebInspector.RemoteObject = function() { } | 41 WebInspector.RemoteObject = function() { } |
37 | 42 |
38 WebInspector.RemoteObject.prototype = { | 43 WebInspector.RemoteObject.prototype = { |
39 | 44 |
40 /** | 45 /** |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 * @param {!RuntimeAgent.CallArgument} name | 172 * @param {!RuntimeAgent.CallArgument} name |
168 * @param {function(string=)} callback | 173 * @param {function(string=)} callback |
169 */ | 174 */ |
170 deleteProperty: function(name, callback) | 175 deleteProperty: function(name, callback) |
171 { | 176 { |
172 throw "Not implemented"; | 177 throw "Not implemented"; |
173 }, | 178 }, |
174 | 179 |
175 /** | 180 /** |
176 * @param {function(this:Object, ...)} functionDeclaration | 181 * @param {function(this:Object, ...)} functionDeclaration |
177 * @param {!Array.<!RuntimeAgent.CallArgument>=} args | 182 * @param {!Array<!RuntimeAgent.CallArgument>=} args |
178 * @param {function(?WebInspector.RemoteObject, boolean=)=} callback | 183 * @param {function(?WebInspector.RemoteObject, boolean=)=} callback |
179 */ | 184 */ |
180 callFunction: function(functionDeclaration, args, callback) | 185 callFunction: function(functionDeclaration, args, callback) |
181 { | 186 { |
182 throw "Not implemented"; | 187 throw "Not implemented"; |
183 }, | 188 }, |
184 | 189 |
185 /** | 190 /** |
186 * @param {function(this:Object, ...)} functionDeclaration | 191 * @param {function(this:Object, ...)} functionDeclaration |
187 * @param {!Array.<!RuntimeAgent.CallArgument>=} args | 192 * @param {!Array<!RuntimeAgent.CallArgument>=} args |
188 * @return {!Promise.<!{object: ?WebInspector.RemoteObject, wasThrown: (bool ean|undefined)}>} | 193 * @return {!Promise<!WebInspector.CallFunctionResult>} |
189 */ | 194 */ |
190 callFunctionPromise: function(functionDeclaration, args) | 195 callFunctionPromise: function(functionDeclaration, args) |
191 { | 196 { |
192 return new Promise(promiseConstructor.bind(this)); | 197 return new Promise(promiseConstructor.bind(this)); |
193 | 198 |
194 /** | 199 /** |
195 * @param {function(!{object: ?WebInspector.RemoteObject, wasThrown: (bo olean|undefined)})} success | 200 * @param {function(!WebInspector.CallFunctionResult)} success |
196 * @this {WebInspector.RemoteObject} | 201 * @this {WebInspector.RemoteObject} |
197 */ | 202 */ |
198 function promiseConstructor(success) | 203 function promiseConstructor(success) |
199 { | 204 { |
200 this.callFunction(functionDeclaration, args, callFunctionCallback.bi nd(null, success)); | 205 this.callFunction(functionDeclaration, args, callFunctionCallback.bi nd(null, success)); |
201 } | 206 } |
202 | 207 |
203 /** | 208 /** |
204 * @param {function(!{object: ?WebInspector.RemoteObject, wasThrown: (bo olean|undefined)})} callback | 209 * @param {function(!WebInspector.CallFunctionResult)} callback |
205 * @param {?WebInspector.RemoteObject} object | 210 * @param {?WebInspector.RemoteObject} object |
206 * @param {boolean=} wasThrown | 211 * @param {boolean=} wasThrown |
207 */ | 212 */ |
208 function callFunctionCallback(callback, object, wasThrown) | 213 function callFunctionCallback(callback, object, wasThrown) |
209 { | 214 { |
210 callback({ | 215 callback({ |
211 object: object, | 216 object: object, |
212 wasThrown: wasThrown | 217 wasThrown: wasThrown |
213 }); | 218 }); |
214 } | 219 } |
215 }, | 220 }, |
216 | 221 |
217 /** | 222 /** |
218 * @param {function(this:Object)} functionDeclaration | 223 * @param {function(this:Object, ...)} functionDeclaration |
219 * @param {!Array<!RuntimeAgent.CallArgument>|undefined} args | 224 * @param {!Array<!RuntimeAgent.CallArgument>|undefined} args |
220 * @param {function(*)} callback | 225 * @param {function(*)} callback |
221 */ | 226 */ |
222 callFunctionJSON: function(functionDeclaration, args, callback) | 227 callFunctionJSON: function(functionDeclaration, args, callback) |
223 { | 228 { |
224 throw "Not implemented"; | 229 throw "Not implemented"; |
225 }, | 230 }, |
226 | 231 |
227 /** | 232 /** |
228 * @param {function(this:Object)} functionDeclaration | 233 * @param {function(this:Object, ...)} functionDeclaration |
229 * @param {!Array<!RuntimeAgent.CallArgument>|undefined} args | 234 * @param {!Array<!RuntimeAgent.CallArgument>|undefined} args |
230 * @return {!Promise<*>} | 235 * @return {!Promise<*>} |
231 */ | 236 */ |
232 callFunctionJSONPromise: function(functionDeclaration, args) | 237 callFunctionJSONPromise: function(functionDeclaration, args) |
233 { | 238 { |
234 return new Promise(promiseConstructor.bind(this)); | 239 return new Promise(promiseConstructor.bind(this)); |
235 | 240 |
236 /** | 241 /** |
237 * @this {WebInspector.RemoteObject} | 242 * @this {WebInspector.RemoteObject} |
238 */ | 243 */ |
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1331 } | 1336 } |
1332 | 1337 |
1333 callback(result); | 1338 callback(result); |
1334 }, | 1339 }, |
1335 | 1340 |
1336 __proto__: WebInspector.RemoteObject.prototype | 1341 __proto__: WebInspector.RemoteObject.prototype |
1337 } | 1342 } |
1338 | 1343 |
1339 /** | 1344 /** |
1340 * @constructor | 1345 * @constructor |
1346 * @param {!WebInspector.RemoteObject} object | |
1347 */ | |
1348 WebInspector.RemoteArray = function(object) | |
1349 { | |
1350 this._object = object; | |
1351 }; | |
1352 | |
1353 /** | |
1354 * @param {?WebInspector.RemoteObject} object | |
1355 * @return {!WebInspector.RemoteArray} | |
1356 */ | |
1357 WebInspector.RemoteArray.createFromObject = function(object) | |
1358 { | |
1359 if (!object || object.subtype !== "array") | |
1360 throw new Error("Object is empty or not an array"); | |
1361 return new WebInspector.RemoteArray(object); | |
1362 } | |
1363 | |
1364 /** | |
1365 * @param {!Array<!WebInspector.RemoteObject>} objects | |
1366 * @return {!Promise<!WebInspector.RemoteArray>} | |
1367 */ | |
1368 WebInspector.RemoteArray.createFromArray = function(objects) | |
pfeldman
2015/09/02 03:05:52
Their names are so close, but their semantics is s
kozy
2015/09/02 16:34:04
Done.
| |
1369 { | |
1370 if (!objects.length) | |
1371 throw new Error("Input array is empty"); | |
1372 var objectArguments = []; | |
1373 for (var i = 0; i < objects.length; ++i) | |
1374 objectArguments.push(WebInspector.RemoteObject.toCallArgument(objects[i] )) | |
1375 return objects[0].callFunctionPromise(createArray, objectArguments).then(ret urnRemoteArray); | |
1376 | |
1377 /** | |
1378 * @return {!Array<*>} | |
1379 */ | |
1380 function createArray() | |
1381 { | |
1382 if (arguments.length > 1) | |
1383 return new Array(arguments); | |
1384 return [arguments[0]]; | |
1385 } | |
1386 | |
1387 /** | |
1388 * @param {!WebInspector.CallFunctionResult} result | |
1389 * @return {!WebInspector.RemoteArray} | |
1390 */ | |
1391 function returnRemoteArray(result) | |
1392 { | |
1393 if (result.wasThrown || !result.object) | |
1394 throw new Error("Call function throws exceptions or returns empty va lue"); | |
1395 return WebInspector.RemoteArray.createFromObject(result.object); | |
1396 } | |
1397 } | |
1398 | |
1399 WebInspector.RemoteArray.prototype = { | |
1400 /** | |
1401 * @param {number} index | |
1402 * @return {!Promise<!WebInspector.RemoteObject>} | |
1403 */ | |
1404 at: function(index) | |
1405 { | |
1406 if (index < 0 || index > this._object.arrayLength()) | |
1407 throw new Error("Out of range"); | |
1408 return this._object.callFunctionPromise(at, [WebInspector.RemoteObject.t oCallArgument(index)]).then(assertCallFunctionResult); | |
1409 | |
1410 /** | |
1411 * @suppressReceiverCheck | |
1412 * @param {number} index | |
1413 * @return {*} | |
1414 * @this {!Object} | |
1415 */ | |
1416 function at(index) | |
1417 { | |
1418 return this[index]; | |
1419 } | |
1420 | |
1421 /** | |
1422 * @param {!WebInspector.CallFunctionResult} result | |
1423 * @return {!WebInspector.RemoteObject} | |
1424 */ | |
1425 function assertCallFunctionResult(result) | |
1426 { | |
1427 if (result.wasThrown || !result.object) | |
1428 throw new Error("Exception in callFunction or result value is em pty"); | |
1429 return result.object; | |
1430 } | |
1431 }, | |
1432 | |
1433 /** | |
1434 * @return {number} | |
1435 */ | |
1436 length: function() | |
1437 { | |
1438 return this._object.arrayLength(); | |
1439 }, | |
1440 | |
1441 /** | |
1442 * @param {function(!WebInspector.RemoteObject):!Promise<T>} func | |
1443 * @return {!Promise<!Array<T>>} | |
1444 * @template T | |
1445 */ | |
1446 map: function(func) | |
1447 { | |
1448 var promises = []; | |
1449 for (var i = 0; i < this.length(); ++i) | |
1450 promises.push(this.at(i).then(func)); | |
1451 return Promise.all(promises); | |
1452 }, | |
1453 | |
1454 /** | |
1455 * @return {!WebInspector.RemoteObject} | |
1456 */ | |
1457 object: function() | |
1458 { | |
1459 return this._object; | |
1460 } | |
1461 } | |
1462 | |
1463 /** | |
1464 * @constructor | |
1465 * @param {!WebInspector.RemoteObject} object | |
1466 */ | |
1467 WebInspector.RemoteFunction = function(object) | |
1468 { | |
1469 this._object = object; | |
1470 } | |
1471 | |
1472 /** | |
1473 * @param {?WebInspector.RemoteObject} object | |
1474 * @return {!WebInspector.RemoteFunction} | |
1475 */ | |
1476 WebInspector.RemoteFunction.createFromObject = function(object) | |
pfeldman
2015/09/02 03:05:52
objectAsFunction
kozy
2015/09/02 16:34:04
Done.
| |
1477 { | |
1478 if (!object || object.type !== "function") | |
1479 throw new Error("Object is empty or not a function"); | |
1480 return new WebInspector.RemoteFunction(object); | |
1481 } | |
1482 | |
1483 WebInspector.RemoteFunction.prototype = { | |
1484 /** | |
1485 * @return {!Promise<!WebInspector.RemoteObject>} | |
1486 */ | |
1487 targetFunction: function() | |
1488 { | |
1489 return this._object.getOwnPropertiesPromise().then(targetFunction.bind(t his)); | |
1490 | |
1491 /** | |
1492 * @param {!{properties: ?Array<!WebInspector.RemoteObjectProperty>, int ernalProperties: ?Array<!WebInspector.RemoteObjectProperty>}} ownProperties | |
1493 * @return {!WebInspector.RemoteObject} | |
1494 * @this {WebInspector.RemoteFunction} | |
1495 */ | |
1496 function targetFunction(ownProperties) | |
1497 { | |
1498 if (!ownProperties.internalProperties) | |
1499 return this._object; | |
1500 var internalProperties = ownProperties.internalProperties; | |
1501 for (var property of internalProperties) { | |
1502 if (property.name === "[[TargetFunction]]") | |
1503 return property.value; | |
1504 } | |
1505 return this._object; | |
1506 } | |
1507 }, | |
1508 | |
1509 /** | |
1510 * @return {!WebInspector.RemoteObject} | |
1511 */ | |
1512 object: function() | |
1513 { | |
1514 return this._object; | |
1515 } | |
1516 } | |
1517 | |
1518 /** | |
1519 * @constructor | |
1341 * @extends {WebInspector.LocalJSONObject} | 1520 * @extends {WebInspector.LocalJSONObject} |
1342 * @param {*} value | 1521 * @param {*} value |
1343 */ | 1522 */ |
1344 WebInspector.MapEntryLocalJSONObject = function(value) | 1523 WebInspector.MapEntryLocalJSONObject = function(value) |
1345 { | 1524 { |
1346 WebInspector.LocalJSONObject.call(this, value); | 1525 WebInspector.LocalJSONObject.call(this, value); |
1347 } | 1526 } |
1348 | 1527 |
1349 WebInspector.MapEntryLocalJSONObject.prototype = { | 1528 WebInspector.MapEntryLocalJSONObject.prototype = { |
1350 /** | 1529 /** |
1351 * @override | 1530 * @override |
1352 * @return {string} | 1531 * @return {string} |
1353 */ | 1532 */ |
1354 get description() | 1533 get description() |
1355 { | 1534 { |
1356 if (!this._cachedDescription) { | 1535 if (!this._cachedDescription) { |
1357 var children = this._children(); | 1536 var children = this._children(); |
1358 this._cachedDescription = "{" + this._formatValue(children[0].value) + " => " + this._formatValue(children[1].value) + "}"; | 1537 this._cachedDescription = "{" + this._formatValue(children[0].value) + " => " + this._formatValue(children[1].value) + "}"; |
1359 } | 1538 } |
1360 return this._cachedDescription; | 1539 return this._cachedDescription; |
1361 }, | 1540 }, |
1362 | 1541 |
1363 __proto__: WebInspector.LocalJSONObject.prototype | 1542 __proto__: WebInspector.LocalJSONObject.prototype |
1364 } | 1543 } |
OLD | NEW |