2012-07-25 16:30:00 +00:00
|
|
|
/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; js-indent-level: 2; -*- */
|
2012-02-07 17:22:30 +00:00
|
|
|
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00: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 17:22:30 +00:00
|
|
|
|
|
|
|
"use strict";
|
2012-08-30 21:10:07 +00:00
|
|
|
|
2013-07-25 00:46:49 +00:00
|
|
|
/**
|
|
|
|
* BreakpointStore objects keep track of all breakpoints that get set so that we
|
|
|
|
* can reset them when the same script is introduced to the thread again (such
|
|
|
|
* as after a refresh).
|
|
|
|
*/
|
|
|
|
function BreakpointStore() {
|
|
|
|
// If we have a whole-line breakpoint set at LINE in URL, then
|
|
|
|
//
|
|
|
|
// this._wholeLineBreakpoints[URL][LINE]
|
|
|
|
//
|
|
|
|
// is an object
|
|
|
|
//
|
|
|
|
// { url, line[, actor] }
|
|
|
|
//
|
|
|
|
// where the `actor` property is optional.
|
|
|
|
this._wholeLineBreakpoints = Object.create(null);
|
|
|
|
|
|
|
|
// If we have a breakpoint set at LINE, COLUMN in URL, then
|
|
|
|
//
|
|
|
|
// this._breakpoints[URL][LINE][COLUMN]
|
|
|
|
//
|
|
|
|
// is an object
|
|
|
|
//
|
|
|
|
// { url, line[, actor] }
|
|
|
|
//
|
|
|
|
// where the `actor` property is optional.
|
|
|
|
this._breakpoints = Object.create(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
BreakpointStore.prototype = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a breakpoint to the breakpoint store.
|
|
|
|
*
|
|
|
|
* @param Object aBreakpoint
|
|
|
|
* The breakpoint to be added (not copied). It is an object with the
|
|
|
|
* following properties:
|
|
|
|
* - url
|
|
|
|
* - line
|
|
|
|
* - column (optional; omission implies that the breakpoint is for
|
|
|
|
* the whole line)
|
|
|
|
* - actor (optional)
|
|
|
|
*/
|
|
|
|
addBreakpoint: function BS_addBreakpoint(aBreakpoint) {
|
|
|
|
let { url, line, column } = aBreakpoint;
|
|
|
|
|
|
|
|
if (column != null) {
|
|
|
|
if (!this._breakpoints[url]) {
|
|
|
|
this._breakpoints[url] = [];
|
|
|
|
}
|
|
|
|
if (!this._breakpoints[url][line]) {
|
|
|
|
this._breakpoints[url][line] = [];
|
|
|
|
}
|
|
|
|
this._breakpoints[url][line][column] = aBreakpoint;
|
|
|
|
} else {
|
|
|
|
// Add a breakpoint that breaks on the whole line.
|
|
|
|
if (!this._wholeLineBreakpoints[url]) {
|
|
|
|
this._wholeLineBreakpoints[url] = [];
|
|
|
|
}
|
|
|
|
this._wholeLineBreakpoints[url][line] = aBreakpoint;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a breakpoint from the breakpoint store.
|
|
|
|
*
|
|
|
|
* @param Object aBreakpoint
|
|
|
|
* The breakpoint to be removed. It is an object with the following
|
|
|
|
* properties:
|
|
|
|
* - url
|
|
|
|
* - line
|
|
|
|
* - column (optional)
|
|
|
|
*/
|
|
|
|
removeBreakpoint: function BS_removeBreakpoint({ url, line, column }) {
|
|
|
|
if (column != null) {
|
|
|
|
if (this._breakpoints[url]) {
|
|
|
|
if (this._breakpoints[url][line]) {
|
|
|
|
delete this._breakpoints[url][line][column];
|
|
|
|
|
|
|
|
// If this was the last breakpoint on this line, delete the line from
|
|
|
|
// `this._breakpoints[url]` as well. Otherwise `_iterLines` will yield
|
|
|
|
// this line even though we no longer have breakpoints on
|
|
|
|
// it. Furthermore, we use Object.keys() instead of just checking
|
|
|
|
// `this._breakpoints[url].length` directly, because deleting
|
|
|
|
// properties from sparse arrays doesn't update the `length` property
|
|
|
|
// like adding them does.
|
|
|
|
if (Object.keys(this._breakpoints[url][line]).length === 0) {
|
|
|
|
delete this._breakpoints[url][line];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (this._wholeLineBreakpoints[url]) {
|
|
|
|
delete this._wholeLineBreakpoints[url][line];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a breakpoint from the breakpoint store. Will throw an error if the
|
2013-07-31 02:34:10 +00:00
|
|
|
* breakpoint is not found.
|
2013-07-25 00:46:49 +00:00
|
|
|
*
|
|
|
|
* @param Object aLocation
|
|
|
|
* The location of the breakpoint you are retrieving. It is an object
|
|
|
|
* with the following properties:
|
|
|
|
* - url
|
|
|
|
* - line
|
|
|
|
* - column (optional)
|
|
|
|
*/
|
2013-07-31 02:34:10 +00:00
|
|
|
getBreakpoint: function BS_getBreakpoint(aLocation) {
|
|
|
|
let { url, line, column } = aLocation;
|
|
|
|
dbg_assert(url != null);
|
|
|
|
dbg_assert(line != null);
|
|
|
|
|
|
|
|
var foundBreakpoint = this.hasBreakpoint(aLocation);
|
|
|
|
if (foundBreakpoint == null) {
|
|
|
|
throw new Error("No breakpoint at url = " + url
|
|
|
|
+ ", line = " + line
|
|
|
|
+ ", column = " + column);
|
|
|
|
}
|
|
|
|
|
|
|
|
return foundBreakpoint;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-08-16 21:59:04 +00:00
|
|
|
* Checks if the breakpoint store has a requested breakpoint.
|
2013-07-31 02:34:10 +00:00
|
|
|
*
|
|
|
|
* @param Object aLocation
|
|
|
|
* The location of the breakpoint you are retrieving. It is an object
|
|
|
|
* with the following properties:
|
|
|
|
* - url
|
|
|
|
* - line
|
|
|
|
* - column (optional)
|
2013-08-16 21:59:04 +00:00
|
|
|
* @returns The stored breakpoint if it exists, null otherwise.
|
2013-07-31 02:34:10 +00:00
|
|
|
*/
|
|
|
|
hasBreakpoint: function BS_hasBreakpoint(aLocation) {
|
2013-07-25 00:46:49 +00:00
|
|
|
let { url, line, column } = aLocation;
|
|
|
|
dbg_assert(url != null);
|
|
|
|
dbg_assert(line != null);
|
|
|
|
for (let bp of this.findBreakpoints(aLocation)) {
|
|
|
|
// We will get whole line breakpoints before individual columns, so just
|
|
|
|
// return the first one and if they didn't specify a column then they will
|
|
|
|
// get the whole line breakpoint, and otherwise we will find the correct
|
|
|
|
// one.
|
|
|
|
return bp;
|
|
|
|
}
|
2013-07-31 02:34:10 +00:00
|
|
|
|
2013-07-25 00:46:49 +00:00
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Iterate over the breakpoints in this breakpoint store. You can optionally
|
|
|
|
* provide search parameters to filter the set of breakpoints down to those
|
|
|
|
* that match your parameters.
|
|
|
|
*
|
|
|
|
* @param Object aSearchParams
|
|
|
|
* Optional. An object with the following properties:
|
|
|
|
* - url
|
|
|
|
* - line (optional; requires the url property)
|
|
|
|
* - column (optional; requires the line property)
|
|
|
|
*/
|
|
|
|
findBreakpoints: function BS_findBreakpoints(aSearchParams={}) {
|
|
|
|
if (aSearchParams.column != null) {
|
|
|
|
dbg_assert(aSearchParams.line != null);
|
|
|
|
}
|
|
|
|
if (aSearchParams.line != null) {
|
|
|
|
dbg_assert(aSearchParams.url != null);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let url of this._iterUrls(aSearchParams.url)) {
|
|
|
|
for (let line of this._iterLines(url, aSearchParams.line)) {
|
|
|
|
// Always yield whole line breakpoints first. See comment in
|
2013-08-16 21:59:04 +00:00
|
|
|
// |BreakpointStore.prototype.hasBreakpoint|.
|
2013-07-25 00:46:49 +00:00
|
|
|
if (aSearchParams.column == null
|
|
|
|
&& this._wholeLineBreakpoints[url]
|
|
|
|
&& this._wholeLineBreakpoints[url][line]) {
|
|
|
|
yield this._wholeLineBreakpoints[url][line];
|
|
|
|
}
|
|
|
|
for (let column of this._iterColumns(url, line, aSearchParams.column)) {
|
|
|
|
yield this._breakpoints[url][line][column];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_iterUrls: function BS__iterUrls(aUrl) {
|
|
|
|
if (aUrl) {
|
|
|
|
if (this._breakpoints[aUrl] || this._wholeLineBreakpoints[aUrl]) {
|
|
|
|
yield aUrl;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (let url of Object.keys(this._wholeLineBreakpoints)) {
|
|
|
|
yield url;
|
|
|
|
}
|
|
|
|
for (let url of Object.keys(this._breakpoints)) {
|
|
|
|
if (url in this._wholeLineBreakpoints) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
yield url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_iterLines: function BS__iterLines(aUrl, aLine) {
|
|
|
|
if (aLine != null) {
|
|
|
|
if ((this._wholeLineBreakpoints[aUrl]
|
|
|
|
&& this._wholeLineBreakpoints[aUrl][aLine])
|
|
|
|
|| (this._breakpoints[aUrl] && this._breakpoints[aUrl][aLine])) {
|
|
|
|
yield aLine;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const wholeLines = this._wholeLineBreakpoints[aUrl]
|
|
|
|
? Object.keys(this._wholeLineBreakpoints[aUrl])
|
|
|
|
: [];
|
|
|
|
const columnLines = this._breakpoints[aUrl]
|
|
|
|
? Object.keys(this._breakpoints[aUrl])
|
|
|
|
: [];
|
|
|
|
|
|
|
|
const lines = wholeLines.concat(columnLines).sort();
|
|
|
|
|
|
|
|
let lastLine;
|
|
|
|
for (let line of lines) {
|
|
|
|
if (line === lastLine) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
yield line;
|
|
|
|
lastLine = line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_iterColumns: function BS__iterColumns(aUrl, aLine, aColumn) {
|
|
|
|
if (!this._breakpoints[aUrl] || !this._breakpoints[aUrl][aLine]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aColumn != null) {
|
|
|
|
if (this._breakpoints[aUrl][aLine][aColumn]) {
|
|
|
|
yield aColumn;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (let column in this._breakpoints[aUrl][aLine]) {
|
|
|
|
yield column;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2013-08-16 21:59:04 +00:00
|
|
|
/**
|
|
|
|
* Manages pushing event loops and automatically pops and exits them in the
|
|
|
|
* correct order as they are resolved.
|
|
|
|
*
|
|
|
|
* @param nsIJSInspector inspector
|
|
|
|
* The underlying JS inspector we use to enter and exit nested event
|
|
|
|
* loops.
|
|
|
|
* @param Object hooks
|
|
|
|
* An object with the following properties:
|
|
|
|
* - url: The URL string of the debuggee we are spinning an event loop
|
|
|
|
* for.
|
|
|
|
* - preNest: function called before entering a nested event loop
|
|
|
|
* - postNest: function called after exiting a nested event loop
|
|
|
|
* @param ThreadActor thread
|
|
|
|
* The thread actor instance that owns this EventLoopStack.
|
|
|
|
*/
|
|
|
|
function EventLoopStack({ inspector, thread, hooks }) {
|
|
|
|
this._inspector = inspector;
|
|
|
|
this._hooks = hooks;
|
|
|
|
this._thread = thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
EventLoopStack.prototype = {
|
|
|
|
/**
|
|
|
|
* The number of nested event loops on the stack.
|
|
|
|
*/
|
|
|
|
get size() {
|
|
|
|
return this._inspector.eventLoopNestLevel;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The URL of the debuggee who pushed the event loop on top of the stack.
|
|
|
|
*/
|
|
|
|
get lastPausedUrl() {
|
|
|
|
return this.size > 0
|
|
|
|
? this._inspector.lastNestRequestor.url
|
|
|
|
: null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Push a new nested event loop onto the stack.
|
|
|
|
*
|
|
|
|
* @returns EventLoop
|
|
|
|
*/
|
|
|
|
push: function () {
|
|
|
|
return new EventLoop({
|
|
|
|
inspector: this._inspector,
|
|
|
|
thread: this._thread,
|
|
|
|
hooks: this._hooks
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An object that represents a nested event loop. It is used as the nest
|
|
|
|
* requestor with nsIJSInspector instances.
|
|
|
|
*
|
|
|
|
* @param nsIJSInspector inspector
|
|
|
|
* The JS Inspector that runs nested event loops.
|
|
|
|
* @param ThreadActor thread
|
|
|
|
* The thread actor that is creating this nested event loop.
|
|
|
|
* @param Object hooks
|
|
|
|
* The same hooks object passed into EventLoopStack during its
|
|
|
|
* initialization.
|
|
|
|
*/
|
|
|
|
function EventLoop({ inspector, thread, hooks }) {
|
|
|
|
this._inspector = inspector;
|
|
|
|
this._thread = thread;
|
|
|
|
this._hooks = hooks;
|
|
|
|
|
|
|
|
this.enter = this.enter.bind(this);
|
|
|
|
this.resolve = this.resolve.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
EventLoop.prototype = {
|
|
|
|
entered: false,
|
|
|
|
resolved: false,
|
|
|
|
get url() { return this._hooks.url; },
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enter this nested event loop.
|
|
|
|
*/
|
|
|
|
enter: function () {
|
|
|
|
let nestData = this._hooks.preNest
|
|
|
|
? this._hooks.preNest()
|
|
|
|
: null;
|
|
|
|
|
|
|
|
this.entered = true;
|
|
|
|
this._inspector.enterNestedEventLoop(this);
|
|
|
|
|
|
|
|
// Keep exiting nested event loops while the last requestor is resolved.
|
|
|
|
if (this._inspector.eventLoopNestLevel > 0) {
|
|
|
|
const { resolved } = this._inspector.lastNestRequestor;
|
|
|
|
if (resolved) {
|
|
|
|
this._inspector.exitNestedEventLoop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dbg_assert(this._thread.state === "running",
|
|
|
|
"Should be in the running state");
|
|
|
|
|
|
|
|
if (this._hooks.postNest) {
|
|
|
|
this._hooks.postNest(nestData);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolve this nested event loop.
|
|
|
|
*
|
|
|
|
* @returns boolean
|
|
|
|
* True if we exited this nested event loop because it was on top of
|
|
|
|
* the stack, false if there is another nested event loop above this
|
|
|
|
* one that hasn't resolved yet.
|
|
|
|
*/
|
|
|
|
resolve: function () {
|
|
|
|
if (!this.entered) {
|
|
|
|
throw new Error("Can't resolve an event loop before it has been entered!");
|
|
|
|
}
|
|
|
|
if (this.resolved) {
|
|
|
|
throw new Error("Already resolved this nested event loop!");
|
|
|
|
}
|
|
|
|
this.resolved = true;
|
|
|
|
if (this === this._inspector.lastNestRequestor) {
|
|
|
|
this._inspector.exitNestedEventLoop();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2012-02-07 17:22:30 +00:00
|
|
|
/**
|
|
|
|
* JSD2 actors.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* Creates a ThreadActor.
|
|
|
|
*
|
|
|
|
* ThreadActors manage a JSInspector object and manage execution/inspection
|
|
|
|
* of debuggees.
|
2012-01-23 08:29:15 +00:00
|
|
|
*
|
|
|
|
* @param aHooks object
|
2012-02-10 07:46:11 +00:00
|
|
|
* An object with preNest and postNest methods for calling when entering
|
2012-10-31 16:31:55 +00:00
|
|
|
* and exiting a nested event loop, addToParentPool and
|
|
|
|
* removeFromParentPool methods for handling the lifetime of actors that
|
2012-11-06 07:14:07 +00:00
|
|
|
* will outlive the thread, like breakpoints.
|
|
|
|
* @param aGlobal object [optional]
|
|
|
|
* An optional (for content debugging only) reference to the content
|
|
|
|
* window.
|
2012-02-07 17:22:30 +00:00
|
|
|
*/
|
2012-11-06 07:14:07 +00:00
|
|
|
function ThreadActor(aHooks, aGlobal)
|
2012-02-07 17:22:30 +00:00
|
|
|
{
|
|
|
|
this._state = "detached";
|
|
|
|
this._frameActors = [];
|
|
|
|
this._environmentActors = [];
|
2012-11-06 07:14:07 +00:00
|
|
|
this._hooks = aHooks;
|
|
|
|
this.global = aGlobal;
|
2013-08-16 21:59:04 +00:00
|
|
|
this._nestedEventLoops = new EventLoopStack({
|
|
|
|
inspector: DebuggerServer.xpcInspector,
|
|
|
|
hooks: aHooks,
|
|
|
|
thread: this
|
|
|
|
});
|
2013-07-18 11:14:16 +00:00
|
|
|
// A map of actorID -> actor for breakpoints created and managed by the server.
|
|
|
|
this._hiddenBreakpoints = new Map();
|
2012-11-01 15:34:10 +00:00
|
|
|
|
2012-10-31 16:31:55 +00:00
|
|
|
this.findGlobals = this.globalManager.findGlobals.bind(this);
|
|
|
|
this.onNewGlobal = this.globalManager.onNewGlobal.bind(this);
|
2013-04-15 21:07:00 +00:00
|
|
|
this.onNewSource = this.onNewSource.bind(this);
|
2013-07-18 11:14:16 +00:00
|
|
|
this._allEventsListener = this._allEventsListener.bind(this);
|
2013-04-15 21:07:00 +00:00
|
|
|
|
|
|
|
this._options = {
|
|
|
|
useSourceMaps: false
|
|
|
|
};
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
|
|
|
|
2012-08-06 09:32:00 +00:00
|
|
|
/**
|
|
|
|
* The breakpoint store must be shared across instances of ThreadActor so that
|
|
|
|
* page reloads don't blow away all of our breakpoints.
|
|
|
|
*/
|
2013-07-25 00:46:49 +00:00
|
|
|
ThreadActor.breakpointStore = new BreakpointStore();
|
2012-08-06 09:32:00 +00:00
|
|
|
|
2012-02-07 17:22:30 +00:00
|
|
|
ThreadActor.prototype = {
|
|
|
|
actorPrefix: "context",
|
|
|
|
|
|
|
|
get state() { return this._state; },
|
2012-10-31 16:31:55 +00:00
|
|
|
get attached() this.state == "attached" ||
|
|
|
|
this.state == "running" ||
|
|
|
|
this.state == "paused",
|
2012-02-07 17:22:30 +00:00
|
|
|
|
2013-07-25 00:46:49 +00:00
|
|
|
get breakpointStore() { return ThreadActor.breakpointStore; },
|
2012-08-06 09:32:00 +00:00
|
|
|
|
2012-02-07 17:22:30 +00:00
|
|
|
get threadLifetimePool() {
|
|
|
|
if (!this._threadLifetimePool) {
|
|
|
|
this._threadLifetimePool = new ActorPool(this.conn);
|
|
|
|
this.conn.addActorPool(this._threadLifetimePool);
|
2012-11-14 08:00:57 +00:00
|
|
|
this._threadLifetimePool.objectActors = new WeakMap();
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
|
|
|
return this._threadLifetimePool;
|
|
|
|
},
|
|
|
|
|
2013-04-15 21:07:00 +00:00
|
|
|
get sources() {
|
|
|
|
if (!this._sources) {
|
|
|
|
this._sources = new ThreadSources(this, this._options.useSourceMaps,
|
|
|
|
this._allowSource, this.onNewSource);
|
|
|
|
}
|
|
|
|
return this._sources;
|
|
|
|
},
|
|
|
|
|
2013-08-16 21:59:04 +00:00
|
|
|
/**
|
|
|
|
* Keep track of all of the nested event loops we use to pause the debuggee
|
|
|
|
* when we hit a breakpoint/debugger statement/etc in one place so we can
|
|
|
|
* resolve them when we get resume packets. We have more than one (and keep
|
|
|
|
* them in a stack) because we can pause within client evals.
|
|
|
|
*/
|
|
|
|
_threadPauseEventLoops: null,
|
|
|
|
_pushThreadPause: function TA__pushThreadPause() {
|
|
|
|
if (!this._threadPauseEventLoops) {
|
|
|
|
this._threadPauseEventLoops = [];
|
|
|
|
}
|
|
|
|
const eventLoop = this._nestedEventLoops.push();
|
|
|
|
this._threadPauseEventLoops.push(eventLoop);
|
|
|
|
eventLoop.enter();
|
|
|
|
},
|
|
|
|
_popThreadPause: function TA__popThreadPause() {
|
|
|
|
const eventLoop = this._threadPauseEventLoops.pop();
|
|
|
|
dbg_assert(eventLoop, "Should have an event loop.");
|
|
|
|
eventLoop.resolve();
|
|
|
|
},
|
|
|
|
|
2012-08-24 07:41:02 +00:00
|
|
|
clearDebuggees: function TA_clearDebuggees() {
|
2012-09-20 21:15:15 +00:00
|
|
|
if (this.dbg) {
|
2012-11-02 16:30:23 +00:00
|
|
|
this.dbg.removeAllDebuggees();
|
2012-08-24 07:41:02 +00:00
|
|
|
}
|
|
|
|
this.conn.removeActorPool(this._threadLifetimePool || undefined);
|
|
|
|
this._threadLifetimePool = null;
|
2013-04-15 21:07:00 +00:00
|
|
|
this._sources = null;
|
2012-08-24 07:41:02 +00:00
|
|
|
},
|
|
|
|
|
2012-02-07 17:22:30 +00:00
|
|
|
/**
|
2012-04-22 09:59:09 +00:00
|
|
|
* Add a debuggee global to the Debugger object.
|
2013-07-18 11:14:16 +00:00
|
|
|
*
|
|
|
|
* @returns the Debugger.Object that corresponds to the global.
|
2012-02-07 17:22:30 +00:00
|
|
|
*/
|
|
|
|
addDebuggee: function TA_addDebuggee(aGlobal) {
|
2013-07-18 11:14:16 +00:00
|
|
|
let globalDebugObject;
|
2012-10-31 16:31:55 +00:00
|
|
|
try {
|
2013-08-14 16:58:41 +00:00
|
|
|
globalDebugObject = this.dbg.addDebuggee(aGlobal);
|
2012-10-31 16:31:55 +00:00
|
|
|
} catch (e) {
|
|
|
|
// Ignore attempts to add the debugger's compartment as a debuggee.
|
|
|
|
dumpn("Ignoring request to add the debugger's compartment as a debuggee");
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
2013-07-18 11:14:16 +00:00
|
|
|
return globalDebugObject;
|
2012-10-31 16:31:55 +00:00
|
|
|
},
|
2012-02-07 17:22:30 +00:00
|
|
|
|
2012-10-31 16:31:55 +00:00
|
|
|
/**
|
|
|
|
* Initialize the Debugger.
|
|
|
|
*/
|
|
|
|
_initDebugger: function TA__initDebugger() {
|
|
|
|
this.dbg = new Debugger();
|
|
|
|
this.dbg.uncaughtExceptionHook = this.uncaughtExceptionHook.bind(this);
|
|
|
|
this.dbg.onDebuggerStatement = this.onDebuggerStatement.bind(this);
|
|
|
|
this.dbg.onNewScript = this.onNewScript.bind(this);
|
|
|
|
this.dbg.onNewGlobalObject = this.globalManager.onNewGlobal.bind(this);
|
|
|
|
// Keep the debugger disabled until a client attaches.
|
|
|
|
this.dbg.enabled = this._state != "detached";
|
2012-02-07 17:22:30 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a debuggee global from the JSInspector.
|
|
|
|
*/
|
|
|
|
removeDebugee: function TA_removeDebuggee(aGlobal) {
|
|
|
|
try {
|
|
|
|
this.dbg.removeDebuggee(aGlobal);
|
|
|
|
} catch(ex) {
|
|
|
|
// XXX: This debuggee has code currently executing on the stack,
|
|
|
|
// we need to save this for later.
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-10-31 16:31:55 +00:00
|
|
|
/**
|
|
|
|
* Add the provided window and all windows in its frame tree as debuggees.
|
2013-07-18 11:14:16 +00:00
|
|
|
*
|
|
|
|
* @returns the Debugger.Object that corresponds to the window.
|
2012-10-31 16:31:55 +00:00
|
|
|
*/
|
|
|
|
_addDebuggees: function TA__addDebuggees(aWindow) {
|
2013-07-18 11:14:16 +00:00
|
|
|
let globalDebugObject = this.addDebuggee(aWindow);
|
2012-10-31 16:31:55 +00:00
|
|
|
let frames = aWindow.frames;
|
|
|
|
if (frames) {
|
|
|
|
for (let i = 0; i < frames.length; i++) {
|
|
|
|
this._addDebuggees(frames[i]);
|
|
|
|
}
|
|
|
|
}
|
2013-07-18 11:14:16 +00:00
|
|
|
return globalDebugObject;
|
2012-10-31 16:31:55 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An object that will be used by ThreadActors to tailor their behavior
|
|
|
|
* depending on the debugging context being required (chrome or content).
|
|
|
|
*/
|
|
|
|
globalManager: {
|
|
|
|
findGlobals: function TA_findGlobals() {
|
2013-07-18 11:14:16 +00:00
|
|
|
this.globalDebugObject = this._addDebuggees(this.global);
|
2012-10-31 16:31:55 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A function that the engine calls when a new global object has been
|
|
|
|
* created.
|
|
|
|
*
|
|
|
|
* @param aGlobal Debugger.Object
|
|
|
|
* The new global object that was created.
|
|
|
|
*/
|
|
|
|
onNewGlobal: function TA_onNewGlobal(aGlobal) {
|
|
|
|
// Content debugging only cares about new globals in the contant window,
|
|
|
|
// like iframe children.
|
|
|
|
if (aGlobal.hostAnnotations &&
|
|
|
|
aGlobal.hostAnnotations.type == "document" &&
|
|
|
|
aGlobal.hostAnnotations.element === this.global) {
|
|
|
|
this.addDebuggee(aGlobal);
|
2013-04-09 11:17:03 +00:00
|
|
|
// Notify the client.
|
|
|
|
this.conn.send({
|
|
|
|
from: this.actorID,
|
|
|
|
type: "newGlobal",
|
|
|
|
// TODO: after bug 801084 lands see if we need to JSONify this.
|
|
|
|
hostAnnotations: aGlobal.hostAnnotations
|
|
|
|
});
|
2012-10-31 16:31:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-02-07 17:22:30 +00:00
|
|
|
disconnect: function TA_disconnect() {
|
2013-04-30 22:00:29 +00:00
|
|
|
dumpn("in ThreadActor.prototype.disconnect");
|
2012-02-17 08:15:43 +00:00
|
|
|
if (this._state == "paused") {
|
|
|
|
this.onResume();
|
|
|
|
}
|
|
|
|
|
2012-02-07 17:22:30 +00:00
|
|
|
this._state = "exited";
|
2012-08-24 07:41:02 +00:00
|
|
|
|
|
|
|
this.clearDebuggees();
|
|
|
|
|
2012-09-20 21:15:15 +00:00
|
|
|
if (!this.dbg) {
|
2012-08-24 07:41:02 +00:00
|
|
|
return;
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
2012-09-20 21:15:15 +00:00
|
|
|
this.dbg.enabled = false;
|
|
|
|
this.dbg = null;
|
2012-02-07 17:22:30 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disconnect the debugger and put the actor in the exited state.
|
|
|
|
*/
|
|
|
|
exit: function TA_exit() {
|
|
|
|
this.disconnect();
|
|
|
|
},
|
|
|
|
|
|
|
|
// Request handlers
|
|
|
|
onAttach: function TA_onAttach(aRequest) {
|
|
|
|
if (this.state === "exited") {
|
|
|
|
return { type: "exited" };
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.state !== "detached") {
|
|
|
|
return { error: "wrongState" };
|
|
|
|
}
|
|
|
|
|
|
|
|
this._state = "attached";
|
|
|
|
|
2013-04-15 21:07:00 +00:00
|
|
|
update(this._options, aRequest.options || {});
|
|
|
|
|
2012-10-31 16:31:55 +00:00
|
|
|
if (!this.dbg) {
|
|
|
|
this._initDebugger();
|
|
|
|
}
|
|
|
|
this.findGlobals();
|
2012-02-07 17:22:30 +00:00
|
|
|
this.dbg.enabled = true;
|
|
|
|
try {
|
|
|
|
// Put ourselves in the paused state.
|
|
|
|
let packet = this._paused();
|
|
|
|
if (!packet) {
|
|
|
|
return { error: "notAttached" };
|
|
|
|
}
|
|
|
|
packet.why = { type: "attached" };
|
|
|
|
|
2013-06-20 17:43:30 +00:00
|
|
|
this._restoreBreakpoints();
|
|
|
|
|
2012-02-07 17:22:30 +00:00
|
|
|
// Send the response to the attach request now (rather than
|
|
|
|
// returning it), because we're going to start a nested event loop
|
|
|
|
// here.
|
|
|
|
this.conn.send(packet);
|
|
|
|
|
|
|
|
// Start a nested event loop.
|
2013-08-16 21:59:04 +00:00
|
|
|
this._pushThreadPause();
|
2013-04-10 13:08:59 +00:00
|
|
|
|
2012-02-07 17:22:30 +00:00
|
|
|
// We already sent a response to this request, don't send one
|
|
|
|
// now.
|
|
|
|
return null;
|
2013-04-15 21:07:00 +00:00
|
|
|
} catch (e) {
|
|
|
|
reportError(e);
|
2012-02-07 17:22:30 +00:00
|
|
|
return { error: "notAttached", message: e.toString() };
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onDetach: function TA_onDetach(aRequest) {
|
|
|
|
this.disconnect();
|
2013-04-30 22:00:29 +00:00
|
|
|
dumpn("ThreadActor.prototype.onDetach: returning 'detached' packet");
|
2013-04-15 21:07:00 +00:00
|
|
|
return {
|
|
|
|
type: "detached"
|
|
|
|
};
|
2012-02-07 17:22:30 +00:00
|
|
|
},
|
|
|
|
|
2013-04-16 15:00:33 +00:00
|
|
|
onReconfigure: function TA_onReconfigure(aRequest) {
|
|
|
|
if (this.state == "exited") {
|
|
|
|
return { error: "wrongState" };
|
|
|
|
}
|
|
|
|
|
|
|
|
update(this._options, aRequest.options || {});
|
|
|
|
// Clear existing sources, so they can be recreated on next access.
|
|
|
|
this._sources = null;
|
|
|
|
|
|
|
|
return {};
|
|
|
|
},
|
|
|
|
|
2012-03-18 06:50:43 +00:00
|
|
|
/**
|
|
|
|
* Pause the debuggee, by entering a nested event loop, and return a 'paused'
|
|
|
|
* packet to the client.
|
|
|
|
*
|
|
|
|
* @param Debugger.Frame aFrame
|
|
|
|
* The newest debuggee frame in the stack.
|
|
|
|
* @param object aReason
|
|
|
|
* An object with a 'type' property containing the reason for the pause.
|
2013-04-15 21:07:00 +00:00
|
|
|
* @param function onPacket
|
|
|
|
* Hook to modify the packet before it is sent. Feel free to return a
|
|
|
|
* promise.
|
2012-03-18 06:50:43 +00:00
|
|
|
*/
|
2013-04-15 21:07:00 +00:00
|
|
|
_pauseAndRespond: function TA__pauseAndRespond(aFrame, aReason,
|
2013-08-16 21:59:04 +00:00
|
|
|
onPacket=function (k) { return k; }) {
|
2012-03-18 06:50:43 +00:00
|
|
|
try {
|
|
|
|
let packet = this._paused(aFrame);
|
|
|
|
if (!packet) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
packet.why = aReason;
|
2013-07-25 00:46:49 +00:00
|
|
|
|
2013-08-24 05:41:28 +00:00
|
|
|
this.sources.getOriginalLocation(packet.frame.where).then(aOrigPosition => {
|
2013-07-25 00:46:49 +00:00
|
|
|
packet.frame.where = aOrigPosition;
|
|
|
|
resolve(onPacket(packet))
|
|
|
|
.then(null, error => {
|
|
|
|
reportError(error);
|
|
|
|
return {
|
|
|
|
error: "unknownError",
|
|
|
|
message: error.message + "\n" + error.stack
|
|
|
|
};
|
|
|
|
})
|
2013-08-16 21:59:04 +00:00
|
|
|
.then(packet => {
|
2013-08-23 22:04:03 +00:00
|
|
|
this.conn.send(packet);
|
2013-08-16 21:59:04 +00:00
|
|
|
});
|
2013-07-25 00:46:49 +00:00
|
|
|
});
|
|
|
|
|
2013-08-16 21:59:04 +00:00
|
|
|
this._pushThreadPause();
|
2012-03-18 06:50:43 +00:00
|
|
|
} catch(e) {
|
2013-07-03 21:10:52 +00:00
|
|
|
reportError(e, "Got an exception during TA__pauseAndRespond: ");
|
2012-03-18 06:50:43 +00:00
|
|
|
}
|
2013-08-16 21:59:04 +00:00
|
|
|
|
|
|
|
return undefined;
|
2012-03-18 06:50:43 +00:00
|
|
|
},
|
|
|
|
|
2013-09-09 21:55:19 +00:00
|
|
|
/**
|
|
|
|
* Handle resume requests that include a forceCompletion request.
|
|
|
|
*
|
|
|
|
* @param Object aRequest
|
|
|
|
* The request packet received over the RDP.
|
|
|
|
* @returns A response packet.
|
|
|
|
*/
|
|
|
|
_forceCompletion: function TA__forceCompletion(aRequest) {
|
|
|
|
// TODO: remove this when Debugger.Frame.prototype.pop is implemented in
|
|
|
|
// bug 736733.
|
|
|
|
return {
|
|
|
|
error: "notImplemented",
|
|
|
|
message: "forced completion is not yet implemented."
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
_makeOnEnterFrame: function TA__makeOnEnterFrame({ pauseAndRespond }) {
|
|
|
|
return aFrame => {
|
|
|
|
const generatedLocation = getFrameLocation(aFrame);
|
|
|
|
let { url } = this.synchronize(this.sources.getOriginalLocation(
|
|
|
|
generatedLocation));
|
|
|
|
|
|
|
|
return this.sources.isBlackBoxed(url)
|
|
|
|
? undefined
|
|
|
|
: pauseAndRespond(aFrame);
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
_makeOnPop: function TA__makeOnPop({ thread, pauseAndRespond, createValueGrip }) {
|
|
|
|
return function (aCompletion) {
|
|
|
|
// onPop is called with 'this' set to the current frame.
|
|
|
|
|
|
|
|
const generatedLocation = getFrameLocation(this);
|
|
|
|
const { url } = thread.synchronize(thread.sources.getOriginalLocation(
|
|
|
|
generatedLocation));
|
|
|
|
|
|
|
|
if (thread.sources.isBlackBoxed(url)) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note that we're popping this frame; we need to watch for
|
|
|
|
// subsequent step events on its caller.
|
|
|
|
this.reportedPop = true;
|
|
|
|
|
|
|
|
return pauseAndRespond(this, aPacket => {
|
|
|
|
aPacket.why.frameFinished = {};
|
|
|
|
if (!aCompletion) {
|
|
|
|
aPacket.why.frameFinished.terminated = true;
|
|
|
|
} else if (aCompletion.hasOwnProperty("return")) {
|
|
|
|
aPacket.why.frameFinished.return = createValueGrip(aCompletion.return);
|
|
|
|
} else if (aCompletion.hasOwnProperty("yield")) {
|
|
|
|
aPacket.why.frameFinished.return = createValueGrip(aCompletion.yield);
|
|
|
|
} else {
|
|
|
|
aPacket.why.frameFinished.throw = createValueGrip(aCompletion.throw);
|
|
|
|
}
|
|
|
|
return aPacket;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
_makeOnStep: function TA__makeOnStep({ thread, pauseAndRespond, startFrame,
|
|
|
|
startLocation }) {
|
|
|
|
return function () {
|
|
|
|
// onStep is called with 'this' set to the current frame.
|
|
|
|
|
|
|
|
const generatedLocation = getFrameLocation(this);
|
|
|
|
const newLocation = thread.synchronize(thread.sources.getOriginalLocation(
|
|
|
|
generatedLocation));
|
|
|
|
|
|
|
|
// Cases when we should pause because we have executed enough to consider
|
|
|
|
// a "step" to have occured:
|
|
|
|
//
|
|
|
|
// 1.1. We change frames.
|
|
|
|
// 1.2. We change URLs (can happen without changing frames thanks to
|
|
|
|
// source mapping).
|
|
|
|
// 1.3. We change lines.
|
|
|
|
//
|
|
|
|
// Cases when we should always continue execution, even if one of the
|
|
|
|
// above cases is true:
|
|
|
|
//
|
|
|
|
// 2.1. We are in a source mapped region, but inside a null mapping
|
|
|
|
// (doesn't correlate to any region of original source)
|
|
|
|
// 2.2. The source we are in is black boxed.
|
|
|
|
|
|
|
|
// Cases 2.1 and 2.2
|
|
|
|
if (newLocation.url == null
|
|
|
|
|| thread.sources.isBlackBoxed(newLocation.url)) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cases 1.1, 1.2 and 1.3
|
|
|
|
if (this !== startFrame
|
|
|
|
|| startLocation.url !== newLocation.url
|
|
|
|
|| startLocation.line !== newLocation.line) {
|
|
|
|
return pauseAndRespond(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, let execution continue (we haven't executed enough code to
|
|
|
|
// consider this a "step" yet).
|
|
|
|
return undefined;
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Define the JS hook functions for stepping.
|
|
|
|
*/
|
|
|
|
_makeSteppingHooks: function TA__makeSteppingHooks(aStartLocation) {
|
|
|
|
// Bind these methods and state because some of the hooks are called
|
|
|
|
// with 'this' set to the current frame. Rather than repeating the
|
|
|
|
// binding in each _makeOnX method, just do it once here and pass it
|
|
|
|
// in to each function.
|
|
|
|
const steppingHookState = {
|
|
|
|
pauseAndRespond: (aFrame, onPacket=(k)=>k) => {
|
|
|
|
this._pauseAndRespond(aFrame, { type: "resumeLimit" }, onPacket);
|
|
|
|
},
|
|
|
|
createValueGrip: this.createValueGrip.bind(this),
|
|
|
|
thread: this,
|
|
|
|
startFrame: this.youngestFrame,
|
|
|
|
startLocation: aStartLocation
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
onEnterFrame: this._makeOnEnterFrame(steppingHookState),
|
|
|
|
onPop: this._makeOnPop(steppingHookState),
|
|
|
|
onStep: this._makeOnStep(steppingHookState)
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle attaching the various stepping hooks we need to attach when we
|
|
|
|
* receive a resume request with a resumeLimit property.
|
|
|
|
*
|
|
|
|
* @param Object aRequest
|
|
|
|
* The request packet received over the RDP.
|
|
|
|
* @returns A promise that resolves to true once the hooks are attached, or is
|
|
|
|
* rejected with an error packet.
|
|
|
|
*/
|
|
|
|
_handleResumeLimit: function TA__handleResumeLimit(aRequest) {
|
|
|
|
let steppingType = aRequest.resumeLimit.type;
|
|
|
|
if (["step", "next", "finish"].indexOf(steppingType) == -1) {
|
|
|
|
return reject({ error: "badParameterType",
|
|
|
|
message: "Unknown resumeLimit type" });
|
|
|
|
}
|
|
|
|
|
|
|
|
const generatedLocation = getFrameLocation(this.youngestFrame);
|
|
|
|
return this.sources.getOriginalLocation(generatedLocation)
|
|
|
|
.then(originalLocation => {
|
|
|
|
const { onEnterFrame, onPop, onStep } = this._makeSteppingHooks(originalLocation);
|
|
|
|
|
|
|
|
// Make sure there is still a frame on the stack if we are to continue
|
|
|
|
// stepping.
|
|
|
|
let stepFrame = this._getNextStepFrame(this.youngestFrame);
|
|
|
|
if (stepFrame) {
|
|
|
|
switch (steppingType) {
|
|
|
|
case "step":
|
|
|
|
this.dbg.onEnterFrame = onEnterFrame;
|
|
|
|
// Fall through.
|
|
|
|
case "next":
|
|
|
|
stepFrame.onStep = onStep;
|
|
|
|
stepFrame.onPop = onPop;
|
|
|
|
break;
|
|
|
|
case "finish":
|
|
|
|
stepFrame.onPop = onPop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear the onStep and onPop hooks from the given frame and all of the frames
|
|
|
|
* below it.
|
|
|
|
*
|
|
|
|
* @param Debugger.Frame aFrame
|
|
|
|
* The frame we want to clear the stepping hooks from.
|
|
|
|
*/
|
|
|
|
_clearSteppingHooks: function TA__clearSteppingHooks(aFrame) {
|
|
|
|
while (aFrame) {
|
|
|
|
aFrame.onStep = undefined;
|
|
|
|
aFrame.onPop = undefined;
|
|
|
|
aFrame = aFrame.older;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Listen to the debuggee's DOM events if we received a request to do so.
|
|
|
|
*
|
|
|
|
* @param Object aRequest
|
|
|
|
* The resume request packet received over the RDP.
|
|
|
|
*/
|
|
|
|
_maybeListenToEvents: function TA__maybeListenToEvents(aRequest) {
|
|
|
|
// Break-on-DOMEvents is only supported in content debugging.
|
|
|
|
let events = aRequest.pauseOnDOMEvents;
|
|
|
|
if (this.global && events &&
|
|
|
|
(events == "*" ||
|
|
|
|
(Array.isArray(events) && events.length))) {
|
|
|
|
this._pauseOnDOMEvents = events;
|
|
|
|
let els = Cc["@mozilla.org/eventlistenerservice;1"]
|
|
|
|
.getService(Ci.nsIEventListenerService);
|
|
|
|
els.addListenerForAllEvents(this.global, this._allEventsListener, true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-03-18 06:50:43 +00:00
|
|
|
/**
|
|
|
|
* Handle a protocol request to resume execution of the debuggee.
|
|
|
|
*/
|
2012-02-07 17:22:30 +00:00
|
|
|
onResume: function TA_onResume(aRequest) {
|
2013-04-15 21:07:00 +00:00
|
|
|
if (this._state !== "paused") {
|
|
|
|
return {
|
|
|
|
error: "wrongState",
|
|
|
|
message: "Can't resume when debuggee isn't paused. Current state is '"
|
|
|
|
+ this._state + "'"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-04-09 11:17:03 +00:00
|
|
|
// In case of multiple nested event loops (due to multiple debuggers open in
|
|
|
|
// different tabs or multiple debugger clients connected to the same tab)
|
|
|
|
// only allow resumption in a LIFO order.
|
2013-08-16 21:59:04 +00:00
|
|
|
if (this._nestedEventLoops.size
|
|
|
|
&& this._nestedEventLoops.lastPausedUrl !== this._hooks.url) {
|
|
|
|
return {
|
|
|
|
error: "wrongOrder",
|
|
|
|
message: "trying to resume in the wrong order.",
|
|
|
|
lastPausedUrl: this._nestedEventLoops.lastPausedUrl
|
|
|
|
};
|
2013-04-09 11:17:03 +00:00
|
|
|
}
|
|
|
|
|
2012-03-18 06:50:43 +00:00
|
|
|
if (aRequest && aRequest.forceCompletion) {
|
2013-09-09 21:55:19 +00:00
|
|
|
return this._forceCompletion(aRequest);
|
2012-03-18 06:50:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-05 23:32:27 +00:00
|
|
|
let resumeLimitHandled;
|
2012-03-18 06:50:43 +00:00
|
|
|
if (aRequest && aRequest.resumeLimit) {
|
2013-09-09 21:55:19 +00:00
|
|
|
resumeLimitHandled = this._handleResumeLimit(aRequest)
|
2013-07-18 09:45:17 +00:00
|
|
|
} else {
|
2013-09-09 21:55:19 +00:00
|
|
|
this._clearSteppingHooks(this.youngestFrame);
|
2013-09-05 23:32:27 +00:00
|
|
|
resumeLimitHandled = resolve(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return resumeLimitHandled.then(() => {
|
|
|
|
if (aRequest) {
|
|
|
|
this._options.pauseOnExceptions = aRequest.pauseOnExceptions;
|
|
|
|
this._options.ignoreCaughtExceptions = aRequest.ignoreCaughtExceptions;
|
|
|
|
this.maybePauseOnExceptions();
|
2013-09-09 21:55:19 +00:00
|
|
|
this._maybeListenToEvents(aRequest);
|
2013-07-18 11:14:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-05 23:32:27 +00:00
|
|
|
let packet = this._resumed();
|
|
|
|
this._popThreadPause();
|
|
|
|
return packet;
|
|
|
|
}, error => {
|
|
|
|
return error instanceof Error
|
|
|
|
? { error: "unknownError",
|
|
|
|
message: safeErrorString(error) }
|
|
|
|
// It is a known error, and the promise was rejected with an error
|
|
|
|
// packet.
|
|
|
|
: error;
|
|
|
|
});
|
2012-02-07 17:22:30 +00:00
|
|
|
},
|
|
|
|
|
2013-08-16 21:59:04 +00:00
|
|
|
/**
|
|
|
|
* Spin up a nested event loop so we can synchronously resolve a promise.
|
|
|
|
*
|
|
|
|
* @param aPromise
|
|
|
|
* The promise we want to resolve.
|
|
|
|
* @returns The promise's resolution.
|
|
|
|
*/
|
|
|
|
synchronize: function(aPromise) {
|
|
|
|
let needNest = true;
|
|
|
|
let eventLoop;
|
|
|
|
let returnVal;
|
|
|
|
|
|
|
|
aPromise
|
|
|
|
.then((aResolvedVal) => {
|
|
|
|
needNest = false;
|
|
|
|
returnVal = aResolvedVal;
|
|
|
|
})
|
|
|
|
.then(null, (aError) => {
|
|
|
|
reportError(aError, "Error inside synchronize:");
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
if (eventLoop) {
|
|
|
|
eventLoop.resolve();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (needNest) {
|
|
|
|
eventLoop = this._nestedEventLoops.push();
|
|
|
|
eventLoop.enter();
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnVal;
|
|
|
|
},
|
|
|
|
|
2013-07-09 07:57:13 +00:00
|
|
|
/**
|
|
|
|
* Set the debugging hook to pause on exceptions if configured to do so.
|
|
|
|
*/
|
|
|
|
maybePauseOnExceptions: function() {
|
|
|
|
if (this._options.pauseOnExceptions) {
|
|
|
|
this.dbg.onExceptionUnwind = this.onExceptionUnwind.bind(this);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-07-18 11:14:16 +00:00
|
|
|
/**
|
|
|
|
* A listener that gets called for every event fired on the page, when a list
|
|
|
|
* of interesting events was provided with the pauseOnDOMEvents property. It
|
|
|
|
* is used to set server-managed breakpoints on any existing event listeners
|
|
|
|
* for those events.
|
|
|
|
*
|
|
|
|
* @param Event event
|
|
|
|
* The event that was fired.
|
|
|
|
*/
|
|
|
|
_allEventsListener: function(event) {
|
|
|
|
if (this._pauseOnDOMEvents == "*" ||
|
|
|
|
this._pauseOnDOMEvents.indexOf(event.type) != -1) {
|
|
|
|
for (let listener of this._getAllEventListeners(event.target)) {
|
|
|
|
if (event.type == listener.type || this._pauseOnDOMEvents == "*") {
|
|
|
|
this._breakOnEnter(listener.script);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an array containing all the event listeners attached to the
|
|
|
|
* specified event target and its ancestors in the event target chain.
|
|
|
|
*
|
|
|
|
* @param EventTarget eventTarget
|
|
|
|
* The target the event was dispatched on.
|
|
|
|
* @returns Array
|
|
|
|
*/
|
|
|
|
_getAllEventListeners: function(eventTarget) {
|
|
|
|
let els = Cc["@mozilla.org/eventlistenerservice;1"]
|
|
|
|
.getService(Ci.nsIEventListenerService);
|
|
|
|
|
|
|
|
let targets = els.getEventTargetChainFor(eventTarget);
|
|
|
|
let listeners = [];
|
|
|
|
|
|
|
|
for (let target of targets) {
|
|
|
|
let handlers = els.getListenerInfoFor(target);
|
|
|
|
for (let handler of handlers) {
|
|
|
|
// Null is returned for all-events handlers, and native event listeners
|
|
|
|
// don't provide any listenerObject, which makes them not that useful to
|
|
|
|
// a JS debugger.
|
|
|
|
if (!handler || !handler.listenerObject || !handler.type)
|
|
|
|
continue;
|
|
|
|
// Create a listener-like object suitable for our purposes.
|
|
|
|
let l = Object.create(null);
|
|
|
|
l.type = handler.type;
|
|
|
|
let listener = handler.listenerObject;
|
|
|
|
l.script = this.globalDebugObject.makeDebuggeeValue(listener).script;
|
|
|
|
// Chrome listeners won't be converted to debuggee values, since their
|
|
|
|
// compartment is not added as a debuggee.
|
|
|
|
if (!l.script)
|
|
|
|
continue;
|
|
|
|
listeners.push(l);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return listeners;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a breakpoint on the first bytecode offset in the provided script.
|
|
|
|
*/
|
|
|
|
_breakOnEnter: function(script) {
|
|
|
|
let offsets = script.getAllOffsets();
|
|
|
|
for (let line = 0, n = offsets.length; line < n; line++) {
|
|
|
|
if (offsets[line]) {
|
|
|
|
let location = { url: script.url, line: line };
|
|
|
|
let resp = this._createAndStoreBreakpoint(location);
|
|
|
|
dbg_assert(!resp.actualLocation, "No actualLocation should be returned");
|
|
|
|
if (resp.error) {
|
|
|
|
reportError(new Error("Unable to set breakpoint on event listener"));
|
|
|
|
return;
|
|
|
|
}
|
2013-07-25 00:46:49 +00:00
|
|
|
let bp = this.breakpointStore.getBreakpoint(location);
|
|
|
|
let bpActor = bp.actor;
|
|
|
|
dbg_assert(bp, "Breakpoint must exist");
|
2013-07-18 11:14:16 +00:00
|
|
|
dbg_assert(bpActor, "Breakpoint actor must be created");
|
|
|
|
this._hiddenBreakpoints.set(bpActor.actorID, bpActor);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-03-18 06:50:43 +00:00
|
|
|
/**
|
|
|
|
* Helper method that returns the next frame when stepping.
|
|
|
|
*/
|
|
|
|
_getNextStepFrame: function TA__getNextStepFrame(aFrame) {
|
|
|
|
let stepFrame = aFrame.reportedPop ? aFrame.older : aFrame;
|
|
|
|
if (!stepFrame || !stepFrame.script) {
|
|
|
|
stepFrame = null;
|
|
|
|
}
|
|
|
|
return stepFrame;
|
|
|
|
},
|
|
|
|
|
2012-02-07 17:22:30 +00:00
|
|
|
onClientEvaluate: function TA_onClientEvaluate(aRequest) {
|
|
|
|
if (this.state !== "paused") {
|
2012-03-13 07:13:02 +00:00
|
|
|
return { error: "wrongState",
|
2012-02-07 17:22:30 +00:00
|
|
|
message: "Debuggee must be paused to evaluate code." };
|
2013-08-23 22:04:03 +00:00
|
|
|
}
|
2012-02-07 17:22:30 +00:00
|
|
|
|
|
|
|
let frame = this._requestFrame(aRequest.frame);
|
|
|
|
if (!frame) {
|
2012-03-13 07:13:02 +00:00
|
|
|
return { error: "unknownFrame",
|
2012-02-07 17:22:30 +00:00
|
|
|
message: "Evaluation frame not found" };
|
|
|
|
}
|
|
|
|
|
2012-03-13 07:13:02 +00:00
|
|
|
if (!frame.environment) {
|
|
|
|
return { error: "notDebuggee",
|
|
|
|
message: "cannot access the environment of this frame." };
|
2013-08-23 22:04:03 +00:00
|
|
|
}
|
2012-02-07 17:22:30 +00:00
|
|
|
|
|
|
|
// We'll clobber the youngest frame if the eval causes a pause, so
|
|
|
|
// save our frame now to be restored after eval returns.
|
|
|
|
// XXX: or we could just start using dbg.getNewestFrame() now that it
|
|
|
|
// works as expected.
|
2013-06-11 14:23:00 +00:00
|
|
|
let youngest = this.youngestFrame;
|
2012-02-07 17:22:30 +00:00
|
|
|
|
|
|
|
// Put ourselves back in the running state and inform the client.
|
|
|
|
let resumedPacket = this._resumed();
|
|
|
|
this.conn.send(resumedPacket);
|
|
|
|
|
|
|
|
// Run the expression.
|
|
|
|
// XXX: test syntax errors
|
|
|
|
let completion = frame.eval(aRequest.expression);
|
|
|
|
|
|
|
|
// Put ourselves back in the pause state.
|
|
|
|
let packet = this._paused(youngest);
|
2012-03-13 07:13:02 +00:00
|
|
|
packet.why = { type: "clientEvaluated",
|
|
|
|
frameFinished: this.createProtocolCompletionValue(completion) };
|
2012-02-07 17:22:30 +00:00
|
|
|
|
|
|
|
// Return back to our previous pause's event loop.
|
|
|
|
return packet;
|
|
|
|
},
|
|
|
|
|
|
|
|
onFrames: function TA_onFrames(aRequest) {
|
|
|
|
if (this.state !== "paused") {
|
|
|
|
return { error: "wrongState",
|
|
|
|
message: "Stack frames are only available while the debuggee is paused."};
|
|
|
|
}
|
|
|
|
|
|
|
|
let start = aRequest.start ? aRequest.start : 0;
|
|
|
|
let count = aRequest.count;
|
|
|
|
|
|
|
|
// Find the starting frame...
|
2013-06-11 14:23:00 +00:00
|
|
|
let frame = this.youngestFrame;
|
2012-02-07 17:22:30 +00:00
|
|
|
let i = 0;
|
|
|
|
while (frame && (i < start)) {
|
|
|
|
frame = frame.older;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return request.count frames, or all remaining
|
|
|
|
// frames if count is not defined.
|
|
|
|
let frames = [];
|
2013-04-15 21:07:00 +00:00
|
|
|
let promises = [];
|
|
|
|
for (; frame && (!count || i < (start + count)); i++, frame=frame.older) {
|
2012-03-13 07:13:02 +00:00
|
|
|
let form = this._createFrameActor(frame).form();
|
|
|
|
form.depth = i;
|
|
|
|
frames.push(form);
|
2013-04-15 21:07:00 +00:00
|
|
|
|
2013-08-24 05:41:28 +00:00
|
|
|
let promise = this.sources.getOriginalLocation(form.where)
|
2013-08-03 18:05:36 +00:00
|
|
|
.then((aOrigLocation) => {
|
2013-04-15 21:07:00 +00:00
|
|
|
form.where = aOrigLocation;
|
2013-08-03 18:05:36 +00:00
|
|
|
let source = this.sources.source(form.where.url);
|
|
|
|
if (source) {
|
|
|
|
form.source = source.form();
|
|
|
|
}
|
2013-04-15 21:07:00 +00:00
|
|
|
});
|
|
|
|
promises.push(promise);
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
|
|
|
|
2013-04-18 13:19:46 +00:00
|
|
|
return all(promises).then(function () {
|
2013-04-15 21:07:00 +00:00
|
|
|
return { frames: frames };
|
|
|
|
});
|
2012-02-07 17:22:30 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onReleaseMany: function TA_onReleaseMany(aRequest) {
|
2012-03-13 07:13:02 +00:00
|
|
|
if (!aRequest.actors) {
|
|
|
|
return { error: "missingParameter",
|
|
|
|
message: "no actors were specified" };
|
|
|
|
}
|
|
|
|
|
2012-10-12 08:26:49 +00:00
|
|
|
let res;
|
2012-02-07 17:22:30 +00:00
|
|
|
for each (let actorID in aRequest.actors) {
|
|
|
|
let actor = this.threadLifetimePool.get(actorID);
|
2012-10-12 08:26:49 +00:00
|
|
|
if (!actor) {
|
|
|
|
if (!res) {
|
|
|
|
res = { error: "notReleasable",
|
|
|
|
message: "Only thread-lifetime actors can be released." };
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
actor.onRelease();
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
2012-10-12 08:26:49 +00:00
|
|
|
return res ? res : {};
|
2012-02-07 17:22:30 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a protocol request to set a breakpoint.
|
|
|
|
*/
|
|
|
|
onSetBreakpoint: function TA_onSetBreakpoint(aRequest) {
|
|
|
|
if (this.state !== "paused") {
|
|
|
|
return { error: "wrongState",
|
|
|
|
message: "Breakpoints can only be set while the debuggee is paused."};
|
|
|
|
}
|
|
|
|
|
2013-04-15 21:07:00 +00:00
|
|
|
let { url: originalSource,
|
|
|
|
line: originalLine,
|
|
|
|
column: originalColumn } = aRequest.location;
|
2013-04-09 08:42:00 +00:00
|
|
|
|
2013-08-24 05:41:28 +00:00
|
|
|
let locationPromise = this.sources.getGeneratedLocation(aRequest.location);
|
2013-07-25 00:46:49 +00:00
|
|
|
return locationPromise.then(({url, line, column}) => {
|
|
|
|
if (line == null ||
|
2013-04-09 08:40:00 +00:00
|
|
|
line < 0 ||
|
2013-07-25 00:46:49 +00:00
|
|
|
this.dbg.findScripts({ url: url }).length == 0) {
|
2013-04-15 21:07:00 +00:00
|
|
|
return { error: "noScript" };
|
|
|
|
}
|
|
|
|
|
2013-07-25 00:46:49 +00:00
|
|
|
let response = this._createAndStoreBreakpoint({
|
|
|
|
url: url,
|
|
|
|
line: line,
|
|
|
|
column: column
|
|
|
|
});
|
2013-04-15 21:07:00 +00:00
|
|
|
// If the original location of our generated location is different from
|
|
|
|
// the original location we attempted to set the breakpoint on, we will
|
|
|
|
// need to know so that we can set actualLocation on the response.
|
2013-08-24 05:41:28 +00:00
|
|
|
let originalLocation = this.sources.getOriginalLocation({
|
|
|
|
url: url,
|
|
|
|
line: line,
|
|
|
|
column: column
|
|
|
|
});
|
2013-04-15 21:07:00 +00:00
|
|
|
|
2013-04-18 13:19:46 +00:00
|
|
|
return all([response, originalLocation])
|
2013-04-15 21:07:00 +00:00
|
|
|
.then(([aResponse, {url, line}]) => {
|
|
|
|
if (aResponse.actualLocation) {
|
2013-08-24 05:41:28 +00:00
|
|
|
let actualOrigLocation = this.sources.getOriginalLocation(aResponse.actualLocation);
|
|
|
|
return actualOrigLocation.then(({ url, line, column }) => {
|
2013-07-25 00:46:49 +00:00
|
|
|
if (url !== originalSource
|
|
|
|
|| line !== originalLine
|
|
|
|
|| column !== originalColumn) {
|
|
|
|
aResponse.actualLocation = {
|
|
|
|
url: url,
|
|
|
|
line: line,
|
|
|
|
column: column
|
|
|
|
};
|
2013-04-15 21:07:00 +00:00
|
|
|
}
|
|
|
|
return aResponse;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (url !== originalSource || line !== originalLine) {
|
|
|
|
aResponse.actualLocation = { url: url, line: line };
|
|
|
|
}
|
2013-04-09 08:42:00 +00:00
|
|
|
|
2013-04-15 21:07:00 +00:00
|
|
|
return aResponse;
|
|
|
|
});
|
|
|
|
});
|
2012-06-03 13:39:50 +00:00
|
|
|
},
|
|
|
|
|
2013-07-18 11:14:16 +00:00
|
|
|
/**
|
2013-07-25 00:46:49 +00:00
|
|
|
* Create a breakpoint at the specified location and store it in the
|
|
|
|
* cache. Takes ownership of `aLocation`.
|
|
|
|
*
|
|
|
|
* @param Object aLocation
|
|
|
|
* An object of the form { url, line[, column] }
|
2013-07-18 11:14:16 +00:00
|
|
|
*/
|
|
|
|
_createAndStoreBreakpoint: function (aLocation) {
|
2013-07-25 00:46:49 +00:00
|
|
|
// Add the breakpoint to the store for later reuse, in case it belongs to a
|
|
|
|
// script that hasn't appeared yet.
|
|
|
|
this.breakpointStore.addBreakpoint(aLocation);
|
|
|
|
return this._setBreakpoint(aLocation);
|
2013-07-18 11:14:16 +00:00
|
|
|
},
|
|
|
|
|
2012-06-03 13:39:50 +00:00
|
|
|
/**
|
2012-06-12 06:47:08 +00:00
|
|
|
* Set a breakpoint using the jsdbg2 API. If the line on which the breakpoint
|
|
|
|
* is being set contains no code, then the breakpoint will slide down to the
|
|
|
|
* next line that has runnable code. In this case the server breakpoint cache
|
|
|
|
* will be updated, so callers that iterate over the breakpoint cache should
|
|
|
|
* take that into account.
|
2012-06-03 13:39:50 +00:00
|
|
|
*
|
|
|
|
* @param object aLocation
|
2013-07-25 00:46:49 +00:00
|
|
|
* The location of the breakpoint (in the generated source, if source
|
|
|
|
* mapping).
|
2012-06-03 13:39:50 +00:00
|
|
|
*/
|
|
|
|
_setBreakpoint: function TA__setBreakpoint(aLocation) {
|
2013-03-14 22:21:00 +00:00
|
|
|
let actor;
|
2013-07-25 00:46:49 +00:00
|
|
|
let storedBp = this.breakpointStore.getBreakpoint(aLocation);
|
|
|
|
if (storedBp.actor) {
|
|
|
|
actor = storedBp.actor;
|
2013-03-14 22:21:00 +00:00
|
|
|
} else {
|
2013-07-25 00:46:49 +00:00
|
|
|
storedBp.actor = actor = new BreakpointActor(this, {
|
2013-03-14 22:21:00 +00:00
|
|
|
url: aLocation.url,
|
2013-07-25 00:46:49 +00:00
|
|
|
line: aLocation.line,
|
|
|
|
column: aLocation.column
|
2013-03-14 22:21:00 +00:00
|
|
|
});
|
|
|
|
this._hooks.addToParentPool(actor);
|
2012-06-03 13:39:50 +00:00
|
|
|
}
|
|
|
|
|
2013-04-22 05:44:00 +00:00
|
|
|
// Find all scripts matching the given location
|
2013-03-14 22:21:00 +00:00
|
|
|
let scripts = this.dbg.findScripts(aLocation);
|
|
|
|
if (scripts.length == 0) {
|
|
|
|
return {
|
|
|
|
error: "noScript",
|
|
|
|
actor: actor.actorID
|
|
|
|
};
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
2012-02-10 07:46:12 +00:00
|
|
|
|
2013-04-22 05:44:00 +00:00
|
|
|
/**
|
2013-07-25 00:46:49 +00:00
|
|
|
* For each script, if the given line has at least one entry point, set a
|
|
|
|
* breakpoint on the bytecode offets for each of them.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Debugger.Script -> array of offset mappings
|
|
|
|
let scriptsAndOffsetMappings = new Map();
|
|
|
|
|
2013-03-14 22:21:00 +00:00
|
|
|
for (let script of scripts) {
|
2013-07-25 00:46:49 +00:00
|
|
|
this._findClosestOffsetMappings(aLocation,
|
|
|
|
script,
|
|
|
|
scriptsAndOffsetMappings);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scriptsAndOffsetMappings.size > 0) {
|
|
|
|
for (let [script, mappings] of scriptsAndOffsetMappings) {
|
|
|
|
for (let offsetMapping of mappings) {
|
|
|
|
script.setBreakpoint(offsetMapping.offset, actor);
|
2012-11-01 15:34:10 +00:00
|
|
|
}
|
2013-03-14 22:21:00 +00:00
|
|
|
actor.addScript(script, this);
|
2012-11-01 15:34:10 +00:00
|
|
|
}
|
2013-07-25 00:46:49 +00:00
|
|
|
|
2013-03-14 22:21:00 +00:00
|
|
|
return {
|
|
|
|
actor: actor.actorID
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-04-22 05:44:00 +00:00
|
|
|
/**
|
2013-07-25 00:46:49 +00:00
|
|
|
* If we get here, no breakpoint was set. This is because the given line
|
|
|
|
* has no entry points, for example because it is empty. As a fallback
|
|
|
|
* strategy, we try to set the breakpoint on the smallest line greater
|
|
|
|
* than or equal to the given line that as at least one entry point.
|
|
|
|
*/
|
2013-04-22 05:44:00 +00:00
|
|
|
|
|
|
|
// Find all innermost scripts matching the given location
|
2013-03-14 22:21:00 +00:00
|
|
|
let scripts = this.dbg.findScripts({
|
|
|
|
url: aLocation.url,
|
|
|
|
line: aLocation.line,
|
|
|
|
innermost: true
|
|
|
|
});
|
2012-02-10 07:46:12 +00:00
|
|
|
|
2013-04-22 05:44:00 +00:00
|
|
|
/**
|
|
|
|
* For each innermost script, look for the smallest line greater than or
|
|
|
|
* equal to the given line that has one or more entry points. If found, set
|
|
|
|
* a breakpoint on the bytecode offset for each of its entry points.
|
|
|
|
*/
|
2012-02-10 07:46:12 +00:00
|
|
|
let actualLocation;
|
2013-03-14 22:21:00 +00:00
|
|
|
let found = false;
|
|
|
|
for (let script of scripts) {
|
|
|
|
let offsets = script.getAllOffsets();
|
|
|
|
for (let line = aLocation.line; line < offsets.length; ++line) {
|
|
|
|
if (offsets[line]) {
|
|
|
|
for (let offset of offsets[line]) {
|
|
|
|
script.setBreakpoint(offset, actor);
|
2012-02-10 07:46:12 +00:00
|
|
|
}
|
2013-03-14 22:21:00 +00:00
|
|
|
actor.addScript(script, this);
|
|
|
|
if (!actualLocation) {
|
|
|
|
actualLocation = {
|
|
|
|
url: aLocation.url,
|
|
|
|
line: line,
|
2013-04-22 05:44:00 +00:00
|
|
|
column: 0
|
2013-03-14 22:21:00 +00:00
|
|
|
};
|
2012-11-27 12:29:46 +00:00
|
|
|
}
|
2013-03-14 22:21:00 +00:00
|
|
|
found = true;
|
2012-02-10 07:46:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
2013-03-14 22:21:00 +00:00
|
|
|
if (found) {
|
2013-07-31 02:34:10 +00:00
|
|
|
let existingBp = this.breakpointStore.hasBreakpoint(actualLocation);
|
|
|
|
|
2013-07-25 00:46:49 +00:00
|
|
|
if (existingBp && existingBp.actor) {
|
2013-04-22 05:44:00 +00:00
|
|
|
/**
|
|
|
|
* We already have a breakpoint actor for the actual location, so
|
|
|
|
* actor we created earlier is now redundant. Delete it, update the
|
|
|
|
* breakpoint store, and return the actor for the actual location.
|
|
|
|
*/
|
2013-03-14 22:21:00 +00:00
|
|
|
actor.onDelete();
|
2013-07-25 00:46:49 +00:00
|
|
|
this.breakpointStore.removeBreakpoint(aLocation);
|
2013-03-14 22:21:00 +00:00
|
|
|
return {
|
2013-07-25 00:46:49 +00:00
|
|
|
actor: existingBp.actor.actorID,
|
2013-03-14 22:21:00 +00:00
|
|
|
actualLocation: actualLocation
|
|
|
|
};
|
|
|
|
} else {
|
2013-04-22 05:44:00 +00:00
|
|
|
/**
|
|
|
|
* We don't have a breakpoint actor for the actual location yet.
|
|
|
|
* Instead or creating a new actor, reuse the actor we created earlier,
|
|
|
|
* and update the breakpoint store.
|
|
|
|
*/
|
2013-03-14 22:21:00 +00:00
|
|
|
actor.location = actualLocation;
|
2013-07-25 00:46:49 +00:00
|
|
|
this.breakpointStore.addBreakpoint({
|
|
|
|
actor: actor,
|
|
|
|
url: actualLocation.url,
|
|
|
|
line: actualLocation.line,
|
|
|
|
column: actualLocation.column
|
|
|
|
});
|
|
|
|
this.breakpointStore.removeBreakpoint(aLocation);
|
2013-03-14 22:21:00 +00:00
|
|
|
return {
|
|
|
|
actor: actor.actorID,
|
|
|
|
actualLocation: actualLocation
|
|
|
|
};
|
|
|
|
}
|
2012-02-10 07:46:12 +00:00
|
|
|
}
|
|
|
|
|
2013-04-22 05:44:00 +00:00
|
|
|
/**
|
|
|
|
* If we get here, no line matching the given line was found, so just
|
2013-07-25 00:46:49 +00:00
|
|
|
* fail epically.
|
2013-04-22 05:44:00 +00:00
|
|
|
*/
|
2013-03-14 22:21:00 +00:00
|
|
|
return {
|
|
|
|
error: "noCodeAtLineColumn",
|
|
|
|
actor: actor.actorID
|
|
|
|
};
|
2012-02-10 07:46:12 +00:00
|
|
|
},
|
|
|
|
|
2013-07-25 00:46:49 +00:00
|
|
|
/**
|
|
|
|
* Find all of the offset mappings associated with `aScript` that are closest
|
|
|
|
* to `aTargetLocation`. If new offset mappings are found that are closer to
|
|
|
|
* `aTargetOffset` than the existing offset mappings inside
|
|
|
|
* `aScriptsAndOffsetMappings`, we empty that map and only consider the
|
|
|
|
* closest offset mappings. If there is no column in `aTargetLocation`, we add
|
|
|
|
* all offset mappings that are on the given line.
|
|
|
|
*
|
|
|
|
* @param Object aTargetLocation
|
|
|
|
* An object of the form { url, line[, column] }.
|
|
|
|
* @param Debugger.Script aScript
|
|
|
|
* The script in which we are searching for offsets.
|
|
|
|
* @param Map aScriptsAndOffsetMappings
|
|
|
|
* A Map object which maps Debugger.Script instances to arrays of
|
|
|
|
* offset mappings. This is an out param.
|
|
|
|
*/
|
|
|
|
_findClosestOffsetMappings: function TA__findClosestOffsetMappings(aTargetLocation,
|
|
|
|
aScript,
|
|
|
|
aScriptsAndOffsetMappings) {
|
|
|
|
// If we are given a column, we will try and break only at that location,
|
|
|
|
// otherwise we will break anytime we get on that line.
|
|
|
|
|
|
|
|
if (aTargetLocation.column == null) {
|
2013-09-09 17:06:08 +00:00
|
|
|
let offsetMappings = aScript.getLineOffsets(aTargetLocation.line)
|
|
|
|
.map(o => ({
|
|
|
|
line: aTargetLocation.line,
|
|
|
|
offset: o
|
|
|
|
}));
|
2013-07-25 00:46:49 +00:00
|
|
|
if (offsetMappings.length) {
|
|
|
|
aScriptsAndOffsetMappings.set(aScript, offsetMappings);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-09 17:06:08 +00:00
|
|
|
let offsetMappings = aScript.getAllColumnOffsets()
|
|
|
|
.filter(({ lineNumber }) => lineNumber === aTargetLocation.line);
|
|
|
|
|
2013-07-25 00:46:49 +00:00
|
|
|
// Attempt to find the current closest offset distance from the target
|
|
|
|
// location by grabbing any offset mapping in the map by doing one iteration
|
|
|
|
// and then breaking (they all have the same distance from the target
|
|
|
|
// location).
|
|
|
|
let closestDistance = Infinity;
|
|
|
|
if (aScriptsAndOffsetMappings.size) {
|
|
|
|
for (let mappings of aScriptsAndOffsetMappings.values()) {
|
|
|
|
closestDistance = Math.abs(aTargetLocation.column - mappings[0].columnNumber);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let mapping of offsetMappings) {
|
|
|
|
let currentDistance = Math.abs(aTargetLocation.column - mapping.columnNumber);
|
|
|
|
|
|
|
|
if (currentDistance > closestDistance) {
|
|
|
|
continue;
|
|
|
|
} else if (currentDistance < closestDistance) {
|
|
|
|
closestDistance = currentDistance;
|
|
|
|
aScriptsAndOffsetMappings.clear();
|
|
|
|
aScriptsAndOffsetMappings.set(aScript, [mapping]);
|
|
|
|
} else {
|
|
|
|
if (!aScriptsAndOffsetMappings.has(aScript)) {
|
|
|
|
aScriptsAndOffsetMappings.set(aScript, []);
|
|
|
|
}
|
|
|
|
aScriptsAndOffsetMappings.get(aScript).push(mapping);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-02-07 17:22:30 +00:00
|
|
|
/**
|
2013-02-28 12:02:00 +00:00
|
|
|
* Get the script and source lists from the debugger.
|
2013-06-20 17:43:30 +00:00
|
|
|
*
|
|
|
|
* TODO bug 637572: we should be dealing with sources directly, not inferring
|
|
|
|
* them through scripts.
|
2012-02-07 17:22:30 +00:00
|
|
|
*/
|
2013-06-20 17:43:30 +00:00
|
|
|
_discoverSources: function TA__discoverSources() {
|
|
|
|
// Only get one script per url.
|
|
|
|
let scriptsByUrl = {};
|
|
|
|
for (let s of this.dbg.findScripts()) {
|
|
|
|
scriptsByUrl[s.url] = s;
|
2013-06-11 07:58:57 +00:00
|
|
|
}
|
2013-06-20 17:43:30 +00:00
|
|
|
|
|
|
|
return all([this.sources.sourcesForScript(scriptsByUrl[s])
|
|
|
|
for (s of Object.keys(scriptsByUrl))]);
|
2013-02-28 12:02:00 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onSources: function TA_onSources(aRequest) {
|
2013-06-20 17:43:30 +00:00
|
|
|
return this._discoverSources().then(() => {
|
2013-04-15 21:07:00 +00:00
|
|
|
return {
|
|
|
|
sources: [s.form() for (s of this.sources.iter())]
|
|
|
|
};
|
|
|
|
});
|
2012-02-07 17:22:30 +00:00
|
|
|
},
|
|
|
|
|
2013-05-01 15:29:33 +00:00
|
|
|
/**
|
|
|
|
* Disassociate all breakpoint actors from their scripts and clear the
|
|
|
|
* breakpoint handlers. This method can be used when the thread actor intends
|
|
|
|
* to keep the breakpoint store, but needs to clear any actual breakpoints,
|
|
|
|
* e.g. due to a page navigation. This way the breakpoint actors' script
|
|
|
|
* caches won't hold on to the Debugger.Script objects leaking memory.
|
|
|
|
*/
|
|
|
|
disableAllBreakpoints: function () {
|
2013-07-25 00:46:49 +00:00
|
|
|
for (let bp of this.breakpointStore.findBreakpoints()) {
|
|
|
|
if (bp.actor) {
|
2013-05-01 15:29:33 +00:00
|
|
|
bp.actor.removeScripts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-02-10 07:46:10 +00:00
|
|
|
/**
|
|
|
|
* Handle a protocol request to pause the debuggee.
|
|
|
|
*/
|
2012-07-13 10:10:22 +00:00
|
|
|
onInterrupt: function TA_onInterrupt(aRequest) {
|
2012-02-10 07:46:10 +00:00
|
|
|
if (this.state == "exited") {
|
|
|
|
return { type: "exited" };
|
|
|
|
} else if (this.state == "paused") {
|
|
|
|
// TODO: return the actual reason for the existing pause.
|
|
|
|
return { type: "paused", why: { type: "alreadyPaused" } };
|
|
|
|
} else if (this.state != "running") {
|
|
|
|
return { error: "wrongState",
|
|
|
|
message: "Received interrupt request in " + this.state +
|
|
|
|
" state." };
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Put ourselves in the paused state.
|
|
|
|
let packet = this._paused();
|
|
|
|
if (!packet) {
|
|
|
|
return { error: "notInterrupted" };
|
|
|
|
}
|
|
|
|
packet.why = { type: "interrupted" };
|
|
|
|
|
|
|
|
// Send the response to the interrupt request now (rather than
|
|
|
|
// returning it), because we're going to start a nested event loop
|
|
|
|
// here.
|
|
|
|
this.conn.send(packet);
|
|
|
|
|
|
|
|
// Start a nested event loop.
|
2013-08-16 21:59:04 +00:00
|
|
|
this._pushThreadPause();
|
2012-02-10 07:46:10 +00:00
|
|
|
|
|
|
|
// We already sent a response to this request, don't send one
|
|
|
|
// now.
|
|
|
|
return null;
|
2013-04-15 21:07:00 +00:00
|
|
|
} catch (e) {
|
|
|
|
reportError(e);
|
2012-02-10 07:46:10 +00:00
|
|
|
return { error: "notInterrupted", message: e.toString() };
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-07-18 11:14:16 +00:00
|
|
|
/**
|
|
|
|
* Handle a protocol request to retrieve all the event listeners on the page.
|
|
|
|
*/
|
|
|
|
onEventListeners: function TA_onEventListeners(aRequest) {
|
|
|
|
// This request is only supported in content debugging.
|
|
|
|
if (!this.global) {
|
|
|
|
return {
|
|
|
|
error: "notImplemented",
|
|
|
|
message: "eventListeners request is only supported in content debugging"
|
2013-08-23 22:04:03 +00:00
|
|
|
};
|
2013-07-18 11:14:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let els = Cc["@mozilla.org/eventlistenerservice;1"]
|
|
|
|
.getService(Ci.nsIEventListenerService);
|
|
|
|
|
|
|
|
let nodes = this.global.document.getElementsByTagName("*");
|
|
|
|
nodes = [this.global].concat([].slice.call(nodes));
|
|
|
|
let listeners = [];
|
|
|
|
|
|
|
|
for (let node of nodes) {
|
|
|
|
let handlers = els.getListenerInfoFor(node);
|
|
|
|
|
|
|
|
for (let handler of handlers) {
|
|
|
|
// Create a form object for serializing the listener via the protocol.
|
|
|
|
let listenerForm = Object.create(null);
|
|
|
|
let listener = handler.listenerObject;
|
|
|
|
// Native event listeners don't provide any listenerObject and are not
|
|
|
|
// that useful to a JS debugger.
|
|
|
|
if (!listener) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// There will be no tagName if the event listener is set on the window.
|
|
|
|
let selector = node.tagName ? findCssSelector(node) : "window";
|
|
|
|
let nodeDO = this.globalDebugObject.makeDebuggeeValue(node);
|
|
|
|
listenerForm.node = {
|
|
|
|
selector: selector,
|
|
|
|
object: this.createValueGrip(nodeDO)
|
|
|
|
};
|
|
|
|
listenerForm.type = handler.type;
|
|
|
|
listenerForm.capturing = handler.capturing;
|
|
|
|
listenerForm.allowsUntrusted = handler.allowsUntrusted;
|
|
|
|
listenerForm.inSystemEventGroup = handler.inSystemEventGroup;
|
|
|
|
listenerForm.isEventHandler = !!node["on" + listenerForm.type];
|
|
|
|
// Get the Debugger.Object for the listener object.
|
|
|
|
let listenerDO = this.globalDebugObject.makeDebuggeeValue(listener);
|
|
|
|
listenerForm.function = this.createValueGrip(listenerDO);
|
|
|
|
listeners.push(listenerForm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return { listeners: listeners };
|
|
|
|
},
|
|
|
|
|
2012-02-07 17:22:30 +00:00
|
|
|
/**
|
|
|
|
* Return the Debug.Frame for a frame mentioned by the protocol.
|
|
|
|
*/
|
|
|
|
_requestFrame: function TA_requestFrame(aFrameID) {
|
|
|
|
if (!aFrameID) {
|
2013-06-11 14:23:00 +00:00
|
|
|
return this.youngestFrame;
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this._framePool.has(aFrameID)) {
|
|
|
|
return this._framePool.get(aFrameID).frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
},
|
|
|
|
|
2013-07-25 00:46:49 +00:00
|
|
|
_paused: function TA__paused(aFrame) {
|
2012-03-13 07:13:02 +00:00
|
|
|
// We don't handle nested pauses correctly. Don't try - if we're
|
2012-02-07 17:22:30 +00:00
|
|
|
// paused, just continue running whatever code triggered the pause.
|
2012-03-13 07:13:02 +00:00
|
|
|
// We don't want to actually have nested pauses (although we
|
2012-02-07 17:22:30 +00:00
|
|
|
// have nested event loops). If code runs in the debuggee during
|
|
|
|
// a pause, it should cause the actor to resume (dropping
|
|
|
|
// pause-lifetime actors etc) and then repause when complete.
|
|
|
|
|
|
|
|
if (this.state === "paused") {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2012-03-18 06:50:43 +00:00
|
|
|
// Clear stepping hooks.
|
|
|
|
this.dbg.onEnterFrame = undefined;
|
2012-06-03 13:39:51 +00:00
|
|
|
this.dbg.onExceptionUnwind = undefined;
|
2012-03-18 06:50:43 +00:00
|
|
|
if (aFrame) {
|
|
|
|
aFrame.onStep = undefined;
|
|
|
|
aFrame.onPop = undefined;
|
|
|
|
}
|
2013-07-18 11:14:16 +00:00
|
|
|
// Clear DOM event breakpoints.
|
|
|
|
// XPCShell tests don't use actual DOM windows for globals and cause
|
|
|
|
// removeListenerForAllEvents to throw.
|
|
|
|
if (this.global && !this.global.toString().contains("Sandbox")) {
|
|
|
|
let els = Cc["@mozilla.org/eventlistenerservice;1"]
|
|
|
|
.getService(Ci.nsIEventListenerService);
|
|
|
|
els.removeListenerForAllEvents(this.global, this._allEventsListener, true);
|
|
|
|
for (let [,bp] of this._hiddenBreakpoints) {
|
|
|
|
bp.onDelete();
|
|
|
|
}
|
|
|
|
this._hiddenBreakpoints.clear();
|
|
|
|
}
|
2012-03-18 06:50:43 +00:00
|
|
|
|
2012-02-07 17:22:30 +00:00
|
|
|
this._state = "paused";
|
|
|
|
|
|
|
|
// Save the pause frame (if any) as the youngest frame for
|
|
|
|
// stack viewing.
|
2013-06-11 14:23:00 +00:00
|
|
|
this.youngestFrame = aFrame;
|
2012-02-07 17:22:30 +00:00
|
|
|
|
|
|
|
// Create the actor pool that will hold the pause actor and its
|
|
|
|
// children.
|
2013-07-18 11:14:16 +00:00
|
|
|
dbg_assert(!this._pausePool, "No pause pool should exist yet");
|
2012-02-07 17:22:30 +00:00
|
|
|
this._pausePool = new ActorPool(this.conn);
|
|
|
|
this.conn.addActorPool(this._pausePool);
|
|
|
|
|
|
|
|
// Give children of the pause pool a quick link back to the
|
|
|
|
// thread...
|
|
|
|
this._pausePool.threadActor = this;
|
|
|
|
|
|
|
|
// Create the pause actor itself...
|
2013-07-18 11:14:16 +00:00
|
|
|
dbg_assert(!this._pauseActor, "No pause actor should exist yet");
|
2012-02-07 17:22:30 +00:00
|
|
|
this._pauseActor = new PauseActor(this._pausePool);
|
|
|
|
this._pausePool.addActor(this._pauseActor);
|
|
|
|
|
|
|
|
// Update the list of frames.
|
|
|
|
let poppedFrames = this._updateFrames();
|
|
|
|
|
|
|
|
// Send off the paused packet and spin an event loop.
|
|
|
|
let packet = { from: this.actorID,
|
|
|
|
type: "paused",
|
|
|
|
actor: this._pauseActor.actorID };
|
|
|
|
if (aFrame) {
|
2012-03-13 07:13:02 +00:00
|
|
|
packet.frame = this._createFrameActor(aFrame).form();
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
2013-04-10 13:08:59 +00:00
|
|
|
|
2012-02-07 17:22:30 +00:00
|
|
|
if (poppedFrames) {
|
|
|
|
packet.poppedFrames = poppedFrames;
|
|
|
|
}
|
|
|
|
|
|
|
|
return packet;
|
|
|
|
},
|
|
|
|
|
|
|
|
_resumed: function TA_resumed() {
|
|
|
|
this._state = "running";
|
|
|
|
|
|
|
|
// Drop the actors in the pause actor pool.
|
|
|
|
this.conn.removeActorPool(this._pausePool);
|
|
|
|
|
|
|
|
this._pausePool = null;
|
|
|
|
this._pauseActor = null;
|
2013-06-11 14:23:00 +00:00
|
|
|
this.youngestFrame = null;
|
2012-02-07 17:22:30 +00:00
|
|
|
|
|
|
|
return { from: this.actorID, type: "resumed" };
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Expire frame actors for frames that have been popped.
|
|
|
|
*
|
|
|
|
* @returns A list of actor IDs whose frames have been popped.
|
|
|
|
*/
|
|
|
|
_updateFrames: function TA_updateFrames() {
|
|
|
|
let popped = [];
|
|
|
|
|
|
|
|
// Create the actor pool that will hold the still-living frames.
|
|
|
|
let framePool = new ActorPool(this.conn);
|
|
|
|
let frameList = [];
|
|
|
|
|
|
|
|
for each (let frameActor in this._frameActors) {
|
|
|
|
if (frameActor.frame.live) {
|
|
|
|
framePool.addActor(frameActor);
|
|
|
|
frameList.push(frameActor);
|
|
|
|
} else {
|
|
|
|
popped.push(frameActor.actorID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the old frame actor pool, this will expire
|
|
|
|
// any actors that weren't added to the new pool.
|
|
|
|
if (this._framePool) {
|
|
|
|
this.conn.removeActorPool(this._framePool);
|
|
|
|
}
|
|
|
|
|
|
|
|
this._frameActors = frameList;
|
|
|
|
this._framePool = framePool;
|
|
|
|
this.conn.addActorPool(framePool);
|
|
|
|
|
|
|
|
return popped;
|
|
|
|
},
|
|
|
|
|
2012-01-23 08:29:15 +00:00
|
|
|
_createFrameActor: function TA_createFrameActor(aFrame) {
|
2012-02-07 17:22:30 +00:00
|
|
|
if (aFrame.actor) {
|
|
|
|
return aFrame.actor;
|
|
|
|
}
|
|
|
|
|
|
|
|
let actor = new FrameActor(aFrame, this);
|
|
|
|
this._frameActors.push(actor);
|
|
|
|
this._framePool.addActor(actor);
|
|
|
|
aFrame.actor = actor;
|
|
|
|
|
|
|
|
return actor;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2012-03-21 15:49:23 +00:00
|
|
|
* Create and return an environment actor that corresponds to the provided
|
|
|
|
* Debugger.Environment.
|
|
|
|
* @param Debugger.Environment aEnvironment
|
|
|
|
* The lexical environment we want to extract.
|
2012-02-07 17:22:30 +00:00
|
|
|
* @param object aPool
|
|
|
|
* The pool where the newly-created actor will be placed.
|
2012-03-21 15:49:23 +00:00
|
|
|
* @return The EnvironmentActor for aEnvironment or undefined for host
|
|
|
|
* functions or functions scoped to a non-debuggee global.
|
2012-02-07 17:22:30 +00:00
|
|
|
*/
|
2012-03-21 15:49:23 +00:00
|
|
|
createEnvironmentActor:
|
|
|
|
function TA_createEnvironmentActor(aEnvironment, aPool) {
|
|
|
|
if (!aEnvironment) {
|
2012-02-07 17:22:30 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2012-03-21 15:49:23 +00:00
|
|
|
if (aEnvironment.actor) {
|
|
|
|
return aEnvironment.actor;
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
|
|
|
|
2012-03-21 15:49:23 +00:00
|
|
|
let actor = new EnvironmentActor(aEnvironment, this);
|
2012-02-07 17:22:30 +00:00
|
|
|
this._environmentActors.push(actor);
|
|
|
|
aPool.addActor(actor);
|
2012-03-21 15:49:23 +00:00
|
|
|
aEnvironment.actor = actor;
|
2012-02-07 17:22:30 +00:00
|
|
|
|
|
|
|
return actor;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a grip for the given debuggee value. If the value is an
|
2012-09-27 08:30:00 +00:00
|
|
|
* object, will create an actor with the given lifetime.
|
2012-02-07 17:22:30 +00:00
|
|
|
*/
|
2012-09-27 08:30:00 +00:00
|
|
|
createValueGrip: function TA_createValueGrip(aValue, aPool=false) {
|
|
|
|
if (!aPool) {
|
|
|
|
aPool = this._pausePool;
|
|
|
|
}
|
2012-08-30 21:10:07 +00:00
|
|
|
|
2013-08-12 17:15:22 +00:00
|
|
|
switch (typeof aValue) {
|
|
|
|
case "boolean":
|
|
|
|
return aValue;
|
|
|
|
case "string":
|
|
|
|
if (this._stringIsLong(aValue)) {
|
|
|
|
return this.longStringGrip(aValue, aPool);
|
|
|
|
}
|
|
|
|
return aValue;
|
|
|
|
case "number":
|
|
|
|
if (aValue === Infinity) {
|
|
|
|
return { type: "Infinity" };
|
|
|
|
} else if (aValue === -Infinity) {
|
|
|
|
return { type: "-Infinity" };
|
|
|
|
} else if (Number.isNaN(aValue)) {
|
|
|
|
return { type: "NaN" };
|
|
|
|
} else if (!aValue && 1 / aValue === -Infinity) {
|
|
|
|
return { type: "-0" };
|
|
|
|
}
|
|
|
|
return aValue;
|
|
|
|
case "undefined":
|
|
|
|
return { type: "undefined" };
|
|
|
|
case "object":
|
|
|
|
if (aValue === null) {
|
|
|
|
return { type: "null" };
|
|
|
|
}
|
|
|
|
return this.objectGrip(aValue, aPool);
|
|
|
|
default:
|
|
|
|
dbg_assert(false, "Failed to provide a grip for: " + aValue);
|
|
|
|
return null;
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-03-13 07:13:02 +00:00
|
|
|
/**
|
|
|
|
* Return a protocol completion value representing the given
|
|
|
|
* Debugger-provided completion value.
|
|
|
|
*/
|
|
|
|
createProtocolCompletionValue:
|
|
|
|
function TA_createProtocolCompletionValue(aCompletion) {
|
|
|
|
let protoValue = {};
|
|
|
|
if ("return" in aCompletion) {
|
|
|
|
protoValue.return = this.createValueGrip(aCompletion.return);
|
|
|
|
} else if ("yield" in aCompletion) {
|
|
|
|
protoValue.return = this.createValueGrip(aCompletion.yield);
|
|
|
|
} else if ("throw" in aCompletion) {
|
|
|
|
protoValue.throw = this.createValueGrip(aCompletion.throw);
|
|
|
|
} else {
|
|
|
|
protoValue.terminated = true;
|
|
|
|
}
|
|
|
|
return protoValue;
|
|
|
|
},
|
|
|
|
|
2012-01-23 08:29:15 +00:00
|
|
|
/**
|
|
|
|
* Create a grip for the given debuggee object.
|
|
|
|
*
|
|
|
|
* @param aValue Debugger.Object
|
|
|
|
* The debuggee object value.
|
|
|
|
* @param aPool ActorPool
|
|
|
|
* The actor pool where the new object actor will be added.
|
|
|
|
*/
|
2012-02-07 17:22:30 +00:00
|
|
|
objectGrip: function TA_objectGrip(aValue, aPool) {
|
|
|
|
if (!aPool.objectActors) {
|
|
|
|
aPool.objectActors = new WeakMap();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aPool.objectActors.has(aValue)) {
|
|
|
|
return aPool.objectActors.get(aValue).grip();
|
2012-11-14 08:00:57 +00:00
|
|
|
} else if (this.threadLifetimePool.objectActors.has(aValue)) {
|
|
|
|
return this.threadLifetimePool.objectActors.get(aValue).grip();
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
|
|
|
|
2013-03-30 11:31:10 +00:00
|
|
|
let actor = new PauseScopedObjectActor(aValue, this);
|
2012-02-07 17:22:30 +00:00
|
|
|
aPool.addActor(actor);
|
|
|
|
aPool.objectActors.set(aValue, actor);
|
|
|
|
return actor.grip();
|
|
|
|
},
|
|
|
|
|
2012-01-23 08:29:15 +00:00
|
|
|
/**
|
|
|
|
* Create a grip for the given debuggee object with a pause lifetime.
|
|
|
|
*
|
|
|
|
* @param aValue Debugger.Object
|
|
|
|
* The debuggee object value.
|
|
|
|
*/
|
2012-02-07 17:22:30 +00:00
|
|
|
pauseObjectGrip: function TA_pauseObjectGrip(aValue) {
|
|
|
|
if (!this._pausePool) {
|
|
|
|
throw "Object grip requested while not paused.";
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.objectGrip(aValue, this._pausePool);
|
|
|
|
},
|
|
|
|
|
2012-01-23 08:29:15 +00:00
|
|
|
/**
|
2012-10-12 08:26:49 +00:00
|
|
|
* Extend the lifetime of the provided object actor to thread lifetime.
|
2012-01-23 08:29:15 +00:00
|
|
|
*
|
2012-10-12 08:26:49 +00:00
|
|
|
* @param aActor object
|
|
|
|
* The object actor.
|
2012-01-23 08:29:15 +00:00
|
|
|
*/
|
2012-10-12 08:26:49 +00:00
|
|
|
threadObjectGrip: function TA_threadObjectGrip(aActor) {
|
|
|
|
// We want to reuse the existing actor ID, so we just remove it from the
|
|
|
|
// current pool's weak map and then let pool.addActor do the rest.
|
|
|
|
aActor.registeredPool.objectActors.delete(aActor.obj);
|
|
|
|
this.threadLifetimePool.addActor(aActor);
|
|
|
|
this.threadLifetimePool.objectActors.set(aActor.obj, aActor);
|
2012-02-07 17:22:30 +00:00
|
|
|
},
|
|
|
|
|
2012-11-14 08:00:57 +00:00
|
|
|
/**
|
|
|
|
* Handle a protocol request to promote multiple pause-lifetime grips to
|
|
|
|
* thread-lifetime grips.
|
|
|
|
*
|
|
|
|
* @param aRequest object
|
|
|
|
* The protocol request object.
|
|
|
|
*/
|
|
|
|
onThreadGrips: function OA_onThreadGrips(aRequest) {
|
|
|
|
if (this.state != "paused") {
|
|
|
|
return { error: "wrongState" };
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aRequest.actors) {
|
|
|
|
return { error: "missingParameter",
|
|
|
|
message: "no actors were specified" };
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let actorID of aRequest.actors) {
|
|
|
|
let actor = this._pausePool.get(actorID);
|
|
|
|
if (actor) {
|
|
|
|
this.threadObjectGrip(actor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
},
|
|
|
|
|
2012-08-30 21:10:07 +00:00
|
|
|
/**
|
|
|
|
* Create a grip for the given string.
|
|
|
|
*
|
|
|
|
* @param aString String
|
|
|
|
* The string we are creating a grip for.
|
2012-09-27 08:29:00 +00:00
|
|
|
* @param aPool ActorPool
|
|
|
|
* The actor pool where the new actor will be added.
|
2012-08-30 21:10:07 +00:00
|
|
|
*/
|
2012-09-27 08:29:00 +00:00
|
|
|
longStringGrip: function TA_longStringGrip(aString, aPool) {
|
|
|
|
if (!aPool.longStringActors) {
|
|
|
|
aPool.longStringActors = {};
|
2012-08-30 21:10:07 +00:00
|
|
|
}
|
|
|
|
|
2012-09-27 08:29:00 +00:00
|
|
|
if (aPool.longStringActors.hasOwnProperty(aString)) {
|
|
|
|
return aPool.longStringActors[aString].grip();
|
2012-08-30 21:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let actor = new LongStringActor(aString, this);
|
2012-09-27 08:29:00 +00:00
|
|
|
aPool.addActor(actor);
|
|
|
|
aPool.longStringActors[aString] = actor;
|
2012-08-30 21:10:07 +00:00
|
|
|
return actor.grip();
|
|
|
|
},
|
|
|
|
|
2012-09-27 08:29:00 +00:00
|
|
|
/**
|
|
|
|
* Create a long string grip that is scoped to a pause.
|
|
|
|
*
|
|
|
|
* @param aString String
|
|
|
|
* The string we are creating a grip for.
|
|
|
|
*/
|
|
|
|
pauseLongStringGrip: function TA_pauseLongStringGrip (aString) {
|
|
|
|
return this.longStringGrip(aString, this._pausePool);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a long string grip that is scoped to a thread.
|
|
|
|
*
|
|
|
|
* @param aString String
|
|
|
|
* The string we are creating a grip for.
|
|
|
|
*/
|
|
|
|
threadLongStringGrip: function TA_pauseLongStringGrip (aString) {
|
|
|
|
return this.longStringGrip(aString, this._threadLifetimePool);
|
|
|
|
},
|
|
|
|
|
2012-08-30 21:10:07 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the string is long enough to use a LongStringActor instead
|
|
|
|
* of passing the value directly over the protocol.
|
|
|
|
*
|
|
|
|
* @param aString String
|
|
|
|
* The string we are checking the length of.
|
|
|
|
*/
|
|
|
|
_stringIsLong: function TA__stringIsLong(aString) {
|
|
|
|
return aString.length >= DebuggerServer.LONG_STRING_LENGTH;
|
|
|
|
},
|
|
|
|
|
2012-01-23 08:29:15 +00:00
|
|
|
// JS Debugger API hooks.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A function that the engine calls when a call to a debug event hook,
|
|
|
|
* breakpoint handler, watchpoint handler, or similar function throws some
|
|
|
|
* exception.
|
|
|
|
*
|
|
|
|
* @param aException exception
|
|
|
|
* The exception that was thrown in the debugger code.
|
|
|
|
*/
|
2012-02-07 17:22:30 +00:00
|
|
|
uncaughtExceptionHook: function TA_uncaughtExceptionHook(aException) {
|
2013-06-11 14:23:00 +00:00
|
|
|
dumpn("Got an exception: " + aException.message + "\n" + aException.stack);
|
2012-02-07 17:22:30 +00:00
|
|
|
},
|
|
|
|
|
2012-01-23 08:29:15 +00:00
|
|
|
/**
|
|
|
|
* A function that the engine calls when a debugger statement has been
|
|
|
|
* executed in the specified frame.
|
|
|
|
*
|
|
|
|
* @param aFrame Debugger.Frame
|
|
|
|
* The stack frame that contained the debugger statement.
|
|
|
|
*/
|
2012-02-07 17:22:30 +00:00
|
|
|
onDebuggerStatement: function TA_onDebuggerStatement(aFrame) {
|
2013-07-18 09:45:17 +00:00
|
|
|
// Don't pause if we are currently stepping (in or over) or the frame is
|
|
|
|
// black-boxed.
|
2013-09-05 23:51:23 +00:00
|
|
|
const generatedLocation = getFrameLocation(aFrame);
|
|
|
|
const { url } = this.synchronize(this.sources.getOriginalLocation(
|
|
|
|
generatedLocation));
|
2013-08-16 21:59:04 +00:00
|
|
|
|
|
|
|
return this.sources.isBlackBoxed(url) || aFrame.onStep
|
|
|
|
? undefined
|
|
|
|
: this._pauseAndRespond(aFrame, { type: "debuggerStatement" });
|
2012-02-07 17:22:30 +00:00
|
|
|
},
|
|
|
|
|
2012-06-03 13:39:51 +00:00
|
|
|
/**
|
|
|
|
* A function that the engine calls when an exception has been thrown and has
|
|
|
|
* propagated to the specified frame.
|
|
|
|
*
|
|
|
|
* @param aFrame Debugger.Frame
|
|
|
|
* The youngest remaining stack frame.
|
|
|
|
* @param aValue object
|
|
|
|
* The exception that was thrown.
|
|
|
|
*/
|
|
|
|
onExceptionUnwind: function TA_onExceptionUnwind(aFrame, aValue) {
|
2013-08-30 08:55:41 +00:00
|
|
|
let willBeCaught = false;
|
|
|
|
for (let frame = aFrame; frame != null; frame = frame.older) {
|
|
|
|
if (frame.script.isInCatchScope(frame.offset)) {
|
|
|
|
willBeCaught = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (willBeCaught && this._options.ignoreCaughtExceptions) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2013-09-05 23:51:23 +00:00
|
|
|
const generatedLocation = getFrameLocation(aFrame);
|
|
|
|
const { url } = this.synchronize(this.sources.getOriginalLocation(
|
|
|
|
generatedLocation));
|
2013-08-16 21:59:04 +00:00
|
|
|
|
|
|
|
if (this.sources.isBlackBoxed(url)) {
|
2013-06-11 14:23:00 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
2013-08-16 21:59:04 +00:00
|
|
|
|
2012-06-03 13:39:51 +00:00
|
|
|
try {
|
|
|
|
let packet = this._paused(aFrame);
|
|
|
|
if (!packet) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
packet.why = { type: "exception",
|
|
|
|
exception: this.createValueGrip(aValue) };
|
|
|
|
this.conn.send(packet);
|
2013-08-16 21:59:04 +00:00
|
|
|
|
|
|
|
this._pushThreadPause();
|
2013-04-10 13:08:59 +00:00
|
|
|
} catch(e) {
|
2013-07-03 21:10:52 +00:00
|
|
|
reportError(e, "Got an exception during TA_onExceptionUnwind: ");
|
2012-06-03 13:39:51 +00:00
|
|
|
}
|
2013-08-16 21:59:04 +00:00
|
|
|
|
|
|
|
return undefined;
|
2012-06-03 13:39:51 +00:00
|
|
|
},
|
|
|
|
|
2012-01-23 08:29:15 +00:00
|
|
|
/**
|
2012-03-30 08:25:52 +00:00
|
|
|
* A function that the engine calls when a new script has been loaded into the
|
|
|
|
* scope of the specified debuggee global.
|
2012-01-23 08:29:15 +00:00
|
|
|
*
|
|
|
|
* @param aScript Debugger.Script
|
|
|
|
* The source script that has been loaded into a debuggee compartment.
|
2012-03-30 08:25:52 +00:00
|
|
|
* @param aGlobal Debugger.Object
|
|
|
|
* A Debugger.Object instance whose referent is the global object.
|
2012-01-23 08:29:15 +00:00
|
|
|
*/
|
2012-03-30 08:25:52 +00:00
|
|
|
onNewScript: function TA_onNewScript(aScript, aGlobal) {
|
2013-03-11 22:35:00 +00:00
|
|
|
this._addScript(aScript);
|
2013-06-20 17:43:30 +00:00
|
|
|
this.sources.sourcesForScript(aScript);
|
2012-03-30 08:25:52 +00:00
|
|
|
},
|
|
|
|
|
2013-04-15 21:07:00 +00:00
|
|
|
onNewSource: function TA_onNewSource(aSource) {
|
|
|
|
this.conn.send({
|
|
|
|
from: this.actorID,
|
|
|
|
type: "newSource",
|
|
|
|
source: aSource.form()
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-03-30 08:25:52 +00:00
|
|
|
/**
|
2013-02-28 12:02:00 +00:00
|
|
|
* Check if scripts from the provided source URL are allowed to be stored in
|
|
|
|
* the cache.
|
2012-03-30 08:25:52 +00:00
|
|
|
*
|
2013-02-28 12:02:00 +00:00
|
|
|
* @param aSourceUrl String
|
|
|
|
* The url of the script's source that will be stored.
|
2012-10-31 16:31:55 +00:00
|
|
|
* @returns true, if the script can be added, false otherwise.
|
2012-03-30 08:25:52 +00:00
|
|
|
*/
|
2013-04-15 21:07:00 +00:00
|
|
|
_allowSource: function TA__allowSource(aSourceUrl) {
|
2012-10-19 16:53:00 +00:00
|
|
|
// Ignore anything we don't have a URL for (eval scripts, for example).
|
2013-02-28 12:02:00 +00:00
|
|
|
if (!aSourceUrl)
|
2012-10-19 16:53:00 +00:00
|
|
|
return false;
|
2012-06-10 23:44:50 +00:00
|
|
|
// Ignore XBL bindings for content debugging.
|
2013-02-28 12:02:00 +00:00
|
|
|
if (aSourceUrl.indexOf("chrome://") == 0) {
|
2012-08-22 08:11:07 +00:00
|
|
|
return false;
|
2012-06-10 23:44:50 +00:00
|
|
|
}
|
2012-07-15 06:50:41 +00:00
|
|
|
// Ignore about:* pages for content debugging.
|
2013-02-28 12:02:00 +00:00
|
|
|
if (aSourceUrl.indexOf("about:") == 0) {
|
2012-08-22 08:11:07 +00:00
|
|
|
return false;
|
2012-07-15 06:50:41 +00:00
|
|
|
}
|
2012-10-31 16:31:55 +00:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2013-06-11 07:58:57 +00:00
|
|
|
/**
|
2013-06-20 17:43:30 +00:00
|
|
|
* Restore any pre-existing breakpoints to the scripts that we have access to.
|
|
|
|
*/
|
|
|
|
_restoreBreakpoints: function TA__restoreBreakpoints() {
|
|
|
|
for (let s of this.dbg.findScripts()) {
|
|
|
|
this._addScript(s);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the provided script to the server cache.
|
2013-06-11 07:58:57 +00:00
|
|
|
*
|
|
|
|
* @param aScript Debugger.Script
|
|
|
|
* The source script that will be stored.
|
|
|
|
* @returns true, if the script was added; false otherwise.
|
|
|
|
*/
|
2013-06-20 17:43:30 +00:00
|
|
|
_addScript: function TA__addScript(aScript) {
|
2013-06-11 07:58:57 +00:00
|
|
|
if (!this._allowSource(aScript.url)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set any stored breakpoints.
|
2013-07-25 00:46:49 +00:00
|
|
|
|
|
|
|
let endLine = aScript.startLine + aScript.lineCount - 1;
|
|
|
|
for (let bp of this.breakpointStore.findBreakpoints({ url: aScript.url })) {
|
|
|
|
// Only consider breakpoints that are not already associated with
|
|
|
|
// scripts, and limit search to the line numbers contained in the new
|
|
|
|
// script.
|
|
|
|
if (!bp.actor.scripts.length
|
|
|
|
&& bp.line >= aScript.startLine
|
|
|
|
&& bp.line <= endLine) {
|
|
|
|
this._setBreakpoint(bp);
|
2013-06-11 07:58:57 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-25 00:46:49 +00:00
|
|
|
|
2013-06-11 07:58:57 +00:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2013-08-20 12:32:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get prototypes and properties of multiple objects.
|
|
|
|
*/
|
|
|
|
onPrototypesAndProperties: function TA_onPrototypesAndProperties(aRequest) {
|
|
|
|
let result = {};
|
|
|
|
for (let actorID of aRequest.actors) {
|
|
|
|
// This code assumes that there are no lazily loaded actors returned
|
|
|
|
// by this call.
|
|
|
|
let actor = this.conn.getActor(actorID);
|
|
|
|
if (!actor) {
|
|
|
|
return { from: this.actorID,
|
|
|
|
error: "noSuchActor" };
|
|
|
|
}
|
|
|
|
let handler = actor.onPrototypeAndProperties;
|
|
|
|
if (!handler) {
|
|
|
|
return { from: this.actorID,
|
|
|
|
error: "unrecognizedPacketType",
|
|
|
|
message: ('Actor "' + actorID +
|
|
|
|
'" does not recognize the packet type ' +
|
|
|
|
'"prototypeAndProperties"') };
|
|
|
|
}
|
|
|
|
result[actorID] = handler.call(actor, {});
|
|
|
|
}
|
|
|
|
return { from: this.actorID,
|
|
|
|
actors: result };
|
|
|
|
}
|
|
|
|
|
2012-02-07 17:22:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ThreadActor.prototype.requestTypes = {
|
|
|
|
"attach": ThreadActor.prototype.onAttach,
|
|
|
|
"detach": ThreadActor.prototype.onDetach,
|
2013-04-16 15:00:33 +00:00
|
|
|
"reconfigure": ThreadActor.prototype.onReconfigure,
|
2012-02-07 17:22:30 +00:00
|
|
|
"resume": ThreadActor.prototype.onResume,
|
|
|
|
"clientEvaluate": ThreadActor.prototype.onClientEvaluate,
|
|
|
|
"frames": ThreadActor.prototype.onFrames,
|
2012-02-10 07:46:10 +00:00
|
|
|
"interrupt": ThreadActor.prototype.onInterrupt,
|
2013-07-18 11:14:16 +00:00
|
|
|
"eventListeners": ThreadActor.prototype.onEventListeners,
|
2012-02-07 17:22:30 +00:00
|
|
|
"releaseMany": ThreadActor.prototype.onReleaseMany,
|
|
|
|
"setBreakpoint": ThreadActor.prototype.onSetBreakpoint,
|
2013-02-28 12:02:00 +00:00
|
|
|
"sources": ThreadActor.prototype.onSources,
|
2013-08-20 12:32:04 +00:00
|
|
|
"threadGrips": ThreadActor.prototype.onThreadGrips,
|
|
|
|
"prototypesAndProperties": ThreadActor.prototype.onPrototypesAndProperties
|
2012-02-07 17:22:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a PauseActor.
|
|
|
|
*
|
|
|
|
* PauseActors exist for the lifetime of a given debuggee pause. Used to
|
|
|
|
* scope pause-lifetime grips.
|
|
|
|
*
|
|
|
|
* @param ActorPool aPool
|
|
|
|
* The actor pool created for this pause.
|
|
|
|
*/
|
|
|
|
function PauseActor(aPool)
|
|
|
|
{
|
|
|
|
this.pool = aPool;
|
|
|
|
}
|
|
|
|
|
|
|
|
PauseActor.prototype = {
|
|
|
|
actorPrefix: "pause"
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-08-30 21:10:07 +00:00
|
|
|
/**
|
|
|
|
* A base actor for any actors that should only respond receive messages in the
|
|
|
|
* paused state. Subclasses may expose a `threadActor` which is used to help
|
|
|
|
* determine when we are in a paused state. Subclasses should set their own
|
|
|
|
* "constructor" property if they want better error messages. You should never
|
|
|
|
* instantiate a PauseScopedActor directly, only through subclasses.
|
|
|
|
*/
|
|
|
|
function PauseScopedActor()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A function decorator for creating methods to handle protocol messages that
|
|
|
|
* should only be received while in the paused state.
|
|
|
|
*
|
|
|
|
* @param aMethod Function
|
|
|
|
* The function we are decorating.
|
|
|
|
*/
|
|
|
|
PauseScopedActor.withPaused = function PSA_withPaused(aMethod) {
|
|
|
|
return function () {
|
|
|
|
if (this.isPaused()) {
|
|
|
|
return aMethod.apply(this, arguments);
|
|
|
|
} else {
|
|
|
|
return this._wrongState();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
PauseScopedActor.prototype = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if we are in the paused state.
|
|
|
|
*/
|
|
|
|
isPaused: function PSA_isPaused() {
|
|
|
|
// When there is not a ThreadActor available (like in the webconsole) we
|
|
|
|
// have to be optimistic and assume that we are paused so that we can
|
|
|
|
// respond to requests.
|
|
|
|
return this.threadActor ? this.threadActor.state === "paused" : true;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the wrongState response packet for this actor.
|
|
|
|
*/
|
|
|
|
_wrongState: function PSA_wrongState() {
|
|
|
|
return {
|
|
|
|
error: "wrongState",
|
|
|
|
message: this.constructor.name +
|
|
|
|
" actors can only be accessed while the thread is paused."
|
2013-04-15 21:07:00 +00:00
|
|
|
};
|
2012-08-30 21:10:07 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-09-27 08:30:00 +00:00
|
|
|
/**
|
|
|
|
* A SourceActor provides information about the source of a script.
|
|
|
|
*
|
2013-02-28 12:02:00 +00:00
|
|
|
* @param aUrl String
|
|
|
|
* The url of the source we are representing.
|
2012-09-27 08:30:00 +00:00
|
|
|
* @param aThreadActor ThreadActor
|
|
|
|
* The current thread actor.
|
2013-05-13 11:53:00 +00:00
|
|
|
* @param aSourceMap SourceMapConsumer
|
|
|
|
* Optional. The source map that introduced this source, if available.
|
2013-09-11 17:15:51 +00:00
|
|
|
* @param aGeneratedSource String
|
|
|
|
* Optional, passed in when aSourceMap is also passed in. The generated
|
|
|
|
* source url that introduced this source.
|
2012-09-27 08:30:00 +00:00
|
|
|
*/
|
2013-09-11 17:15:51 +00:00
|
|
|
function SourceActor(aUrl, aThreadActor, aSourceMap=null, aGeneratedSource=null) {
|
2012-09-27 08:30:00 +00:00
|
|
|
this._threadActor = aThreadActor;
|
2013-02-28 12:02:00 +00:00
|
|
|
this._url = aUrl;
|
2013-05-13 11:53:00 +00:00
|
|
|
this._sourceMap = aSourceMap;
|
2013-09-11 17:15:51 +00:00
|
|
|
this._generatedSource = aGeneratedSource;
|
|
|
|
|
|
|
|
this.onSource = this.onSource.bind(this);
|
|
|
|
this._invertSourceMap = this._invertSourceMap.bind(this);
|
|
|
|
this._saveMap = this._saveMap.bind(this);
|
2012-09-27 08:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SourceActor.prototype = {
|
|
|
|
constructor: SourceActor,
|
|
|
|
actorPrefix: "source",
|
|
|
|
|
2013-04-15 21:07:00 +00:00
|
|
|
get threadActor() this._threadActor,
|
|
|
|
get url() this._url,
|
2012-09-27 08:30:00 +00:00
|
|
|
|
2013-02-28 12:02:00 +00:00
|
|
|
form: function SA_form() {
|
|
|
|
return {
|
|
|
|
actor: this.actorID,
|
2013-06-11 14:23:00 +00:00
|
|
|
url: this._url,
|
|
|
|
isBlackBoxed: this.threadActor.sources.isBlackBoxed(this.url)
|
2013-02-28 12:02:00 +00:00
|
|
|
// TODO bug 637572: introductionScript
|
|
|
|
};
|
2012-09-27 08:30:00 +00:00
|
|
|
},
|
|
|
|
|
2013-09-11 17:15:51 +00:00
|
|
|
disconnect: function SA_disconnect() {
|
2012-09-27 08:30:00 +00:00
|
|
|
if (this.registeredPool && this.registeredPool.sourceActors) {
|
|
|
|
delete this.registeredPool.sourceActors[this.actorID];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-09-11 17:15:51 +00:00
|
|
|
_getSourceText: function SA__getSourceText() {
|
2013-05-13 11:53:00 +00:00
|
|
|
let sourceContent = null;
|
|
|
|
if (this._sourceMap) {
|
|
|
|
sourceContent = this._sourceMap.sourceContentFor(this._url);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sourceContent) {
|
2013-09-11 17:15:51 +00:00
|
|
|
return resolve({
|
|
|
|
content: sourceContent
|
|
|
|
});
|
2013-05-13 11:16:00 +00:00
|
|
|
}
|
|
|
|
|
2013-05-13 11:53:00 +00:00
|
|
|
// XXX bug 865252: Don't load from the cache if this is a source mapped
|
|
|
|
// source because we can't guarantee that the cache has the most up to date
|
|
|
|
// content for this source like we can if it isn't source mapped.
|
2013-09-11 17:15:51 +00:00
|
|
|
return fetch(this._url, { loadFromCache: !this._sourceMap });
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for the "source" packet.
|
|
|
|
*/
|
|
|
|
onSource: function SA_onSource(aRequest) {
|
|
|
|
return this._getSourceText()
|
2013-08-23 22:04:03 +00:00
|
|
|
.then(({ content, contentType }) => {
|
2012-09-27 08:30:00 +00:00
|
|
|
return {
|
|
|
|
from: this.actorID,
|
2013-08-23 22:04:03 +00:00
|
|
|
source: this.threadActor.createValueGrip(
|
|
|
|
content, this.threadActor.threadLifetimePool),
|
|
|
|
contentType: contentType
|
2012-09-27 08:30:00 +00:00
|
|
|
};
|
2013-08-23 22:04:03 +00:00
|
|
|
})
|
|
|
|
.then(null, (aError) => {
|
2013-07-03 21:10:52 +00:00
|
|
|
reportError(aError, "Got an exception during SA_onSource: ");
|
2012-09-27 08:30:00 +00:00
|
|
|
return {
|
|
|
|
"from": this.actorID,
|
|
|
|
"error": "loadSourceError",
|
2013-08-23 22:04:03 +00:00
|
|
|
"message": "Could not load the source for " + this._url + ".\n"
|
|
|
|
+ safeErrorString(aError)
|
2012-09-27 08:30:00 +00:00
|
|
|
};
|
2013-05-13 11:53:00 +00:00
|
|
|
});
|
2013-06-11 14:23:00 +00:00
|
|
|
},
|
|
|
|
|
2013-09-11 17:15:51 +00:00
|
|
|
/**
|
|
|
|
* Handler for the "prettyPrint" packet.
|
|
|
|
*/
|
|
|
|
onPrettyPrint: function ({ indent }) {
|
|
|
|
return this._getSourceText()
|
|
|
|
.then(this._parseAST)
|
|
|
|
.then(this._generatePrettyCodeAndMap(indent))
|
|
|
|
.then(this._invertSourceMap)
|
|
|
|
.then(this._saveMap)
|
|
|
|
.then(this.onSource)
|
|
|
|
.then(null, error => ({
|
|
|
|
from: this.actorID,
|
|
|
|
error: "prettyPrintError",
|
|
|
|
message: DevToolsUtils.safeErrorString(error)
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse the source content into an AST.
|
|
|
|
*/
|
|
|
|
_parseAST: function SA__parseAST({ content}) {
|
|
|
|
return Reflect.parse(content);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Take the number of spaces to indent and return a function that takes an AST
|
|
|
|
* and generates code and a source map from the ugly code to the pretty code.
|
|
|
|
*/
|
|
|
|
_generatePrettyCodeAndMap: function SA__generatePrettyCodeAndMap(aNumSpaces) {
|
|
|
|
let indent = "";
|
|
|
|
for (let i = 0; i < aNumSpaces; i++) {
|
|
|
|
indent += " ";
|
|
|
|
}
|
|
|
|
return aAST => escodegen.generate(aAST, {
|
|
|
|
format: {
|
|
|
|
indent: {
|
|
|
|
style: indent
|
|
|
|
}
|
|
|
|
},
|
|
|
|
sourceMap: this._url,
|
|
|
|
sourceMapWithCode: true
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invert a source map. So if a source map maps from a to b, return a new
|
|
|
|
* source map from b to a. We need to do this because the source map we get
|
|
|
|
* from _generatePrettyCodeAndMap goes the opposite way we want it to for
|
|
|
|
* debugging.
|
|
|
|
*/
|
|
|
|
_invertSourceMap: function SA__invertSourceMap({ code, map }) {
|
|
|
|
const smc = new SourceMapConsumer(map.toJSON());
|
|
|
|
const invertedMap = new SourceMapGenerator({
|
|
|
|
file: this._url
|
|
|
|
});
|
|
|
|
|
|
|
|
smc.eachMapping(m => {
|
|
|
|
if (!m.originalLine || !m.originalColumn) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const invertedMapping = {
|
|
|
|
source: m.source,
|
|
|
|
name: m.name,
|
|
|
|
original: {
|
|
|
|
line: m.generatedLine,
|
|
|
|
column: m.generatedColumn
|
|
|
|
},
|
|
|
|
generated: {
|
|
|
|
line: m.originalLine,
|
|
|
|
column: m.originalColumn
|
|
|
|
}
|
|
|
|
};
|
|
|
|
invertedMap.addMapping(invertedMapping);
|
|
|
|
});
|
|
|
|
|
|
|
|
invertedMap.setSourceContent(this._url, code);
|
|
|
|
|
|
|
|
return {
|
|
|
|
code: code,
|
|
|
|
map: new SourceMapConsumer(invertedMap.toJSON())
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save the source map back to our thread's ThreadSources object so that
|
|
|
|
* stepping, breakpoints, debugger statements, etc can use it. If we are
|
|
|
|
* pretty printing a source mapped source, we need to compose the existing
|
|
|
|
* source map with our new one.
|
|
|
|
*/
|
|
|
|
_saveMap: function SA__saveMap({ map }) {
|
|
|
|
if (this._sourceMap) {
|
|
|
|
// Compose the source maps
|
|
|
|
this._sourceMap = SourceMapGenerator.fromSourceMap(this._sourceMap);
|
|
|
|
this._sourceMap.applySourceMap(map, this._url);
|
|
|
|
this._sourceMap = new SourceMapConsumer(this._sourceMap.toJSON());
|
|
|
|
this._threadActor.sources.saveSourceMap(this._sourceMap,
|
|
|
|
this._generatedSource);
|
|
|
|
} else {
|
|
|
|
this._sourceMap = map;
|
|
|
|
this._threadActor.sources.saveSourceMap(this._sourceMap, this._url);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-06-11 14:23:00 +00:00
|
|
|
/**
|
|
|
|
* Handler for the "blackbox" packet.
|
|
|
|
*/
|
|
|
|
onBlackBox: function SA_onBlackBox(aRequest) {
|
|
|
|
this.threadActor.sources.blackBox(this.url);
|
|
|
|
let packet = {
|
|
|
|
from: this.actorID
|
|
|
|
};
|
|
|
|
if (this.threadActor.state == "paused"
|
|
|
|
&& this.threadActor.youngestFrame
|
|
|
|
&& this.threadActor.youngestFrame.script.url == this.url) {
|
|
|
|
packet.pausedInSource = true;
|
|
|
|
}
|
|
|
|
return packet;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for the "unblackbox" packet.
|
|
|
|
*/
|
|
|
|
onUnblackBox: function SA_onUnblackBox(aRequest) {
|
|
|
|
this.threadActor.sources.unblackBox(this.url);
|
|
|
|
return {
|
|
|
|
from: this.actorID
|
|
|
|
};
|
2012-09-27 08:30:00 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
SourceActor.prototype.requestTypes = {
|
2013-06-11 14:23:00 +00:00
|
|
|
"source": SourceActor.prototype.onSource,
|
|
|
|
"blackbox": SourceActor.prototype.onBlackBox,
|
2013-09-11 17:15:51 +00:00
|
|
|
"unblackbox": SourceActor.prototype.onUnblackBox,
|
|
|
|
"prettyPrint": SourceActor.prototype.onPrettyPrint
|
2012-09-27 08:30:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-01-23 08:29:15 +00:00
|
|
|
/**
|
|
|
|
* Creates an actor for the specified object.
|
|
|
|
*
|
|
|
|
* @param aObj Debugger.Object
|
|
|
|
* The debuggee object.
|
|
|
|
* @param aThreadActor ThreadActor
|
|
|
|
* The parent thread actor for this object.
|
|
|
|
*/
|
2012-02-07 17:22:30 +00:00
|
|
|
function ObjectActor(aObj, aThreadActor)
|
|
|
|
{
|
|
|
|
this.obj = aObj;
|
|
|
|
this.threadActor = aThreadActor;
|
|
|
|
}
|
|
|
|
|
2013-03-30 11:31:10 +00:00
|
|
|
ObjectActor.prototype = {
|
2012-08-30 21:10:07 +00:00
|
|
|
actorPrefix: "obj",
|
2012-02-07 17:22:30 +00:00
|
|
|
|
2012-01-23 08:29:15 +00:00
|
|
|
/**
|
|
|
|
* Returns a grip for this actor for returning in a protocol message.
|
|
|
|
*/
|
2012-02-07 17:22:30 +00:00
|
|
|
grip: function OA_grip() {
|
2013-05-29 16:47:00 +00:00
|
|
|
let g = {
|
|
|
|
"type": "object",
|
|
|
|
"class": this.obj.class,
|
|
|
|
"actor": this.actorID,
|
|
|
|
"extensible": this.obj.isExtensible(),
|
|
|
|
"frozen": this.obj.isFrozen(),
|
|
|
|
"sealed": this.obj.isSealed()
|
|
|
|
};
|
2012-12-14 18:26:47 +00:00
|
|
|
|
|
|
|
// Add additional properties for functions.
|
|
|
|
if (this.obj.class === "Function") {
|
|
|
|
if (this.obj.name) {
|
|
|
|
g.name = this.obj.name;
|
2013-09-12 16:54:56 +00:00
|
|
|
}
|
|
|
|
if (this.obj.displayName) {
|
2012-12-14 18:26:47 +00:00
|
|
|
g.displayName = this.obj.displayName;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the developer has added a de-facto standard displayName
|
|
|
|
// property for us to use.
|
|
|
|
let desc = this.obj.getOwnPropertyDescriptor("displayName");
|
|
|
|
if (desc && desc.value && typeof desc.value == "string") {
|
|
|
|
g.userDisplayName = this.threadActor.createValueGrip(desc.value);
|
|
|
|
}
|
2013-07-18 11:14:16 +00:00
|
|
|
|
|
|
|
// Add source location information.
|
|
|
|
if (this.obj.script) {
|
|
|
|
g.url = this.obj.script.url;
|
|
|
|
g.line = this.obj.script.startLine;
|
|
|
|
}
|
2012-12-14 18:26:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return g;
|
2012-02-07 17:22:30 +00:00
|
|
|
},
|
|
|
|
|
2012-01-23 08:29:15 +00:00
|
|
|
/**
|
|
|
|
* Releases this actor from the pool.
|
|
|
|
*/
|
2012-02-07 17:22:30 +00:00
|
|
|
release: function OA_release() {
|
2013-03-30 11:31:10 +00:00
|
|
|
if (this.registeredPool.objectActors) {
|
|
|
|
this.registeredPool.objectActors.delete(this.obj);
|
|
|
|
}
|
2012-10-12 08:26:49 +00:00
|
|
|
this.registeredPool.removeActor(this);
|
2012-02-07 17:22:30 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a protocol request to provide the names of the properties defined on
|
|
|
|
* the object and not its prototype.
|
2012-01-23 08:29:15 +00:00
|
|
|
*
|
|
|
|
* @param aRequest object
|
|
|
|
* The protocol request object.
|
2012-02-07 17:22:30 +00:00
|
|
|
*/
|
2013-03-30 11:31:10 +00:00
|
|
|
onOwnPropertyNames: function OA_onOwnPropertyNames(aRequest) {
|
2012-02-07 17:22:30 +00:00
|
|
|
return { from: this.actorID,
|
|
|
|
ownPropertyNames: this.obj.getOwnPropertyNames() };
|
2013-03-30 11:31:10 +00:00
|
|
|
},
|
2012-02-07 17:22:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a protocol request to provide the prototype and own properties of
|
|
|
|
* the object.
|
2012-01-23 08:29:15 +00:00
|
|
|
*
|
|
|
|
* @param aRequest object
|
|
|
|
* The protocol request object.
|
2012-02-07 17:22:30 +00:00
|
|
|
*/
|
2013-03-30 11:31:10 +00:00
|
|
|
onPrototypeAndProperties: function OA_onPrototypeAndProperties(aRequest) {
|
2013-05-11 09:05:21 +00:00
|
|
|
let ownProperties = Object.create(null);
|
2013-06-21 17:40:00 +00:00
|
|
|
let names;
|
|
|
|
try {
|
|
|
|
names = this.obj.getOwnPropertyNames();
|
|
|
|
} catch (ex) {
|
|
|
|
// The above can throw if this.obj points to a dead object.
|
|
|
|
// TODO: we should use Cu.isDeadWrapper() - see bug 885800.
|
|
|
|
return { from: this.actorID,
|
|
|
|
prototype: this.threadActor.createValueGrip(null),
|
|
|
|
ownProperties: ownProperties,
|
|
|
|
safeGetterValues: Object.create(null) };
|
|
|
|
}
|
|
|
|
for (let name of names) {
|
2013-02-12 08:38:24 +00:00
|
|
|
ownProperties[name] = this._propertyDescriptor(name);
|
|
|
|
}
|
2012-02-07 17:22:30 +00:00
|
|
|
return { from: this.actorID,
|
2012-01-23 08:29:15 +00:00
|
|
|
prototype: this.threadActor.createValueGrip(this.obj.proto),
|
2013-05-11 09:05:21 +00:00
|
|
|
ownProperties: ownProperties,
|
|
|
|
safeGetterValues: this._findSafeGetterValues(ownProperties) };
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find the safe getter values for the current Debugger.Object, |this.obj|.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param object aOwnProperties
|
|
|
|
* The object that holds the list of known ownProperties for
|
|
|
|
* |this.obj|.
|
|
|
|
* @return object
|
|
|
|
* An object that maps property names to safe getter descriptors as
|
|
|
|
* defined by the remote debugging protocol.
|
|
|
|
*/
|
|
|
|
_findSafeGetterValues: function OA__findSafeGetterValues(aOwnProperties)
|
|
|
|
{
|
|
|
|
let safeGetterValues = Object.create(null);
|
|
|
|
let obj = this.obj;
|
|
|
|
let level = 0;
|
|
|
|
|
|
|
|
while (obj) {
|
|
|
|
let getters = this._findSafeGetters(obj);
|
|
|
|
for (let name of getters) {
|
|
|
|
// Avoid overwriting properties from prototypes closer to this.obj. Also
|
|
|
|
// avoid providing safeGetterValues from prototypes if property |name|
|
|
|
|
// is already defined as an own property.
|
|
|
|
if (name in safeGetterValues ||
|
|
|
|
(obj != this.obj && name in aOwnProperties)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
let desc = null, getter = null;
|
|
|
|
try {
|
|
|
|
desc = obj.getOwnPropertyDescriptor(name);
|
|
|
|
getter = desc.get;
|
|
|
|
} catch (ex) {
|
|
|
|
// The above can throw if the cache becomes stale.
|
|
|
|
}
|
|
|
|
if (!getter) {
|
|
|
|
obj._safeGetters = null;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
let result = getter.call(this.obj);
|
|
|
|
if (result && !("throw" in result)) {
|
|
|
|
let getterValue = undefined;
|
|
|
|
if ("return" in result) {
|
|
|
|
getterValue = result.return;
|
|
|
|
} else if ("yield" in result) {
|
|
|
|
getterValue = result.yield;
|
|
|
|
}
|
2013-05-16 15:42:15 +00:00
|
|
|
// WebIDL attributes specified with the LenientThis extended attribute
|
|
|
|
// return undefined and should be ignored.
|
|
|
|
if (getterValue !== undefined) {
|
|
|
|
safeGetterValues[name] = {
|
|
|
|
getterValue: this.threadActor.createValueGrip(getterValue),
|
|
|
|
getterPrototypeLevel: level,
|
|
|
|
enumerable: desc.enumerable,
|
|
|
|
writable: level == 0 ? desc.writable : true,
|
|
|
|
};
|
|
|
|
}
|
2013-05-11 09:05:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
obj = obj.proto;
|
|
|
|
level++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return safeGetterValues;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find the safe getters for a given Debugger.Object. Safe getters are native
|
|
|
|
* getters which are safe to execute.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param Debugger.Object aObject
|
|
|
|
* The Debugger.Object where you want to find safe getters.
|
|
|
|
* @return Set
|
|
|
|
* A Set of names of safe getters. This result is cached for each
|
|
|
|
* Debugger.Object.
|
|
|
|
*/
|
|
|
|
_findSafeGetters: function OA__findSafeGetters(aObject)
|
|
|
|
{
|
|
|
|
if (aObject._safeGetters) {
|
|
|
|
return aObject._safeGetters;
|
|
|
|
}
|
|
|
|
|
|
|
|
let getters = new Set();
|
|
|
|
for (let name of aObject.getOwnPropertyNames()) {
|
|
|
|
let desc = null;
|
|
|
|
try {
|
|
|
|
desc = aObject.getOwnPropertyDescriptor(name);
|
|
|
|
} catch (e) {
|
|
|
|
// Calling getOwnPropertyDescriptor on wrapped native prototypes is not
|
|
|
|
// allowed (bug 560072).
|
|
|
|
}
|
|
|
|
if (!desc || desc.value !== undefined || !("get" in desc)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
let fn = desc.get;
|
|
|
|
if (fn && fn.callable && fn.class == "Function" &&
|
|
|
|
fn.script === undefined) {
|
|
|
|
getters.add(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aObject._safeGetters = getters;
|
|
|
|
return getters;
|
2013-03-30 11:31:10 +00:00
|
|
|
},
|
2012-02-07 17:22:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a protocol request to provide the prototype of the object.
|
2012-01-23 08:29:15 +00:00
|
|
|
*
|
|
|
|
* @param aRequest object
|
|
|
|
* The protocol request object.
|
2012-02-07 17:22:30 +00:00
|
|
|
*/
|
2013-03-30 11:31:10 +00:00
|
|
|
onPrototype: function OA_onPrototype(aRequest) {
|
2012-02-07 17:22:30 +00:00
|
|
|
return { from: this.actorID,
|
2012-01-23 08:29:15 +00:00
|
|
|
prototype: this.threadActor.createValueGrip(this.obj.proto) };
|
2013-03-30 11:31:10 +00:00
|
|
|
},
|
2012-02-07 17:22:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a protocol request to provide the property descriptor of the
|
|
|
|
* object's specified property.
|
2012-01-23 08:29:15 +00:00
|
|
|
*
|
|
|
|
* @param aRequest object
|
|
|
|
* The protocol request object.
|
2012-02-07 17:22:30 +00:00
|
|
|
*/
|
2013-03-30 11:31:10 +00:00
|
|
|
onProperty: function OA_onProperty(aRequest) {
|
2012-02-07 17:22:30 +00:00
|
|
|
if (!aRequest.name) {
|
2012-03-13 07:13:02 +00:00
|
|
|
return { error: "missingParameter",
|
2012-02-07 17:22:30 +00:00
|
|
|
message: "no property name was specified" };
|
|
|
|
}
|
|
|
|
|
|
|
|
return { from: this.actorID,
|
2013-02-12 08:38:24 +00:00
|
|
|
descriptor: this._propertyDescriptor(aRequest.name) };
|
2013-03-30 11:31:10 +00:00
|
|
|
},
|
2012-02-07 17:22:30 +00:00
|
|
|
|
2013-07-23 16:58:27 +00:00
|
|
|
/**
|
|
|
|
* Handle a protocol request to provide the display string for the object.
|
|
|
|
*
|
|
|
|
* @param aRequest object
|
|
|
|
* The protocol request object.
|
|
|
|
*/
|
|
|
|
onDisplayString: function OA_onDisplayString(aRequest) {
|
|
|
|
let toString;
|
|
|
|
try {
|
|
|
|
// Attempt to locate the object's "toString" method.
|
|
|
|
let obj = this.obj;
|
|
|
|
do {
|
|
|
|
let desc = obj.getOwnPropertyDescriptor("toString");
|
|
|
|
if (desc) {
|
|
|
|
toString = desc.value;
|
|
|
|
break;
|
|
|
|
}
|
2013-08-08 16:28:15 +00:00
|
|
|
obj = obj.proto;
|
|
|
|
} while ((obj));
|
2013-07-23 16:58:27 +00:00
|
|
|
} catch (e) {
|
|
|
|
dumpn(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
let result = null;
|
|
|
|
if (toString && toString.callable) {
|
|
|
|
// If a toString method was found then call it on the object.
|
|
|
|
let ret = toString.call(this.obj).return;
|
|
|
|
if (typeof ret == "string") {
|
|
|
|
// Only use the result if it was a returned string.
|
|
|
|
result = ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return { from: this.actorID,
|
|
|
|
displayString: this.threadActor.createValueGrip(result) };
|
|
|
|
},
|
|
|
|
|
2012-02-07 17:22:30 +00:00
|
|
|
/**
|
2012-01-23 08:29:15 +00:00
|
|
|
* A helper method that creates a property descriptor for the provided object,
|
|
|
|
* properly formatted for sending in a protocol response.
|
|
|
|
*
|
2013-02-12 08:38:24 +00:00
|
|
|
* @param string aName
|
|
|
|
* The property that the descriptor is generated for.
|
2012-02-07 17:22:30 +00:00
|
|
|
*/
|
2013-02-12 08:38:24 +00:00
|
|
|
_propertyDescriptor: function OA_propertyDescriptor(aName) {
|
|
|
|
let desc;
|
|
|
|
try {
|
|
|
|
desc = this.obj.getOwnPropertyDescriptor(aName);
|
|
|
|
} catch (e) {
|
|
|
|
// Calling getOwnPropertyDescriptor on wrapped native prototypes is not
|
|
|
|
// allowed (bug 560072). Inform the user with a bogus, but hopefully
|
|
|
|
// explanatory, descriptor.
|
|
|
|
return {
|
|
|
|
configurable: false,
|
|
|
|
writable: false,
|
|
|
|
enumerable: false,
|
|
|
|
value: e.name
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-07-23 16:58:27 +00:00
|
|
|
if (!desc) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2013-02-12 08:38:24 +00:00
|
|
|
let retval = {
|
|
|
|
configurable: desc.configurable,
|
|
|
|
enumerable: desc.enumerable
|
|
|
|
};
|
|
|
|
|
2013-06-21 14:33:57 +00:00
|
|
|
if ("value" in desc) {
|
2013-02-12 08:38:24 +00:00
|
|
|
retval.writable = desc.writable;
|
|
|
|
retval.value = this.threadActor.createValueGrip(desc.value);
|
2012-02-07 17:22:30 +00:00
|
|
|
} else {
|
2013-02-12 08:38:24 +00:00
|
|
|
if ("get" in desc) {
|
2013-05-11 09:05:21 +00:00
|
|
|
retval.get = this.threadActor.createValueGrip(desc.get);
|
2013-02-12 08:38:24 +00:00
|
|
|
}
|
2013-05-11 09:05:21 +00:00
|
|
|
if ("set" in desc) {
|
2013-02-12 08:38:24 +00:00
|
|
|
retval.set = this.threadActor.createValueGrip(desc.set);
|
|
|
|
}
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
2013-02-12 08:38:24 +00:00
|
|
|
return retval;
|
2012-02-07 17:22:30 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a protocol request to provide the source code of a function.
|
2012-01-23 08:29:15 +00:00
|
|
|
*
|
|
|
|
* @param aRequest object
|
|
|
|
* The protocol request object.
|
2012-02-07 17:22:30 +00:00
|
|
|
*/
|
2013-03-30 11:31:10 +00:00
|
|
|
onDecompile: function OA_onDecompile(aRequest) {
|
2012-03-13 07:13:02 +00:00
|
|
|
if (this.obj.class !== "Function") {
|
|
|
|
return { error: "objectNotFunction",
|
2012-02-07 17:22:30 +00:00
|
|
|
message: "decompile request is only valid for object grips " +
|
|
|
|
"with a 'Function' class." };
|
|
|
|
}
|
|
|
|
|
|
|
|
return { from: this.actorID,
|
|
|
|
decompiledCode: this.obj.decompile(!!aRequest.pretty) };
|
2013-03-30 11:31:10 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a protocol request to provide the parameters of a function.
|
|
|
|
*
|
|
|
|
* @param aRequest object
|
|
|
|
* The protocol request object.
|
|
|
|
*/
|
|
|
|
onParameterNames: function OA_onParameterNames(aRequest) {
|
|
|
|
if (this.obj.class !== "Function") {
|
|
|
|
return { error: "objectNotFunction",
|
|
|
|
message: "'parameterNames' request is only valid for object " +
|
|
|
|
"grips with a 'Function' class." };
|
|
|
|
}
|
|
|
|
|
|
|
|
return { parameterNames: this.obj.parameterNames };
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a protocol request to release a thread-lifetime grip.
|
|
|
|
*
|
|
|
|
* @param aRequest object
|
|
|
|
* The protocol request object.
|
|
|
|
*/
|
|
|
|
onRelease: function OA_onRelease(aRequest) {
|
|
|
|
this.release();
|
|
|
|
return {};
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
ObjectActor.prototype.requestTypes = {
|
|
|
|
"parameterNames": ObjectActor.prototype.onParameterNames,
|
|
|
|
"prototypeAndProperties": ObjectActor.prototype.onPrototypeAndProperties,
|
|
|
|
"prototype": ObjectActor.prototype.onPrototype,
|
|
|
|
"property": ObjectActor.prototype.onProperty,
|
2013-07-23 16:58:27 +00:00
|
|
|
"displayString": ObjectActor.prototype.onDisplayString,
|
2013-03-30 11:31:10 +00:00
|
|
|
"ownPropertyNames": ObjectActor.prototype.onOwnPropertyNames,
|
|
|
|
"decompile": ObjectActor.prototype.onDecompile,
|
|
|
|
"release": ObjectActor.prototype.onRelease,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-05-29 16:47:00 +00:00
|
|
|
* Creates a pause-scoped actor for the specified object.
|
2013-03-30 11:31:10 +00:00
|
|
|
* @see ObjectActor
|
|
|
|
*/
|
|
|
|
function PauseScopedObjectActor()
|
|
|
|
{
|
|
|
|
ObjectActor.apply(this, arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
PauseScopedObjectActor.prototype = Object.create(PauseScopedActor.prototype);
|
|
|
|
|
|
|
|
update(PauseScopedObjectActor.prototype, ObjectActor.prototype);
|
|
|
|
|
|
|
|
update(PauseScopedObjectActor.prototype, {
|
|
|
|
constructor: PauseScopedObjectActor,
|
|
|
|
|
|
|
|
onOwnPropertyNames:
|
|
|
|
PauseScopedActor.withPaused(ObjectActor.prototype.onOwnPropertyNames),
|
|
|
|
|
|
|
|
onPrototypeAndProperties:
|
|
|
|
PauseScopedActor.withPaused(ObjectActor.prototype.onPrototypeAndProperties),
|
|
|
|
|
|
|
|
onPrototype: PauseScopedActor.withPaused(ObjectActor.prototype.onPrototype),
|
|
|
|
onProperty: PauseScopedActor.withPaused(ObjectActor.prototype.onProperty),
|
|
|
|
onDecompile: PauseScopedActor.withPaused(ObjectActor.prototype.onDecompile),
|
|
|
|
|
2013-07-23 16:58:27 +00:00
|
|
|
onDisplayString:
|
|
|
|
PauseScopedActor.withPaused(ObjectActor.prototype.onDisplayString),
|
|
|
|
|
2013-03-30 11:31:10 +00:00
|
|
|
onParameterNames:
|
|
|
|
PauseScopedActor.withPaused(ObjectActor.prototype.onParameterNames),
|
2012-02-07 17:22:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a protocol request to provide the lexical scope of a function.
|
2012-01-23 08:29:15 +00:00
|
|
|
*
|
|
|
|
* @param aRequest object
|
|
|
|
* The protocol request object.
|
2012-02-07 17:22:30 +00:00
|
|
|
*/
|
2012-08-30 21:10:07 +00:00
|
|
|
onScope: PauseScopedActor.withPaused(function OA_onScope(aRequest) {
|
2012-03-13 07:13:02 +00:00
|
|
|
if (this.obj.class !== "Function") {
|
|
|
|
return { error: "objectNotFunction",
|
2012-02-07 17:22:30 +00:00
|
|
|
message: "scope request is only valid for object grips with a" +
|
|
|
|
" 'Function' class." };
|
|
|
|
}
|
|
|
|
|
2012-03-21 15:49:23 +00:00
|
|
|
let envActor = this.threadActor.createEnvironmentActor(this.obj.environment,
|
2012-03-13 07:13:02 +00:00
|
|
|
this.registeredPool);
|
|
|
|
if (!envActor) {
|
|
|
|
return { error: "notDebuggee",
|
|
|
|
message: "cannot access the environment of this function." };
|
|
|
|
}
|
2012-02-07 17:22:30 +00:00
|
|
|
|
2013-01-15 00:15:58 +00:00
|
|
|
return { from: this.actorID, scope: envActor.form() };
|
2012-08-30 21:10:07 +00:00
|
|
|
}),
|
2012-02-07 17:22:30 +00:00
|
|
|
|
2012-01-23 08:29:15 +00:00
|
|
|
/**
|
|
|
|
* Handle a protocol request to promote a pause-lifetime grip to a
|
|
|
|
* thread-lifetime grip.
|
|
|
|
*
|
|
|
|
* @param aRequest object
|
|
|
|
* The protocol request object.
|
|
|
|
*/
|
2012-08-30 21:10:07 +00:00
|
|
|
onThreadGrip: PauseScopedActor.withPaused(function OA_onThreadGrip(aRequest) {
|
2012-10-12 08:26:49 +00:00
|
|
|
this.threadActor.threadObjectGrip(this);
|
|
|
|
return {};
|
2012-08-30 21:10:07 +00:00
|
|
|
}),
|
2012-02-07 17:22:30 +00:00
|
|
|
|
2012-01-23 08:29:15 +00:00
|
|
|
/**
|
|
|
|
* Handle a protocol request to release a thread-lifetime grip.
|
|
|
|
*
|
|
|
|
* @param aRequest object
|
|
|
|
* The protocol request object.
|
|
|
|
*/
|
2012-08-30 21:10:07 +00:00
|
|
|
onRelease: PauseScopedActor.withPaused(function OA_onRelease(aRequest) {
|
2012-02-07 17:22:30 +00:00
|
|
|
if (this.registeredPool !== this.threadActor.threadLifetimePool) {
|
2012-03-13 07:13:02 +00:00
|
|
|
return { error: "notReleasable",
|
2012-10-12 08:26:49 +00:00
|
|
|
message: "Only thread-lifetime actors can be released." };
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.release();
|
|
|
|
return {};
|
2012-08-30 21:10:07 +00:00
|
|
|
}),
|
|
|
|
});
|
2012-02-07 17:22:30 +00:00
|
|
|
|
2013-03-30 11:31:10 +00:00
|
|
|
update(PauseScopedObjectActor.prototype.requestTypes, {
|
|
|
|
"scope": PauseScopedObjectActor.prototype.onScope,
|
|
|
|
"threadGrip": PauseScopedObjectActor.prototype.onThreadGrip,
|
|
|
|
});
|
2012-02-07 17:22:30 +00:00
|
|
|
|
|
|
|
|
2012-08-30 21:10:07 +00:00
|
|
|
/**
|
|
|
|
* Creates an actor for the specied "very long" string. "Very long" is specified
|
|
|
|
* at the server's discretion.
|
|
|
|
*
|
|
|
|
* @param aString String
|
|
|
|
* The string.
|
|
|
|
*/
|
|
|
|
function LongStringActor(aString)
|
|
|
|
{
|
|
|
|
this.string = aString;
|
|
|
|
this.stringLength = aString.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
LongStringActor.prototype = {
|
|
|
|
|
|
|
|
actorPrefix: "longString",
|
|
|
|
|
|
|
|
disconnect: function LSA_disconnect() {
|
|
|
|
// Because longStringActors is not a weak map, we won't automatically leave
|
|
|
|
// it so we need to manually leave on disconnect so that we don't leak
|
|
|
|
// memory.
|
|
|
|
if (this.registeredPool && this.registeredPool.longStringActors) {
|
|
|
|
delete this.registeredPool.longStringActors[this.actorID];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a grip for this actor for returning in a protocol message.
|
|
|
|
*/
|
|
|
|
grip: function LSA_grip() {
|
|
|
|
return {
|
|
|
|
"type": "longString",
|
|
|
|
"initial": this.string.substring(
|
|
|
|
0, DebuggerServer.LONG_STRING_INITIAL_LENGTH),
|
|
|
|
"length": this.stringLength,
|
|
|
|
"actor": this.actorID
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a request to extract part of this actor's string.
|
|
|
|
*
|
|
|
|
* @param aRequest object
|
|
|
|
* The protocol request object.
|
|
|
|
*/
|
|
|
|
onSubstring: function LSA_onSubString(aRequest) {
|
|
|
|
return {
|
|
|
|
"from": this.actorID,
|
|
|
|
"substring": this.string.substring(aRequest.start, aRequest.end)
|
|
|
|
};
|
2012-11-05 16:41:59 +00:00
|
|
|
},
|
2012-08-30 21:10:07 +00:00
|
|
|
|
2012-11-05 16:41:59 +00:00
|
|
|
/**
|
|
|
|
* Handle a request to release this LongStringActor instance.
|
|
|
|
*/
|
|
|
|
onRelease: function LSA_onRelease() {
|
|
|
|
// TODO: also check if registeredPool === threadActor.threadLifetimePool
|
|
|
|
// when the web console moves aray from manually releasing pause-scoped
|
|
|
|
// actors.
|
|
|
|
if (this.registeredPool.longStringActors) {
|
|
|
|
delete this.registeredPool.longStringActors[this.actorID];
|
|
|
|
}
|
|
|
|
this.registeredPool.removeActor(this);
|
|
|
|
return {};
|
|
|
|
},
|
2012-08-30 21:10:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
LongStringActor.prototype.requestTypes = {
|
2012-11-05 16:41:59 +00:00
|
|
|
"substring": LongStringActor.prototype.onSubstring,
|
|
|
|
"release": LongStringActor.prototype.onRelease
|
2012-08-30 21:10:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-01-23 08:29:15 +00:00
|
|
|
/**
|
|
|
|
* Creates an actor for the specified stack frame.
|
|
|
|
*
|
|
|
|
* @param aFrame Debugger.Frame
|
|
|
|
* The debuggee frame.
|
|
|
|
* @param aThreadActor ThreadActor
|
|
|
|
* The parent thread actor for this frame.
|
|
|
|
*/
|
2012-02-07 17:22:30 +00:00
|
|
|
function FrameActor(aFrame, aThreadActor)
|
|
|
|
{
|
|
|
|
this.frame = aFrame;
|
|
|
|
this.threadActor = aThreadActor;
|
|
|
|
}
|
|
|
|
|
|
|
|
FrameActor.prototype = {
|
|
|
|
actorPrefix: "frame",
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A pool that contains frame-lifetime objects, like the environment.
|
|
|
|
*/
|
|
|
|
_frameLifetimePool: null,
|
|
|
|
get frameLifetimePool() {
|
|
|
|
if (!this._frameLifetimePool) {
|
|
|
|
this._frameLifetimePool = new ActorPool(this.conn);
|
|
|
|
this.conn.addActorPool(this._frameLifetimePool);
|
|
|
|
}
|
|
|
|
return this._frameLifetimePool;
|
|
|
|
},
|
|
|
|
|
2012-01-23 08:29:15 +00:00
|
|
|
/**
|
|
|
|
* Finalization handler that is called when the actor is being evicted from
|
|
|
|
* the pool.
|
|
|
|
*/
|
2012-02-07 17:22:30 +00:00
|
|
|
disconnect: function FA_disconnect() {
|
|
|
|
this.conn.removeActorPool(this._frameLifetimePool);
|
|
|
|
this._frameLifetimePool = null;
|
|
|
|
},
|
|
|
|
|
2012-01-23 08:29:15 +00:00
|
|
|
/**
|
2012-03-13 07:13:02 +00:00
|
|
|
* Returns a frame form for use in a protocol message.
|
2012-01-23 08:29:15 +00:00
|
|
|
*/
|
2012-03-13 07:13:02 +00:00
|
|
|
form: function FA_form() {
|
|
|
|
let form = { actor: this.actorID,
|
2012-02-07 17:22:30 +00:00
|
|
|
type: this.frame.type };
|
|
|
|
if (this.frame.type === "call") {
|
2012-03-13 07:13:02 +00:00
|
|
|
form.callee = this.threadActor.createValueGrip(this.frame.callee);
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
|
|
|
|
2013-01-15 00:15:58 +00:00
|
|
|
if (this.frame.environment) {
|
|
|
|
let envActor = this.threadActor
|
|
|
|
.createEnvironmentActor(this.frame.environment,
|
|
|
|
this.frameLifetimePool);
|
|
|
|
form.environment = envActor.form();
|
|
|
|
}
|
2012-03-13 07:13:02 +00:00
|
|
|
form.this = this.threadActor.createValueGrip(this.frame.this);
|
|
|
|
form.arguments = this._args();
|
2012-02-11 09:44:20 +00:00
|
|
|
if (this.frame.script) {
|
2013-09-05 23:51:23 +00:00
|
|
|
form.where = getFrameLocation(this.frame);
|
2012-02-11 09:44:20 +00:00
|
|
|
}
|
2012-02-07 17:22:30 +00:00
|
|
|
|
|
|
|
if (!this.frame.older) {
|
2012-03-13 07:13:02 +00:00
|
|
|
form.oldest = true;
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
|
|
|
|
2012-03-13 07:13:02 +00:00
|
|
|
return form;
|
2012-02-07 17:22:30 +00:00
|
|
|
},
|
|
|
|
|
2012-01-23 08:29:15 +00:00
|
|
|
_args: function FA__args() {
|
2012-03-13 07:13:02 +00:00
|
|
|
if (!this.frame.arguments) {
|
2012-02-07 17:22:30 +00:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2012-01-23 08:29:15 +00:00
|
|
|
return [this.threadActor.createValueGrip(arg)
|
2012-03-13 07:13:02 +00:00
|
|
|
for each (arg in this.frame.arguments)];
|
2012-02-07 17:22:30 +00:00
|
|
|
},
|
|
|
|
|
2012-01-23 08:29:15 +00:00
|
|
|
/**
|
|
|
|
* Handle a protocol request to pop this frame from the stack.
|
|
|
|
*
|
|
|
|
* @param aRequest object
|
|
|
|
* The protocol request object.
|
|
|
|
*/
|
2012-02-07 17:22:30 +00:00
|
|
|
onPop: function FA_onPop(aRequest) {
|
2012-03-18 06:50:43 +00:00
|
|
|
// TODO: remove this when Debugger.Frame.prototype.pop is implemented
|
|
|
|
if (typeof this.frame.pop != "function") {
|
|
|
|
return { error: "notImplemented",
|
|
|
|
message: "Popping frames is not yet implemented." };
|
|
|
|
}
|
|
|
|
|
|
|
|
while (this.frame != this.threadActor.dbg.getNewestFrame()) {
|
|
|
|
this.threadActor.dbg.getNewestFrame().pop();
|
|
|
|
}
|
|
|
|
this.frame.pop(aRequest.completionValue);
|
|
|
|
|
|
|
|
// TODO: return the watches property when frame pop watch actors are
|
|
|
|
// implemented.
|
|
|
|
return { from: this.actorID };
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
FrameActor.prototype.requestTypes = {
|
|
|
|
"pop": FrameActor.prototype.onPop,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a BreakpointActor. BreakpointActors exist for the lifetime of their
|
|
|
|
* containing thread and are responsible for deleting breakpoints, handling
|
|
|
|
* breakpoint hits and associating breakpoints with scripts.
|
2012-01-23 08:29:15 +00:00
|
|
|
*
|
2012-02-07 17:22:30 +00:00
|
|
|
* @param ThreadActor aThreadActor
|
|
|
|
* The parent thread actor that contains this breakpoint.
|
2012-06-03 13:39:50 +00:00
|
|
|
* @param object aLocation
|
|
|
|
* The location of the breakpoint as specified in the protocol.
|
2012-02-07 17:22:30 +00:00
|
|
|
*/
|
2012-06-03 13:39:50 +00:00
|
|
|
function BreakpointActor(aThreadActor, aLocation)
|
2012-02-07 17:22:30 +00:00
|
|
|
{
|
2012-06-03 13:39:50 +00:00
|
|
|
this.scripts = [];
|
2012-02-07 17:22:30 +00:00
|
|
|
this.threadActor = aThreadActor;
|
2012-06-03 13:39:50 +00:00
|
|
|
this.location = aLocation;
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BreakpointActor.prototype = {
|
|
|
|
actorPrefix: "breakpoint",
|
|
|
|
|
2012-06-03 13:39:50 +00:00
|
|
|
/**
|
|
|
|
* Called when this same breakpoint is added to another Debugger.Script
|
|
|
|
* instance, in the case of a page reload.
|
|
|
|
*
|
|
|
|
* @param aScript Debugger.Script
|
|
|
|
* The new source script on which the breakpoint has been set.
|
|
|
|
* @param ThreadActor aThreadActor
|
|
|
|
* The parent thread actor that contains this breakpoint.
|
|
|
|
*/
|
|
|
|
addScript: function BA_addScript(aScript, aThreadActor) {
|
|
|
|
this.threadActor = aThreadActor;
|
|
|
|
this.scripts.push(aScript);
|
|
|
|
},
|
|
|
|
|
2013-05-01 15:29:33 +00:00
|
|
|
/**
|
|
|
|
* Remove the breakpoints from associated scripts and clear the script cache.
|
|
|
|
*/
|
|
|
|
removeScripts: function () {
|
|
|
|
for (let script of this.scripts) {
|
|
|
|
script.clearBreakpoint(this);
|
|
|
|
}
|
|
|
|
this.scripts = [];
|
|
|
|
},
|
|
|
|
|
2012-01-23 08:29:15 +00:00
|
|
|
/**
|
|
|
|
* A function that the engine calls when a breakpoint has been hit.
|
|
|
|
*
|
|
|
|
* @param aFrame Debugger.Frame
|
|
|
|
* The stack frame that contained the breakpoint.
|
|
|
|
*/
|
2012-02-07 17:22:30 +00:00
|
|
|
hit: function BA_hit(aFrame) {
|
2013-07-18 09:45:17 +00:00
|
|
|
// Don't pause if we are currently stepping (in or over) or the frame is
|
|
|
|
// black-boxed.
|
2013-08-16 21:59:04 +00:00
|
|
|
let { url } = this.threadActor.synchronize(
|
2013-08-24 05:41:28 +00:00
|
|
|
this.threadActor.sources.getOriginalLocation({
|
|
|
|
url: this.location.url,
|
|
|
|
line: this.location.line,
|
|
|
|
column: this.location.column
|
|
|
|
}));
|
2013-08-16 21:59:04 +00:00
|
|
|
|
|
|
|
if (this.threadActor.sources.isBlackBoxed(url) || aFrame.onStep) {
|
2013-06-11 14:23:00 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2013-07-18 11:14:16 +00:00
|
|
|
let reason = {};
|
|
|
|
if (this.threadActor._hiddenBreakpoints.has(this.actorID)) {
|
|
|
|
reason.type = "pauseOnDOMEvents";
|
|
|
|
} else {
|
|
|
|
reason.type = "breakpoint";
|
|
|
|
// TODO: add the rest of the breakpoints on that line (bug 676602).
|
|
|
|
reason.actors = [ this.actorID ];
|
|
|
|
}
|
2013-07-25 00:46:49 +00:00
|
|
|
return this.threadActor._pauseAndRespond(aFrame, reason);
|
2012-02-07 17:22:30 +00:00
|
|
|
},
|
|
|
|
|
2012-01-23 08:29:15 +00:00
|
|
|
/**
|
|
|
|
* Handle a protocol request to remove this breakpoint.
|
|
|
|
*
|
|
|
|
* @param aRequest object
|
|
|
|
* The protocol request object.
|
|
|
|
*/
|
2012-02-07 17:22:30 +00:00
|
|
|
onDelete: function BA_onDelete(aRequest) {
|
2012-06-03 13:39:50 +00:00
|
|
|
// Remove from the breakpoint store.
|
2013-07-25 00:46:49 +00:00
|
|
|
this.threadActor.breakpointStore.removeBreakpoint(this.location);
|
2012-10-31 16:31:55 +00:00
|
|
|
this.threadActor._hooks.removeFromParentPool(this);
|
2013-05-01 15:29:33 +00:00
|
|
|
// Remove the actual breakpoint from the associated scripts.
|
|
|
|
this.removeScripts();
|
2012-02-07 17:22:30 +00:00
|
|
|
return { from: this.actorID };
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
BreakpointActor.prototype.requestTypes = {
|
|
|
|
"delete": BreakpointActor.prototype.onDelete
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an EnvironmentActor. EnvironmentActors are responsible for listing
|
|
|
|
* the bindings introduced by a lexical environment and assigning new values to
|
|
|
|
* those identifier bindings.
|
2012-01-23 08:29:15 +00:00
|
|
|
*
|
2012-03-21 15:49:23 +00:00
|
|
|
* @param Debugger.Environment aEnvironment
|
|
|
|
* The lexical environment that will be used to create the actor.
|
2012-02-07 17:22:30 +00:00
|
|
|
* @param ThreadActor aThreadActor
|
|
|
|
* The parent thread actor that contains this environment.
|
|
|
|
*/
|
2012-03-21 15:49:23 +00:00
|
|
|
function EnvironmentActor(aEnvironment, aThreadActor)
|
2012-02-07 17:22:30 +00:00
|
|
|
{
|
2012-03-21 15:49:23 +00:00
|
|
|
this.obj = aEnvironment;
|
2012-02-07 17:22:30 +00:00
|
|
|
this.threadActor = aThreadActor;
|
|
|
|
}
|
|
|
|
|
|
|
|
EnvironmentActor.prototype = {
|
|
|
|
actorPrefix: "environment",
|
|
|
|
|
2012-01-23 08:29:15 +00:00
|
|
|
/**
|
2013-01-15 00:15:58 +00:00
|
|
|
* Return an environment form for use in a protocol message.
|
|
|
|
*/
|
|
|
|
form: function EA_form() {
|
|
|
|
let form = { actor: this.actorID };
|
|
|
|
|
|
|
|
// What is this environment's type?
|
|
|
|
if (this.obj.type == "declarative") {
|
|
|
|
form.type = this.obj.callee ? "function" : "block";
|
|
|
|
} else {
|
|
|
|
form.type = this.obj.type;
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
|
|
|
|
2013-01-15 00:15:58 +00:00
|
|
|
// Does this environment have a parent?
|
2012-03-21 15:49:23 +00:00
|
|
|
if (this.obj.parent) {
|
2013-01-15 00:15:58 +00:00
|
|
|
form.parent = (this.threadActor
|
|
|
|
.createEnvironmentActor(this.obj.parent,
|
|
|
|
this.registeredPool)
|
|
|
|
.form());
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
2012-05-29 09:08:20 +00:00
|
|
|
|
2013-01-15 00:15:58 +00:00
|
|
|
// Does this environment reflect the properties of an object as variables?
|
|
|
|
if (this.obj.type == "object" || this.obj.type == "with") {
|
2012-05-29 09:08:20 +00:00
|
|
|
form.object = this.threadActor.createValueGrip(this.obj.object);
|
2013-01-15 00:15:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Is this the environment created for a function call?
|
|
|
|
if (this.obj.callee) {
|
|
|
|
form.function = this.threadActor.createValueGrip(this.obj.callee);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Shall we list this environment's bindings?
|
|
|
|
if (this.obj.type == "declarative") {
|
|
|
|
form.bindings = this._bindings();
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
|
|
|
|
2012-03-13 07:13:02 +00:00
|
|
|
return form;
|
2012-02-07 17:22:30 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the identifier bindings object as required by the remote protocol
|
2013-01-15 00:15:58 +00:00
|
|
|
* specification.
|
2012-02-07 17:22:30 +00:00
|
|
|
*/
|
2013-01-15 00:15:58 +00:00
|
|
|
_bindings: function EA_bindings() {
|
2012-03-13 07:13:02 +00:00
|
|
|
let bindings = { arguments: [], variables: {} };
|
2012-02-07 17:22:30 +00:00
|
|
|
|
2012-03-21 15:49:23 +00:00
|
|
|
// TODO: this part should be removed in favor of the commented-out part
|
|
|
|
// below when getVariableDescriptor lands (bug 725815).
|
|
|
|
if (typeof this.obj.getVariable != "function") {
|
|
|
|
//if (typeof this.obj.getVariableDescriptor != "function") {
|
2012-02-07 17:22:30 +00:00
|
|
|
return bindings;
|
|
|
|
}
|
|
|
|
|
2012-03-21 15:49:23 +00:00
|
|
|
let parameterNames;
|
2013-01-15 00:15:58 +00:00
|
|
|
if (this.obj.callee) {
|
|
|
|
parameterNames = this.obj.callee.parameterNames;
|
2012-03-21 15:49:23 +00:00
|
|
|
}
|
|
|
|
for each (let name in parameterNames) {
|
2012-03-13 07:13:02 +00:00
|
|
|
let arg = {};
|
2012-03-21 15:49:23 +00:00
|
|
|
// TODO: this part should be removed in favor of the commented-out part
|
|
|
|
// below when getVariableDescriptor lands (bug 725815).
|
|
|
|
let desc = {
|
|
|
|
value: this.obj.getVariable(name),
|
|
|
|
configurable: false,
|
|
|
|
writable: true,
|
|
|
|
enumerable: true
|
|
|
|
};
|
|
|
|
|
|
|
|
// let desc = this.obj.getVariableDescriptor(name);
|
2012-03-13 07:13:02 +00:00
|
|
|
let descForm = {
|
|
|
|
enumerable: true,
|
|
|
|
configurable: desc.configurable
|
|
|
|
};
|
|
|
|
if ("value" in desc) {
|
|
|
|
descForm.value = this.threadActor.createValueGrip(desc.value);
|
|
|
|
descForm.writable = desc.writable;
|
|
|
|
} else {
|
|
|
|
descForm.get = this.threadActor.createValueGrip(desc.get);
|
|
|
|
descForm.set = this.threadActor.createValueGrip(desc.set);
|
|
|
|
}
|
|
|
|
arg[name] = descForm;
|
|
|
|
bindings.arguments.push(arg);
|
|
|
|
}
|
|
|
|
|
2012-03-21 15:49:23 +00:00
|
|
|
for each (let name in this.obj.names()) {
|
2012-03-13 07:13:02 +00:00
|
|
|
if (bindings.arguments.some(function exists(element) {
|
|
|
|
return !!element[name];
|
|
|
|
})) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-03-21 15:49:23 +00:00
|
|
|
// TODO: this part should be removed in favor of the commented-out part
|
|
|
|
// below when getVariableDescriptor lands.
|
|
|
|
let desc = {
|
|
|
|
configurable: false,
|
|
|
|
writable: true,
|
|
|
|
enumerable: true
|
|
|
|
};
|
2012-06-10 23:44:50 +00:00
|
|
|
try {
|
|
|
|
desc.value = this.obj.getVariable(name);
|
|
|
|
} catch (e) {
|
|
|
|
// Avoid "Debugger scope is not live" errors for |arguments|, introduced
|
|
|
|
// in bug 746601.
|
|
|
|
if (name != "arguments") {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
2012-03-21 15:49:23 +00:00
|
|
|
//let desc = this.obj.getVariableDescriptor(name);
|
2012-03-13 07:13:02 +00:00
|
|
|
let descForm = {
|
|
|
|
enumerable: true,
|
|
|
|
configurable: desc.configurable
|
|
|
|
};
|
|
|
|
if ("value" in desc) {
|
|
|
|
descForm.value = this.threadActor.createValueGrip(desc.value);
|
|
|
|
descForm.writable = desc.writable;
|
2012-02-07 17:22:30 +00:00
|
|
|
} else {
|
2012-03-13 07:13:02 +00:00
|
|
|
descForm.get = this.threadActor.createValueGrip(desc.get);
|
|
|
|
descForm.set = this.threadActor.createValueGrip(desc.set);
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
2012-03-13 07:13:02 +00:00
|
|
|
bindings.variables[name] = descForm;
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return bindings;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a protocol request to change the value of a variable bound in this
|
|
|
|
* lexical environment.
|
2012-01-23 08:29:15 +00:00
|
|
|
*
|
|
|
|
* @param aRequest object
|
|
|
|
* The protocol request object.
|
2012-02-07 17:22:30 +00:00
|
|
|
*/
|
|
|
|
onAssign: function EA_onAssign(aRequest) {
|
2012-05-24 11:23:53 +00:00
|
|
|
// TODO: enable the commented-out part when getVariableDescriptor lands
|
|
|
|
// (bug 725815).
|
|
|
|
/*let desc = this.obj.getVariableDescriptor(aRequest.name);
|
2012-02-07 17:22:30 +00:00
|
|
|
|
|
|
|
if (!desc.writable) {
|
|
|
|
return { error: "immutableBinding",
|
|
|
|
message: "Changing the value of an immutable binding is not " +
|
|
|
|
"allowed" };
|
2012-05-24 11:23:53 +00:00
|
|
|
}*/
|
2012-02-07 17:22:30 +00:00
|
|
|
|
|
|
|
try {
|
2012-03-21 15:49:23 +00:00
|
|
|
this.obj.setVariable(aRequest.name, aRequest.value);
|
2012-02-07 17:22:30 +00:00
|
|
|
} catch (e) {
|
|
|
|
if (e instanceof Debugger.DebuggeeWouldRun) {
|
2012-03-13 07:13:02 +00:00
|
|
|
return { error: "threadWouldRun",
|
|
|
|
cause: e.cause ? e.cause : "setter",
|
|
|
|
message: "Assigning a value would cause the debuggee to run" };
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
|
|
|
// This should never happen, so let it complain loudly if it does.
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
return { from: this.actorID };
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a protocol request to fully enumerate the bindings introduced by the
|
|
|
|
* lexical environment.
|
2012-01-23 08:29:15 +00:00
|
|
|
*
|
|
|
|
* @param aRequest object
|
|
|
|
* The protocol request object.
|
2012-02-07 17:22:30 +00:00
|
|
|
*/
|
|
|
|
onBindings: function EA_onBindings(aRequest) {
|
|
|
|
return { from: this.actorID,
|
|
|
|
bindings: this._bindings() };
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
EnvironmentActor.prototype.requestTypes = {
|
|
|
|
"assign": EnvironmentActor.prototype.onAssign,
|
|
|
|
"bindings": EnvironmentActor.prototype.onBindings
|
|
|
|
};
|
2012-05-29 09:08:20 +00:00
|
|
|
|
2012-11-01 15:34:10 +00:00
|
|
|
/**
|
|
|
|
* Override the toString method in order to get more meaningful script output
|
|
|
|
* for debugging the debugger.
|
|
|
|
*/
|
|
|
|
Debugger.Script.prototype.toString = function() {
|
|
|
|
let output = "";
|
|
|
|
if (this.url) {
|
|
|
|
output += this.url;
|
|
|
|
}
|
|
|
|
if (typeof this.startLine != "undefined") {
|
|
|
|
output += ":" + this.startLine;
|
|
|
|
if (this.lineCount && this.lineCount > 1) {
|
|
|
|
output += "-" + (this.startLine + this.lineCount - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.strictMode) {
|
|
|
|
output += ":strict";
|
|
|
|
}
|
|
|
|
return output;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper property for quickly getting to the line number a stack frame is
|
|
|
|
* currently paused at.
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Debugger.Frame.prototype, "line", {
|
|
|
|
configurable: true,
|
|
|
|
get: function() {
|
|
|
|
if (this.script) {
|
|
|
|
return this.script.getOffsetLine(this.offset);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-10-31 16:31:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an actor for handling chrome debugging. ChromeDebuggerActor is a
|
|
|
|
* thin wrapper over ThreadActor, slightly changing some of its behavior.
|
|
|
|
*
|
2013-04-19 14:33:00 +00:00
|
|
|
* @param aConnection object
|
|
|
|
* The DebuggerServerConnection with which this ChromeDebuggerActor
|
|
|
|
* is associated. (Currently unused, but required to make this
|
|
|
|
* constructor usable with addGlobalActor.)
|
|
|
|
*
|
2012-10-31 16:31:55 +00:00
|
|
|
* @param aHooks object
|
|
|
|
* An object with preNest and postNest methods for calling when entering
|
|
|
|
* and exiting a nested event loop and also addToParentPool and
|
|
|
|
* removeFromParentPool methods for handling the lifetime of actors that
|
|
|
|
* will outlive the thread, like breakpoints.
|
|
|
|
*/
|
2013-04-19 14:33:00 +00:00
|
|
|
function ChromeDebuggerActor(aConnection, aHooks)
|
2012-10-31 16:31:55 +00:00
|
|
|
{
|
|
|
|
ThreadActor.call(this, aHooks);
|
|
|
|
}
|
|
|
|
|
|
|
|
ChromeDebuggerActor.prototype = Object.create(ThreadActor.prototype);
|
|
|
|
|
|
|
|
update(ChromeDebuggerActor.prototype, {
|
|
|
|
constructor: ChromeDebuggerActor,
|
|
|
|
|
|
|
|
// A constant prefix that will be used to form the actor ID by the server.
|
|
|
|
actorPrefix: "chromeDebugger",
|
|
|
|
|
|
|
|
/**
|
2013-02-28 12:02:00 +00:00
|
|
|
* Override the eligibility check for scripts and sources to make sure every
|
|
|
|
* script and source with a URL is stored when debugging chrome.
|
2012-10-31 16:31:55 +00:00
|
|
|
*/
|
2013-02-28 12:02:00 +00:00
|
|
|
_allowSource: function(aSourceURL) !!aSourceURL,
|
2012-10-31 16:31:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An object that will be used by ThreadActors to tailor their behavior
|
|
|
|
* depending on the debugging context being required (chrome or content).
|
|
|
|
* The methods that this object provides must be bound to the ThreadActor
|
|
|
|
* before use.
|
|
|
|
*/
|
|
|
|
globalManager: {
|
|
|
|
findGlobals: function CDA_findGlobals() {
|
2013-01-04 19:34:43 +00:00
|
|
|
// Add every global known to the debugger as debuggee.
|
|
|
|
this.dbg.addAllGlobalsAsDebuggees();
|
2012-10-31 16:31:55 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A function that the engine calls when a new global object has been
|
|
|
|
* created.
|
|
|
|
*
|
|
|
|
* @param aGlobal Debugger.Object
|
|
|
|
* The new global object that was created.
|
|
|
|
*/
|
|
|
|
onNewGlobal: function CDA_onNewGlobal(aGlobal) {
|
|
|
|
this.addDebuggee(aGlobal);
|
|
|
|
// Notify the client.
|
|
|
|
this.conn.send({
|
|
|
|
from: this.actorID,
|
|
|
|
type: "newGlobal",
|
|
|
|
// TODO: after bug 801084 lands see if we need to JSONify this.
|
|
|
|
hostAnnotations: aGlobal.hostAnnotations
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-04-15 21:07:00 +00:00
|
|
|
/**
|
|
|
|
* Manages the sources for a thread. Handles source maps, locations in the
|
|
|
|
* sources, etc for ThreadActors.
|
|
|
|
*/
|
2013-06-11 14:23:00 +00:00
|
|
|
function ThreadSources(aThreadActor, aUseSourceMaps, aAllowPredicate,
|
|
|
|
aOnNewSource) {
|
2013-04-15 21:07:00 +00:00
|
|
|
this._thread = aThreadActor;
|
|
|
|
this._useSourceMaps = aUseSourceMaps;
|
|
|
|
this._allow = aAllowPredicate;
|
|
|
|
this._onNewSource = aOnNewSource;
|
|
|
|
|
|
|
|
// generated source url --> promise of SourceMapConsumer
|
|
|
|
this._sourceMapsByGeneratedSource = Object.create(null);
|
|
|
|
// original source url --> promise of SourceMapConsumer
|
|
|
|
this._sourceMapsByOriginalSource = Object.create(null);
|
|
|
|
// source url --> SourceActor
|
|
|
|
this._sourceActors = Object.create(null);
|
|
|
|
// original url --> generated url
|
|
|
|
this._generatedUrlsByOriginalUrl = Object.create(null);
|
|
|
|
}
|
|
|
|
|
2013-06-11 14:23:00 +00:00
|
|
|
/**
|
|
|
|
* Must be a class property because it needs to persist across reloads, same as
|
|
|
|
* the breakpoint store.
|
|
|
|
*/
|
|
|
|
ThreadSources._blackBoxedSources = new Set();
|
|
|
|
|
2013-04-15 21:07:00 +00:00
|
|
|
ThreadSources.prototype = {
|
|
|
|
/**
|
2013-06-06 01:06:43 +00:00
|
|
|
* Return the source actor representing |aURL|, creating one if none
|
|
|
|
* exists already. Returns null if |aURL| is not allowed by the 'allow'
|
|
|
|
* predicate.
|
2013-04-15 21:07:00 +00:00
|
|
|
*
|
|
|
|
* Right now this takes a URL, but in the future it should
|
|
|
|
* take a Debugger.Source. See bug 637572.
|
|
|
|
*
|
2013-05-13 11:16:00 +00:00
|
|
|
* @param String aURL
|
|
|
|
* The source URL.
|
2013-05-13 11:53:00 +00:00
|
|
|
* @param optional SourceMapConsumer aSourceMap
|
2013-06-06 01:06:43 +00:00
|
|
|
* The source map that introduced this source, if any.
|
2013-09-11 17:15:51 +00:00
|
|
|
* @param optional String aGeneratedSource
|
|
|
|
* The generated source url that introduced this source via source map,
|
|
|
|
* if any.
|
2013-06-06 01:06:43 +00:00
|
|
|
* @returns a SourceActor representing the source at aURL or null.
|
2013-04-15 21:07:00 +00:00
|
|
|
*/
|
2013-09-11 17:15:51 +00:00
|
|
|
source: function TS_source(aURL, aSourceMap=null, aGeneratedSource=null) {
|
2013-04-15 21:07:00 +00:00
|
|
|
if (!this._allow(aURL)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aURL in this._sourceActors) {
|
|
|
|
return this._sourceActors[aURL];
|
|
|
|
}
|
|
|
|
|
2013-09-11 17:15:51 +00:00
|
|
|
let actor = new SourceActor(aURL, this._thread, aSourceMap, aGeneratedSource);
|
2013-04-15 21:07:00 +00:00
|
|
|
this._thread.threadLifetimePool.addActor(actor);
|
|
|
|
this._sourceActors[aURL] = actor;
|
|
|
|
try {
|
|
|
|
this._onNewSource(actor);
|
|
|
|
} catch (e) {
|
|
|
|
reportError(e);
|
|
|
|
}
|
|
|
|
return actor;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-06-06 01:06:43 +00:00
|
|
|
* Return a promise of an array of source actors representing all the
|
|
|
|
* sources of |aScript|.
|
|
|
|
*
|
|
|
|
* If source map handling is enabled and |aScript| has a source map, then
|
|
|
|
* use it to find all of |aScript|'s *original* sources; return a promise
|
|
|
|
* of an array of source actors for those.
|
2013-04-15 21:07:00 +00:00
|
|
|
*/
|
|
|
|
sourcesForScript: function TS_sourcesForScript(aScript) {
|
|
|
|
if (!this._useSourceMaps || !aScript.sourceMapURL) {
|
|
|
|
return resolve([this.source(aScript.url)].filter(isNotNull));
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.sourceMap(aScript)
|
|
|
|
.then((aSourceMap) => {
|
|
|
|
return [
|
2013-09-11 17:15:51 +00:00
|
|
|
this.source(s, aSourceMap, aScript.url) for (s of aSourceMap.sources)
|
2013-04-15 21:07:00 +00:00
|
|
|
];
|
2013-06-20 17:43:30 +00:00
|
|
|
})
|
|
|
|
.then(null, (e) => {
|
2013-04-15 21:07:00 +00:00
|
|
|
reportError(e);
|
|
|
|
delete this._sourceMapsByGeneratedSource[aScript.url];
|
|
|
|
return [this.source(aScript.url)];
|
|
|
|
})
|
|
|
|
.then(function (aSources) {
|
|
|
|
return aSources.filter(isNotNull);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-06-06 01:06:43 +00:00
|
|
|
* Return a promise of a SourceMapConsumer for the source map for
|
|
|
|
* |aScript|; if we already have such a promise extant, return that.
|
|
|
|
* |aScript| must have a non-null sourceMapURL.
|
2013-04-15 21:07:00 +00:00
|
|
|
*/
|
|
|
|
sourceMap: function TS_sourceMap(aScript) {
|
2013-07-18 11:14:16 +00:00
|
|
|
dbg_assert(aScript.sourceMapURL, "Script should have a sourceMapURL");
|
2013-06-06 01:06:43 +00:00
|
|
|
let sourceMapURL = this._normalize(aScript.sourceMapURL, aScript.url);
|
2013-07-27 05:27:15 +00:00
|
|
|
let map = this._fetchSourceMap(sourceMapURL, aScript.url)
|
2013-09-11 17:15:51 +00:00
|
|
|
.then(aSourceMap => this.saveSourceMap(aSourceMap, aScript.url));
|
2013-04-15 21:07:00 +00:00
|
|
|
this._sourceMapsByGeneratedSource[aScript.url] = map;
|
|
|
|
return map;
|
|
|
|
},
|
|
|
|
|
2013-09-11 17:15:51 +00:00
|
|
|
/**
|
|
|
|
* Save the given source map so that we can use it to query source locations
|
|
|
|
* down the line.
|
|
|
|
*/
|
|
|
|
saveSourceMap: function TS_saveSourceMap(aSourceMap, aGeneratedSource) {
|
|
|
|
this._sourceMapsByGeneratedSource[aGeneratedSource] = resolve(aSourceMap);
|
|
|
|
for (let s of aSourceMap.sources) {
|
|
|
|
this._generatedUrlsByOriginalUrl[s] = aGeneratedSource;
|
|
|
|
this._sourceMapsByOriginalSource[s] = resolve(aSourceMap);
|
|
|
|
}
|
|
|
|
return aSourceMap;
|
|
|
|
},
|
|
|
|
|
2013-04-15 21:07:00 +00:00
|
|
|
/**
|
2013-06-06 01:06:43 +00:00
|
|
|
* Return a promise of a SourceMapConsumer for the source map located at
|
|
|
|
* |aAbsSourceMapURL|, which must be absolute. If there is already such a
|
|
|
|
* promise extant, return it.
|
2013-07-27 05:27:15 +00:00
|
|
|
*
|
|
|
|
* @param string aAbsSourceMapURL
|
|
|
|
* The source map URL, in absolute form, not relative.
|
|
|
|
* @param string aScriptURL
|
|
|
|
* When the source map URL is a data URI, there is no sourceRoot on the
|
|
|
|
* source map, and the source map's sources are relative, we resolve
|
|
|
|
* them from aScriptURL.
|
|
|
|
*/
|
|
|
|
_fetchSourceMap: function TS__fetchSourceMap(aAbsSourceMapURL, aScriptURL) {
|
2013-09-05 16:50:10 +00:00
|
|
|
return fetch(aAbsSourceMapURL, { loadFromCache: false })
|
|
|
|
.then(({ content }) => {
|
|
|
|
let map = new SourceMapConsumer(content);
|
|
|
|
this._setSourceMapRoot(map, aAbsSourceMapURL, aScriptURL);
|
|
|
|
return map;
|
|
|
|
});
|
2013-07-27 05:27:15 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the source map's sourceRoot to be relative to the source map url.
|
|
|
|
*/
|
|
|
|
_setSourceMapRoot: function TS__setSourceMapRoot(aSourceMap, aAbsSourceMapURL,
|
|
|
|
aScriptURL) {
|
|
|
|
const base = this._dirname(
|
|
|
|
aAbsSourceMapURL.indexOf("data:") === 0
|
|
|
|
? aScriptURL
|
|
|
|
: aAbsSourceMapURL);
|
|
|
|
aSourceMap.sourceRoot = aSourceMap.sourceRoot
|
|
|
|
? this._normalize(aSourceMap.sourceRoot, base)
|
|
|
|
: base;
|
|
|
|
},
|
|
|
|
|
|
|
|
_dirname: function TS__dirname(aPath) {
|
|
|
|
return Services.io.newURI(
|
|
|
|
".", null, Services.io.newURI(aPath, null, null)).spec;
|
2013-04-15 21:07:00 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-06-06 01:06:43 +00:00
|
|
|
* Returns a promise of the location in the original source if the source is
|
2013-04-15 21:07:00 +00:00
|
|
|
* source mapped, otherwise a promise of the same location.
|
|
|
|
*/
|
2013-08-24 05:41:28 +00:00
|
|
|
getOriginalLocation: function TS_getOriginalLocation({ url, line, column }) {
|
|
|
|
if (url in this._sourceMapsByGeneratedSource) {
|
|
|
|
return this._sourceMapsByGeneratedSource[url]
|
|
|
|
.then((aSourceMap) => {
|
|
|
|
let { source: aSourceURL, line: aLine, column: aColumn } = aSourceMap.originalPositionFor({
|
2013-07-25 00:46:49 +00:00
|
|
|
line: line,
|
|
|
|
column: column
|
2013-08-24 05:41:28 +00:00
|
|
|
});
|
|
|
|
return {
|
|
|
|
url: aSourceURL,
|
|
|
|
line: aLine,
|
|
|
|
column: aColumn
|
2013-04-15 21:07:00 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// No source map
|
|
|
|
return resolve({
|
2013-08-24 05:41:28 +00:00
|
|
|
url: url,
|
|
|
|
line: line,
|
|
|
|
column: column
|
2013-04-15 21:07:00 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a promise of the location in the generated source corresponding to
|
|
|
|
* the original source and line given.
|
|
|
|
*
|
2013-06-06 01:06:43 +00:00
|
|
|
* When we pass a script S representing generated code to |sourceMap|,
|
|
|
|
* above, that returns a promise P. The process of resolving P populates
|
|
|
|
* the tables this function uses; thus, it won't know that S's original
|
|
|
|
* source URLs map to S until P is resolved.
|
2013-04-15 21:07:00 +00:00
|
|
|
*/
|
2013-08-24 05:41:28 +00:00
|
|
|
getGeneratedLocation: function TS_getGeneratedLocation({ url, line, column }) {
|
|
|
|
if (url in this._sourceMapsByOriginalSource) {
|
|
|
|
return this._sourceMapsByOriginalSource[url]
|
2013-04-15 21:07:00 +00:00
|
|
|
.then((aSourceMap) => {
|
2013-08-24 05:41:28 +00:00
|
|
|
let { line: aLine, column: aColumn } = aSourceMap.generatedPositionFor({
|
|
|
|
source: url,
|
|
|
|
line: line,
|
|
|
|
column: column == null ? Infinity : column
|
2013-04-15 21:07:00 +00:00
|
|
|
});
|
|
|
|
return {
|
2013-08-24 05:41:28 +00:00
|
|
|
url: this._generatedUrlsByOriginalUrl[url],
|
|
|
|
line: aLine,
|
|
|
|
column: aColumn
|
2013-04-15 21:07:00 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// No source map
|
|
|
|
return resolve({
|
2013-08-24 05:41:28 +00:00
|
|
|
url: url,
|
|
|
|
line: line,
|
|
|
|
column: column
|
2013-04-15 21:07:00 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-06-11 14:23:00 +00:00
|
|
|
/**
|
|
|
|
* Returns true if URL for the given source is black boxed.
|
|
|
|
*
|
|
|
|
* @param aURL String
|
|
|
|
* The URL of the source which we are checking whether it is black
|
|
|
|
* boxed or not.
|
|
|
|
*/
|
|
|
|
isBlackBoxed: function TS_isBlackBoxed(aURL) {
|
|
|
|
return ThreadSources._blackBoxedSources.has(aURL);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the given source URL to the set of sources that are black boxed. If the
|
|
|
|
* thread is currently paused and we are black boxing the yougest frame's
|
|
|
|
* source, this will force a step.
|
|
|
|
*
|
|
|
|
* @param aURL String
|
|
|
|
* The URL of the source which we are black boxing.
|
|
|
|
*/
|
|
|
|
blackBox: function TS_blackBox(aURL) {
|
|
|
|
ThreadSources._blackBoxedSources.add(aURL);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the given source URL to the set of sources that are black boxed.
|
|
|
|
*
|
|
|
|
* @param aURL String
|
|
|
|
* The URL of the source which we are no longer black boxing.
|
|
|
|
*/
|
|
|
|
unblackBox: function TS_unblackBox(aURL) {
|
|
|
|
ThreadSources._blackBoxedSources.delete(aURL);
|
|
|
|
},
|
|
|
|
|
2013-04-09 08:40:00 +00:00
|
|
|
/**
|
|
|
|
* Normalize multiple relative paths towards the base paths on the right.
|
|
|
|
*/
|
|
|
|
_normalize: function TS__normalize(...aURLs) {
|
2013-07-18 11:14:16 +00:00
|
|
|
dbg_assert(aURLs.length > 1, "Should have more than 1 URL");
|
2013-04-09 08:40:00 +00:00
|
|
|
let base = Services.io.newURI(aURLs.pop(), null, null);
|
|
|
|
let url;
|
|
|
|
while ((url = aURLs.pop())) {
|
|
|
|
base = Services.io.newURI(url, null, base);
|
|
|
|
}
|
|
|
|
return base.spec;
|
|
|
|
},
|
|
|
|
|
2013-04-15 21:07:00 +00:00
|
|
|
iter: function TS_iter() {
|
|
|
|
for (let url in this._sourceActors) {
|
|
|
|
yield this._sourceActors[url];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-10-31 16:31:55 +00:00
|
|
|
// Utility functions.
|
|
|
|
|
2013-07-25 00:46:49 +00:00
|
|
|
// TODO bug 863089: use Debugger.Script.prototype.getOffsetColumn when it is
|
|
|
|
// implemented.
|
|
|
|
function getOffsetColumn(aOffset, aScript) {
|
|
|
|
let bestOffsetMapping = null;
|
|
|
|
for (let offsetMapping of aScript.getAllColumnOffsets()) {
|
|
|
|
if (!bestOffsetMapping ||
|
|
|
|
(offsetMapping.offset <= aOffset &&
|
|
|
|
offsetMapping.offset > bestOffsetMapping.offset)) {
|
|
|
|
bestOffsetMapping = offsetMapping;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bestOffsetMapping) {
|
|
|
|
// XXX: Try not to completely break the experience of using the debugger for
|
|
|
|
// the user by assuming column 0. Simultaneously, report the error so that
|
|
|
|
// there is a paper trail if the assumption is bad and the debugging
|
|
|
|
// experience becomes wonky.
|
|
|
|
reportError(new Error("Could not find a column for offset " + aOffset
|
|
|
|
+ " in the script " + aScript));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bestOffsetMapping.columnNumber;
|
|
|
|
}
|
|
|
|
|
2013-09-05 23:51:23 +00:00
|
|
|
/**
|
|
|
|
* Return the non-source-mapped location of the given Debugger.Frame. If the
|
|
|
|
* frame does not have a script, the location's properties are all null.
|
|
|
|
*
|
|
|
|
* @param Debugger.Frame aFrame
|
|
|
|
* The frame whose location we are getting.
|
|
|
|
* @returns Object
|
|
|
|
* Returns an object of the form { url, line, column }
|
|
|
|
*/
|
|
|
|
function getFrameLocation(aFrame) {
|
|
|
|
if (!aFrame.script) {
|
|
|
|
return { url: null, line: null, column: null };
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
url: aFrame.script.url,
|
|
|
|
line: aFrame.script.getOffsetLine(aFrame.offset),
|
|
|
|
column: getOffsetColumn(aFrame.offset, aFrame.script)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-31 16:31:55 +00:00
|
|
|
/**
|
|
|
|
* Utility function for updating an object with the properties of another
|
|
|
|
* object.
|
|
|
|
*
|
|
|
|
* @param aTarget Object
|
|
|
|
* The object being updated.
|
|
|
|
* @param aNewAttrs Object
|
|
|
|
* The new attributes being set on the target.
|
|
|
|
*/
|
|
|
|
function update(aTarget, aNewAttrs) {
|
|
|
|
for (let key in aNewAttrs) {
|
|
|
|
let desc = Object.getOwnPropertyDescriptor(aNewAttrs, key);
|
|
|
|
|
|
|
|
if (desc) {
|
|
|
|
Object.defineProperty(aTarget, key, desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-15 21:07:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if its argument is not null.
|
|
|
|
*/
|
|
|
|
function isNotNull(aThing) {
|
|
|
|
return aThing !== null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Performs a request to load the desired URL and returns a promise.
|
|
|
|
*
|
|
|
|
* @param aURL String
|
|
|
|
* The URL we will request.
|
|
|
|
* @returns Promise
|
2013-06-06 01:06:43 +00:00
|
|
|
* A promise of the document at that URL, as a string.
|
2013-04-15 21:07:00 +00:00
|
|
|
*
|
|
|
|
* XXX: It may be better to use nsITraceableChannel to get to the sources
|
|
|
|
* without relying on caching when we can (not for eval, etc.):
|
|
|
|
* http://www.softwareishard.com/blog/firebug/nsitraceablechannel-intercept-http-traffic/
|
|
|
|
*/
|
2013-05-13 11:53:00 +00:00
|
|
|
function fetch(aURL, aOptions={ loadFromCache: true }) {
|
2013-04-15 21:07:00 +00:00
|
|
|
let deferred = defer();
|
|
|
|
let scheme;
|
|
|
|
let url = aURL.split(" -> ").pop();
|
|
|
|
let charset;
|
2013-08-23 22:04:03 +00:00
|
|
|
let contentType;
|
2013-04-15 21:07:00 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
scheme = Services.io.extractScheme(url);
|
|
|
|
} catch (e) {
|
|
|
|
// In the xpcshell tests, the script url is the absolute path of the test
|
|
|
|
// file, which will make a malformed URI error be thrown. Add the file
|
|
|
|
// scheme prefix ourselves.
|
|
|
|
url = "file://" + url;
|
|
|
|
scheme = Services.io.extractScheme(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (scheme) {
|
|
|
|
case "file":
|
|
|
|
case "chrome":
|
|
|
|
case "resource":
|
|
|
|
try {
|
2013-08-23 22:04:03 +00:00
|
|
|
NetUtil.asyncFetch(url, function onFetch(aStream, aStatus, aRequest) {
|
2013-04-15 21:07:00 +00:00
|
|
|
if (!Components.isSuccessCode(aStatus)) {
|
2013-09-05 16:43:09 +00:00
|
|
|
deferred.reject(new Error("Request failed with status code = "
|
|
|
|
+ aStatus
|
|
|
|
+ " after NetUtil.asyncFetch for url = "
|
|
|
|
+ url));
|
2013-04-15 21:07:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let source = NetUtil.readInputStreamToString(aStream, aStream.available());
|
2013-08-23 22:04:03 +00:00
|
|
|
contentType = aRequest.contentType;
|
2013-04-15 21:07:00 +00:00
|
|
|
deferred.resolve(source);
|
|
|
|
aStream.close();
|
|
|
|
});
|
|
|
|
} catch (ex) {
|
2013-09-05 16:43:09 +00:00
|
|
|
deferred.reject(ex);
|
2013-04-15 21:07:00 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
let channel;
|
|
|
|
try {
|
|
|
|
channel = Services.io.newChannel(url, null, null);
|
|
|
|
} catch (e if e.name == "NS_ERROR_UNKNOWN_PROTOCOL") {
|
|
|
|
// On Windows xpcshell tests, c:/foo/bar can pass as a valid URL, but
|
|
|
|
// newChannel won't be able to handle it.
|
|
|
|
url = "file:///" + url;
|
|
|
|
channel = Services.io.newChannel(url, null, null);
|
|
|
|
}
|
|
|
|
let chunks = [];
|
|
|
|
let streamListener = {
|
|
|
|
onStartRequest: function(aRequest, aContext, aStatusCode) {
|
|
|
|
if (!Components.isSuccessCode(aStatusCode)) {
|
2013-09-05 16:43:09 +00:00
|
|
|
deferred.reject(new Error("Request failed with status code = "
|
|
|
|
+ aStatusCode
|
|
|
|
+ " in onStartRequest handler for url = "
|
|
|
|
+ url));
|
2013-04-15 21:07:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
onDataAvailable: function(aRequest, aContext, aStream, aOffset, aCount) {
|
|
|
|
chunks.push(NetUtil.readInputStreamToString(aStream, aCount));
|
|
|
|
},
|
|
|
|
onStopRequest: function(aRequest, aContext, aStatusCode) {
|
|
|
|
if (!Components.isSuccessCode(aStatusCode)) {
|
2013-09-05 16:43:09 +00:00
|
|
|
deferred.reject(new Error("Request failed with status code = "
|
|
|
|
+ aStatusCode
|
|
|
|
+ " in onStopRequest handler for url = "
|
|
|
|
+ url));
|
2013-04-15 21:07:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
charset = channel.contentCharset;
|
2013-08-23 22:04:03 +00:00
|
|
|
contentType = channel.contentType;
|
2013-04-15 21:07:00 +00:00
|
|
|
deferred.resolve(chunks.join(""));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-05-13 11:53:00 +00:00
|
|
|
channel.loadFlags = aOptions.loadFromCache
|
|
|
|
? channel.LOAD_FROM_CACHE
|
|
|
|
: channel.LOAD_BYPASS_CACHE;
|
2013-04-15 21:07:00 +00:00
|
|
|
channel.asyncOpen(streamListener, null);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-08-23 22:04:03 +00:00
|
|
|
return deferred.promise.then(source => {
|
|
|
|
return {
|
|
|
|
content: convertToUnicode(source, charset),
|
|
|
|
contentType: contentType
|
|
|
|
};
|
2013-04-15 21:07:00 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a given string, encoded in a given character set, to unicode.
|
|
|
|
*
|
|
|
|
* @param string aString
|
|
|
|
* A string.
|
|
|
|
* @param string aCharset
|
|
|
|
* A character set.
|
|
|
|
*/
|
|
|
|
function convertToUnicode(aString, aCharset=null) {
|
|
|
|
// Decoding primitives.
|
|
|
|
let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
|
|
|
|
.createInstance(Ci.nsIScriptableUnicodeConverter);
|
|
|
|
try {
|
|
|
|
converter.charset = aCharset || "UTF-8";
|
|
|
|
return converter.ConvertToUnicode(aString);
|
|
|
|
} catch(e) {
|
|
|
|
return aString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Report the given error in the error console and to stdout.
|
2013-07-03 21:10:52 +00:00
|
|
|
*
|
|
|
|
* @param Error aError
|
|
|
|
* The error object you wish to report.
|
|
|
|
* @param String aPrefix
|
|
|
|
* An optional prefix for the reported error message.
|
2013-04-15 21:07:00 +00:00
|
|
|
*/
|
2013-07-03 21:10:52 +00:00
|
|
|
function reportError(aError, aPrefix="") {
|
2013-07-11 17:56:23 +00:00
|
|
|
dbg_assert(aError instanceof Error, "Must pass Error objects to reportError");
|
2013-07-10 23:02:28 +00:00
|
|
|
let msg = aPrefix + aError.message + ":\n" + aError.stack;
|
2013-07-03 21:10:52 +00:00
|
|
|
Cu.reportError(msg);
|
|
|
|
dumpn(msg);
|
2013-04-15 21:07:00 +00:00
|
|
|
}
|
2013-07-18 11:14:16 +00:00
|
|
|
|
|
|
|
// The following are copied here verbatim from css-logic.js, until we create a
|
|
|
|
// server-friendly helper module.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find a unique CSS selector for a given element
|
|
|
|
* @returns a string such that ele.ownerDocument.querySelector(reply) === ele
|
|
|
|
* and ele.ownerDocument.querySelectorAll(reply).length === 1
|
|
|
|
*/
|
|
|
|
function findCssSelector(ele) {
|
|
|
|
var document = ele.ownerDocument;
|
|
|
|
if (ele.id && document.getElementById(ele.id) === ele) {
|
|
|
|
return '#' + ele.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Inherently unique by tag name
|
|
|
|
var tagName = ele.tagName.toLowerCase();
|
|
|
|
if (tagName === 'html') {
|
|
|
|
return 'html';
|
|
|
|
}
|
|
|
|
if (tagName === 'head') {
|
|
|
|
return 'head';
|
|
|
|
}
|
|
|
|
if (tagName === 'body') {
|
|
|
|
return 'body';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ele.parentNode == null) {
|
|
|
|
console.log('danger: ' + tagName);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We might be able to find a unique class name
|
|
|
|
var selector, index, matches;
|
|
|
|
if (ele.classList.length > 0) {
|
|
|
|
for (var i = 0; i < ele.classList.length; i++) {
|
|
|
|
// Is this className unique by itself?
|
|
|
|
selector = '.' + ele.classList.item(i);
|
|
|
|
matches = document.querySelectorAll(selector);
|
|
|
|
if (matches.length === 1) {
|
|
|
|
return selector;
|
|
|
|
}
|
|
|
|
// Maybe it's unique with a tag name?
|
|
|
|
selector = tagName + selector;
|
|
|
|
matches = document.querySelectorAll(selector);
|
|
|
|
if (matches.length === 1) {
|
|
|
|
return selector;
|
|
|
|
}
|
|
|
|
// Maybe it's unique using a tag name and nth-child
|
|
|
|
index = positionInNodeList(ele, ele.parentNode.children) + 1;
|
|
|
|
selector = selector + ':nth-child(' + index + ')';
|
|
|
|
matches = document.querySelectorAll(selector);
|
|
|
|
if (matches.length === 1) {
|
|
|
|
return selector;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// So we can be unique w.r.t. our parent, and use recursion
|
|
|
|
index = positionInNodeList(ele, ele.parentNode.children) + 1;
|
|
|
|
selector = findCssSelector(ele.parentNode) + ' > ' +
|
|
|
|
tagName + ':nth-child(' + index + ')';
|
|
|
|
|
|
|
|
return selector;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find the position of [element] in [nodeList].
|
|
|
|
* @returns an index of the match, or -1 if there is no match
|
|
|
|
*/
|
|
|
|
function positionInNodeList(element, nodeList) {
|
|
|
|
for (var i = 0; i < nodeList.length; i++) {
|
|
|
|
if (element === nodeList[i]) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|