Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/protocol/Protocol.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/sdk/InspectorBackend.js b/third_party/WebKit/Source/devtools/front_end/protocol/Protocol.js |
| similarity index 60% |
| rename from third_party/WebKit/Source/devtools/front_end/sdk/InspectorBackend.js |
| rename to third_party/WebKit/Source/devtools/front_end/protocol/Protocol.js |
| index 9009fd49b348b38b7d35a8f83414047be0e74ed3..6536bdb891b34db97b4f1e82d4a037ad5d53848d 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/sdk/InspectorBackend.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/protocol/Protocol.js |
| @@ -28,255 +28,242 @@ |
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| */ |
| -/** |
| - * @constructor |
| - */ |
| -function InspectorBackendClass() |
| -{ |
| - this._agentPrototypes = {}; |
| - this._dispatcherPrototypes = {}; |
| - this._initialized = false; |
| -} |
| +var Protocol = {}; |
| + |
| +/** @typedef {string} */ |
| +Protocol.Error; |
| + |
| +Protocol.Options = { |
| + dumpInspectorTimeStats: false, |
| + dumpInspectorProtocolMessages: false, |
| + suppressRequestErrors: false |
| +}; |
| -InspectorBackendClass._DevToolsErrorCode = -32000; |
| -InspectorBackendClass.DevToolsStubErrorCode = -32015; |
| +Protocol.StubErrorCode = -32015; |
| /** |
| - * @param {string} error |
| - * @param {!Object} messageObject |
| + * @interface |
| */ |
| -InspectorBackendClass.reportProtocolError = function(error, messageObject) |
| +Protocol.Connection = function() |
| { |
| - console.error(error + ": " + JSON.stringify(messageObject)); |
| }; |
| -InspectorBackendClass.prototype = { |
| +Protocol.Connection.prototype = { |
| /** |
| - * @return {boolean} |
| + * @param {string} message |
| */ |
| - isInitialized: function() |
| - { |
| - return this._initialized; |
| - }, |
| + sendMessage: function(message) { }, |
| /** |
| - * @param {string} domain |
| + * @return {!Promise} |
| */ |
| - _addAgentGetterMethodToProtocolTargetPrototype: function(domain) |
| - { |
| - var upperCaseLength = 0; |
| - while (upperCaseLength < domain.length && domain[upperCaseLength].toLowerCase() !== domain[upperCaseLength]) |
| - ++upperCaseLength; |
| + disconnect: function() { }, |
| +}; |
| - var methodName = domain.substr(0, upperCaseLength).toLowerCase() + domain.slice(upperCaseLength) + "Agent"; |
| +/** |
| + * @typedef {!{ |
| + * onMessage: function((!Object|string)), |
| + * onDisconnect: function(string) |
| + * }} |
| + */ |
| +Protocol.Connection.Params; |
|
caseq
2016/10/26 23:43:20
Let's make it an interface instead.
|
| - /** |
| - * @this {Protocol.Target} |
| - */ |
| - function agentGetter() |
| - { |
| - return this._agents[domain]; |
| - } |
| +/** |
| + * @typedef {function(!Protocol.Connection.Params):!Protocol.Connection} |
| + */ |
| +Protocol.Connection.Factory; |
| - Protocol.Target.prototype[methodName] = agentGetter; |
| +/** |
| + * @return {boolean} |
| + */ |
| +Protocol.isInitialized = function() |
| +{ |
| + return Protocol._initialized; |
| +}; |
| - /** |
| - * @this {Protocol.Target} |
| - */ |
| - function registerDispatcher(dispatcher) |
| - { |
| - this.registerDispatcher(domain, dispatcher); |
| - } |
| +/** |
| + * @param {string} method |
| + * @param {!Array.<!Object>} signature |
| + * @param {!Array.<string>} replyArgs |
| + * @param {boolean} hasErrorData |
| + */ |
| +Protocol.registerCommand = function(method, signature, replyArgs, hasErrorData) |
| +{ |
| + var domainAndMethod = method.split("."); |
| + Protocol._agentPrototype(domainAndMethod[0]).registerCommand(domainAndMethod[1], signature, replyArgs, hasErrorData); |
| + Protocol._initialized = true; |
| +}; |
| - Protocol.Target.prototype["register" + domain + "Dispatcher"] = registerDispatcher; |
| - }, |
| +/** |
| + * @param {string} type |
| + * @param {!Object} values |
| + */ |
| +Protocol.registerEnum = function(type, values) |
| +{ |
| + var domainAndMethod = type.split("."); |
| + var agentName = domainAndMethod[0] + "Agent"; |
| + if (!window[agentName]) |
| + window[agentName] = {}; |
| - /** |
| - * @param {string} domain |
| - * @return {!InspectorBackendClass._AgentPrototype} |
| - */ |
| - _agentPrototype: function(domain) |
| - { |
| - if (!this._agentPrototypes[domain]) { |
| - this._agentPrototypes[domain] = new InspectorBackendClass._AgentPrototype(domain); |
| - this._addAgentGetterMethodToProtocolTargetPrototype(domain); |
| - } |
| + window[agentName][domainAndMethod[1]] = values; |
| + Protocol._initialized = true; |
| +}; |
| - return this._agentPrototypes[domain]; |
| - }, |
| +/** |
| + * @param {string} eventName |
| + * @param {!Object} params |
| + */ |
| +Protocol.registerEvent = function(eventName, params) |
| +{ |
| + var domain = eventName.split(".")[0]; |
| + Protocol._dispatcherPrototype(domain).registerEvent(eventName, params); |
| + Protocol._initialized = true; |
| +}; |
| +/** |
| + * @param {function(T)} clientCallback |
| + * @param {string} errorPrefix |
| + * @param {function(new:T,S)=} constructor |
| + * @param {T=} defaultValue |
| + * @return {function(?string, S)} |
| + * @template T,S |
| + */ |
| +Protocol.wrapClientCallback = function(clientCallback, errorPrefix, constructor, defaultValue) |
| +{ |
| /** |
| - * @param {string} domain |
| - * @return {!InspectorBackendClass._DispatcherPrototype} |
| + * @param {?string} error |
| + * @param {S} value |
| + * @template S |
| */ |
| - _dispatcherPrototype: function(domain) |
| + function callbackWrapper(error, value) |
| { |
| - if (!this._dispatcherPrototypes[domain]) |
| - this._dispatcherPrototypes[domain] = new InspectorBackendClass._DispatcherPrototype(); |
| - return this._dispatcherPrototypes[domain]; |
| - }, |
| + if (error) { |
| + console.error(errorPrefix + error); |
| + clientCallback(defaultValue); |
| + return; |
| + } |
| + if (constructor) |
| + clientCallback(new constructor(value)); |
| + else |
| + clientCallback(value); |
| + } |
| + return callbackWrapper; |
| +}; |
| - /** |
| - * @param {string} method |
| - * @param {!Array.<!Object>} signature |
| - * @param {!Array.<string>} replyArgs |
| - * @param {boolean} hasErrorData |
| - */ |
| - registerCommand: function(method, signature, replyArgs, hasErrorData) |
| - { |
| - var domainAndMethod = method.split("."); |
| - this._agentPrototype(domainAndMethod[0]).registerCommand(domainAndMethod[1], signature, replyArgs, hasErrorData); |
| - this._initialized = true; |
| - }, |
| - /** |
| - * @param {string} type |
| - * @param {!Object} values |
| - */ |
| - registerEnum: function(type, values) |
| - { |
| - var domainAndMethod = type.split("."); |
| - var agentName = domainAndMethod[0] + "Agent"; |
| - if (!window[agentName]) |
| - window[agentName] = {}; |
| +Protocol._DisconnectedErrorCode = -32000; |
|
caseq
2016/10/26 23:43:20
Let's move it up to the rest of error code -- perh
|
| - window[agentName][domainAndMethod[1]] = values; |
| - this._initialized = true; |
| - }, |
| +/** |
| + * @param {string} error |
| + * @param {!Object} messageObject |
| + */ |
| +Protocol._reportError = function(error, messageObject) |
| +{ |
| + console.error(error + ": " + JSON.stringify(messageObject)); |
| +}; |
| - /** |
| - * @param {string} eventName |
| - * @param {!Object} params |
| - */ |
| - registerEvent: function(eventName, params) |
| - { |
| - var domain = eventName.split(".")[0]; |
| - this._dispatcherPrototype(domain).registerEvent(eventName, params); |
| - this._initialized = true; |
| - }, |
| +/** @type {!Map<string, !Protocol._AgentPrototype>} */ |
| +Protocol._agentPrototypes = new Map(); |
| - /** |
| - * @param {function(T)} clientCallback |
| - * @param {string} errorPrefix |
| - * @param {function(new:T,S)=} constructor |
| - * @param {T=} defaultValue |
| - * @return {function(?string, S)} |
| - * @template T,S |
| - */ |
| - wrapClientCallback: function(clientCallback, errorPrefix, constructor, defaultValue) |
| - { |
| - /** |
| - * @param {?string} error |
| - * @param {S} value |
| - * @template S |
| - */ |
| - function callbackWrapper(error, value) |
| - { |
| - if (error) { |
| - console.error(errorPrefix + error); |
| - clientCallback(defaultValue); |
| - return; |
| - } |
| - if (constructor) |
| - clientCallback(new constructor(value)); |
| - else |
| - clientCallback(value); |
| - } |
| - return callbackWrapper; |
| - } |
| -}; |
| +/** @type {!Map<string, !Protocol._DispatcherPrototype>} */ |
| +Protocol._dispatcherPrototypes = new Map(); |
| -var InspectorBackend = new InspectorBackendClass(); |
| +/** @type {boolean} */ |
| +Protocol._initialized = false; |
| /** |
| - * @interface |
| + * @param {string} domain |
| */ |
| -InspectorBackendClass.Connection = function() |
| +Protocol._addAgentGetterMethodToProtocolTargetPrototype = function(domain) |
| { |
| -}; |
| + var upperCaseLength = 0; |
| + while (upperCaseLength < domain.length && domain[upperCaseLength].toLowerCase() !== domain[upperCaseLength]) |
| + ++upperCaseLength; |
| + |
| + var methodName = domain.substr(0, upperCaseLength).toLowerCase() + domain.slice(upperCaseLength) + "Agent"; |
| -InspectorBackendClass.Connection.prototype = { |
| /** |
| - * @param {string} message |
| + * @this {Protocol.Target} |
| */ |
| - sendMessage: function(message) { }, |
| + function agentGetter() |
| + { |
| + return this._agents.get(domain); |
| + } |
| + |
| + Protocol.Target.prototype[methodName] = agentGetter; |
| /** |
| - * @return {!Promise} |
| + * @this {Protocol.Target} |
| */ |
| - disconnect: function() { }, |
| + function registerDispatcher(dispatcher) |
| + { |
| + this.registerDispatcher(domain, dispatcher); |
| + } |
| + |
| + Protocol.Target.prototype["register" + domain + "Dispatcher"] = registerDispatcher; |
| }; |
| /** |
| - * @typedef {!{ |
| - * onMessage: function((!Object|string)), |
| - * onDisconnect: function(string) |
| - * }} |
| + * @param {string} domain |
| + * @return {!Protocol._AgentPrototype} |
| */ |
| -InspectorBackendClass.Connection.Params; |
| +Protocol._agentPrototype = function(domain) |
|
caseq
2016/10/26 23:43:20
So we now have Protocol._agentPrototype, Protocol.
|
| +{ |
| + if (!Protocol._agentPrototypes.has(domain)) { |
| + Protocol._agentPrototypes.set(domain, new Protocol._AgentPrototype(domain)); |
| + Protocol._addAgentGetterMethodToProtocolTargetPrototype(domain); |
| + } |
| + return Protocol._agentPrototypes.get(domain); |
| +}; |
| /** |
| - * @typedef {function(!InspectorBackendClass.Connection.Params):!InspectorBackendClass.Connection} |
| + * @param {string} domain |
| + * @return {!Protocol._DispatcherPrototype} |
| */ |
| -InspectorBackendClass.Connection.Factory; |
| - |
| -var Protocol = {}; |
| +Protocol._dispatcherPrototype = function(domain) |
| +{ |
| + if (!Protocol._dispatcherPrototypes.has(domain)) |
| + Protocol._dispatcherPrototypes.set(domain, new Protocol._DispatcherPrototype()); |
| + return Protocol._dispatcherPrototypes.get(domain); |
| +}; |
| -/** @typedef {string} */ |
| -Protocol.Error; |
| +/** @typedef {!{methodName: string, domain: string, callback: function(*):?, sendRequestTime: (number|undefined)}} */ |
| +Protocol._WrappedCallback; |
| /** |
| * @constructor |
| - * @param {!InspectorBackendClass.Connection.Factory} connectionFactory |
| + * @param {!Protocol.Connection.Factory} connectionFactory |
| */ |
| Protocol.Target = function(connectionFactory) |
| { |
| this._connection = connectionFactory({onMessage: this._onMessage.bind(this), onDisconnect: this._onDisconnect.bind(this)}); |
| this._lastMessageId = 1; |
| this._pendingResponsesCount = 0; |
| - this._agents = {}; |
| - this._dispatchers = {}; |
| - this._callbacks = {}; |
| - this._initialize(InspectorBackend._agentPrototypes, InspectorBackend._dispatcherPrototypes); |
| - if (!InspectorBackendClass.deprecatedRunAfterPendingDispatches) |
| - InspectorBackendClass.deprecatedRunAfterPendingDispatches = this._deprecatedRunAfterPendingDispatches.bind(this); |
| - if (!InspectorBackendClass.sendRawMessageForTesting) |
| - InspectorBackendClass.sendRawMessageForTesting = this._sendRawMessageForTesting.bind(this); |
| -}; |
| - |
| -Protocol.Target.prototype = { |
| - /** |
| - * @param {!Object.<string, !InspectorBackendClass._AgentPrototype>} agentPrototypes |
| - * @param {!Object.<string, !InspectorBackendClass._DispatcherPrototype>} dispatcherPrototypes |
| - */ |
| - _initialize: function(agentPrototypes, dispatcherPrototypes) |
| - { |
| - for (var domain in agentPrototypes) { |
| - this._agents[domain] = Object.create(agentPrototypes[domain]); |
| - this._agents[domain].setTarget(this); |
| - } |
| - |
| - for (var domain in dispatcherPrototypes) |
| - this._dispatchers[domain] = Object.create(dispatcherPrototypes[domain]); |
| - }, |
| + /** @type {!Map<string, !Protocol._AgentPrototype>} */ |
| + this._agents = new Map(); |
| + /** @type {!Map<string, !Protocol._DispatcherPrototype>} */ |
| + this._dispatchers = new Map(); |
| + /** @type {!Map<number, !Protocol._WrappedCallback>} */ |
| + this._callbacks = new Map(); |
| + |
| + for (var domain of Protocol._agentPrototypes.keys()) { |
| + var agent = /** @type {!Protocol._AgentPrototype} */ (Object.create(Protocol._agentPrototypes.get(domain))); |
| + agent.setTarget(this); |
| + this._agents.set(domain, agent); |
| + } |
| - /** |
| - * @return {number} |
| - */ |
| - _nextMessageId: function() |
| - { |
| - return this._lastMessageId++; |
| - }, |
| + for (var domain of Protocol._dispatcherPrototypes.keys()) { |
| + var dispatcher = /** @type {!Protocol._DispatcherPrototype} */ (Object.create(Protocol._dispatcherPrototypes.get(domain))); |
| + this._dispatchers.set(domain, dispatcher); |
| + } |
| - /** |
| - * @param {string} domain |
| - * @return {!InspectorBackendClass._AgentPrototype} |
| - */ |
| - _agent: function(domain) |
| - { |
| - return this._agents[domain]; |
| - }, |
| + if (!Protocol.deprecatedRunAfterPendingDispatches) |
| + Protocol.deprecatedRunAfterPendingDispatches = this._deprecatedRunAfterPendingDispatches.bind(this); |
| + if (!Protocol.sendRawMessageForTesting) |
| + Protocol.sendRawMessageForTesting = this._sendRawMessageForTesting.bind(this); |
| +}; |
| +Protocol.Target.prototype = { |
| /** |
| * @param {string} domain |
| * @param {string} method |
| @@ -292,7 +279,7 @@ Protocol.Target.prototype = { |
| } |
| var messageObject = {}; |
| - var messageId = this._nextMessageId(); |
| + var messageId = this._lastMessageId++; |
| messageObject.id = messageId; |
| messageObject.method = method; |
| if (params) |
| @@ -301,31 +288,27 @@ Protocol.Target.prototype = { |
| var wrappedCallback = this._wrap(callback, domain, method); |
| var message = JSON.stringify(messageObject); |
| - if (InspectorBackendClass.Options.dumpInspectorProtocolMessages) |
| + if (Protocol.Options.dumpInspectorProtocolMessages) |
| this._dumpProtocolMessage("frontend: " + message); |
| this._connection.sendMessage(message); |
| ++this._pendingResponsesCount; |
| - this._callbacks[messageId] = wrappedCallback; |
| + this._callbacks.set(messageId, wrappedCallback); |
| }, |
| /** |
| * @param {?function(*)} callback |
| * @param {string} method |
| * @param {string} domain |
| - * @return {function(*)} |
| + * @return {!Protocol._WrappedCallback} |
| */ |
| _wrap: function(callback, domain, method) |
| { |
| - if (!callback) |
| - callback = function() {}; |
| - |
| - callback.methodName = method; |
| - callback.domain = domain; |
| - if (InspectorBackendClass.Options.dumpInspectorTimeStats) |
| - callback.sendRequestTime = Date.now(); |
| - |
| - return callback; |
| + callback = /** @type {function(*)} */ (callback || function() {}); |
| + var result = {methodName: method, domain: domain, callback: callback, sendRequestTime: undefined}; |
|
caseq
2016/10/26 23:43:20
nit: drop sendRequestTime?
|
| + if (Protocol.Options.dumpInspectorTimeStats) |
| + result.sendRequestTime = Date.now(); |
| + return result; |
| }, |
| /** |
| @@ -344,45 +327,45 @@ Protocol.Target.prototype = { |
| */ |
| _onMessage: function(message) |
| { |
| - if (InspectorBackendClass.Options.dumpInspectorProtocolMessages) |
| + if (Protocol.Options.dumpInspectorProtocolMessages) |
| this._dumpProtocolMessage("backend: " + ((typeof message === "string") ? message : JSON.stringify(message))); |
| var messageObject = /** @type {!Object} */ ((typeof message === "string") ? JSON.parse(message) : message); |
| if ("id" in messageObject) { // just a response for some request |
| - var callback = this._callbacks[messageObject.id]; |
| + var callback = this._callbacks.get(messageObject.id); |
| if (!callback) { |
| - InspectorBackendClass.reportProtocolError("Protocol Error: the message with wrong id", messageObject); |
| + Protocol._reportError("Protocol Error: the message with wrong id", messageObject); |
| return; |
| } |
| var processingStartTime; |
| - if (InspectorBackendClass.Options.dumpInspectorTimeStats) |
| + if (Protocol.Options.dumpInspectorTimeStats) |
| processingStartTime = Date.now(); |
| - this._agent(callback.domain).dispatchResponse(messageObject, callback.methodName, callback); |
| + this._agents.get(callback.domain).dispatchResponse(messageObject, callback.methodName, callback.callback); |
| --this._pendingResponsesCount; |
| - delete this._callbacks[messageObject.id]; |
| + this._callbacks.delete(messageObject.id); |
| - if (InspectorBackendClass.Options.dumpInspectorTimeStats) |
| + if (Protocol.Options.dumpInspectorTimeStats) |
| console.log("time-stats: " + callback.methodName + " = " + (processingStartTime - callback.sendRequestTime) + " + " + (Date.now() - processingStartTime)); |
| if (this._scripts && !this._pendingResponsesCount) |
| this._deprecatedRunAfterPendingDispatches(); |
| } else { |
| if (!("method" in messageObject)) { |
| - InspectorBackendClass.reportProtocolError("Protocol Error: the message without method", messageObject); |
| + Protocol._reportError("Protocol Error: the message without method", messageObject); |
| return; |
| } |
| var method = messageObject.method.split("."); |
| var domainName = method[0]; |
| - if (!(domainName in this._dispatchers)) { |
| - InspectorBackendClass.reportProtocolError("Protocol Error: the message " + messageObject.method + " is for non-existing domain '" + domainName + "'", messageObject); |
| + if (!this._dispatchers.has(domainName)) { |
| + Protocol._reportError("Protocol Error: the message " + messageObject.method + " is for non-existing domain '" + domainName + "'", messageObject); |
| return; |
| } |
| - this._dispatchers[domainName].dispatch(method[1], messageObject); |
| + this._dispatchers.get(domainName).dispatch(method[1], messageObject); |
| } |
| }, |
| @@ -392,10 +375,8 @@ Protocol.Target.prototype = { |
| */ |
| registerDispatcher: function(domain, dispatcher) |
| { |
| - if (!this._dispatchers[domain]) |
| - return; |
| - |
| - this._dispatchers[domain].setDomainDispatcher(dispatcher); |
| + console.assert(this._dispatchers.has(domain)); |
| + this._dispatchers.get(domain).setDomainDispatcher(dispatcher); |
| }, |
| /** |
| @@ -463,12 +444,10 @@ Protocol.Target.prototype = { |
| _runPendingCallbacks: function() |
| { |
| - var keys = Object.keys(this._callbacks).map(function(num) { return parseInt(num, 10); }); |
| - for (var i = 0; i < keys.length; ++i) { |
| - var callback = this._callbacks[keys[i]]; |
| - this._dispatchConnectionErrorResponse(callback.domain, callback.methodName, callback); |
| - } |
| - this._callbacks = {}; |
| + var callbacks = Array.from(this._callbacks.values()); |
|
caseq
2016/10/26 23:43:20
You don't need a copy here, just iterate over valu
|
| + for (var callback of callbacks) |
| + this._dispatchConnectionErrorResponse(callback.domain, callback.methodName, callback.callback); |
| + this._callbacks.clear(); |
| }, |
| /** |
| @@ -478,9 +457,9 @@ Protocol.Target.prototype = { |
| */ |
| _dispatchConnectionErrorResponse: function(domain, methodName, callback) |
| { |
| - var error = { message: "Connection is closed, can't dispatch pending " + methodName, code: InspectorBackendClass._DevToolsErrorCode, data: null}; |
| + var error = { message: "Connection is closed, can't dispatch pending " + methodName, code: Protocol._DisconnectedErrorCode, data: null}; |
| var messageObject = {error: error}; |
| - setTimeout(InspectorBackendClass._AgentPrototype.prototype.dispatchResponse.bind(this._agent(domain), messageObject, methodName, callback), 0); |
| + setTimeout(Protocol._AgentPrototype.prototype.dispatchResponse.bind(this._agents.get(domain), messageObject, methodName, callback), 0); |
| }, |
| }; |
| @@ -488,14 +467,14 @@ Protocol.Target.prototype = { |
| * @constructor |
| * @param {string} domain |
| */ |
| -InspectorBackendClass._AgentPrototype = function(domain) |
| +Protocol._AgentPrototype = function(domain) |
| { |
| this._replyArgs = {}; |
| this._hasErrorData = {}; |
| this._domain = domain; |
| }; |
| -InspectorBackendClass._AgentPrototype.prototype = { |
| +Protocol._AgentPrototype.prototype = { |
| /** |
| * @param {!Protocol.Target} target |
| */ |
| @@ -516,25 +495,25 @@ InspectorBackendClass._AgentPrototype.prototype = { |
| /** |
| * @param {...*} vararg |
| - * @this {InspectorBackendClass._AgentPrototype} |
| + * @this {Protocol._AgentPrototype} |
| * @return {!Promise.<*>} |
| */ |
| function sendMessagePromise(vararg) |
| { |
| var params = Array.prototype.slice.call(arguments); |
| - return InspectorBackendClass._AgentPrototype.prototype._sendMessageToBackendPromise.call(this, domainAndMethod, signature, params); |
| + return Protocol._AgentPrototype.prototype._sendMessageToBackendPromise.call(this, domainAndMethod, signature, params); |
| } |
| this[methodName] = sendMessagePromise; |
| /** |
| * @param {...*} vararg |
| - * @this {InspectorBackendClass._AgentPrototype} |
| + * @this {Protocol._AgentPrototype} |
| */ |
| function invoke(vararg) |
| { |
| var params = [domainAndMethod].concat(Array.prototype.slice.call(arguments)); |
| - InspectorBackendClass._AgentPrototype.prototype._invoke.apply(this, params); |
| + Protocol._AgentPrototype.prototype._invoke.apply(this, params); |
| } |
| this["invoke_" + methodName] = invoke; |
| @@ -620,7 +599,7 @@ InspectorBackendClass._AgentPrototype.prototype = { |
| /** |
| * @param {function(?)} resolve |
| * @param {function(!Error)} reject |
| - * @this {InspectorBackendClass._AgentPrototype} |
| + * @this {Protocol._AgentPrototype} |
| */ |
| function promiseAction(resolve, reject) |
| { |
| @@ -653,8 +632,8 @@ InspectorBackendClass._AgentPrototype.prototype = { |
| */ |
| dispatchResponse: function(messageObject, methodName, callback) |
| { |
| - if (messageObject.error && messageObject.error.code !== InspectorBackendClass._DevToolsErrorCode && messageObject.error.code !== InspectorBackendClass.DevToolsStubErrorCode && !InspectorBackendClass.Options.suppressRequestErrors) { |
| - var id = InspectorBackendClass.Options.dumpInspectorProtocolMessages ? " with id = " + messageObject.id : ""; |
| + if (messageObject.error && messageObject.error.code !== Protocol._DisconnectedErrorCode && messageObject.error.code !== Protocol.StubErrorCode && !Protocol.Options.suppressRequestErrors) { |
| + var id = Protocol.Options.dumpInspectorProtocolMessages ? " with id = " + messageObject.id : ""; |
| console.error("Request " + methodName + id + " failed. " + JSON.stringify(messageObject.error)); |
| } |
| @@ -677,13 +656,13 @@ InspectorBackendClass._AgentPrototype.prototype = { |
| /** |
| * @constructor |
| */ |
| -InspectorBackendClass._DispatcherPrototype = function() |
| +Protocol._DispatcherPrototype = function() |
| { |
| this._eventArgs = {}; |
| this._dispatcher = null; |
| }; |
| -InspectorBackendClass._DispatcherPrototype.prototype = { |
| +Protocol._DispatcherPrototype.prototype = { |
| /** |
| * @param {string} eventName |
| @@ -712,12 +691,12 @@ InspectorBackendClass._DispatcherPrototype.prototype = { |
| return; |
| if (!(functionName in this._dispatcher)) { |
| - InspectorBackendClass.reportProtocolError("Protocol Error: Attempted to dispatch an unimplemented method '" + messageObject.method + "'", messageObject); |
| + Protocol._reportError("Protocol Error: Attempted to dispatch an unimplemented method '" + messageObject.method + "'", messageObject); |
| return; |
| } |
| if (!this._eventArgs[messageObject.method]) { |
| - InspectorBackendClass.reportProtocolError("Protocol Error: Attempted to dispatch an unspecified method '" + messageObject.method + "'", messageObject); |
| + Protocol._reportError("Protocol Error: Attempted to dispatch an unspecified method '" + messageObject.method + "'", messageObject); |
| return; |
| } |
| @@ -729,18 +708,12 @@ InspectorBackendClass._DispatcherPrototype.prototype = { |
| } |
| var processingStartTime; |
| - if (InspectorBackendClass.Options.dumpInspectorTimeStats) |
| + if (Protocol.Options.dumpInspectorTimeStats) |
| processingStartTime = Date.now(); |
| this._dispatcher[functionName].apply(this._dispatcher, params); |
| - if (InspectorBackendClass.Options.dumpInspectorTimeStats) |
| + if (Protocol.Options.dumpInspectorTimeStats) |
| console.log("time-stats: " + messageObject.method + " = " + (Date.now() - processingStartTime)); |
| } |
| }; |
| - |
| -InspectorBackendClass.Options = { |
| - dumpInspectorTimeStats: false, |
| - dumpInspectorProtocolMessages: false, |
| - suppressRequestErrors: false |
| -}; |