mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-25 02:40:22 -10:00
While trying to implement the invoke getter from autocomplete popup, it became clear to me that the initial implementation in js-property-provider wasn't good enough, as we need to keep track of all the authorizations the user gave when working on a given expression. In order to handle this, JsPropertyProvider now returns an array of strings representing the path to the unsafe getter when no matching authorizations are provided. If authorizations are provided, we can check for each properties that the user authorized the execution. This way, we can handle deep object access after a getter (e.g. `x.myGetter.foo.bar.baz.entries`) without asking the user if they want to invoke `myGetter` on each step of the completion. This makes handling intermediary getters (e.g. `x.myGetter.foo.myOtherGetter.bar`) way easier as well. In the UI, the user will be prompted to invoke the getter one after the other (if for example they try to complete a pasted expression which contains multiple getters, they will have prompts for `myGetter`, and then for `myOtherGetter`). We wire-up the webconsole client and the webconsole actor for the autocomplete function, to make them ready for frontend use. The existing JsPropertyProvider getters test are updated to match the change of parameter (invokeGetter -> authorizedEvaluations), and some tests are added to make sure everything work as intended. Differential Revision: https://phabricator.services.mozilla.com/D12940
786 lines
24 KiB
JavaScript
786 lines
24 KiB
JavaScript
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
"use strict";
|
|
|
|
const DevToolsUtils = require("devtools/shared/DevToolsUtils");
|
|
const EventEmitter = require("devtools/shared/event-emitter");
|
|
const LongStringClient = require("devtools/shared/client/long-string-client");
|
|
|
|
/**
|
|
* A WebConsoleClient is used as a front end for the WebConsoleActor that is
|
|
* created on the server, hiding implementation details.
|
|
*
|
|
* @param object debuggerClient
|
|
* The DebuggerClient instance we live for.
|
|
* @param object response
|
|
* The response packet received from the "startListeners" request sent to
|
|
* the WebConsoleActor.
|
|
*/
|
|
function WebConsoleClient(debuggerClient, response) {
|
|
this._actor = response.from;
|
|
this._client = debuggerClient;
|
|
this._longStrings = {};
|
|
this.traits = response.traits || {};
|
|
|
|
/**
|
|
* Tells if the window.console object of the remote web page is the native
|
|
* object or not.
|
|
* @private
|
|
* @type boolean
|
|
*/
|
|
this.hasNativeConsoleAPI = response.nativeConsoleAPI;
|
|
|
|
this.events = [];
|
|
this._networkRequests = new Map();
|
|
|
|
this.pendingEvaluationResults = new Map();
|
|
this.onEvaluationResult = this.onEvaluationResult.bind(this);
|
|
this.onNetworkEvent = this._onNetworkEvent.bind(this);
|
|
this.onNetworkEventUpdate = this._onNetworkEventUpdate.bind(this);
|
|
this.onInspectObject = this._onInspectObject.bind(this);
|
|
this.onDocEvent = this._onDocEvent.bind(this);
|
|
|
|
this._client.addListener("evaluationResult", this.onEvaluationResult);
|
|
this._client.addListener("networkEvent", this.onNetworkEvent);
|
|
this._client.addListener("networkEventUpdate", this.onNetworkEventUpdate);
|
|
this._client.addListener("inspectObject", this.onInspectObject);
|
|
this._client.addListener("documentEvent", this.onDocEvent);
|
|
EventEmitter.decorate(this);
|
|
}
|
|
|
|
exports.WebConsoleClient = WebConsoleClient;
|
|
|
|
WebConsoleClient.prototype = {
|
|
_longStrings: null,
|
|
traits: null,
|
|
|
|
/**
|
|
* Holds the network requests currently displayed by the Web Console. Each key
|
|
* represents the connection ID and the value is network request information.
|
|
* @private
|
|
* @type object
|
|
*/
|
|
_networkRequests: null,
|
|
|
|
getNetworkRequest(actorId) {
|
|
return this._networkRequests.get(actorId);
|
|
},
|
|
|
|
hasNetworkRequest(actorId) {
|
|
return this._networkRequests.has(actorId);
|
|
},
|
|
|
|
removeNetworkRequest(actorId) {
|
|
this._networkRequests.delete(actorId);
|
|
},
|
|
|
|
getNetworkEvents() {
|
|
return this._networkRequests.values();
|
|
},
|
|
|
|
get actor() {
|
|
return this._actor;
|
|
},
|
|
|
|
/**
|
|
* The "networkEvent" message type handler. We redirect any message to
|
|
* the UI for displaying.
|
|
*
|
|
* @private
|
|
* @param string type
|
|
* Message type.
|
|
* @param object packet
|
|
* The message received from the server.
|
|
*/
|
|
_onNetworkEvent: function(type, packet) {
|
|
if (packet.from == this._actor) {
|
|
const actor = packet.eventActor;
|
|
const networkInfo = {
|
|
_type: "NetworkEvent",
|
|
timeStamp: actor.timeStamp,
|
|
node: null,
|
|
actor: actor.actor,
|
|
discardRequestBody: true,
|
|
discardResponseBody: true,
|
|
startedDateTime: actor.startedDateTime,
|
|
request: {
|
|
url: actor.url,
|
|
method: actor.method,
|
|
},
|
|
isXHR: actor.isXHR,
|
|
cause: actor.cause,
|
|
response: {},
|
|
timings: {},
|
|
// track the list of network event updates
|
|
updates: [],
|
|
private: actor.private,
|
|
fromCache: actor.fromCache,
|
|
fromServiceWorker: actor.fromServiceWorker,
|
|
isThirdPartyTrackingResource: actor.isThirdPartyTrackingResource,
|
|
referrerPolicy: actor.referrerPolicy,
|
|
};
|
|
this._networkRequests.set(actor.actor, networkInfo);
|
|
|
|
this.emit("networkEvent", networkInfo);
|
|
}
|
|
},
|
|
|
|
/**
|
|
* The "networkEventUpdate" message type handler. We redirect any message to
|
|
* the UI for displaying.
|
|
*
|
|
* @private
|
|
* @param string type
|
|
* Message type.
|
|
* @param object packet
|
|
* The message received from the server.
|
|
*/
|
|
_onNetworkEventUpdate: function(type, packet) {
|
|
const networkInfo = this.getNetworkRequest(packet.from);
|
|
if (!networkInfo) {
|
|
return;
|
|
}
|
|
|
|
networkInfo.updates.push(packet.updateType);
|
|
|
|
switch (packet.updateType) {
|
|
case "requestHeaders":
|
|
networkInfo.request.headersSize = packet.headersSize;
|
|
break;
|
|
case "requestPostData":
|
|
networkInfo.discardRequestBody = packet.discardRequestBody;
|
|
networkInfo.request.bodySize = packet.dataSize;
|
|
break;
|
|
case "responseStart":
|
|
networkInfo.response.httpVersion = packet.response.httpVersion;
|
|
networkInfo.response.status = packet.response.status;
|
|
networkInfo.response.statusText = packet.response.statusText;
|
|
networkInfo.response.headersSize = packet.response.headersSize;
|
|
networkInfo.response.remoteAddress = packet.response.remoteAddress;
|
|
networkInfo.response.remotePort = packet.response.remotePort;
|
|
networkInfo.discardResponseBody = packet.response.discardResponseBody;
|
|
break;
|
|
case "responseContent":
|
|
networkInfo.response.content = {
|
|
mimeType: packet.mimeType,
|
|
};
|
|
networkInfo.response.bodySize = packet.contentSize;
|
|
networkInfo.response.transferredSize = packet.transferredSize;
|
|
networkInfo.discardResponseBody = packet.discardResponseBody;
|
|
break;
|
|
case "eventTimings":
|
|
networkInfo.totalTime = packet.totalTime;
|
|
break;
|
|
case "securityInfo":
|
|
networkInfo.securityState = packet.state;
|
|
break;
|
|
case "responseCache":
|
|
networkInfo.response.responseCache = packet.responseCache;
|
|
break;
|
|
}
|
|
|
|
this.emit("networkEventUpdate", {
|
|
packet: packet,
|
|
networkInfo,
|
|
});
|
|
},
|
|
|
|
/**
|
|
* The "inspectObject" message type handler. We just re-emit it so that
|
|
* the toolbox can listen to the event and decide how to handle it.
|
|
*
|
|
* @private
|
|
* @param string type
|
|
* Message type.
|
|
* @param object packet
|
|
* The message received from the server.
|
|
*/
|
|
_onInspectObject: function(type, packet) {
|
|
this.emit("inspectObject", packet);
|
|
},
|
|
|
|
/**
|
|
* The "docEvent" message type handler. We just re-emit it so that
|
|
* the tools can listen for them on the console client.
|
|
*
|
|
* @private
|
|
* @param string type
|
|
* Message type.
|
|
* @param object packet
|
|
* The message received from the server.
|
|
*/
|
|
_onDocEvent: function(type, packet) {
|
|
this.emit("documentEvent", packet);
|
|
},
|
|
|
|
/**
|
|
* Retrieve the cached messages from the server.
|
|
*
|
|
* @see this.CACHED_MESSAGES
|
|
* @param array types
|
|
* The array of message types you want from the server. See
|
|
* this.CACHED_MESSAGES for known types.
|
|
* @param function onResponse
|
|
* The function invoked when the response is received.
|
|
* @return request
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
|
*/
|
|
getCachedMessages: function(types, onResponse) {
|
|
const packet = {
|
|
to: this._actor,
|
|
type: "getCachedMessages",
|
|
messageTypes: types,
|
|
};
|
|
return this._client.request(packet, onResponse);
|
|
},
|
|
|
|
/**
|
|
* Inspect the properties of an object.
|
|
*
|
|
* @param string actor
|
|
* The WebConsoleObjectActor ID to send the request to.
|
|
* @param function onResponse
|
|
* The function invoked when the response is received.
|
|
* @return request
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
|
*/
|
|
inspectObjectProperties: function(actor, onResponse) {
|
|
const packet = {
|
|
to: actor,
|
|
type: "inspectProperties",
|
|
};
|
|
return this._client.request(packet, onResponse);
|
|
},
|
|
|
|
/**
|
|
* Evaluate a JavaScript expression.
|
|
*
|
|
* @param string string
|
|
* The code you want to evaluate.
|
|
* @param function onResponse
|
|
* The function invoked when the response is received.
|
|
* @param object [options={}]
|
|
* Options for evaluation:
|
|
*
|
|
* - bindObjectActor: an ObjectActor ID. The OA holds a reference to
|
|
* a Debugger.Object that wraps a content object. This option allows
|
|
* you to bind |_self| to the D.O of the given OA, during string
|
|
* evaluation.
|
|
*
|
|
* See: Debugger.Object.executeInGlobalWithBindings() for information
|
|
* about bindings.
|
|
*
|
|
* Use case: the variable view needs to update objects and it does so
|
|
* by knowing the ObjectActor it inspects and binding |_self| to the
|
|
* D.O of the OA. As such, variable view sends strings like these for
|
|
* eval:
|
|
* _self["prop"] = value;
|
|
*
|
|
* - frameActor: a FrameActor ID. The FA holds a reference to
|
|
* a Debugger.Frame. This option allows you to evaluate the string in
|
|
* the frame of the given FA.
|
|
*
|
|
* - url: the url to evaluate the script as. Defaults to
|
|
* "debugger eval code".
|
|
*
|
|
* - selectedNodeActor: the NodeActor ID of the current
|
|
* selection in the Inspector, if such a selection
|
|
* exists. This is used by helper functions that can
|
|
* reference the currently selected node in the Inspector,
|
|
* like $0.
|
|
* @return request
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
|
*/
|
|
evaluateJS: function(string, onResponse, options = {}) {
|
|
const packet = {
|
|
to: this._actor,
|
|
type: "evaluateJS",
|
|
text: string,
|
|
bindObjectActor: options.bindObjectActor,
|
|
frameActor: options.frameActor,
|
|
url: options.url,
|
|
selectedNodeActor: options.selectedNodeActor,
|
|
selectedObjectActor: options.selectedObjectActor,
|
|
};
|
|
return this._client.request(packet, onResponse);
|
|
},
|
|
|
|
/**
|
|
* Evaluate a JavaScript expression asynchronously.
|
|
* See evaluateJS for parameter and response information.
|
|
*/
|
|
evaluateJSAsync: function(string, onResponse, options = {}) {
|
|
const packet = {
|
|
to: this._actor,
|
|
type: "evaluateJSAsync",
|
|
text: string,
|
|
bindObjectActor: options.bindObjectActor,
|
|
frameActor: options.frameActor,
|
|
url: options.url,
|
|
selectedNodeActor: options.selectedNodeActor,
|
|
selectedObjectActor: options.selectedObjectActor,
|
|
mapped: options.mapped,
|
|
};
|
|
|
|
return new Promise((resolve, reject) => {
|
|
this._client.request(packet, response => {
|
|
// Null check this in case the client has been detached while waiting
|
|
// for a response.
|
|
if (this.pendingEvaluationResults) {
|
|
this.pendingEvaluationResults.set(response.resultID, resp => {
|
|
if (onResponse) {
|
|
onResponse(resp);
|
|
}
|
|
if (resp.error) {
|
|
reject(resp);
|
|
} else {
|
|
resolve(resp);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
});
|
|
},
|
|
|
|
/**
|
|
* Handler for the actors's unsolicited evaluationResult packet.
|
|
*/
|
|
onEvaluationResult: function(notification, packet) {
|
|
// The client on the main thread can receive notification packets from
|
|
// multiple webconsole actors: the one on the main thread and the ones
|
|
// on worker threads. So make sure we should be handling this request.
|
|
if (packet.from !== this._actor) {
|
|
return;
|
|
}
|
|
|
|
// Find the associated callback based on this ID, and fire it.
|
|
// In a sync evaluation, this would have already been called in
|
|
// direct response to the client.request function.
|
|
const onResponse = this.pendingEvaluationResults.get(packet.resultID);
|
|
if (onResponse) {
|
|
onResponse(packet);
|
|
this.pendingEvaluationResults.delete(packet.resultID);
|
|
} else {
|
|
DevToolsUtils.reportException("onEvaluationResult",
|
|
"No response handler for an evaluateJSAsync result (resultID: " +
|
|
packet.resultID + ")");
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Autocomplete a JavaScript expression.
|
|
*
|
|
* @param {String} string
|
|
* The code you want to autocomplete.
|
|
* @param {Number} cursor
|
|
* Cursor location inside the string. Index starts from 0.
|
|
* @param {String} frameActor
|
|
* The id of the frame actor that made the call.
|
|
* @param {String} selectedNodeActor: Actor id of the selected node in the inspector.
|
|
* @param {Array} authorizedEvaluations
|
|
* Array of the properties access which can be executed by the engine.
|
|
* Example: [["x", "myGetter"], ["x", "myGetter", "y", "anotherGetter"]] to
|
|
* retrieve properties of `x.myGetter.` and `x.myGetter.y.anotherGetter`.
|
|
* @return request
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
|
*/
|
|
autocomplete: function(
|
|
string,
|
|
cursor,
|
|
frameActor,
|
|
selectedNodeActor,
|
|
authorizedEvaluations
|
|
) {
|
|
const packet = {
|
|
to: this._actor,
|
|
type: "autocomplete",
|
|
text: string,
|
|
cursor,
|
|
frameActor,
|
|
selectedNodeActor,
|
|
authorizedEvaluations,
|
|
};
|
|
return this._client.request(packet);
|
|
},
|
|
|
|
/**
|
|
* Clear the cache of messages (page errors and console API calls).
|
|
*
|
|
* @return request
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
|
*/
|
|
clearMessagesCache: function() {
|
|
const packet = {
|
|
to: this._actor,
|
|
type: "clearMessagesCache",
|
|
};
|
|
return this._client.request(packet);
|
|
},
|
|
|
|
/**
|
|
* Get Web Console-related preferences on the server.
|
|
*
|
|
* @param array preferences
|
|
* An array with the preferences you want to retrieve.
|
|
* @param function [onResponse]
|
|
* Optional function to invoke when the response is received.
|
|
* @return request
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
|
*/
|
|
getPreferences: function(preferences, onResponse) {
|
|
const packet = {
|
|
to: this._actor,
|
|
type: "getPreferences",
|
|
preferences: preferences,
|
|
};
|
|
return this._client.request(packet, onResponse);
|
|
},
|
|
|
|
/**
|
|
* Set Web Console-related preferences on the server.
|
|
*
|
|
* @param object preferences
|
|
* An object with the preferences you want to change.
|
|
* @param function [onResponse]
|
|
* Optional function to invoke when the response is received.
|
|
* @return request
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
|
*/
|
|
setPreferences: function(preferences, onResponse) {
|
|
const packet = {
|
|
to: this._actor,
|
|
type: "setPreferences",
|
|
preferences: preferences,
|
|
};
|
|
return this._client.request(packet, onResponse);
|
|
},
|
|
|
|
/**
|
|
* Retrieve the request headers from the given NetworkEventActor.
|
|
*
|
|
* @param string actor
|
|
* The NetworkEventActor ID.
|
|
* @param function onResponse
|
|
* The function invoked when the response is received.
|
|
* @return request
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
|
*/
|
|
getRequestHeaders: function(actor, onResponse) {
|
|
const packet = {
|
|
to: actor,
|
|
type: "getRequestHeaders",
|
|
};
|
|
return this._client.request(packet, onResponse);
|
|
},
|
|
|
|
/**
|
|
* Retrieve the request cookies from the given NetworkEventActor.
|
|
*
|
|
* @param string actor
|
|
* The NetworkEventActor ID.
|
|
* @param function onResponse
|
|
* The function invoked when the response is received.
|
|
* @return request
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
|
*/
|
|
getRequestCookies: function(actor, onResponse) {
|
|
const packet = {
|
|
to: actor,
|
|
type: "getRequestCookies",
|
|
};
|
|
return this._client.request(packet, onResponse);
|
|
},
|
|
|
|
/**
|
|
* Retrieve the request post data from the given NetworkEventActor.
|
|
*
|
|
* @param string actor
|
|
* The NetworkEventActor ID.
|
|
* @param function onResponse
|
|
* The function invoked when the response is received.
|
|
* @return request
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
|
*/
|
|
getRequestPostData: function(actor, onResponse) {
|
|
const packet = {
|
|
to: actor,
|
|
type: "getRequestPostData",
|
|
};
|
|
return this._client.request(packet, onResponse);
|
|
},
|
|
|
|
/**
|
|
* Retrieve the response headers from the given NetworkEventActor.
|
|
*
|
|
* @param string actor
|
|
* The NetworkEventActor ID.
|
|
* @param function onResponse
|
|
* The function invoked when the response is received.
|
|
* @return request
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
|
*/
|
|
getResponseHeaders: function(actor, onResponse) {
|
|
const packet = {
|
|
to: actor,
|
|
type: "getResponseHeaders",
|
|
};
|
|
return this._client.request(packet, onResponse);
|
|
},
|
|
|
|
/**
|
|
* Retrieve the response cookies from the given NetworkEventActor.
|
|
*
|
|
* @param string actor
|
|
* The NetworkEventActor ID.
|
|
* @param function onResponse
|
|
* The function invoked when the response is received.
|
|
* @return request
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
|
*/
|
|
getResponseCookies: function(actor, onResponse) {
|
|
const packet = {
|
|
to: actor,
|
|
type: "getResponseCookies",
|
|
};
|
|
return this._client.request(packet, onResponse);
|
|
},
|
|
|
|
/**
|
|
* Retrieve the response content from the given NetworkEventActor.
|
|
*
|
|
* @param string actor
|
|
* The NetworkEventActor ID.
|
|
* @param function onResponse
|
|
* The function invoked when the response is received.
|
|
* @return request
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
|
*/
|
|
getResponseContent: function(actor, onResponse) {
|
|
const packet = {
|
|
to: actor,
|
|
type: "getResponseContent",
|
|
};
|
|
return this._client.request(packet, onResponse);
|
|
},
|
|
|
|
/**
|
|
* Retrieve the response cache from the given NetworkEventActor
|
|
*
|
|
* @param string actor
|
|
* The NetworkEventActor ID.
|
|
* @param function onResponse
|
|
* The function invoked when the response is received.
|
|
* @return request
|
|
* Request object that implements both Promise and EventEmitter interfaces.
|
|
*/
|
|
getResponseCache: function(actor, onResponse) {
|
|
const packet = {
|
|
to: actor,
|
|
type: "getResponseCache",
|
|
};
|
|
return this._client.request(packet, onResponse);
|
|
},
|
|
|
|
/**
|
|
* Retrieve the timing information for the given NetworkEventActor.
|
|
*
|
|
* @param string actor
|
|
* The NetworkEventActor ID.
|
|
* @param function onResponse
|
|
* The function invoked when the response is received.
|
|
* @return request
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
|
*/
|
|
getEventTimings: function(actor, onResponse) {
|
|
const packet = {
|
|
to: actor,
|
|
type: "getEventTimings",
|
|
};
|
|
return this._client.request(packet, onResponse);
|
|
},
|
|
|
|
/**
|
|
* Retrieve the security information for the given NetworkEventActor.
|
|
*
|
|
* @param string actor
|
|
* The NetworkEventActor ID.
|
|
* @param function onResponse
|
|
* The function invoked when the response is received.
|
|
* @return request
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
|
*/
|
|
getSecurityInfo: function(actor, onResponse) {
|
|
const packet = {
|
|
to: actor,
|
|
type: "getSecurityInfo",
|
|
};
|
|
return this._client.request(packet, onResponse);
|
|
},
|
|
|
|
/**
|
|
* Retrieve the stack-trace information for the given NetworkEventActor.
|
|
*
|
|
* @param string actor
|
|
* The NetworkEventActor ID.
|
|
* @param function onResponse
|
|
* The function invoked when the stack-trace is received.
|
|
* @return request
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
|
*/
|
|
getStackTrace: function(actor, onResponse) {
|
|
const packet = {
|
|
to: actor,
|
|
type: "getStackTrace",
|
|
};
|
|
return this._client.request(packet, onResponse);
|
|
},
|
|
|
|
/**
|
|
* Send a HTTP request with the given data.
|
|
*
|
|
* @param string data
|
|
* The details of the HTTP request.
|
|
* @param function onResponse
|
|
* The function invoked when the response is received.
|
|
* @return request
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
|
*/
|
|
sendHTTPRequest: function(data, onResponse) {
|
|
const packet = {
|
|
to: this._actor,
|
|
type: "sendHTTPRequest",
|
|
request: data,
|
|
};
|
|
return this._client.request(packet, onResponse);
|
|
},
|
|
|
|
/**
|
|
* Start the given Web Console listeners.
|
|
*
|
|
* @see this.LISTENERS
|
|
* @param array listeners
|
|
* Array of listeners you want to start. See this.LISTENERS for
|
|
* known listeners.
|
|
* @param function onResponse
|
|
* Function to invoke when the server response is received.
|
|
* @return request
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
|
*/
|
|
startListeners: function(listeners, onResponse) {
|
|
const packet = {
|
|
to: this._actor,
|
|
type: "startListeners",
|
|
listeners: listeners,
|
|
};
|
|
return this._client.request(packet, onResponse);
|
|
},
|
|
|
|
/**
|
|
* Stop the given Web Console listeners.
|
|
*
|
|
* @see this.LISTENERS
|
|
* @param array listeners
|
|
* Array of listeners you want to stop. See this.LISTENERS for
|
|
* known listeners.
|
|
* @param function onResponse
|
|
* Function to invoke when the server response is received.
|
|
* @return request
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
|
*/
|
|
stopListeners: function(listeners, onResponse) {
|
|
const packet = {
|
|
to: this._actor,
|
|
type: "stopListeners",
|
|
listeners: listeners,
|
|
};
|
|
return this._client.request(packet, onResponse);
|
|
},
|
|
|
|
/**
|
|
* Return an instance of LongStringClient for the given long string grip.
|
|
*
|
|
* @param object grip
|
|
* The long string grip returned by the protocol.
|
|
* @return object
|
|
* The LongStringClient for the given long string grip.
|
|
*/
|
|
longString: function(grip) {
|
|
if (grip.actor in this._longStrings) {
|
|
return this._longStrings[grip.actor];
|
|
}
|
|
|
|
const client = new LongStringClient(this._client, grip);
|
|
this._longStrings[grip.actor] = client;
|
|
return client;
|
|
},
|
|
|
|
/**
|
|
* Close the WebConsoleClient. This stops all the listeners on the server and
|
|
* detaches from the console actor.
|
|
*
|
|
* @param function onResponse
|
|
* Function to invoke when the server response is received.
|
|
*/
|
|
detach: function(onResponse) {
|
|
this._client.removeListener("evaluationResult", this.onEvaluationResult);
|
|
this._client.removeListener("networkEvent", this.onNetworkEvent);
|
|
this._client.removeListener("networkEventUpdate",
|
|
this.onNetworkEventUpdate);
|
|
this._client.removeListener("inspectObject", this.onInspectObject);
|
|
this._client.removeListener("documentEvent", this.onDocEvent);
|
|
this.stopListeners(null, onResponse);
|
|
this._longStrings = null;
|
|
this._client = null;
|
|
this.pendingEvaluationResults.clear();
|
|
this.pendingEvaluationResults = null;
|
|
this.clearNetworkRequests();
|
|
this._networkRequests = null;
|
|
},
|
|
|
|
clearNetworkRequests: function() {
|
|
this._networkRequests.clear();
|
|
},
|
|
|
|
/**
|
|
* Fetches the full text of a LongString.
|
|
*
|
|
* @param object | string stringGrip
|
|
* The long string grip containing the corresponding actor.
|
|
* If you pass in a plain string (by accident or because you're lazy),
|
|
* then a promise of the same string is simply returned.
|
|
* @return object Promise
|
|
* A promise that is resolved when the full string contents
|
|
* are available, or rejected if something goes wrong.
|
|
*/
|
|
getString: function(stringGrip) {
|
|
// Make sure this is a long string.
|
|
if (typeof stringGrip !== "object" || stringGrip.type !== "longString") {
|
|
// Go home string, you're drunk.
|
|
return Promise.resolve(stringGrip);
|
|
}
|
|
|
|
// Fetch the long string only once.
|
|
if (stringGrip._fullText) {
|
|
return stringGrip._fullText;
|
|
}
|
|
|
|
return new Promise((resolve, reject) => {
|
|
const { initial, length } = stringGrip;
|
|
const longStringClient = this.longString(stringGrip);
|
|
|
|
longStringClient.substring(initial.length, length, response => {
|
|
if (response.error) {
|
|
DevToolsUtils.reportException("getString",
|
|
response.error + ": " + response.message);
|
|
reject(response);
|
|
}
|
|
resolve(initial + response.substring);
|
|
});
|
|
});
|
|
},
|
|
};
|