Chromium Code Reviews| 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 11 matching lines...) Expand all Loading... | |
| 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 /** | 31 /** |
| 32 * @typedef {{object: ?WebInspector.RemoteObject, wasThrown: (boolean|undefined) }} | |
| 33 */ | |
| 34 WebInspector.CallFunctionResult; | |
| 35 | |
| 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 /** |
| 41 * @return {?RuntimeAgent.CustomPreview} | 46 * @return {?RuntimeAgent.CustomPreview} |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 | 162 |
| 158 /** | 163 /** |
| 159 * @return {!Promise<?Array<!WebInspector.EventListener>>} | 164 * @return {!Promise<?Array<!WebInspector.EventListener>>} |
| 160 */ | 165 */ |
| 161 eventListeners: function() | 166 eventListeners: function() |
| 162 { | 167 { |
| 163 throw "Not implemented"; | 168 throw "Not implemented"; |
| 164 }, | 169 }, |
| 165 | 170 |
| 166 /** | 171 /** |
| 172 * @param {function(this:Object):!Array<!{handler:function(), useCapture: bo olean, type:string}>} getter | |
| 173 * @return {!Promise<?Array<!WebInspector.EventListener>>} | |
| 174 */ | |
| 175 frameworkEventListeners: function(getter) | |
| 176 { | |
| 177 throw "Not implemented"; | |
| 178 }, | |
| 179 | |
| 180 /** | |
| 181 * @param {function(this:Object):!Array<function()>} getter | |
| 182 * @return {!Promise<?WebInspector.RemoteSet>} | |
| 183 */ | |
| 184 frameworkInternalHandlers: function(getter) | |
| 185 { | |
| 186 throw "Not implemented"; | |
| 187 }, | |
| 188 | |
| 189 /** | |
| 167 * @param {!RuntimeAgent.CallArgument} name | 190 * @param {!RuntimeAgent.CallArgument} name |
| 168 * @param {function(string=)} callback | 191 * @param {function(string=)} callback |
| 169 */ | 192 */ |
| 170 deleteProperty: function(name, callback) | 193 deleteProperty: function(name, callback) |
| 171 { | 194 { |
| 172 throw "Not implemented"; | 195 throw "Not implemented"; |
| 173 }, | 196 }, |
| 174 | 197 |
| 175 /** | 198 /** |
| 176 * @param {function(this:Object, ...)} functionDeclaration | 199 * @param {function(this:Object, ...)} functionDeclaration |
| 177 * @param {!Array.<!RuntimeAgent.CallArgument>=} args | 200 * @param {!Array.<!RuntimeAgent.CallArgument>=} args |
| 178 * @param {function(?WebInspector.RemoteObject, boolean=)=} callback | 201 * @param {function(?WebInspector.RemoteObject, boolean=)=} callback |
| 179 */ | 202 */ |
| 180 callFunction: function(functionDeclaration, args, callback) | 203 callFunction: function(functionDeclaration, args, callback) |
| 181 { | 204 { |
| 182 throw "Not implemented"; | 205 throw "Not implemented"; |
| 183 }, | 206 }, |
| 184 | 207 |
| 185 /** | 208 /** |
| 186 * @param {function(this:Object, ...)} functionDeclaration | 209 * @param {function(this:Object, ...)} functionDeclaration |
| 187 * @param {!Array.<!RuntimeAgent.CallArgument>=} args | 210 * @param {!Array.<!RuntimeAgent.CallArgument>=} args |
| 188 * @return {!Promise.<!{object: ?WebInspector.RemoteObject, wasThrown: (bool ean|undefined)}>} | 211 * @return {!Promise<!WebInspector.CallFunctionResult>} |
| 189 */ | 212 */ |
| 190 callFunctionPromise: function(functionDeclaration, args) | 213 callFunctionPromise: function(functionDeclaration, args) |
| 191 { | 214 { |
| 192 return new Promise(promiseConstructor.bind(this)); | 215 return new Promise(promiseConstructor.bind(this)); |
| 193 | 216 |
| 194 /** | 217 /** |
| 195 * @param {function(!{object: ?WebInspector.RemoteObject, wasThrown: (bo olean|undefined)})} success | 218 * @param {function(!WebInspector.CallFunctionResult)} success |
| 196 * @this {WebInspector.RemoteObject} | 219 * @this {WebInspector.RemoteObject} |
| 197 */ | 220 */ |
| 198 function promiseConstructor(success) | 221 function promiseConstructor(success) |
| 199 { | 222 { |
| 200 this.callFunction(functionDeclaration, args, callFunctionCallback.bi nd(null, success)); | 223 this.callFunction(functionDeclaration, args, callFunctionCallback.bi nd(null, success)); |
| 201 } | 224 } |
| 202 | 225 |
| 203 /** | 226 /** |
| 204 * @param {function(!{object: ?WebInspector.RemoteObject, wasThrown: (bo olean|undefined)})} callback | 227 * @param {function(!WebInspector.CallFunctionResult)} callback |
| 205 * @param {?WebInspector.RemoteObject} object | 228 * @param {?WebInspector.RemoteObject} object |
| 206 * @param {boolean=} wasThrown | 229 * @param {boolean=} wasThrown |
| 207 */ | 230 */ |
| 208 function callFunctionCallback(callback, object, wasThrown) | 231 function callFunctionCallback(callback, object, wasThrown) |
| 209 { | 232 { |
| 210 callback({ | 233 callback({ |
| 211 object: object, | 234 object: object, |
| 212 wasThrown: wasThrown | 235 wasThrown: wasThrown |
| 213 }); | 236 }); |
| 214 } | 237 } |
| 215 }, | 238 }, |
| 216 | 239 |
| 217 /** | 240 /** |
| 218 * @param {function(this:Object)} functionDeclaration | 241 * @param {function(this:Object, ...)} functionDeclaration |
| 219 * @param {!Array<!RuntimeAgent.CallArgument>|undefined} args | 242 * @param {!Array<!RuntimeAgent.CallArgument>|undefined} args |
| 220 * @param {function(*)} callback | 243 * @param {function(*)} callback |
| 221 */ | 244 */ |
| 222 callFunctionJSON: function(functionDeclaration, args, callback) | 245 callFunctionJSON: function(functionDeclaration, args, callback) |
| 223 { | 246 { |
| 224 throw "Not implemented"; | 247 throw "Not implemented"; |
| 225 }, | 248 }, |
| 226 | 249 |
| 227 /** | 250 /** |
| 228 * @param {function(this:Object)} functionDeclaration | 251 * @param {function(this:Object, ...)} functionDeclaration |
| 229 * @param {!Array<!RuntimeAgent.CallArgument>|undefined} args | 252 * @param {!Array<!RuntimeAgent.CallArgument>|undefined} args |
| 230 * @return {!Promise<*>} | 253 * @return {!Promise<*>} |
| 231 */ | 254 */ |
| 232 callFunctionJSONPromise: function(functionDeclaration, args) | 255 callFunctionJSONPromise: function(functionDeclaration, args) |
| 233 { | 256 { |
| 234 return new Promise(promiseConstructor.bind(this)); | 257 return new Promise(promiseConstructor.bind(this)); |
| 235 | 258 |
| 236 /** | 259 /** |
| 237 * @this {WebInspector.RemoteObject} | 260 * @this {WebInspector.RemoteObject} |
| 238 */ | 261 */ |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 558 return new WebInspector.EventListener(this._target, | 581 return new WebInspector.EventListener(this._target, |
| 559 payload.type, | 582 payload.type, |
| 560 payload.useCapture, | 583 payload.useCapture, |
| 561 payload.handler ? this.tar get().runtimeModel.createRemoteObject(payload.handler) : null, | 584 payload.handler ? this.tar get().runtimeModel.createRemoteObject(payload.handler) : null, |
| 562 WebInspector.DebuggerModel .Location.fromPayload(this._debuggerModel, payload.location)); | 585 WebInspector.DebuggerModel .Location.fromPayload(this._debuggerModel, payload.location)); |
| 563 } | 586 } |
| 564 } | 587 } |
| 565 }, | 588 }, |
| 566 | 589 |
| 567 /** | 590 /** |
| 591 * @override | |
| 592 * @param {function(this:Object):!Array<!{handler:function(), useCapture: bo olean, type:string}>} getter | |
| 593 * @return {!Promise<?Array<!WebInspector.EventListener>>} | |
| 594 */ | |
| 595 frameworkEventListeners: function(getter) | |
|
pfeldman
2015/08/27 01:21:32
This does not belong to RemoteObject, I thought we
| |
| 596 { | |
| 597 return this.callFunctionPromise(getter, undefined) | |
| 598 .then(WebInspector.assertCallFunctionResult) | |
| 599 .then(WebInspector.RemoteArray.createPromise) | |
| 600 .then(toEventListeners) | |
| 601 .catchException(/** @type {?Array<!WebInspector.EventListener >} */(null)); | |
| 602 | |
| 603 /** | |
| 604 * @param {!WebInspector.RemoteArray} array | |
| 605 * @return {!Promise<?Array<!WebInspector.EventListener>>} | |
| 606 */ | |
| 607 function toEventListeners(array) | |
| 608 { | |
| 609 var promises = []; | |
| 610 for (var i = 0; i < array.length(); ++i) { | |
| 611 var promise = array.at(i) | |
| 612 .then(WebInspector.assertCallFunctionResult) | |
| 613 .then(toEventListener) | |
| 614 .catchException(/** @type {?WebInspector.Even tListener} */(null)); | |
| 615 promises.push(promise); | |
| 616 } | |
| 617 return /** @type {!Promise<?Array<!WebInspector.EventListener>>} */( Promise.all(promises).then(nonEmptyListeners)); | |
| 618 } | |
| 619 | |
| 620 /** | |
| 621 * @param {!WebInspector.RemoteObject} object | |
| 622 * @return {!Promise<!WebInspector.EventListener>} | |
| 623 */ | |
| 624 function toEventListener(object) | |
| 625 { | |
| 626 var data = {}; | |
| 627 var promises = []; | |
| 628 promises.push(object.callFunctionPromise(listenerEffectiveFunction, undefined) | |
| 629 .then(WebInspector.assertCallFunctionResult) | |
| 630 .then(WebInspector.RemoteFunction.createPromise) | |
| 631 .then(storeTargetFunctionWithDetails.bind(null, data))); | |
| 632 promises.push(object.callFunctionJSONPromise(WebInspector.identity, undefined) | |
| 633 .then(WebInspector.storeTo.bind(null, data, "lis tenerJSON"))); | |
| 634 return Promise.all(promises).then(createEventListener.bind(null, /** @type {!{targetFunction: !WebInspector.RemoteObject, listenerJSON: !Object, tar getFunctionDetails: !WebInspector.DebuggerModel.FunctionDetails}}*/ (data))); | |
| 635 } | |
| 636 | |
| 637 /** | |
| 638 * @param {?} data | |
| 639 * @param {!WebInspector.RemoteFunction} functionObject | |
| 640 * @return {!Promise<void>} | |
| 641 */ | |
| 642 function storeTargetFunctionWithDetails(data, functionObject) | |
| 643 { | |
| 644 return functionObject.targetFunction() | |
| 645 .then(WebInspector.storeTo.bind(null, data, "ta rgetFunction")) | |
| 646 .then(functionDetails); | |
| 647 | |
| 648 /** | |
| 649 * @param {!WebInspector.RemoteObject} functionObject | |
| 650 * @return {!Promise<void>} | |
| 651 */ | |
| 652 function functionDetails(functionObject) | |
| 653 { | |
| 654 return functionObject.functionDetailsPromise() | |
| 655 .then(WebInspector.storeTo.bind(null, data, "targetFunctionDetails")); | |
| 656 } | |
| 657 } | |
| 658 | |
| 659 /** | |
| 660 * @param {!{targetFunction: !WebInspector.RemoteObject, listenerJSON: ! Object, targetFunctionDetails: !WebInspector.DebuggerModel.FunctionDetails}} dat a | |
| 661 * @return {!WebInspector.EventListener} | |
| 662 */ | |
| 663 function createEventListener(data) | |
| 664 { | |
| 665 return new WebInspector.EventListener(data.targetFunction._target, | |
| 666 data.listenerJSON.type, | |
| 667 data.listenerJSON.useCapture, | |
| 668 data.targetFunction, | |
| 669 /** @type {!WebInspector.Debug gerModel.Location}} */ (data.targetFunctionDetails.location)); | |
| 670 } | |
| 671 | |
| 672 /** | |
| 673 * @suppressReceiverCheck | |
| 674 * @return {function()} | |
| 675 * @this {Object} | |
| 676 */ | |
| 677 function listenerEffectiveFunction() | |
| 678 { | |
| 679 if (typeof this.handler === "function") | |
| 680 return this.handler; | |
| 681 return typeof this.handler === "object" ? (this.handler.handlerEvent || this.handler.constructor) : null; | |
| 682 } | |
| 683 | |
| 684 /** | |
| 685 * @param {!Array<?WebInspector.EventListener>} listeners | |
| 686 * @return {!Array<!WebInspector.EventListener>} | |
| 687 */ | |
| 688 function nonEmptyListeners(listeners) | |
| 689 { | |
| 690 return listeners.filter(filterOutEmpty); | |
| 691 | |
| 692 /** | |
| 693 * @param {?WebInspector.EventListener} listener | |
| 694 */ | |
| 695 function filterOutEmpty(listener) | |
| 696 { | |
| 697 return !!listener; | |
| 698 } | |
| 699 } | |
| 700 }, | |
| 701 | |
| 702 /** | |
| 703 * @override | |
| 704 * @param {function(this:Object):!Array<function()>} getter | |
| 705 * @return {!Promise<?WebInspector.RemoteSet>} | |
| 706 */ | |
| 707 frameworkInternalHandlers: function(getter) | |
| 708 { | |
| 709 return this.callFunctionPromise(getter, undefined) | |
| 710 .then(WebInspector.assertCallFunctionResult) | |
| 711 .then(WebInspector.RemoteArray.createPromise) | |
| 712 .then(toInternalHandlers.bind(this)) | |
| 713 .catchException(/** @type {?WebInspector.RemoteSet} */(null)) ; | |
| 714 | |
| 715 /** | |
| 716 * @param {!WebInspector.RemoteArray} array | |
| 717 * @return {!Promise<!WebInspector.RemoteSet>} | |
| 718 * @this {WebInspector.RemoteObject} | |
| 719 */ | |
| 720 function toInternalHandlers(array) | |
| 721 { | |
| 722 var promises = []; | |
| 723 for (var i = 0; i < array.length(); ++i) { | |
| 724 var promise = array.at(i) | |
| 725 .then(WebInspector.assertCallFunctionResult) | |
| 726 .then(WebInspector.RemoteFunction.createPromi se) | |
| 727 .then(toInternalHandler) | |
| 728 .catchException(/** @type {?WebInspector.Remo teObject} */(null)); | |
| 729 promises.push(promise); | |
| 730 } | |
| 731 return Promise.all(promises).then(nonEmptyHandlers).then(WebInspecto r.RemoteSet.createFromArrayPromise.bind(this)); | |
| 732 } | |
| 733 | |
| 734 /** | |
| 735 * @param {!WebInspector.RemoteFunction} handler | |
| 736 * @return {!Promise<!WebInspector.RemoteObject>} | |
| 737 */ | |
| 738 function toInternalHandler(handler) | |
| 739 { | |
| 740 return handler.targetFunction(); | |
| 741 } | |
| 742 | |
| 743 /** | |
| 744 * @param {!Array<?WebInspector.RemoteObject>} handlers | |
| 745 * @return {!Array<!WebInspector.RemoteObject>} | |
| 746 */ | |
| 747 function nonEmptyHandlers(handlers) | |
| 748 { | |
| 749 return handlers.filter(filterOutEmpty); | |
| 750 | |
| 751 /** | |
| 752 * @param {?WebInspector.RemoteObject} handler | |
| 753 */ | |
| 754 function filterOutEmpty(handler) | |
| 755 { | |
| 756 return !!handler; | |
| 757 } | |
| 758 } | |
| 759 }, | |
| 760 | |
| 761 /** | |
| 568 * @param {!Array.<string>} propertyPath | 762 * @param {!Array.<string>} propertyPath |
| 569 * @param {function(?WebInspector.RemoteObject, boolean=)} callback | 763 * @param {function(?WebInspector.RemoteObject, boolean=)} callback |
| 570 */ | 764 */ |
| 571 getProperty: function(propertyPath, callback) | 765 getProperty: function(propertyPath, callback) |
| 572 { | 766 { |
| 573 /** | 767 /** |
| 574 * @param {string} arrayStr | 768 * @param {string} arrayStr |
| 575 * @suppressReceiverCheck | 769 * @suppressReceiverCheck |
| 576 * @this {Object} | 770 * @this {Object} |
| 577 */ | 771 */ |
| (...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1355 { | 1549 { |
| 1356 if (!this._cachedDescription) { | 1550 if (!this._cachedDescription) { |
| 1357 var children = this._children(); | 1551 var children = this._children(); |
| 1358 this._cachedDescription = "{" + this._formatValue(children[0].value) + " => " + this._formatValue(children[1].value) + "}"; | 1552 this._cachedDescription = "{" + this._formatValue(children[0].value) + " => " + this._formatValue(children[1].value) + "}"; |
| 1359 } | 1553 } |
| 1360 return this._cachedDescription; | 1554 return this._cachedDescription; |
| 1361 }, | 1555 }, |
| 1362 | 1556 |
| 1363 __proto__: WebInspector.LocalJSONObject.prototype | 1557 __proto__: WebInspector.LocalJSONObject.prototype |
| 1364 } | 1558 } |
| OLD | NEW |