Chromium Code Reviews| 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 var responseArguments; | |
| 602 if (errorMessage) | 603 if (errorMessage) |
| 603 return Promise.reject(new Error(errorMessage)); | 604 return Promise.reject(new Error(errorMessage)); |
|
pfeldman
2017/02/16 22:43:02
You aren't calling it here, are you?
| |
| 604 else | 605 else |
| 605 return new Promise(promiseAction.bind(this)); | 606 return new Promise(promiseAction.bind(this)).then(runUserCallback); |
| 606 | 607 |
| 607 /** | 608 /** |
| 608 * @param {function(?)} resolve | 609 * @param {function()} resolve |
| 609 * @param {function(!Error)} reject | 610 * @param {function(!Error)} reject |
| 610 * @this {Protocol.InspectorBackend._AgentPrototype} | 611 * @this {Protocol.InspectorBackend._AgentPrototype} |
| 611 */ | 612 */ |
| 612 function promiseAction(resolve, reject) { | 613 function promiseAction(resolve, reject) { |
| 613 /** | 614 /** |
| 614 * @param {...*} vararg | 615 * @param {...*} vararg |
| 615 */ | 616 */ |
| 616 function callback(vararg) { | 617 function callback(vararg) { |
| 617 var result = userCallback ? userCallback.apply(null, arguments) : undefi ned; | 618 responseArguments = arguments; |
| 618 resolve(result); | 619 resolve(); |
| 619 } | 620 } |
| 620 this._target._wrapCallbackAndSendMessageObject(this._domain, method, param s, callback); | 621 this._target._wrapCallbackAndSendMessageObject(this._domain, method, param s, callback); |
| 621 } | 622 } |
| 623 | |
| 624 function runUserCallback() { | |
|
pfeldman
2017/02/16 22:43:02
You are changing the order of callback and promise
| |
| 625 return userCallback ? userCallback.apply(null, responseArguments) : undefi ned; | |
| 626 } | |
| 622 } | 627 } |
| 623 | 628 |
| 624 /** | 629 /** |
| 625 * @param {string} method | 630 * @param {string} method |
| 626 * @param {?Object} args | 631 * @param {?Object} args |
| 627 * @param {?function(*)} callback | 632 * @param {?function(*)} callback |
| 628 */ | 633 */ |
| 629 _invoke(method, args, callback) { | 634 _invoke(method, args, callback) { |
| 630 this._target._wrapCallbackAndSendMessageObject(this._domain, method, args, c allback); | 635 this._target._wrapCallbackAndSendMessageObject(this._domain, method, args, c allback); |
| 631 } | 636 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 721 if (Protocol.InspectorBackend.Options.dumpInspectorTimeStats) | 726 if (Protocol.InspectorBackend.Options.dumpInspectorTimeStats) |
| 722 console.timeEnd(timingLabel); | 727 console.timeEnd(timingLabel); |
| 723 } | 728 } |
| 724 }; | 729 }; |
| 725 | 730 |
| 726 Protocol.InspectorBackend.Options = { | 731 Protocol.InspectorBackend.Options = { |
| 727 dumpInspectorTimeStats: false, | 732 dumpInspectorTimeStats: false, |
| 728 dumpInspectorProtocolMessages: false, | 733 dumpInspectorProtocolMessages: false, |
| 729 suppressRequestErrors: false | 734 suppressRequestErrors: false |
| 730 }; | 735 }; |
| OLD | NEW |