| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 var errorMessage; | 592 var errorMessage; |
| 593 /** | 593 /** |
| 594 * @param {string} message | 594 * @param {string} message |
| 595 */ | 595 */ |
| 596 function onError(message) { | 596 function onError(message) { |
| 597 console.error(message); | 597 console.error(message); |
| 598 errorMessage = message; | 598 errorMessage = message; |
| 599 } | 599 } |
| 600 var userCallback = (args.length && typeof args.peekLast() === 'function') ?
args.pop() : null; | 600 var userCallback = (args.length && typeof args.peekLast() === 'function') ?
args.pop() : null; |
| 601 var params = this._prepareParameters(method, signature, args, !userCallback,
onError); | 601 var params = this._prepareParameters(method, signature, args, !userCallback,
onError); |
| 602 if (errorMessage) | 602 var responseArguments; |
| 603 return Promise.reject(new Error(errorMessage)); | 603 if (errorMessage) { |
| 604 else | 604 responseArguments = [errorMessage]; |
| 605 return new Promise(promiseAction.bind(this)); | 605 return Promise.resolve().then(runUserCallback); |
| 606 } |
| 607 return new Promise(promiseAction.bind(this)).then(runUserCallback); |
| 606 | 608 |
| 607 /** | 609 /** |
| 608 * @param {function(?)} resolve | 610 * @param {function()} resolve |
| 609 * @param {function(!Error)} reject | 611 * @param {function(!Error)} reject |
| 610 * @this {Protocol.InspectorBackend._AgentPrototype} | 612 * @this {Protocol.InspectorBackend._AgentPrototype} |
| 611 */ | 613 */ |
| 612 function promiseAction(resolve, reject) { | 614 function promiseAction(resolve, reject) { |
| 613 /** | 615 /** |
| 614 * @param {...*} vararg | 616 * @param {...*} vararg |
| 615 */ | 617 */ |
| 616 function callback(vararg) { | 618 function callback(vararg) { |
| 617 var result = userCallback ? userCallback.apply(null, arguments) : undefi
ned; | 619 responseArguments = arguments; |
| 618 resolve(result); | 620 resolve(); |
| 619 } | 621 } |
| 620 this._target._wrapCallbackAndSendMessageObject(this._domain, method, param
s, callback); | 622 this._target._wrapCallbackAndSendMessageObject(this._domain, method, param
s, callback); |
| 621 } | 623 } |
| 624 |
| 625 function runUserCallback() { |
| 626 return userCallback ? userCallback.apply(null, responseArguments) : undefi
ned; |
| 627 } |
| 622 } | 628 } |
| 623 | 629 |
| 624 /** | 630 /** |
| 625 * @param {string} method | 631 * @param {string} method |
| 626 * @param {?Object} args | 632 * @param {?Object} args |
| 627 * @param {?function(*)} callback | 633 * @param {?function(*)} callback |
| 628 */ | 634 */ |
| 629 _invoke(method, args, callback) { | 635 _invoke(method, args, callback) { |
| 630 this._target._wrapCallbackAndSendMessageObject(this._domain, method, args, c
allback); | 636 this._target._wrapCallbackAndSendMessageObject(this._domain, method, args, c
allback); |
| 631 } | 637 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 if (Protocol.InspectorBackend.Options.dumpInspectorTimeStats) | 727 if (Protocol.InspectorBackend.Options.dumpInspectorTimeStats) |
| 722 console.timeEnd(timingLabel); | 728 console.timeEnd(timingLabel); |
| 723 } | 729 } |
| 724 }; | 730 }; |
| 725 | 731 |
| 726 Protocol.InspectorBackend.Options = { | 732 Protocol.InspectorBackend.Options = { |
| 727 dumpInspectorTimeStats: false, | 733 dumpInspectorTimeStats: false, |
| 728 dumpInspectorProtocolMessages: false, | 734 dumpInspectorProtocolMessages: false, |
| 729 suppressRequestErrors: false | 735 suppressRequestErrors: false |
| 730 }; | 736 }; |
| OLD | NEW |