| 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 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 InspectorBackendClass.AgentPrototype = function(domain) | 753 InspectorBackendClass.AgentPrototype = function(domain) |
| 754 { | 754 { |
| 755 this._replyArgs = {}; | 755 this._replyArgs = {}; |
| 756 this._hasErrorData = {}; | 756 this._hasErrorData = {}; |
| 757 this._domain = domain; | 757 this._domain = domain; |
| 758 this._suppressErrorLogging = false; | 758 this._suppressErrorLogging = false; |
| 759 this._promisified = domain in InspectorBackendClass.AgentPrototype.Promisifi
edDomains; | 759 this._promisified = domain in InspectorBackendClass.AgentPrototype.Promisifi
edDomains; |
| 760 } | 760 } |
| 761 | 761 |
| 762 InspectorBackendClass.AgentPrototype.PromisifiedDomains = { | 762 InspectorBackendClass.AgentPrototype.PromisifiedDomains = { |
| 763 "CSS": true, |
| 763 "Profiler": true | 764 "Profiler": true |
| 764 } | 765 } |
| 765 | 766 |
| 766 InspectorBackendClass.AgentPrototype.prototype = { | 767 InspectorBackendClass.AgentPrototype.prototype = { |
| 767 | 768 |
| 768 /** | 769 /** |
| 769 * @param {!InspectorBackendClass.Connection} connection | 770 * @param {!InspectorBackendClass.Connection} connection |
| 770 */ | 771 */ |
| 771 setConnection: function(connection) | 772 setConnection: function(connection) |
| 772 { | 773 { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 906 { | 907 { |
| 907 var errorMessage; | 908 var errorMessage; |
| 908 /** | 909 /** |
| 909 * @param {string} message | 910 * @param {string} message |
| 910 */ | 911 */ |
| 911 function onError(message) | 912 function onError(message) |
| 912 { | 913 { |
| 913 console.error(message) | 914 console.error(message) |
| 914 errorMessage = message; | 915 errorMessage = message; |
| 915 } | 916 } |
| 917 var userCallback = (args.length && typeof args.peekLast() === "function"
) ? args.pop() : null; |
| 916 var params = this._prepareParameters(method, signature, args, false, onE
rror); | 918 var params = this._prepareParameters(method, signature, args, false, onE
rror); |
| 917 if (errorMessage) | 919 if (errorMessage) |
| 918 return Promise.reject(new Error(errorMessage)); | 920 return Promise.reject(new Error(errorMessage)); |
| 919 else | 921 else |
| 920 return new Promise(promiseAction.bind(this)); | 922 return new Promise(promiseAction.bind(this)); |
| 921 | 923 |
| 922 /** | 924 /** |
| 923 * @param {function(?)} resolve | 925 * @param {function(?)} resolve |
| 924 * @param {function(!Error)} reject | 926 * @param {function(!Error)} reject |
| 925 * @this {InspectorBackendClass.AgentPrototype} | 927 * @this {InspectorBackendClass.AgentPrototype} |
| 926 */ | 928 */ |
| 927 function promiseAction(resolve, reject) | 929 function promiseAction(resolve, reject) |
| 928 { | 930 { |
| 929 /** | 931 /** |
| 930 * @param {?Protocol.Error} error | 932 * @param {...*} vararg |
| 931 * @param {?Object} result | |
| 932 */ | 933 */ |
| 933 function callback(error, result) | 934 function callback(vararg) |
| 934 { | 935 { |
| 935 if (error) { | 936 var result = userCallback ? userCallback.apply(null, arguments)
: undefined; |
| 936 console.error(error); | 937 resolve(result); |
| 937 resolve(null); | |
| 938 return; | |
| 939 } | |
| 940 resolve(replyArgs.length ? result : undefined); | |
| 941 } | 938 } |
| 942 this._connection._wrapCallbackAndSendMessageObject(this._domain, met
hod, params, callback); | 939 this._connection._wrapCallbackAndSendMessageObject(this._domain, met
hod, params, callback); |
| 943 } | 940 } |
| 944 }, | 941 }, |
| 945 | 942 |
| 946 /** | 943 /** |
| 947 * @param {string} method | 944 * @param {string} method |
| 948 * @param {?Object} args | 945 * @param {?Object} args |
| 949 * @param {?function(*)} callback | 946 * @param {?function(*)} callback |
| 950 */ | 947 */ |
| 951 _invoke: function(method, args, callback) | 948 _invoke: function(method, args, callback) |
| 952 { | 949 { |
| 953 this._connection._wrapCallbackAndSendMessageObject(this._domain, method,
args, callback); | 950 this._connection._wrapCallbackAndSendMessageObject(this._domain, method,
args, callback); |
| 954 }, | 951 }, |
| 955 | 952 |
| 956 /** | 953 /** |
| 957 * @param {!Object} messageObject | 954 * @param {!Object} messageObject |
| 958 * @param {string} methodName | 955 * @param {string} methodName |
| 959 * @param {function(*)|function(?Protocol.Error, ?Object)} callback | 956 * @param {function(*)|function(?Protocol.Error, ?Object)} callback |
| 960 */ | 957 */ |
| 961 dispatchResponse: function(messageObject, methodName, callback) | 958 dispatchResponse: function(messageObject, methodName, callback) |
| 962 { | 959 { |
| 963 if (messageObject.error && messageObject.error.code !== InspectorBackend
Class._DevToolsErrorCode && !InspectorBackendClass.Options.suppressRequestErrors
&& !this._suppressErrorLogging) { | 960 if (messageObject.error && messageObject.error.code !== InspectorBackend
Class._DevToolsErrorCode && !InspectorBackendClass.Options.suppressRequestErrors
&& !this._suppressErrorLogging) { |
| 964 var id = InspectorFrontendHost.isUnderTest() ? "##" : messageObject.
id; | 961 var id = InspectorFrontendHost.isUnderTest() ? "##" : messageObject.
id; |
| 965 console.error("Request with id = " + id + " failed. " + JSON.stringi
fy(messageObject.error)); | 962 console.error("Request with id = " + id + " failed. " + JSON.stringi
fy(messageObject.error)); |
| 966 } | 963 } |
| 967 | 964 |
| 968 if (this._promisified) { | |
| 969 callback(messageObject.error && messageObject.error.message, message
Object.result); | |
| 970 return; | |
| 971 } | |
| 972 | |
| 973 var argumentsArray = []; | 965 var argumentsArray = []; |
| 974 argumentsArray[0] = messageObject.error ? messageObject.error.message: n
ull; | 966 argumentsArray[0] = messageObject.error ? messageObject.error.message: n
ull; |
| 975 | 967 |
| 976 if (this._hasErrorData[methodName]) | 968 if (this._hasErrorData[methodName]) |
| 977 argumentsArray[1] = messageObject.error ? messageObject.error.data :
null; | 969 argumentsArray[1] = messageObject.error ? messageObject.error.data :
null; |
| 978 | 970 |
| 979 if (messageObject.result) { | 971 if (messageObject.result) { |
| 980 var paramNames = this._replyArgs[methodName] || []; | 972 var paramNames = this._replyArgs[methodName] || []; |
| 981 for (var i = 0; i < paramNames.length; ++i) | 973 for (var i = 0; i < paramNames.length; ++i) |
| 982 argumentsArray.push(messageObject.result[paramNames[i]]); | 974 argumentsArray.push(messageObject.result[paramNames[i]]); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1047 | 1039 |
| 1048 var processingStartTime; | 1040 var processingStartTime; |
| 1049 if (InspectorBackendClass.Options.dumpInspectorTimeStats) | 1041 if (InspectorBackendClass.Options.dumpInspectorTimeStats) |
| 1050 processingStartTime = Date.now(); | 1042 processingStartTime = Date.now(); |
| 1051 | 1043 |
| 1052 this._dispatcher[functionName].apply(this._dispatcher, params); | 1044 this._dispatcher[functionName].apply(this._dispatcher, params); |
| 1053 | 1045 |
| 1054 if (InspectorBackendClass.Options.dumpInspectorTimeStats) | 1046 if (InspectorBackendClass.Options.dumpInspectorTimeStats) |
| 1055 console.log("time-stats: " + messageObject.method + " = " + (Date.no
w() - processingStartTime)); | 1047 console.log("time-stats: " + messageObject.method + " = " + (Date.no
w() - processingStartTime)); |
| 1056 } | 1048 } |
| 1057 | |
| 1058 } | 1049 } |
| 1059 | 1050 |
| 1060 InspectorBackendClass.Options = { | 1051 InspectorBackendClass.Options = { |
| 1061 dumpInspectorTimeStats: false, | 1052 dumpInspectorTimeStats: false, |
| 1062 dumpInspectorProtocolMessages: false, | 1053 dumpInspectorProtocolMessages: false, |
| 1063 suppressRequestErrors: false | 1054 suppressRequestErrors: false |
| 1064 } | 1055 } |
| 1065 | 1056 |
| 1066 InspectorBackend = new InspectorBackendClass(); | 1057 InspectorBackend = new InspectorBackendClass(); |
| OLD | NEW |