2012-02-07 09:22:30 -08:00
|
|
|
/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2012-02-07 09:22:30 -08:00
|
|
|
|
|
|
|
"use strict";
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
const Cr = Components.results;
|
|
|
|
|
2012-10-31 09:13:28 -07:00
|
|
|
this.EXPORTED_SYMBOLS = ["DebuggerTransport",
|
|
|
|
"DebuggerClient",
|
2012-11-05 08:41:59 -08:00
|
|
|
"debuggerSocketConnect",
|
2013-03-30 04:31:10 -07:00
|
|
|
"LongStringClient",
|
|
|
|
"GripClient"];
|
2012-02-07 09:22:30 -08:00
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/NetUtil.jsm");
|
2012-03-07 23:14:41 -08:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2013-02-28 04:02:00 -08:00
|
|
|
Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js");
|
|
|
|
const { defer, resolve, reject } = Promise;
|
2012-02-07 09:22:30 -08:00
|
|
|
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "socketTransportService",
|
|
|
|
"@mozilla.org/network/socket-transport-service;1",
|
|
|
|
"nsISocketTransportService");
|
|
|
|
|
2012-09-26 10:07:57 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "WebConsoleClient",
|
|
|
|
"resource://gre/modules/devtools/WebConsoleClient.jsm");
|
|
|
|
|
2012-03-07 23:14:41 -08:00
|
|
|
let wantLogging = Services.prefs.getBoolPref("devtools.debugger.log");
|
|
|
|
|
2012-02-07 09:22:30 -08:00
|
|
|
function dumpn(str)
|
|
|
|
{
|
2012-03-07 23:14:41 -08:00
|
|
|
if (wantLogging) {
|
|
|
|
dump("DBG-CLIENT: " + str + "\n");
|
|
|
|
}
|
2012-02-07 09:22:30 -08:00
|
|
|
}
|
|
|
|
|
2012-01-23 00:29:15 -08:00
|
|
|
let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
|
|
|
.getService(Ci.mozIJSSubScriptLoader);
|
2012-11-02 18:03:13 -07:00
|
|
|
loader.loadSubScript("chrome://global/content/devtools/dbg-transport.js", this);
|
2012-02-07 09:22:30 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add simple event notification to a prototype object. Any object that has
|
|
|
|
* some use for event notifications or the observer pattern in general can be
|
|
|
|
* augmented with the necessary facilities by passing its prototype to this
|
|
|
|
* function.
|
|
|
|
*
|
|
|
|
* @param aProto object
|
|
|
|
* The prototype object that will be modified.
|
|
|
|
*/
|
|
|
|
function eventSource(aProto) {
|
|
|
|
/**
|
|
|
|
* Add a listener to the event source for a given event.
|
|
|
|
*
|
|
|
|
* @param aName string
|
2012-08-30 14:29:55 -07:00
|
|
|
* The event to listen for.
|
2012-01-23 00:29:15 -08:00
|
|
|
* @param aListener function
|
2012-02-07 09:22:30 -08:00
|
|
|
* Called when the event is fired. If the same listener
|
2012-08-30 14:29:55 -07:00
|
|
|
* is added more than once, it will be called once per
|
2012-02-07 09:22:30 -08:00
|
|
|
* addListener call.
|
|
|
|
*/
|
|
|
|
aProto.addListener = function EV_addListener(aName, aListener) {
|
2012-01-23 00:29:15 -08:00
|
|
|
if (typeof aListener != "function") {
|
2012-08-30 14:29:55 -07:00
|
|
|
throw TypeError("Listeners must be functions.");
|
2012-01-23 00:29:15 -08:00
|
|
|
}
|
|
|
|
|
2012-02-07 09:22:30 -08:00
|
|
|
if (!this._listeners) {
|
|
|
|
this._listeners = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
this._getListeners(aName).push(aListener);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a listener to the event source for a given event. The
|
|
|
|
* listener will be removed after it is called for the first time.
|
|
|
|
*
|
|
|
|
* @param aName string
|
2012-08-30 14:29:55 -07:00
|
|
|
* The event to listen for.
|
2012-02-07 09:22:30 -08:00
|
|
|
* @param aListener function
|
|
|
|
* Called when the event is fired.
|
|
|
|
*/
|
|
|
|
aProto.addOneTimeListener = function EV_addOneTimeListener(aName, aListener) {
|
|
|
|
let self = this;
|
|
|
|
|
|
|
|
let l = function() {
|
|
|
|
self.removeListener(aName, l);
|
|
|
|
aListener.apply(null, arguments);
|
|
|
|
};
|
|
|
|
this.addListener(aName, l);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a listener from the event source previously added with
|
|
|
|
* addListener().
|
|
|
|
*
|
|
|
|
* @param aName string
|
|
|
|
* The event name used during addListener to add the listener.
|
|
|
|
* @param aListener function
|
|
|
|
* The callback to remove. If addListener was called multiple
|
|
|
|
* times, all instances will be removed.
|
|
|
|
*/
|
|
|
|
aProto.removeListener = function EV_removeListener(aName, aListener) {
|
|
|
|
if (!this._listeners || !this._listeners[aName]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._listeners[aName] =
|
|
|
|
this._listeners[aName].filter(function(l) { return l != aListener });
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the listeners for the specified event name. If none are defined it
|
|
|
|
* initializes an empty list and returns that.
|
|
|
|
*
|
|
|
|
* @param aName string
|
|
|
|
* The event name.
|
|
|
|
*/
|
|
|
|
aProto._getListeners = function EV_getListeners(aName) {
|
|
|
|
if (aName in this._listeners) {
|
|
|
|
return this._listeners[aName];
|
|
|
|
}
|
|
|
|
this._listeners[aName] = [];
|
|
|
|
return this._listeners[aName];
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify listeners of an event.
|
|
|
|
*
|
|
|
|
* @param aName string
|
|
|
|
* The event to fire.
|
|
|
|
* @param arguments
|
|
|
|
* All arguments will be passed along to the listeners,
|
|
|
|
* including the name argument.
|
|
|
|
*/
|
|
|
|
aProto.notify = function EV_notify() {
|
|
|
|
if (!this._listeners) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let name = arguments[0];
|
|
|
|
let listeners = this._getListeners(name).slice(0);
|
|
|
|
|
|
|
|
for each (let listener in listeners) {
|
2012-01-23 00:29:15 -08:00
|
|
|
try {
|
|
|
|
listener.apply(null, arguments);
|
|
|
|
} catch (e) {
|
|
|
|
// Prevent a bad listener from interfering with the others.
|
2012-06-10 16:44:50 -07:00
|
|
|
let msg = e + ": " + e.stack;
|
|
|
|
Cu.reportError(msg);
|
|
|
|
dumpn(msg);
|
2012-01-23 00:29:15 -08:00
|
|
|
}
|
2012-02-07 09:22:30 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set of protocol messages that affect thread state, and the
|
|
|
|
* state the actor is in after each message.
|
|
|
|
*/
|
|
|
|
const ThreadStateTypes = {
|
|
|
|
"paused": "paused",
|
|
|
|
"resumed": "attached",
|
|
|
|
"detached": "detached"
|
|
|
|
};
|
|
|
|
|
2012-02-09 23:46:11 -08:00
|
|
|
/**
|
|
|
|
* Set of protocol messages that are sent by the server without a prior request
|
|
|
|
* by the client.
|
|
|
|
*/
|
|
|
|
const UnsolicitedNotifications = {
|
2012-09-26 10:02:04 -07:00
|
|
|
"consoleAPICall": "consoleAPICall",
|
2012-10-08 06:28:17 -07:00
|
|
|
"eventNotification": "eventNotification",
|
2012-10-05 04:54:43 -07:00
|
|
|
"fileActivity": "fileActivity",
|
|
|
|
"networkEvent": "networkEvent",
|
|
|
|
"networkEventUpdate": "networkEventUpdate",
|
2012-10-31 09:31:55 -07:00
|
|
|
"newGlobal": "newGlobal",
|
2012-02-09 23:46:11 -08:00
|
|
|
"newScript": "newScript",
|
2013-02-28 04:02:00 -08:00
|
|
|
"newSource": "newSource",
|
2012-02-09 23:46:11 -08:00
|
|
|
"tabDetached": "tabDetached",
|
2012-09-12 15:14:12 -07:00
|
|
|
"tabNavigated": "tabNavigated",
|
2013-01-10 07:38:51 -08:00
|
|
|
"pageError": "pageError",
|
2013-04-25 09:46:13 -07:00
|
|
|
"webappsEvent": "webappsEvent",
|
|
|
|
"styleSheetsAdded": "styleSheetsAdded"
|
2012-02-09 23:46:11 -08:00
|
|
|
};
|
|
|
|
|
2012-08-24 00:41:02 -07:00
|
|
|
/**
|
|
|
|
* Set of pause types that are sent by the server and not as an immediate
|
|
|
|
* response to a client request.
|
|
|
|
*/
|
|
|
|
const UnsolicitedPauses = {
|
|
|
|
"resumeLimit": "resumeLimit",
|
|
|
|
"debuggerStatement": "debuggerStatement",
|
|
|
|
"breakpoint": "breakpoint",
|
2013-04-26 14:37:44 -07:00
|
|
|
"watchpoint": "watchpoint",
|
|
|
|
"exception": "exception"
|
2012-08-24 00:41:02 -07:00
|
|
|
};
|
|
|
|
|
2012-02-07 09:22:30 -08:00
|
|
|
const ROOT_ACTOR_NAME = "root";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a client for the remote debugging protocol server. This client
|
|
|
|
* provides the means to communicate with the server and exchange the messages
|
|
|
|
* required by the protocol in a traditional JavaScript API.
|
|
|
|
*/
|
2012-10-31 09:13:28 -07:00
|
|
|
this.DebuggerClient = function DebuggerClient(aTransport)
|
2012-02-07 09:22:30 -08:00
|
|
|
{
|
|
|
|
this._transport = aTransport;
|
|
|
|
this._transport.hooks = this;
|
|
|
|
this._threadClients = {};
|
|
|
|
this._tabClients = {};
|
2012-09-26 10:07:57 -07:00
|
|
|
this._consoleClients = {};
|
2012-02-07 09:22:30 -08:00
|
|
|
|
|
|
|
this._pendingRequests = [];
|
|
|
|
this._activeRequests = {};
|
|
|
|
this._eventsEnabled = true;
|
2013-02-28 04:02:00 -08:00
|
|
|
|
|
|
|
this.compat = new ProtocolCompatibility(this, [
|
|
|
|
new SourcesShim(),
|
|
|
|
]);
|
2013-04-09 03:47:00 -07:00
|
|
|
|
|
|
|
this.request = this.request.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A declarative helper for defining methods that send requests to the server.
|
|
|
|
*
|
|
|
|
* @param aPacketSkeleton
|
|
|
|
* The form of the packet to send. Can specify fields to be filled from
|
|
|
|
* the parameters by using the |args| function.
|
|
|
|
* @param telemetry
|
|
|
|
* The unique suffix of the telemetry histogram id.
|
|
|
|
* @param before
|
|
|
|
* The function to call before sending the packet. Is passed the packet,
|
|
|
|
* and the return value is used as the new packet. The |this| context is
|
|
|
|
* the instance of the client object we are defining a method for.
|
|
|
|
* @param after
|
|
|
|
* The function to call after the response is received. It is passed the
|
|
|
|
* response, and the return value is considered the new response that
|
|
|
|
* will be passed to the callback. The |this| context is the instance of
|
|
|
|
* the client object we are defining a method for.
|
|
|
|
*/
|
|
|
|
DebuggerClient.requester = function DC_requester(aPacketSkeleton, { telemetry,
|
|
|
|
before, after }) {
|
|
|
|
return function (...args) {
|
|
|
|
let histogram, startTime;
|
|
|
|
if (telemetry) {
|
2013-04-15 22:52:55 -07:00
|
|
|
let transportType = this._transport.onOutputStreamReady === undefined
|
2013-04-09 03:47:00 -07:00
|
|
|
? "LOCAL_"
|
|
|
|
: "REMOTE_";
|
|
|
|
let histogramId = "DEVTOOLS_DEBUGGER_RDP_"
|
|
|
|
+ transportType + telemetry + "_MS";
|
|
|
|
histogram = Services.telemetry.getHistogramById(histogramId);
|
|
|
|
startTime = +new Date;
|
|
|
|
}
|
|
|
|
let outgoingPacket = {
|
|
|
|
to: aPacketSkeleton.to || this.actor
|
|
|
|
};
|
|
|
|
|
|
|
|
let maxPosition = -1;
|
|
|
|
for (let k of Object.keys(aPacketSkeleton)) {
|
|
|
|
if (aPacketSkeleton[k] instanceof DebuggerClient.Argument) {
|
|
|
|
let { position } = aPacketSkeleton[k];
|
|
|
|
outgoingPacket[k] = aPacketSkeleton[k].getArgument(args);
|
|
|
|
maxPosition = Math.max(position, maxPosition);
|
|
|
|
} else {
|
|
|
|
outgoingPacket[k] = aPacketSkeleton[k];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (before) {
|
|
|
|
outgoingPacket = before.call(this, outgoingPacket);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.request(outgoingPacket, function (aResponse) {
|
|
|
|
if (after) {
|
|
|
|
let { from } = aResponse;
|
|
|
|
aResponse = after.call(this, aResponse);
|
|
|
|
if (!aResponse.from) {
|
|
|
|
aResponse.from = from;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The callback is always the last parameter.
|
|
|
|
let thisCallback = args[maxPosition + 1];
|
|
|
|
if (thisCallback) {
|
|
|
|
thisCallback(aResponse);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (histogram) {
|
|
|
|
histogram.add(+new Date - startTime);
|
|
|
|
}
|
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
function args(aPos) {
|
|
|
|
return new DebuggerClient.Argument(aPos);
|
2012-02-07 09:22:30 -08:00
|
|
|
}
|
|
|
|
|
2013-04-09 03:47:00 -07:00
|
|
|
DebuggerClient.Argument = function DCP(aPosition) {
|
|
|
|
this.position = aPosition;
|
|
|
|
};
|
|
|
|
|
|
|
|
DebuggerClient.Argument.prototype.getArgument = function DCP_getArgument(aParams) {
|
|
|
|
if (!this.position in aParams) {
|
|
|
|
throw new Error("Bad index into params: " + this.position);
|
|
|
|
}
|
|
|
|
return aParams[this.position];
|
|
|
|
};
|
|
|
|
|
2012-02-07 09:22:30 -08:00
|
|
|
DebuggerClient.prototype = {
|
|
|
|
/**
|
2012-01-23 00:29:15 -08:00
|
|
|
* Connect to the server and start exchanging protocol messages.
|
2012-02-07 09:22:30 -08:00
|
|
|
*
|
|
|
|
* @param aOnConnected function
|
|
|
|
* If specified, will be called when the greeting packet is
|
|
|
|
* received from the debugging server.
|
|
|
|
*/
|
2012-01-23 00:29:15 -08:00
|
|
|
connect: function DC_connect(aOnConnected) {
|
2012-02-07 09:22:30 -08:00
|
|
|
if (aOnConnected) {
|
|
|
|
this.addOneTimeListener("connected", function(aName, aApplicationType, aTraits) {
|
|
|
|
aOnConnected(aApplicationType, aTraits);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this._transport.ready();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shut down communication with the debugging server.
|
|
|
|
*
|
|
|
|
* @param aOnClosed function
|
|
|
|
* If specified, will be called when the debugging connection
|
|
|
|
* has been closed.
|
|
|
|
*/
|
|
|
|
close: function DC_close(aOnClosed) {
|
|
|
|
// Disable detach event notifications, because event handlers will be in a
|
|
|
|
// cleared scope by the time they run.
|
|
|
|
this._eventsEnabled = false;
|
|
|
|
|
|
|
|
if (aOnClosed) {
|
|
|
|
this.addOneTimeListener('closed', function(aEvent) {
|
|
|
|
aOnClosed();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-04-30 15:18:04 -07:00
|
|
|
let self = this;
|
2012-09-26 10:07:57 -07:00
|
|
|
|
2013-04-30 15:18:05 -07:00
|
|
|
let continuation = function () {
|
|
|
|
self._consoleClients = {};
|
2012-09-26 10:07:57 -07:00
|
|
|
detachThread();
|
2012-02-07 09:22:30 -08:00
|
|
|
}
|
2013-04-30 15:18:04 -07:00
|
|
|
|
2013-04-30 15:18:05 -07:00
|
|
|
for each (let client in this._consoleClients) {
|
|
|
|
continuation = client.close.bind(client, continuation);
|
2013-04-30 15:18:04 -07:00
|
|
|
}
|
|
|
|
|
2013-04-30 15:18:05 -07:00
|
|
|
continuation();
|
|
|
|
|
2013-04-30 15:18:04 -07:00
|
|
|
function detachThread() {
|
|
|
|
if (self.activeThread) {
|
|
|
|
self.activeThread.detach(detachTab);
|
|
|
|
} else {
|
|
|
|
detachTab();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function detachTab() {
|
|
|
|
if (self.activeTab) {
|
|
|
|
self.activeTab.detach(closeTransport);
|
|
|
|
} else {
|
|
|
|
closeTransport();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function closeTransport() {
|
|
|
|
self._transport.close();
|
|
|
|
self._transport = null;
|
|
|
|
}
|
2012-02-07 09:22:30 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List the open tabs.
|
|
|
|
*
|
|
|
|
* @param function aOnResponse
|
|
|
|
* Called with the response packet.
|
|
|
|
*/
|
2013-04-09 03:47:00 -07:00
|
|
|
listTabs: DebuggerClient.requester({
|
|
|
|
to: ROOT_ACTOR_NAME,
|
|
|
|
type: "listTabs"
|
|
|
|
}, {
|
|
|
|
telemetry: "LISTTABS"
|
|
|
|
}),
|
2012-02-07 09:22:30 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Attach to a tab actor.
|
|
|
|
*
|
|
|
|
* @param string aTabActor
|
|
|
|
* The actor ID for the tab to attach.
|
|
|
|
* @param function aOnResponse
|
|
|
|
* Called with the response packet and a TabClient
|
|
|
|
* (which will be undefined on error).
|
|
|
|
*/
|
|
|
|
attachTab: function DC_attachTab(aTabActor, aOnResponse) {
|
|
|
|
let self = this;
|
2013-04-15 14:07:00 -07:00
|
|
|
let packet = {
|
|
|
|
to: aTabActor,
|
|
|
|
type: "attach"
|
|
|
|
};
|
2012-02-07 09:22:30 -08:00
|
|
|
this.request(packet, function(aResponse) {
|
2012-09-26 10:07:57 -07:00
|
|
|
let tabClient;
|
2012-02-07 09:22:30 -08:00
|
|
|
if (!aResponse.error) {
|
2012-09-26 10:07:57 -07:00
|
|
|
tabClient = new TabClient(self, aTabActor);
|
2012-02-07 09:22:30 -08:00
|
|
|
self._tabClients[aTabActor] = tabClient;
|
|
|
|
self.activeTab = tabClient;
|
|
|
|
}
|
|
|
|
aOnResponse(aResponse, tabClient);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-09-26 10:07:57 -07:00
|
|
|
/**
|
|
|
|
* Attach to a Web Console actor.
|
|
|
|
*
|
|
|
|
* @param string aConsoleActor
|
|
|
|
* The ID for the console actor to attach to.
|
|
|
|
* @param array aListeners
|
|
|
|
* The console listeners you want to start.
|
|
|
|
* @param function aOnResponse
|
|
|
|
* Called with the response packet and a WebConsoleClient
|
|
|
|
* instance (which will be undefined on error).
|
|
|
|
*/
|
|
|
|
attachConsole:
|
|
|
|
function DC_attachConsole(aConsoleActor, aListeners, aOnResponse) {
|
|
|
|
let self = this;
|
|
|
|
let packet = {
|
|
|
|
to: aConsoleActor,
|
|
|
|
type: "startListeners",
|
|
|
|
listeners: aListeners,
|
|
|
|
};
|
|
|
|
|
|
|
|
this.request(packet, function(aResponse) {
|
|
|
|
let consoleClient;
|
|
|
|
if (!aResponse.error) {
|
|
|
|
consoleClient = new WebConsoleClient(self, aConsoleActor);
|
|
|
|
self._consoleClients[aConsoleActor] = consoleClient;
|
|
|
|
}
|
|
|
|
aOnResponse(aResponse, consoleClient);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-02-07 09:22:30 -08:00
|
|
|
/**
|
|
|
|
* Attach to a thread actor.
|
|
|
|
*
|
|
|
|
* @param string aThreadActor
|
|
|
|
* The actor ID for the thread to attach.
|
|
|
|
* @param function aOnResponse
|
|
|
|
* Called with the response packet and a ThreadClient
|
|
|
|
* (which will be undefined on error).
|
2013-04-15 14:07:00 -07:00
|
|
|
* @param object aOptions
|
|
|
|
* Configuration options.
|
|
|
|
* - useSourceMaps: whether to use source maps or not.
|
2012-02-07 09:22:30 -08:00
|
|
|
*/
|
2013-04-15 14:07:00 -07:00
|
|
|
attachThread: function DC_attachThread(aThreadActor, aOnResponse, aOptions={}) {
|
2012-02-07 09:22:30 -08:00
|
|
|
let self = this;
|
2013-04-15 14:07:00 -07:00
|
|
|
let packet = {
|
|
|
|
to: aThreadActor,
|
|
|
|
type: "attach",
|
|
|
|
options: aOptions
|
|
|
|
};
|
2012-02-07 09:22:30 -08:00
|
|
|
this.request(packet, function(aResponse) {
|
|
|
|
if (!aResponse.error) {
|
|
|
|
var threadClient = new ThreadClient(self, aThreadActor);
|
|
|
|
self._threadClients[aThreadActor] = threadClient;
|
|
|
|
self.activeThread = threadClient;
|
|
|
|
}
|
|
|
|
aOnResponse(aResponse, threadClient);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-04-16 08:00:33 -07:00
|
|
|
/**
|
|
|
|
* Reconfigure a thread actor.
|
|
|
|
*
|
|
|
|
* @param boolean aUseSourceMaps
|
|
|
|
* A flag denoting whether to use source maps or not.
|
|
|
|
* @param function aOnResponse
|
|
|
|
* Called with the response packet.
|
|
|
|
*/
|
|
|
|
reconfigureThread: function DC_reconfigureThread(aUseSourceMaps, aOnResponse) {
|
|
|
|
let packet = {
|
|
|
|
to: this.activeThread._actor,
|
|
|
|
type: "reconfigure",
|
|
|
|
options: { useSourceMaps: aUseSourceMaps }
|
|
|
|
};
|
|
|
|
this.request(packet, aOnResponse);
|
|
|
|
},
|
|
|
|
|
2012-09-26 10:02:04 -07:00
|
|
|
/**
|
|
|
|
* Release an object actor.
|
|
|
|
*
|
|
|
|
* @param string aActor
|
|
|
|
* The actor ID to send the request to.
|
2012-10-12 01:26:49 -07:00
|
|
|
* @param aOnResponse function
|
|
|
|
* If specified, will be called with the response packet when
|
|
|
|
* debugging server responds.
|
2012-09-26 10:02:04 -07:00
|
|
|
*/
|
2013-04-09 03:47:00 -07:00
|
|
|
release: DebuggerClient.requester({
|
|
|
|
to: args(0),
|
|
|
|
type: "release"
|
|
|
|
}, {
|
|
|
|
telemetry: "RELEASE"
|
|
|
|
}),
|
2012-09-26 10:02:04 -07:00
|
|
|
|
2012-02-07 09:22:30 -08:00
|
|
|
/**
|
|
|
|
* Send a request to the debugging server.
|
|
|
|
*
|
2012-01-23 00:29:15 -08:00
|
|
|
* @param aRequest object
|
|
|
|
* A JSON packet to send to the debugging server.
|
|
|
|
* @param aOnResponse function
|
|
|
|
* If specified, will be called with the response packet when
|
|
|
|
* debugging server responds.
|
2012-02-07 09:22:30 -08:00
|
|
|
*/
|
|
|
|
request: function DC_request(aRequest, aOnResponse) {
|
|
|
|
if (!this._connected) {
|
2012-05-02 13:11:19 -07:00
|
|
|
throw Error("Have not yet received a hello packet from the server.");
|
2012-02-07 09:22:30 -08:00
|
|
|
}
|
|
|
|
if (!aRequest.to) {
|
2012-06-03 06:39:50 -07:00
|
|
|
let type = aRequest.type || "";
|
|
|
|
throw Error("'" + type + "' request packet has no destination.");
|
2012-02-07 09:22:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
this._pendingRequests.push({ to: aRequest.to,
|
|
|
|
request: aRequest,
|
|
|
|
onResponse: aOnResponse });
|
|
|
|
this._sendRequests();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send pending requests to any actors that don't already have an
|
|
|
|
* active request.
|
|
|
|
*/
|
|
|
|
_sendRequests: function DC_sendRequests() {
|
|
|
|
let self = this;
|
2013-04-15 14:07:00 -07:00
|
|
|
this._pendingRequests = this._pendingRequests.filter(function (request) {
|
2012-02-07 09:22:30 -08:00
|
|
|
if (request.to in self._activeRequests) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
self._activeRequests[request.to] = request;
|
|
|
|
self._transport.send(request.request);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-01-23 00:29:15 -08:00
|
|
|
// Transport hooks.
|
2012-02-07 09:22:30 -08:00
|
|
|
|
2012-01-23 00:29:15 -08:00
|
|
|
/**
|
|
|
|
* Called by DebuggerTransport to dispatch incoming packets as appropriate.
|
|
|
|
*
|
|
|
|
* @param aPacket object
|
|
|
|
* The incoming packet.
|
2013-02-28 04:02:00 -08:00
|
|
|
* @param aIgnoreCompatibility boolean
|
|
|
|
* Set true to not pass the packet through the compatibility layer.
|
2012-01-23 00:29:15 -08:00
|
|
|
*/
|
2013-02-28 04:02:00 -08:00
|
|
|
onPacket: function DC_onPacket(aPacket, aIgnoreCompatibility=false) {
|
|
|
|
let packet = aIgnoreCompatibility
|
|
|
|
? aPacket
|
|
|
|
: this.compat.onPacket(aPacket);
|
|
|
|
|
2013-04-15 14:07:00 -07:00
|
|
|
resolve(packet).then((aPacket) => {
|
2013-02-28 04:02:00 -08:00
|
|
|
if (!this._connected) {
|
|
|
|
// Hello packet.
|
|
|
|
this._connected = true;
|
|
|
|
this.notify("connected",
|
|
|
|
aPacket.applicationType,
|
|
|
|
aPacket.traits);
|
2012-02-07 09:22:30 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-15 14:07:00 -07:00
|
|
|
if (!aPacket.from) {
|
|
|
|
let msg = "Server did not specify an actor, dropping packet: " +
|
|
|
|
JSON.stringify(aPacket);
|
|
|
|
Cu.reportError(msg);
|
|
|
|
dumpn(msg);
|
|
|
|
return;
|
|
|
|
}
|
2013-04-10 06:08:59 -07:00
|
|
|
|
2013-04-15 14:07:00 -07:00
|
|
|
let onResponse;
|
|
|
|
// Don't count unsolicited notifications or pauses as responses.
|
|
|
|
if (aPacket.from in this._activeRequests &&
|
|
|
|
!(aPacket.type in UnsolicitedNotifications) &&
|
|
|
|
!(aPacket.type == ThreadStateTypes.paused &&
|
|
|
|
aPacket.why.type in UnsolicitedPauses)) {
|
|
|
|
onResponse = this._activeRequests[aPacket.from].onResponse;
|
|
|
|
delete this._activeRequests[aPacket.from];
|
|
|
|
}
|
2013-04-10 06:08:59 -07:00
|
|
|
|
2013-04-15 14:07:00 -07:00
|
|
|
// Packets that indicate thread state changes get special treatment.
|
|
|
|
if (aPacket.type in ThreadStateTypes &&
|
|
|
|
aPacket.from in this._threadClients) {
|
|
|
|
this._threadClients[aPacket.from]._onThreadState(aPacket);
|
|
|
|
}
|
|
|
|
// On navigation the server resumes, so the client must resume as well.
|
|
|
|
// We achieve that by generating a fake resumption packet that triggers
|
|
|
|
// the client's thread state change listeners.
|
|
|
|
if (this.activeThread &&
|
|
|
|
aPacket.type == UnsolicitedNotifications.tabNavigated &&
|
|
|
|
aPacket.from in this._tabClients) {
|
|
|
|
let resumption = { from: this.activeThread._actor, type: "resumed" };
|
|
|
|
this.activeThread._onThreadState(resumption);
|
|
|
|
}
|
|
|
|
// Only try to notify listeners on events, not responses to requests
|
|
|
|
// that lack a packet type.
|
|
|
|
if (aPacket.type) {
|
|
|
|
this.notify(aPacket.type, aPacket);
|
|
|
|
}
|
2013-04-10 06:08:59 -07:00
|
|
|
|
2013-04-15 14:07:00 -07:00
|
|
|
if (onResponse) {
|
|
|
|
onResponse(aPacket);
|
2012-02-07 09:22:30 -08:00
|
|
|
}
|
|
|
|
|
2013-02-28 04:02:00 -08:00
|
|
|
this._sendRequests();
|
2013-04-15 14:07:00 -07:00
|
|
|
}, function (ex) {
|
|
|
|
dumpn("Error handling response: " + ex + " - stack:\n" + ex.stack);
|
|
|
|
Cu.reportError(ex.message + "\n" + ex.stack);
|
|
|
|
});
|
2012-02-07 09:22:30 -08:00
|
|
|
},
|
|
|
|
|
2012-01-23 00:29:15 -08:00
|
|
|
/**
|
|
|
|
* Called by DebuggerTransport when the underlying stream is closed.
|
|
|
|
*
|
|
|
|
* @param aStatus nsresult
|
|
|
|
* The status code that corresponds to the reason for closing
|
|
|
|
* the stream.
|
|
|
|
*/
|
|
|
|
onClosed: function DC_onClosed(aStatus) {
|
2012-02-07 09:22:30 -08:00
|
|
|
this.notify("closed");
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
eventSource(DebuggerClient.prototype);
|
|
|
|
|
2013-02-28 04:02:00 -08:00
|
|
|
// Constants returned by `FeatureCompatibilityShim.onPacketTest`.
|
|
|
|
const SUPPORTED = 1;
|
|
|
|
const NOT_SUPPORTED = 2;
|
|
|
|
const SKIP = 3;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This object provides an abstraction layer over all of our backwards
|
|
|
|
* compatibility, feature detection, and shimming with regards to the remote
|
|
|
|
* debugging prototcol.
|
|
|
|
*
|
|
|
|
* @param aFeatures Array
|
|
|
|
* An array of FeatureCompatibilityShim objects
|
|
|
|
*/
|
|
|
|
function ProtocolCompatibility(aClient, aFeatures) {
|
|
|
|
this._client = aClient;
|
|
|
|
this._featuresWithUnknownSupport = new Set(aFeatures);
|
|
|
|
this._featuresWithoutSupport = new Set();
|
|
|
|
|
|
|
|
this._featureDeferreds = Object.create(null)
|
|
|
|
for (let f of aFeatures) {
|
|
|
|
this._featureDeferreds[f.name] = defer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ProtocolCompatibility.prototype = {
|
|
|
|
/**
|
|
|
|
* Returns a promise that resolves to true if the RDP supports the feature,
|
|
|
|
* and is rejected otherwise.
|
|
|
|
*
|
|
|
|
* @param aFeatureName String
|
|
|
|
* The name of the feature we are testing.
|
|
|
|
*/
|
|
|
|
supportsFeature: function PC_supportsFeature(aFeatureName) {
|
|
|
|
return this._featureDeferreds[aFeatureName].promise;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Force a feature to be considered unsupported.
|
|
|
|
*
|
|
|
|
* @param aFeatureName String
|
|
|
|
* The name of the feature we are testing.
|
|
|
|
*/
|
|
|
|
rejectFeature: function PC_rejectFeature(aFeatureName) {
|
|
|
|
this._featureDeferreds[aFeatureName].reject(false);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called for each packet received over the RDP from the server. Tests for
|
|
|
|
* protocol features and shims packets to support needed features.
|
|
|
|
*
|
|
|
|
* @param aPacket Object
|
|
|
|
* Packet received over the RDP from the server.
|
|
|
|
*/
|
|
|
|
onPacket: function PC_onPacket(aPacket) {
|
|
|
|
this._detectFeatures(aPacket);
|
|
|
|
return this._shimPacket(aPacket);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For each of the features we don't know whether the server supports or not,
|
|
|
|
* attempt to detect support based on the packet we just received.
|
|
|
|
*/
|
|
|
|
_detectFeatures: function PC__detectFeatures(aPacket) {
|
|
|
|
for (let feature of this._featuresWithUnknownSupport) {
|
|
|
|
try {
|
|
|
|
switch (feature.onPacketTest(aPacket)) {
|
|
|
|
case SKIP:
|
|
|
|
break;
|
|
|
|
case SUPPORTED:
|
|
|
|
this._featuresWithUnknownSupport.delete(feature);
|
|
|
|
this._featureDeferreds[feature.name].resolve(true);
|
|
|
|
break;
|
|
|
|
case NOT_SUPPORTED:
|
|
|
|
this._featuresWithUnknownSupport.delete(feature);
|
|
|
|
this._featuresWithoutSupport.add(feature);
|
|
|
|
this.rejectFeature(feature.name);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Cu.reportError(new Error(
|
|
|
|
"Bad return value from `onPacketTest` for feature '"
|
|
|
|
+ feature.name + "'"));
|
|
|
|
}
|
|
|
|
} catch (ex) {
|
|
|
|
Cu.reportError("Error detecting support for feature '"
|
|
|
|
+ feature.name + "':" + ex.message + "\n"
|
|
|
|
+ ex.stack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Go through each of the features that we know are unsupported by the current
|
|
|
|
* server and attempt to shim support.
|
|
|
|
*/
|
|
|
|
_shimPacket: function PC__shimPacket(aPacket) {
|
|
|
|
let extraPackets = [];
|
|
|
|
|
|
|
|
let loop = function (aFeatures, aPacket) {
|
|
|
|
if (aFeatures.length === 0) {
|
|
|
|
for (let packet of extraPackets) {
|
|
|
|
this._client.onPacket(packet, true);
|
|
|
|
}
|
|
|
|
return aPacket;
|
|
|
|
} else {
|
|
|
|
let replacePacket = function (aNewPacket) {
|
|
|
|
return aNewPacket;
|
|
|
|
};
|
|
|
|
let extraPacket = function (aExtraPacket) {
|
|
|
|
extraPackets.push(aExtraPacket);
|
|
|
|
return aPacket;
|
|
|
|
};
|
|
|
|
let keepPacket = function () {
|
|
|
|
return aPacket;
|
|
|
|
};
|
|
|
|
let newPacket = aFeatures[0].translatePacket(aPacket,
|
|
|
|
replacePacket,
|
|
|
|
extraPacket,
|
|
|
|
keepPacket);
|
|
|
|
return resolve(newPacket).then(loop.bind(null, aFeatures.slice(1)));
|
|
|
|
}
|
|
|
|
}.bind(this);
|
|
|
|
|
|
|
|
return loop([f for (f of this._featuresWithoutSupport)],
|
|
|
|
aPacket);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interface defining what methods a feature compatibility shim should have.
|
|
|
|
*/
|
|
|
|
const FeatureCompatibilityShim = {
|
|
|
|
// The name of the feature
|
|
|
|
name: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Takes a packet and returns boolean (or promise of boolean) indicating
|
|
|
|
* whether the server supports the RDP feature we are possibly shimming.
|
|
|
|
*/
|
|
|
|
onPacketTest: function (aPacket) {
|
|
|
|
throw new Error("Not yet implemented");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Takes a packet actually sent from the server and decides whether to replace
|
|
|
|
* it with a new packet, create an extra packet, or keep it.
|
|
|
|
*/
|
|
|
|
translatePacket: function (aPacket, aReplacePacket, aExtraPacket, aKeepPacket) {
|
|
|
|
throw new Error("Not yet implemented");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A shim to support the "sources" and "newSource" packets for older servers
|
|
|
|
* which don't support them.
|
|
|
|
*/
|
|
|
|
function SourcesShim() {
|
|
|
|
this._sourcesSeen = new Set();
|
|
|
|
}
|
|
|
|
|
|
|
|
SourcesShim.prototype = Object.create(FeatureCompatibilityShim);
|
|
|
|
let SSProto = SourcesShim.prototype;
|
|
|
|
|
|
|
|
SSProto.name = "sources";
|
|
|
|
|
|
|
|
SSProto.onPacketTest = function SS_onPacketTest(aPacket) {
|
|
|
|
if (aPacket.traits) {
|
|
|
|
return aPacket.traits.sources
|
|
|
|
? SUPPORTED
|
|
|
|
: NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
return SKIP;
|
|
|
|
};
|
|
|
|
|
|
|
|
SSProto.translatePacket = function SS_translatePacket(aPacket,
|
|
|
|
aReplacePacket,
|
|
|
|
aExtraPacket,
|
|
|
|
aKeepPacket) {
|
|
|
|
if (aPacket.type !== "newScript" || this._sourcesSeen.has(aPacket.url)) {
|
|
|
|
return aKeepPacket();
|
|
|
|
}
|
|
|
|
this._sourcesSeen.add(aPacket.url);
|
|
|
|
return aExtraPacket({
|
|
|
|
from: aPacket.from,
|
|
|
|
type: "newSource",
|
|
|
|
source: aPacket.source
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2012-02-07 09:22:30 -08:00
|
|
|
/**
|
|
|
|
* Creates a tab client for the remote debugging protocol server. This client
|
|
|
|
* is a front to the tab actor created in the server side, hiding the protocol
|
|
|
|
* details in a traditional JavaScript API.
|
2012-01-23 00:29:15 -08:00
|
|
|
*
|
|
|
|
* @param aClient DebuggerClient
|
|
|
|
* The debugger client parent.
|
|
|
|
* @param aActor string
|
|
|
|
* The actor ID for this tab.
|
2012-02-07 09:22:30 -08:00
|
|
|
*/
|
|
|
|
function TabClient(aClient, aActor) {
|
|
|
|
this._client = aClient;
|
|
|
|
this._actor = aActor;
|
2013-04-09 03:47:00 -07:00
|
|
|
this.request = this._client.request;
|
2012-02-07 09:22:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
TabClient.prototype = {
|
2013-04-09 03:47:00 -07:00
|
|
|
get actor() { return this._actor },
|
2013-04-15 22:52:55 -07:00
|
|
|
get _transport() { return this._client._transport; },
|
2013-04-09 03:47:00 -07:00
|
|
|
|
2012-02-07 09:22:30 -08:00
|
|
|
/**
|
|
|
|
* Detach the client from the tab actor.
|
|
|
|
*
|
|
|
|
* @param function aOnResponse
|
|
|
|
* Called with the response packet.
|
|
|
|
*/
|
2013-04-09 03:47:00 -07:00
|
|
|
detach: DebuggerClient.requester({
|
|
|
|
type: "detach"
|
|
|
|
}, {
|
|
|
|
after: function (aResponse) {
|
|
|
|
if (this.activeTab === this._client._tabClients[this.actor]) {
|
|
|
|
delete this.activeTab;
|
2012-02-07 09:22:30 -08:00
|
|
|
}
|
2013-04-09 03:47:00 -07:00
|
|
|
delete this._client._tabClients[this.actor];
|
|
|
|
return aResponse;
|
|
|
|
},
|
|
|
|
telemetry: "TABDETACH"
|
|
|
|
}),
|
2012-02-07 09:22:30 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
eventSource(TabClient.prototype);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a thread client for the remote debugging protocol server. This client
|
|
|
|
* is a front to the thread actor created in the server side, hiding the
|
|
|
|
* protocol details in a traditional JavaScript API.
|
2012-01-23 00:29:15 -08:00
|
|
|
*
|
|
|
|
* @param aClient DebuggerClient
|
|
|
|
* The debugger client parent.
|
|
|
|
* @param aActor string
|
|
|
|
* The actor ID for this thread.
|
2012-02-07 09:22:30 -08:00
|
|
|
*/
|
|
|
|
function ThreadClient(aClient, aActor) {
|
|
|
|
this._client = aClient;
|
|
|
|
this._actor = aActor;
|
|
|
|
this._frameCache = [];
|
|
|
|
this._scriptCache = {};
|
2012-08-30 14:10:07 -07:00
|
|
|
this._pauseGrips = {};
|
2012-09-27 01:29:00 -07:00
|
|
|
this._threadGrips = {};
|
2013-04-09 03:47:00 -07:00
|
|
|
this.request = this._client.request;
|
2012-02-07 09:22:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
ThreadClient.prototype = {
|
|
|
|
_state: "paused",
|
|
|
|
get state() { return this._state; },
|
2012-02-09 23:46:10 -08:00
|
|
|
get paused() { return this._state === "paused"; },
|
2012-02-07 09:22:30 -08:00
|
|
|
|
2012-06-03 06:39:51 -07:00
|
|
|
_pauseOnExceptions: false,
|
|
|
|
|
2012-02-07 09:22:30 -08:00
|
|
|
_actor: null,
|
|
|
|
get actor() { return this._actor; },
|
|
|
|
|
2013-02-28 04:02:00 -08:00
|
|
|
get compat() { return this._client.compat; },
|
2013-04-15 22:52:55 -07:00
|
|
|
get _transport() { return this._client._transport; },
|
2013-02-28 04:02:00 -08:00
|
|
|
|
2012-02-07 09:22:30 -08:00
|
|
|
_assertPaused: function TC_assertPaused(aCommand) {
|
2012-02-09 23:46:10 -08:00
|
|
|
if (!this.paused) {
|
2012-05-02 13:11:19 -07:00
|
|
|
throw Error(aCommand + " command sent while not paused.");
|
2012-02-07 09:22:30 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2012-03-17 23:50:43 -07:00
|
|
|
* Resume a paused thread. If the optional aLimit parameter is present, then
|
|
|
|
* the thread will also pause when that limit is reached.
|
2012-02-07 09:22:30 -08:00
|
|
|
*
|
2012-03-17 23:50:43 -07:00
|
|
|
* @param [optional] object aLimit
|
|
|
|
* An object with a type property set to the appropriate limit (next,
|
|
|
|
* step, or finish) per the remote debugging protocol specification.
|
2013-04-09 03:47:00 -07:00
|
|
|
* Use null to specify no limit.
|
|
|
|
* @param function aOnResponse
|
|
|
|
* Called with the response packet.
|
2012-02-07 09:22:30 -08:00
|
|
|
*/
|
2013-04-09 03:47:00 -07:00
|
|
|
_doResume: DebuggerClient.requester({
|
|
|
|
type: "resume",
|
|
|
|
resumeLimit: args(0)
|
|
|
|
}, {
|
|
|
|
before: function (aPacket) {
|
|
|
|
this._assertPaused("resume");
|
|
|
|
|
|
|
|
// Put the client in a tentative "resuming" state so we can prevent
|
|
|
|
// further requests that should only be sent in the paused state.
|
|
|
|
this._state = "resuming";
|
|
|
|
|
|
|
|
aPacket.pauseOnExceptions = this._pauseOnExceptions;
|
|
|
|
return aPacket;
|
|
|
|
},
|
|
|
|
after: function (aResponse) {
|
2012-02-07 09:22:30 -08:00
|
|
|
if (aResponse.error) {
|
|
|
|
// There was an error resuming, back to paused state.
|
2013-04-09 03:47:00 -07:00
|
|
|
this._state = "paused";
|
2012-02-07 09:22:30 -08:00
|
|
|
}
|
2013-04-09 03:47:00 -07:00
|
|
|
return aResponse;
|
|
|
|
},
|
|
|
|
telemetry: "RESUME"
|
|
|
|
}),
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resume a paused thread.
|
|
|
|
*/
|
|
|
|
resume: function TC_resume(aOnResponse) {
|
|
|
|
this._doResume(null, aOnResponse);
|
2012-02-07 09:22:30 -08:00
|
|
|
},
|
|
|
|
|
2012-03-17 23:50:43 -07:00
|
|
|
/**
|
|
|
|
* Step over a function call.
|
|
|
|
*
|
|
|
|
* @param function aOnResponse
|
|
|
|
* Called with the response packet.
|
|
|
|
*/
|
|
|
|
stepOver: function TC_stepOver(aOnResponse) {
|
2013-04-09 03:47:00 -07:00
|
|
|
this._doResume({ type: "next" }, aOnResponse);
|
2012-03-17 23:50:43 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Step into a function call.
|
|
|
|
*
|
|
|
|
* @param function aOnResponse
|
|
|
|
* Called with the response packet.
|
|
|
|
*/
|
|
|
|
stepIn: function TC_stepIn(aOnResponse) {
|
2013-04-09 03:47:00 -07:00
|
|
|
this._doResume({ type: "step" }, aOnResponse);
|
2012-03-17 23:50:43 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Step out of a function call.
|
|
|
|
*
|
|
|
|
* @param function aOnResponse
|
|
|
|
* Called with the response packet.
|
|
|
|
*/
|
|
|
|
stepOut: function TC_stepOut(aOnResponse) {
|
2013-04-09 03:47:00 -07:00
|
|
|
this._doResume({ type: "finish" }, aOnResponse);
|
2012-03-17 23:50:43 -07:00
|
|
|
},
|
|
|
|
|
2012-02-09 23:46:10 -08:00
|
|
|
/**
|
|
|
|
* Interrupt a running thread.
|
|
|
|
*
|
|
|
|
* @param function aOnResponse
|
|
|
|
* Called with the response packet.
|
|
|
|
*/
|
2013-04-09 03:47:00 -07:00
|
|
|
interrupt: DebuggerClient.requester({
|
|
|
|
type: "interrupt"
|
|
|
|
}, {
|
|
|
|
telemetry: "INTERRUPT"
|
|
|
|
}),
|
2012-02-09 23:46:10 -08:00
|
|
|
|
2012-06-03 06:39:51 -07:00
|
|
|
/**
|
|
|
|
* Enable or disable pausing when an exception is thrown.
|
|
|
|
*
|
|
|
|
* @param boolean aFlag
|
|
|
|
* Enables pausing if true, disables otherwise.
|
|
|
|
* @param function aOnResponse
|
|
|
|
* Called with the response packet.
|
|
|
|
*/
|
|
|
|
pauseOnExceptions: function TC_pauseOnExceptions(aFlag, aOnResponse) {
|
|
|
|
this._pauseOnExceptions = aFlag;
|
|
|
|
// If the debuggee is paused, the value of the flag will be communicated in
|
|
|
|
// the next resumption. Otherwise we have to force a pause in order to send
|
|
|
|
// the flag.
|
|
|
|
if (!this.paused) {
|
|
|
|
this.interrupt(function(aResponse) {
|
|
|
|
if (aResponse.error) {
|
|
|
|
// Can't continue if pausing failed.
|
|
|
|
aOnResponse(aResponse);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.resume(aOnResponse);
|
|
|
|
}.bind(this));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-02-07 09:22:30 -08:00
|
|
|
/**
|
|
|
|
* Send a clientEvaluate packet to the debuggee. Response
|
|
|
|
* will be a resume packet.
|
2012-05-24 04:23:53 -07:00
|
|
|
*
|
|
|
|
* @param string aFrame
|
|
|
|
* The actor ID of the frame where the evaluation should take place.
|
|
|
|
* @param string aExpression
|
|
|
|
* The expression that will be evaluated in the scope of the frame
|
|
|
|
* above.
|
|
|
|
* @param function aOnResponse
|
|
|
|
* Called with the response packet.
|
2012-02-07 09:22:30 -08:00
|
|
|
*/
|
2013-04-09 03:47:00 -07:00
|
|
|
eval: DebuggerClient.requester({
|
|
|
|
type: "clientEvaluate",
|
|
|
|
frame: args(0),
|
|
|
|
expression: args(1)
|
|
|
|
}, {
|
|
|
|
before: function (aPacket) {
|
|
|
|
this._assertPaused("eval");
|
|
|
|
// Put the client in a tentative "resuming" state so we can prevent
|
|
|
|
// further requests that should only be sent in the paused state.
|
|
|
|
this._state = "resuming";
|
|
|
|
return aPacket;
|
|
|
|
},
|
|
|
|
after: function (aResponse) {
|
2012-02-07 09:22:30 -08:00
|
|
|
if (aResponse.error) {
|
|
|
|
// There was an error resuming, back to paused state.
|
|
|
|
self._state = "paused";
|
|
|
|
}
|
2013-04-09 03:47:00 -07:00
|
|
|
return aResponse;
|
|
|
|
},
|
|
|
|
telemetry: "CLIENTEVALUATE"
|
|
|
|
}),
|
2012-02-07 09:22:30 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Detach from the thread actor.
|
|
|
|
*
|
|
|
|
* @param function aOnResponse
|
|
|
|
* Called with the response packet.
|
|
|
|
*/
|
2013-04-09 03:47:00 -07:00
|
|
|
detach: DebuggerClient.requester({
|
|
|
|
type: "detach"
|
|
|
|
}, {
|
|
|
|
after: function (aResponse) {
|
|
|
|
if (this.activeThread === this._client._threadClients[this.actor]) {
|
|
|
|
delete this.activeThread;
|
2012-02-07 09:22:30 -08:00
|
|
|
}
|
2013-04-09 03:47:00 -07:00
|
|
|
delete this._client._threadClients[this.actor];
|
|
|
|
return aResponse;
|
|
|
|
},
|
|
|
|
telemetry: "THREADDETACH"
|
|
|
|
}),
|
2012-02-07 09:22:30 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Request to set a breakpoint in the specified location.
|
|
|
|
*
|
2012-05-24 04:23:53 -07:00
|
|
|
* @param object aLocation
|
2012-02-09 23:46:11 -08:00
|
|
|
* The source location object where the breakpoint will be set.
|
2012-05-24 04:23:53 -07:00
|
|
|
* @param function aOnResponse
|
2012-01-23 00:29:15 -08:00
|
|
|
* Called with the thread's response.
|
2012-02-07 09:22:30 -08:00
|
|
|
*/
|
|
|
|
setBreakpoint: function TC_setBreakpoint(aLocation, aOnResponse) {
|
2012-02-09 23:46:11 -08:00
|
|
|
// A helper function that sets the breakpoint.
|
|
|
|
let doSetBreakpoint = function _doSetBreakpoint(aCallback) {
|
2012-08-30 14:11:54 -07:00
|
|
|
let packet = { to: this._actor, type: "setBreakpoint",
|
2012-02-09 23:46:11 -08:00
|
|
|
location: aLocation };
|
|
|
|
this._client.request(packet, function (aResponse) {
|
2012-06-03 06:39:50 -07:00
|
|
|
// Ignoring errors, since the user may be setting a breakpoint in a
|
|
|
|
// dead script that will reappear on a page reload.
|
|
|
|
if (aOnResponse) {
|
|
|
|
let bpClient = new BreakpointClient(this._client, aResponse.actor,
|
|
|
|
aLocation);
|
|
|
|
if (aCallback) {
|
|
|
|
aCallback(aOnResponse(aResponse, bpClient));
|
|
|
|
} else {
|
|
|
|
aOnResponse(aResponse, bpClient);
|
2012-02-09 23:46:11 -08:00
|
|
|
}
|
2012-06-03 06:39:50 -07:00
|
|
|
}
|
|
|
|
}.bind(this));
|
2012-02-09 23:46:11 -08:00
|
|
|
}.bind(this);
|
2012-02-07 09:22:30 -08:00
|
|
|
|
2012-02-09 23:46:11 -08:00
|
|
|
// If the debuggee is paused, just set the breakpoint.
|
|
|
|
if (this.paused) {
|
|
|
|
doSetBreakpoint();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Otherwise, force a pause in order to set the breakpoint.
|
|
|
|
this.interrupt(function(aResponse) {
|
|
|
|
if (aResponse.error) {
|
|
|
|
// Can't set the breakpoint if pausing failed.
|
|
|
|
aOnResponse(aResponse);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
doSetBreakpoint(this.resume.bind(this));
|
|
|
|
}.bind(this));
|
2012-02-07 09:22:30 -08:00
|
|
|
},
|
|
|
|
|
2012-10-12 01:26:49 -07:00
|
|
|
/**
|
|
|
|
* Release multiple thread-lifetime object actors. If any pause-lifetime
|
|
|
|
* actors are included in the request, a |notReleasable| error will return,
|
|
|
|
* but all the thread-lifetime ones will have been released.
|
|
|
|
*
|
2013-04-09 03:47:00 -07:00
|
|
|
* @param array actors
|
2012-10-12 01:26:49 -07:00
|
|
|
* An array with actor IDs to release.
|
|
|
|
*/
|
2013-04-09 03:47:00 -07:00
|
|
|
releaseMany: DebuggerClient.requester({
|
|
|
|
type: "releaseMany",
|
|
|
|
actors: args(0),
|
|
|
|
}, {
|
|
|
|
telemetry: "RELEASEMANY"
|
|
|
|
}),
|
2012-10-12 01:26:49 -07:00
|
|
|
|
2012-11-14 00:00:57 -08:00
|
|
|
/**
|
|
|
|
* Promote multiple pause-lifetime object actors to thread-lifetime ones.
|
|
|
|
*
|
2013-04-09 03:47:00 -07:00
|
|
|
* @param array actors
|
2012-11-14 00:00:57 -08:00
|
|
|
* An array with actor IDs to promote.
|
|
|
|
*/
|
2013-04-09 03:47:00 -07:00
|
|
|
threadGrips: DebuggerClient.requester({
|
|
|
|
type: "threadGrips",
|
|
|
|
actors: args(0)
|
|
|
|
}, {
|
|
|
|
telemetry: "THREADGRIPS"
|
|
|
|
}),
|
2012-11-14 00:00:57 -08:00
|
|
|
|
2013-02-28 04:02:00 -08:00
|
|
|
/**
|
|
|
|
* Request the loaded sources for the current thread.
|
|
|
|
*
|
|
|
|
* @param aOnResponse Function
|
|
|
|
* Called with the thread's response.
|
|
|
|
*/
|
|
|
|
getSources: function TC_getSources(aOnResponse) {
|
|
|
|
// This is how we should get sources if the server supports "sources"
|
|
|
|
// requests.
|
2013-04-09 03:47:00 -07:00
|
|
|
let getSources = DebuggerClient.requester({
|
|
|
|
type: "sources"
|
|
|
|
}, {
|
|
|
|
telemetry: "SOURCES"
|
|
|
|
});
|
2013-02-28 04:02:00 -08:00
|
|
|
|
|
|
|
// This is how we should deduct what sources exist from the existing scripts
|
|
|
|
// when the server does not support "sources" requests.
|
2013-04-09 03:47:00 -07:00
|
|
|
let getSourcesBackwardsCompat = DebuggerClient.requester({
|
|
|
|
type: "scripts"
|
|
|
|
}, {
|
|
|
|
after: function (aResponse) {
|
2013-02-28 04:02:00 -08:00
|
|
|
if (aResponse.error) {
|
2013-04-09 03:47:00 -07:00
|
|
|
return aResponse;
|
2013-02-28 04:02:00 -08:00
|
|
|
}
|
2013-04-09 03:47:00 -07:00
|
|
|
|
|
|
|
let sourceActorsByURL = aResponse.scripts
|
|
|
|
.reduce(function (aSourceActorsByURL, aScript) {
|
|
|
|
aSourceActorsByURL[aScript.url] = aScript.source;
|
|
|
|
return aSourceActorsByURL;
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
return {
|
2013-02-28 04:02:00 -08:00
|
|
|
sources: [
|
|
|
|
{ url: url, actor: sourceActorsByURL[url] }
|
|
|
|
for (url of Object.keys(sourceActorsByURL))
|
|
|
|
]
|
2013-04-09 03:47:00 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
telemetry: "SOURCES"
|
|
|
|
});
|
2013-02-28 04:02:00 -08:00
|
|
|
|
|
|
|
// On the first time `getSources` is called, patch the thread client with
|
|
|
|
// the best method for the server's capabilities.
|
|
|
|
let threadClient = this;
|
|
|
|
this.compat.supportsFeature("sources").then(function () {
|
|
|
|
threadClient.getSources = getSources;
|
|
|
|
}, function () {
|
|
|
|
threadClient.getSources = getSourcesBackwardsCompat;
|
|
|
|
}).then(function () {
|
|
|
|
threadClient.getSources(aOnResponse);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-08-24 00:41:02 -07:00
|
|
|
_doInterrupted: function TC_doInterrupted(aAction, aError) {
|
|
|
|
if (this.paused) {
|
|
|
|
aAction();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.interrupt(function(aResponse) {
|
|
|
|
if (aResponse) {
|
|
|
|
aError(aResponse);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aAction();
|
2013-04-09 03:47:00 -07:00
|
|
|
this.resume();
|
2012-08-24 00:41:02 -07:00
|
|
|
}.bind(this));
|
|
|
|
},
|
2012-02-07 09:22:30 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear the thread's source script cache. A scriptscleared event
|
|
|
|
* will be sent.
|
|
|
|
*/
|
|
|
|
_clearScripts: function TC_clearScripts() {
|
|
|
|
if (Object.keys(this._scriptCache).length > 0) {
|
|
|
|
this._scriptCache = {}
|
|
|
|
this.notify("scriptscleared");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Request frames from the callstack for the current thread.
|
|
|
|
*
|
2012-01-23 00:29:15 -08:00
|
|
|
* @param aStart integer
|
|
|
|
* The number of the youngest stack frame to return (the youngest
|
|
|
|
* frame is 0).
|
|
|
|
* @param aCount integer
|
|
|
|
* The maximum number of frames to return, or null to return all
|
|
|
|
* frames.
|
|
|
|
* @param aOnResponse function
|
|
|
|
* Called with the thread's response.
|
|
|
|
*/
|
2013-04-09 03:47:00 -07:00
|
|
|
getFrames: DebuggerClient.requester({
|
|
|
|
type: "frames",
|
|
|
|
start: args(0),
|
|
|
|
count: args(1)
|
|
|
|
}, {
|
|
|
|
telemetry: "FRAMES"
|
|
|
|
}),
|
2012-02-07 09:22:30 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An array of cached frames. Clients can observe the framesadded and
|
|
|
|
* framescleared event to keep up to date on changes to this cache,
|
|
|
|
* and can fill it using the fillFrames method.
|
|
|
|
*/
|
|
|
|
get cachedFrames() { return this._frameCache; },
|
|
|
|
|
|
|
|
/**
|
|
|
|
* true if there are more stack frames available on the server.
|
|
|
|
*/
|
|
|
|
get moreFrames() {
|
2012-02-09 23:46:10 -08:00
|
|
|
return this.paused && (!this._frameCache || this._frameCache.length == 0
|
2012-02-07 09:22:30 -08:00
|
|
|
|| !this._frameCache[this._frameCache.length - 1].oldest);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure that at least aTotal stack frames have been loaded in the
|
|
|
|
* ThreadClient's stack frame cache. A framesadded event will be
|
|
|
|
* sent when the stack frame cache is updated.
|
|
|
|
*
|
2012-01-23 00:29:15 -08:00
|
|
|
* @param aTotal number
|
|
|
|
* The minimum number of stack frames to be included.
|
2012-02-07 09:22:30 -08:00
|
|
|
*
|
|
|
|
* @returns true if a framesadded notification should be expected.
|
|
|
|
*/
|
|
|
|
fillFrames: function TC_fillFrames(aTotal) {
|
|
|
|
this._assertPaused("fillFrames");
|
|
|
|
|
|
|
|
if (this._frameCache.length >= aTotal) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
let numFrames = this._frameCache.length;
|
|
|
|
|
|
|
|
let self = this;
|
2012-01-23 00:29:15 -08:00
|
|
|
this.getFrames(numFrames, aTotal - numFrames, function(aResponse) {
|
2012-02-07 09:22:30 -08:00
|
|
|
for each (let frame in aResponse.frames) {
|
|
|
|
self._frameCache[frame.depth] = frame;
|
|
|
|
}
|
|
|
|
// If we got as many frames as we asked for, there might be more
|
|
|
|
// frames available.
|
|
|
|
|
|
|
|
self.notify("framesadded");
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear the thread's stack frame cache. A framescleared event
|
|
|
|
* will be sent.
|
|
|
|
*/
|
|
|
|
_clearFrames: function TC_clearFrames() {
|
|
|
|
if (this._frameCache.length > 0) {
|
|
|
|
this._frameCache = [];
|
|
|
|
this.notify("framescleared");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a GripClient object for the given object grip.
|
|
|
|
*
|
2012-01-23 00:29:15 -08:00
|
|
|
* @param aGrip object
|
|
|
|
* A pause-lifetime object grip returned by the protocol.
|
2012-02-07 09:22:30 -08:00
|
|
|
*/
|
2012-01-23 00:29:15 -08:00
|
|
|
pauseGrip: function TC_pauseGrip(aGrip) {
|
2012-08-30 14:10:07 -07:00
|
|
|
if (aGrip.actor in this._pauseGrips) {
|
|
|
|
return this._pauseGrips[aGrip.actor];
|
2012-02-07 09:22:30 -08:00
|
|
|
}
|
|
|
|
|
2012-08-30 14:10:07 -07:00
|
|
|
let client = new GripClient(this._client, aGrip);
|
|
|
|
this._pauseGrips[aGrip.actor] = client;
|
|
|
|
return client;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2012-09-27 01:29:00 -07:00
|
|
|
* Get or create a long string client, checking the grip client cache if it
|
|
|
|
* already exists.
|
2012-08-30 14:10:07 -07:00
|
|
|
*
|
|
|
|
* @param aGrip Object
|
|
|
|
* The long string grip returned by the protocol.
|
2012-09-27 01:29:00 -07:00
|
|
|
* @param aGripCacheName String
|
|
|
|
* The property name of the grip client cache to check for existing
|
|
|
|
* clients in.
|
2012-08-30 14:10:07 -07:00
|
|
|
*/
|
2012-09-27 01:29:00 -07:00
|
|
|
_longString: function TC__longString(aGrip, aGripCacheName) {
|
|
|
|
if (aGrip.actor in this[aGripCacheName]) {
|
|
|
|
return this[aGripCacheName][aGrip.actor];
|
2012-02-07 09:22:30 -08:00
|
|
|
}
|
|
|
|
|
2012-08-30 14:10:07 -07:00
|
|
|
let client = new LongStringClient(this._client, aGrip);
|
2012-09-27 01:29:00 -07:00
|
|
|
this[aGripCacheName][aGrip.actor] = client;
|
2012-02-07 09:22:30 -08:00
|
|
|
return client;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2012-09-27 01:29:00 -07:00
|
|
|
* Return an instance of LongStringClient for the given long string grip that
|
|
|
|
* is scoped to the current pause.
|
|
|
|
*
|
|
|
|
* @param aGrip Object
|
|
|
|
* The long string grip returned by the protocol.
|
|
|
|
*/
|
|
|
|
pauseLongString: function TC_pauseLongString(aGrip) {
|
|
|
|
return this._longString(aGrip, "_pauseGrips");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an instance of LongStringClient for the given long string grip that
|
|
|
|
* is scoped to the thread lifetime.
|
|
|
|
*
|
|
|
|
* @param aGrip Object
|
|
|
|
* The long string grip returned by the protocol.
|
|
|
|
*/
|
|
|
|
threadLongString: function TC_threadLongString(aGrip) {
|
|
|
|
return this._longString(aGrip, "_threadGrips");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear and invalidate all the grip clients from the given cache.
|
|
|
|
*
|
|
|
|
* @param aGripCacheName
|
|
|
|
* The property name of the grip cache we want to clear.
|
2012-02-07 09:22:30 -08:00
|
|
|
*/
|
2012-09-27 01:29:00 -07:00
|
|
|
_clearGripClients: function TC_clearGrips(aGripCacheName) {
|
|
|
|
for each (let grip in this[aGripCacheName]) {
|
2012-02-07 09:22:30 -08:00
|
|
|
grip.valid = false;
|
|
|
|
}
|
2012-09-27 01:29:00 -07:00
|
|
|
this[aGripCacheName] = {};
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invalidate pause-lifetime grip clients and clear the list of
|
|
|
|
* current grip clients.
|
|
|
|
*/
|
|
|
|
_clearPauseGrips: function TC_clearPauseGrips() {
|
|
|
|
this._clearGripClients("_pauseGrips");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invalidate pause-lifetime grip clients and clear the list of
|
|
|
|
* current grip clients.
|
|
|
|
*/
|
|
|
|
_clearThreadGrips: function TC_clearPauseGrips() {
|
|
|
|
this._clearGripClients("_threadGrips");
|
2012-02-07 09:22:30 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle thread state change by doing necessary cleanup and notifying all
|
|
|
|
* registered listeners.
|
|
|
|
*/
|
|
|
|
_onThreadState: function TC_onThreadState(aPacket) {
|
|
|
|
this._state = ThreadStateTypes[aPacket.type];
|
|
|
|
this._clearFrames();
|
|
|
|
this._clearPauseGrips();
|
2012-09-27 01:29:00 -07:00
|
|
|
aPacket.type === ThreadStateTypes.detached && this._clearThreadGrips();
|
2012-02-07 09:22:30 -08:00
|
|
|
this._client._eventsEnabled && this.notify(aPacket.type, aPacket);
|
|
|
|
},
|
2012-09-27 01:30:00 -07:00
|
|
|
|
|
|
|
/**
|
2013-02-28 04:02:00 -08:00
|
|
|
* Return an instance of SourceClient for the given source actor form.
|
2012-09-27 01:30:00 -07:00
|
|
|
*/
|
2013-02-28 04:02:00 -08:00
|
|
|
source: function TC_source(aForm) {
|
|
|
|
return new SourceClient(this._client, aForm);
|
2012-09-27 01:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-02-07 09:22:30 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
eventSource(ThreadClient.prototype);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Grip clients are used to retrieve information about the relevant object.
|
2012-01-23 00:29:15 -08:00
|
|
|
*
|
|
|
|
* @param aClient DebuggerClient
|
|
|
|
* The debugger client parent.
|
|
|
|
* @param aGrip object
|
|
|
|
* A pause-lifetime object grip returned by the protocol.
|
2012-02-07 09:22:30 -08:00
|
|
|
*/
|
|
|
|
function GripClient(aClient, aGrip)
|
|
|
|
{
|
|
|
|
this._grip = aGrip;
|
|
|
|
this._client = aClient;
|
2013-04-09 03:47:00 -07:00
|
|
|
this.request = this._client.request;
|
2012-02-07 09:22:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
GripClient.prototype = {
|
|
|
|
get actor() { return this._grip.actor },
|
2013-04-15 22:52:55 -07:00
|
|
|
get _transport() { return this._client._transport; },
|
2012-02-07 09:22:30 -08:00
|
|
|
|
2012-08-30 14:10:07 -07:00
|
|
|
valid: true,
|
2012-02-07 09:22:30 -08:00
|
|
|
|
|
|
|
/**
|
2012-12-14 10:26:47 -08:00
|
|
|
* Request the names of a function's formal parameters.
|
2012-02-07 09:22:30 -08:00
|
|
|
*
|
2012-01-23 00:29:15 -08:00
|
|
|
* @param aOnResponse function
|
2012-12-14 10:26:47 -08:00
|
|
|
* Called with an object of the form:
|
|
|
|
* { parameterNames:[<parameterName>, ...] }
|
|
|
|
* where each <parameterName> is the name of a parameter.
|
2012-02-07 09:22:30 -08:00
|
|
|
*/
|
2013-04-09 03:47:00 -07:00
|
|
|
getParameterNames: DebuggerClient.requester({
|
|
|
|
type: "parameterNames"
|
|
|
|
}, {
|
|
|
|
before: function (aPacket) {
|
|
|
|
if (this._grip["class"] !== "Function") {
|
|
|
|
throw new Error("getParameterNames is only valid for function grips.");
|
|
|
|
}
|
|
|
|
return aPacket;
|
|
|
|
},
|
|
|
|
telemetry: "PARAMETERNAMES"
|
|
|
|
}),
|
2012-02-07 09:22:30 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Request the names of the properties defined on the object and not its
|
|
|
|
* prototype.
|
|
|
|
*
|
|
|
|
* @param aOnResponse function Called with the request's response.
|
|
|
|
*/
|
2013-04-09 03:47:00 -07:00
|
|
|
getOwnPropertyNames: DebuggerClient.requester({
|
|
|
|
type: "ownPropertyNames"
|
|
|
|
}, {
|
|
|
|
telemetry: "OWNPROPERTYNAMES"
|
|
|
|
}),
|
2012-02-07 09:22:30 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Request the prototype and own properties of the object.
|
|
|
|
*
|
|
|
|
* @param aOnResponse function Called with the request's response.
|
|
|
|
*/
|
2013-04-09 03:47:00 -07:00
|
|
|
getPrototypeAndProperties: DebuggerClient.requester({
|
|
|
|
type: "prototypeAndProperties"
|
|
|
|
}, {
|
|
|
|
telemetry: "PROTOTYPEANDPROPERTIES"
|
|
|
|
}),
|
2012-02-07 09:22:30 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Request the property descriptor of the object's specified property.
|
|
|
|
*
|
|
|
|
* @param aName string The name of the requested property.
|
|
|
|
* @param aOnResponse function Called with the request's response.
|
|
|
|
*/
|
2013-04-09 03:47:00 -07:00
|
|
|
getProperty: DebuggerClient.requester({
|
|
|
|
type: "property",
|
|
|
|
name: args(0)
|
|
|
|
}, {
|
|
|
|
telemetry: "PROPERTY"
|
|
|
|
}),
|
2012-02-07 09:22:30 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Request the prototype of the object.
|
|
|
|
*
|
|
|
|
* @param aOnResponse function Called with the request's response.
|
|
|
|
*/
|
2013-04-09 03:47:00 -07:00
|
|
|
getPrototype: DebuggerClient.requester({
|
|
|
|
type: "prototype"
|
|
|
|
}, {
|
|
|
|
telemetry: "PROTOTYPE"
|
|
|
|
}),
|
2012-02-07 09:22:30 -08:00
|
|
|
};
|
|
|
|
|
2012-08-30 14:10:07 -07:00
|
|
|
/**
|
|
|
|
* A LongStringClient provides a way to access "very long" strings from the
|
|
|
|
* debugger server.
|
|
|
|
*
|
|
|
|
* @param aClient DebuggerClient
|
|
|
|
* The debugger client parent.
|
|
|
|
* @param aGrip Object
|
|
|
|
* A pause-lifetime long string grip returned by the protocol.
|
|
|
|
*/
|
|
|
|
function LongStringClient(aClient, aGrip) {
|
|
|
|
this._grip = aGrip;
|
|
|
|
this._client = aClient;
|
2013-04-09 03:47:00 -07:00
|
|
|
this.request = this._client.request;
|
2012-08-30 14:10:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
LongStringClient.prototype = {
|
|
|
|
get actor() { return this._grip.actor; },
|
|
|
|
get length() { return this._grip.length; },
|
2012-11-05 08:41:59 -08:00
|
|
|
get initial() { return this._grip.initial; },
|
2013-04-15 22:52:55 -07:00
|
|
|
get _transport() { return this._client._transport; },
|
2012-08-30 14:10:07 -07:00
|
|
|
|
|
|
|
valid: true,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the substring of this LongString from aStart to aEnd.
|
|
|
|
*
|
|
|
|
* @param aStart Number
|
|
|
|
* The starting index.
|
|
|
|
* @param aEnd Number
|
|
|
|
* The ending index.
|
|
|
|
* @param aCallback Function
|
|
|
|
* The function called when we receive the substring.
|
|
|
|
*/
|
2013-04-09 03:47:00 -07:00
|
|
|
substring: DebuggerClient.requester({
|
|
|
|
type: "substring",
|
|
|
|
start: args(0),
|
|
|
|
end: args(1)
|
|
|
|
}, {
|
|
|
|
telemetry: "SUBSTRING"
|
|
|
|
}),
|
2012-08-30 14:10:07 -07:00
|
|
|
};
|
|
|
|
|
2012-09-27 01:30:00 -07:00
|
|
|
/**
|
|
|
|
* A SourceClient provides a way to access the source text of a script.
|
|
|
|
*
|
|
|
|
* @param aClient DebuggerClient
|
|
|
|
* The debugger client parent.
|
2013-02-28 04:02:00 -08:00
|
|
|
* @param aForm Object
|
|
|
|
* The form sent across the remote debugging protocol.
|
2012-09-27 01:30:00 -07:00
|
|
|
*/
|
2013-02-28 04:02:00 -08:00
|
|
|
function SourceClient(aClient, aForm) {
|
|
|
|
this._form = aForm;
|
2012-09-27 01:30:00 -07:00
|
|
|
this._client = aClient;
|
|
|
|
}
|
|
|
|
|
|
|
|
SourceClient.prototype = {
|
2013-04-15 22:52:55 -07:00
|
|
|
get _transport() { return this._client._transport; },
|
|
|
|
|
2012-09-27 01:30:00 -07:00
|
|
|
/**
|
|
|
|
* Get a long string grip for this SourceClient's source.
|
|
|
|
*/
|
|
|
|
source: function SC_source(aCallback) {
|
|
|
|
let packet = {
|
2013-02-28 04:02:00 -08:00
|
|
|
to: this._form.actor,
|
2012-09-27 01:30:00 -07:00
|
|
|
type: "source"
|
|
|
|
};
|
2012-09-27 22:27:00 -07:00
|
|
|
this._client.request(packet, function (aResponse) {
|
|
|
|
if (aResponse.error) {
|
|
|
|
aCallback(aResponse);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof aResponse.source === "string") {
|
|
|
|
aCallback(aResponse);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let longString = this._client.activeThread.threadLongString(
|
|
|
|
aResponse.source);
|
|
|
|
longString.substring(0, longString.length, function (aResponse) {
|
|
|
|
if (aResponse.error) {
|
|
|
|
aCallback(aResponse);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aCallback({
|
|
|
|
source: aResponse.substring
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}.bind(this));
|
2012-09-27 01:30:00 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-07 09:22:30 -08:00
|
|
|
/**
|
|
|
|
* Breakpoint clients are used to remove breakpoints that are no longer used.
|
2012-01-23 00:29:15 -08:00
|
|
|
*
|
|
|
|
* @param aClient DebuggerClient
|
|
|
|
* The debugger client parent.
|
|
|
|
* @param aActor string
|
|
|
|
* The actor ID for this breakpoint.
|
2012-03-05 09:56:13 -08:00
|
|
|
* @param aLocation object
|
|
|
|
* The location of the breakpoint. This is an object with two properties:
|
|
|
|
* url and line.
|
2012-02-07 09:22:30 -08:00
|
|
|
*/
|
2012-03-05 09:56:13 -08:00
|
|
|
function BreakpointClient(aClient, aActor, aLocation) {
|
2012-02-07 09:22:30 -08:00
|
|
|
this._client = aClient;
|
|
|
|
this._actor = aActor;
|
2012-03-05 09:56:13 -08:00
|
|
|
this.location = aLocation;
|
2013-04-09 03:47:00 -07:00
|
|
|
this.request = this._client.request;
|
2012-02-07 09:22:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
BreakpointClient.prototype = {
|
|
|
|
|
|
|
|
_actor: null,
|
|
|
|
get actor() { return this._actor; },
|
2013-04-15 22:52:55 -07:00
|
|
|
get _transport() { return this._client._transport; },
|
2012-02-07 09:22:30 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the breakpoint from the server.
|
|
|
|
*/
|
2013-04-09 03:47:00 -07:00
|
|
|
remove: DebuggerClient.requester({
|
|
|
|
type: "delete"
|
|
|
|
}, {
|
|
|
|
telemetry: "DELETE"
|
|
|
|
}),
|
2012-02-07 09:22:30 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
eventSource(BreakpointClient.prototype);
|
|
|
|
|
|
|
|
/**
|
2012-01-23 00:29:15 -08:00
|
|
|
* Connects to a debugger server socket and returns a DebuggerTransport.
|
|
|
|
*
|
|
|
|
* @param aHost string
|
|
|
|
* The host name or IP address of the debugger server.
|
|
|
|
* @param aPort number
|
|
|
|
* The port number of the debugger server.
|
2012-02-07 09:22:30 -08:00
|
|
|
*/
|
2012-10-31 09:13:28 -07:00
|
|
|
this.debuggerSocketConnect = function debuggerSocketConnect(aHost, aPort)
|
2012-02-07 09:22:30 -08:00
|
|
|
{
|
|
|
|
let s = socketTransportService.createTransport(null, 0, aHost, aPort, null);
|
|
|
|
let transport = new DebuggerTransport(s.openInputStream(0, 0, 0),
|
|
|
|
s.openOutputStream(0, 0, 0));
|
|
|
|
return transport;
|
|
|
|
}
|
2013-02-28 04:02:00 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Takes a pair of items and returns them as an array.
|
|
|
|
*/
|
|
|
|
function pair(aItemOne, aItemTwo) {
|
|
|
|
return [aItemOne, aItemTwo];
|
|
|
|
}
|