2014-06-25 05:12:07 +00:00
|
|
|
/* -*- indent-tabs-mode: nil; js-indent-level: 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/. */
|
2014-04-24 11:23:30 +00:00
|
|
|
|
2012-02-07 17:22:30 +00:00
|
|
|
"use strict";
|
2012-08-30 21:10:07 +00:00
|
|
|
|
2014-04-29 15:52:44 +00:00
|
|
|
const Services = require("Services");
|
2014-07-07 10:07:00 +00:00
|
|
|
const { Cc, Ci, Cu, components, ChromeWorker } = require("chrome");
|
2015-03-23 14:50:00 +00:00
|
|
|
const { ActorPool, OriginalLocation, GeneratedLocation } = require("devtools/server/actors/common");
|
2014-04-29 15:52:44 +00:00
|
|
|
const { DebuggerServer } = require("devtools/server/main");
|
|
|
|
const DevToolsUtils = require("devtools/toolkit/DevToolsUtils");
|
2015-01-03 03:06:12 +00:00
|
|
|
const { dbg_assert, dumpn, update, fetch } = DevToolsUtils;
|
2014-12-09 20:00:00 +00:00
|
|
|
const { dirname, joinURI } = require("devtools/toolkit/path");
|
2014-07-07 10:07:00 +00:00
|
|
|
const promise = require("promise");
|
2014-10-23 13:52:00 +00:00
|
|
|
const PromiseDebugging = require("PromiseDebugging");
|
2014-07-07 10:07:00 +00:00
|
|
|
const xpcInspector = require("xpcInspector");
|
2014-12-19 22:40:58 +00:00
|
|
|
const ScriptStore = require("./utils/ScriptStore");
|
2015-05-21 16:06:32 +00:00
|
|
|
const {DevToolsWorker} = require("devtools/toolkit/shared/worker.js");
|
2014-07-07 10:07:00 +00:00
|
|
|
|
2015-05-15 14:38:33 +00:00
|
|
|
const { defer, resolve, reject, all } = require("devtools/toolkit/deprecated-sync-thenables");
|
|
|
|
|
2014-12-22 15:48:00 +00:00
|
|
|
loader.lazyGetter(this, "Debugger", () => {
|
|
|
|
let Debugger = require("Debugger");
|
|
|
|
hackDebugger(Debugger);
|
|
|
|
return Debugger;
|
|
|
|
});
|
|
|
|
loader.lazyRequireGetter(this, "SourceMapConsumer", "source-map", true);
|
|
|
|
loader.lazyRequireGetter(this, "SourceMapGenerator", "source-map", true);
|
|
|
|
loader.lazyRequireGetter(this, "CssLogic", "devtools/styleinspector/css-logic", true);
|
2014-08-29 17:51:24 +00:00
|
|
|
loader.lazyRequireGetter(this, "events", "sdk/event/core");
|
2015-03-25 18:11:28 +00:00
|
|
|
loader.lazyRequireGetter(this, "mapURIToAddonID", "devtools/server/actors/utils/map-uri-to-addon-id");
|
2014-04-29 15:52:44 +00:00
|
|
|
|
2013-12-19 13:04:59 +00:00
|
|
|
let TYPED_ARRAY_CLASSES = ["Uint8Array", "Uint8ClampedArray", "Uint16Array",
|
|
|
|
"Uint32Array", "Int8Array", "Int16Array", "Int32Array", "Float32Array",
|
|
|
|
"Float64Array"];
|
|
|
|
|
|
|
|
// Number of items to preview in objects, arrays, maps, sets, lists,
|
|
|
|
// collections, etc.
|
|
|
|
let OBJECT_PREVIEW_MAX_ITEMS = 10;
|
|
|
|
|
2014-10-23 13:52:00 +00:00
|
|
|
/**
|
|
|
|
* Call PromiseDebugging.getState on this Debugger.Object's referent and wrap
|
|
|
|
* the resulting `value` or `reason` properties in a Debugger.Object instance.
|
|
|
|
*
|
|
|
|
* See dom/webidl/PromiseDebugging.webidl
|
|
|
|
*
|
|
|
|
* @returns Object
|
|
|
|
* An object of one of the following forms:
|
|
|
|
* - { state: "pending" }
|
|
|
|
* - { state: "fulfilled", value }
|
|
|
|
* - { state: "rejected", reason }
|
|
|
|
*/
|
2014-12-22 15:48:00 +00:00
|
|
|
function getPromiseState(obj) {
|
|
|
|
if (obj.class != "Promise") {
|
2014-10-23 13:52:00 +00:00
|
|
|
throw new Error(
|
|
|
|
"Can't call `getPromiseState` on `Debugger.Object`s that don't " +
|
|
|
|
"refer to Promise objects.");
|
|
|
|
}
|
|
|
|
|
2014-12-22 15:48:00 +00:00
|
|
|
const state = PromiseDebugging.getState(obj.unsafeDereference());
|
2014-10-23 13:52:00 +00:00
|
|
|
return {
|
|
|
|
state: state.state,
|
2014-12-22 15:48:00 +00:00
|
|
|
value: obj.makeDebuggeeValue(state.value),
|
|
|
|
reason: obj.makeDebuggeeValue(state.reason)
|
2014-10-23 13:52:00 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2013-07-25 00:46:49 +00:00
|
|
|
/**
|
2014-12-10 15:33:37 +00:00
|
|
|
* A BreakpointActorMap is a map from locations to instances of BreakpointActor.
|
2013-07-25 00:46:49 +00:00
|
|
|
*/
|
2014-12-10 15:33:37 +00:00
|
|
|
function BreakpointActorMap() {
|
2014-02-18 22:35:50 +00:00
|
|
|
this._size = 0;
|
2014-12-10 18:08:11 +00:00
|
|
|
this._actors = {};
|
2013-07-25 00:46:49 +00:00
|
|
|
}
|
|
|
|
|
2014-12-10 15:33:37 +00:00
|
|
|
BreakpointActorMap.prototype = {
|
|
|
|
/**
|
2015-02-23 08:36:58 +00:00
|
|
|
* Return the number of BreakpointActors in this BreakpointActorMap.
|
2014-12-10 15:33:37 +00:00
|
|
|
*
|
|
|
|
* @returns Number
|
2015-02-23 08:36:58 +00:00
|
|
|
* The number of BreakpointActor in this BreakpointActorMap.
|
2014-12-10 15:33:37 +00:00
|
|
|
*/
|
|
|
|
get size() {
|
|
|
|
return this._size;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-02-23 08:36:58 +00:00
|
|
|
* Generate all BreakpointActors that match the given location in
|
|
|
|
* this BreakpointActorMap.
|
2014-12-10 15:33:37 +00:00
|
|
|
*
|
2015-02-23 15:14:57 +00:00
|
|
|
* @param OriginalLocation location
|
2015-02-23 08:36:58 +00:00
|
|
|
* The location for which matching BreakpointActors should be generated.
|
2014-12-10 15:33:37 +00:00
|
|
|
*/
|
2015-02-23 15:14:57 +00:00
|
|
|
findActors: function* (location = new OriginalLocation()) {
|
2014-12-10 18:08:11 +00:00
|
|
|
function* findKeys(object, key) {
|
|
|
|
if (key !== undefined) {
|
|
|
|
if (key in object) {
|
|
|
|
yield key;
|
2014-12-10 15:33:37 +00:00
|
|
|
}
|
2014-12-10 18:08:11 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (let key of Object.keys(object)) {
|
|
|
|
yield key;
|
2014-12-10 15:33:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-12-10 18:08:11 +00:00
|
|
|
|
2015-02-23 08:36:58 +00:00
|
|
|
let query = {
|
2015-02-23 15:14:57 +00:00
|
|
|
sourceActorID: location.originalSourceActor ? location.originalSourceActor.actorID : undefined,
|
|
|
|
line: location.originalLine,
|
2015-02-23 08:36:58 +00:00
|
|
|
};
|
2014-12-10 18:08:11 +00:00
|
|
|
|
2015-02-23 15:14:57 +00:00
|
|
|
// If location contains a line, assume we are searching for a whole line
|
|
|
|
// breakpoint, and set begin/endColumn accordingly. Otherwise, we are
|
|
|
|
// searching for all breakpoints, so begin/endColumn should be left unset.
|
|
|
|
if (location.originalLine) {
|
|
|
|
query.beginColumn = location.originalColumn ? location.originalColumn : 0;
|
|
|
|
query.endColumn = location.originalColumn ? location.originalColumn + 1 : Infinity;
|
|
|
|
} else {
|
|
|
|
query.beginColumn = location.originalColumn ? query.originalColumn : undefined;
|
|
|
|
query.endColumn = location.originalColumn ? query.originalColumn + 1 : undefined;
|
|
|
|
}
|
|
|
|
|
2015-01-19 13:09:15 +00:00
|
|
|
for (let sourceActorID of findKeys(this._actors, query.sourceActorID))
|
|
|
|
for (let line of findKeys(this._actors[sourceActorID], query.line))
|
|
|
|
for (let beginColumn of findKeys(this._actors[sourceActorID][line], query.beginColumn))
|
|
|
|
for (let endColumn of findKeys(this._actors[sourceActorID][line][beginColumn], query.endColumn)) {
|
|
|
|
yield this._actors[sourceActorID][line][beginColumn][endColumn];
|
2014-12-10 18:08:11 +00:00
|
|
|
}
|
2014-12-10 15:33:37 +00:00
|
|
|
},
|
2013-07-25 00:46:49 +00:00
|
|
|
|
|
|
|
/**
|
2015-02-23 08:36:58 +00:00
|
|
|
* Return the BreakpointActor at the given location in this
|
|
|
|
* BreakpointActorMap.
|
2014-12-10 15:33:37 +00:00
|
|
|
*
|
2015-02-23 15:14:57 +00:00
|
|
|
* @param OriginalLocation location
|
2015-02-23 08:36:58 +00:00
|
|
|
* The location for which the BreakpointActor should be returned.
|
2013-07-25 00:46:49 +00:00
|
|
|
*
|
2014-12-10 15:33:37 +00:00
|
|
|
* @returns BreakpointActor actor
|
2015-02-23 08:36:58 +00:00
|
|
|
* The BreakpointActor at the given location.
|
2013-07-25 00:46:49 +00:00
|
|
|
*/
|
2015-02-23 15:14:57 +00:00
|
|
|
getActor: function (originalLocation) {
|
|
|
|
for (let actor of this.findActors(originalLocation)) {
|
2014-12-10 15:33:37 +00:00
|
|
|
return actor;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-02-23 08:36:58 +00:00
|
|
|
* Set the given BreakpointActor to the given location in this
|
|
|
|
* BreakpointActorMap.
|
2014-12-10 15:33:37 +00:00
|
|
|
*
|
2015-02-23 15:14:57 +00:00
|
|
|
* @param OriginalLocation location
|
2015-02-23 08:36:58 +00:00
|
|
|
* The location to which the given BreakpointActor should be set.
|
2014-12-10 15:33:37 +00:00
|
|
|
*
|
|
|
|
* @param BreakpointActor actor
|
2015-02-23 08:36:58 +00:00
|
|
|
* The BreakpointActor to be set to the given location.
|
2014-12-10 15:33:37 +00:00
|
|
|
*/
|
|
|
|
setActor: function (location, actor) {
|
2015-02-23 15:14:57 +00:00
|
|
|
let { originalSourceActor, originalLine, originalColumn } = location;
|
2013-07-25 00:46:49 +00:00
|
|
|
|
2015-02-23 15:14:57 +00:00
|
|
|
let sourceActorID = originalSourceActor.actorID;
|
|
|
|
let line = originalLine;
|
|
|
|
let beginColumn = originalColumn ? originalColumn : 0;
|
|
|
|
let endColumn = originalColumn ? originalColumn + 1 : Infinity;
|
2014-11-25 23:02:39 +00:00
|
|
|
|
2015-01-19 13:09:15 +00:00
|
|
|
if (!this._actors[sourceActorID]) {
|
|
|
|
this._actors[sourceActorID] = [];
|
2014-12-10 18:08:11 +00:00
|
|
|
}
|
2015-01-19 13:09:15 +00:00
|
|
|
if (!this._actors[sourceActorID][line]) {
|
|
|
|
this._actors[sourceActorID][line] = [];
|
2014-12-10 18:08:11 +00:00
|
|
|
}
|
2015-01-19 13:09:15 +00:00
|
|
|
if (!this._actors[sourceActorID][line][beginColumn]) {
|
|
|
|
this._actors[sourceActorID][line][beginColumn] = [];
|
2013-07-25 00:46:49 +00:00
|
|
|
}
|
2015-01-19 13:09:15 +00:00
|
|
|
if (!this._actors[sourceActorID][line][beginColumn][endColumn]) {
|
2014-12-10 18:08:11 +00:00
|
|
|
++this._size;
|
|
|
|
}
|
2015-01-19 13:09:15 +00:00
|
|
|
this._actors[sourceActorID][line][beginColumn][endColumn] = actor;
|
2013-07-25 00:46:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-02-23 08:36:58 +00:00
|
|
|
* Delete the BreakpointActor from the given location in this
|
|
|
|
* BreakpointActorMap.
|
2013-07-25 00:46:49 +00:00
|
|
|
*
|
2015-02-23 15:14:57 +00:00
|
|
|
* @param OriginalLocation location
|
2015-02-23 08:36:58 +00:00
|
|
|
* The location from which the BreakpointActor should be deleted.
|
2013-07-25 00:46:49 +00:00
|
|
|
*/
|
2014-12-10 15:33:37 +00:00
|
|
|
deleteActor: function (location) {
|
2015-02-23 15:14:57 +00:00
|
|
|
let { originalSourceActor, originalLine, originalColumn } = location;
|
2014-12-10 15:33:37 +00:00
|
|
|
|
2015-02-23 15:14:57 +00:00
|
|
|
let sourceActorID = originalSourceActor.actorID;
|
|
|
|
let line = originalLine;
|
|
|
|
let beginColumn = originalColumn ? originalColumn : 0;
|
|
|
|
let endColumn = originalColumn ? originalColumn + 1 : Infinity;
|
2014-02-18 22:35:50 +00:00
|
|
|
|
2015-01-19 13:09:15 +00:00
|
|
|
if (this._actors[sourceActorID]) {
|
|
|
|
if (this._actors[sourceActorID][line]) {
|
|
|
|
if (this._actors[sourceActorID][line][beginColumn]) {
|
|
|
|
if (this._actors[sourceActorID][line][beginColumn][endColumn]) {
|
2014-12-10 18:08:11 +00:00
|
|
|
--this._size;
|
|
|
|
}
|
2015-01-19 13:09:15 +00:00
|
|
|
delete this._actors[sourceActorID][line][beginColumn][endColumn];
|
|
|
|
if (Object.keys(this._actors[sourceActorID][line][beginColumn]).length === 0) {
|
|
|
|
delete this._actors[sourceActorID][line][beginColumn];
|
2013-07-25 00:46:49 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-19 13:09:15 +00:00
|
|
|
if (Object.keys(this._actors[sourceActorID][line]).length === 0) {
|
|
|
|
delete this._actors[sourceActorID][line];
|
2013-07-25 00:46:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-12-10 18:08:11 +00:00
|
|
|
}
|
2013-07-25 00:46:49 +00:00
|
|
|
};
|
|
|
|
|
2014-12-10 15:33:37 +00:00
|
|
|
exports.BreakpointActorMap = BreakpointActorMap;
|
2014-04-29 15:52:44 +00:00
|
|
|
|
2014-11-25 23:02:39 +00:00
|
|
|
/**
|
|
|
|
* Keeps track of persistent sources across reloads and ties different
|
|
|
|
* source instances to the same actor id so that things like
|
|
|
|
* breakpoints survive reloads. ThreadSources uses this to force the
|
|
|
|
* same actorID on a SourceActor.
|
|
|
|
*/
|
|
|
|
function SourceActorStore() {
|
|
|
|
// source identifier --> actor id
|
|
|
|
this._sourceActorIds = Object.create(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
SourceActorStore.prototype = {
|
|
|
|
/**
|
|
|
|
* Lookup an existing actor id that represents this source, if available.
|
|
|
|
*/
|
|
|
|
getReusableActorId: function(aSource, aOriginalUrl) {
|
|
|
|
let url = this.getUniqueKey(aSource, aOriginalUrl);
|
|
|
|
if (url && url in this._sourceActorIds) {
|
|
|
|
return this._sourceActorIds[url];
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update a source with an actorID.
|
|
|
|
*/
|
|
|
|
setReusableActorId: function(aSource, aOriginalUrl, actorID) {
|
|
|
|
let url = this.getUniqueKey(aSource, aOriginalUrl);
|
|
|
|
if (url) {
|
|
|
|
this._sourceActorIds[url] = actorID;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make a unique URL from a source that identifies it across reloads.
|
|
|
|
*/
|
|
|
|
getUniqueKey: function(aSource, aOriginalUrl) {
|
|
|
|
if (aOriginalUrl) {
|
|
|
|
// Original source from a sourcemap.
|
|
|
|
return aOriginalUrl;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return getSourceURL(aSource);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.SourceActorStore = SourceActorStore;
|
|
|
|
|
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.
|
|
|
|
*
|
2013-12-09 20:09:15 +00:00
|
|
|
* @param ThreadActor thread
|
|
|
|
* The thread actor instance that owns this EventLoopStack.
|
|
|
|
* @param DebuggerServerConnection connection
|
|
|
|
* The remote protocol connection associated with this event loop stack.
|
2013-08-16 21:59:04 +00:00
|
|
|
* @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
|
|
|
|
*/
|
2014-06-17 19:51:43 +00:00
|
|
|
function EventLoopStack({ thread, connection, hooks }) {
|
2013-08-16 21:59:04 +00:00
|
|
|
this._hooks = hooks;
|
|
|
|
this._thread = thread;
|
2013-12-09 20:09:15 +00:00
|
|
|
this._connection = connection;
|
2013-08-16 21:59:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EventLoopStack.prototype = {
|
|
|
|
/**
|
|
|
|
* The number of nested event loops on the stack.
|
|
|
|
*/
|
|
|
|
get size() {
|
2014-06-17 19:51:43 +00:00
|
|
|
return xpcInspector.eventLoopNestLevel;
|
2013-08-16 21:59:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The URL of the debuggee who pushed the event loop on top of the stack.
|
|
|
|
*/
|
|
|
|
get lastPausedUrl() {
|
2013-09-18 09:58:37 +00:00
|
|
|
let url = null;
|
|
|
|
if (this.size > 0) {
|
|
|
|
try {
|
2014-06-17 19:51:43 +00:00
|
|
|
url = xpcInspector.lastNestRequestor.url
|
2013-09-18 09:58:37 +00:00
|
|
|
} catch (e) {
|
|
|
|
// The tab's URL getter may throw if the tab is destroyed by the time
|
|
|
|
// this code runs, but we don't really care at this point.
|
|
|
|
dumpn(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return url;
|
2013-08-16 21:59:04 +00:00
|
|
|
},
|
|
|
|
|
2013-12-09 20:09:15 +00:00
|
|
|
/**
|
|
|
|
* The DebuggerServerConnection of the debugger who pushed the event loop on
|
|
|
|
* top of the stack
|
|
|
|
*/
|
|
|
|
get lastConnection() {
|
2014-06-17 19:51:43 +00:00
|
|
|
return xpcInspector.lastNestRequestor._connection;
|
2013-12-09 20:09:15 +00:00
|
|
|
},
|
|
|
|
|
2013-08-16 21:59:04 +00:00
|
|
|
/**
|
|
|
|
* Push a new nested event loop onto the stack.
|
|
|
|
*
|
|
|
|
* @returns EventLoop
|
|
|
|
*/
|
|
|
|
push: function () {
|
|
|
|
return new EventLoop({
|
|
|
|
thread: this._thread,
|
2013-12-09 20:09:15 +00:00
|
|
|
connection: this._connection,
|
2013-08-16 21:59:04 +00:00
|
|
|
hooks: this._hooks
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An object that represents a nested event loop. It is used as the nest
|
|
|
|
* requestor with nsIJSInspector instances.
|
|
|
|
*
|
|
|
|
* @param ThreadActor thread
|
|
|
|
* The thread actor that is creating this nested event loop.
|
2013-12-09 20:09:15 +00:00
|
|
|
* @param DebuggerServerConnection connection
|
|
|
|
* The remote protocol connection associated with this event loop.
|
2013-08-16 21:59:04 +00:00
|
|
|
* @param Object hooks
|
|
|
|
* The same hooks object passed into EventLoopStack during its
|
|
|
|
* initialization.
|
|
|
|
*/
|
2014-06-17 19:51:43 +00:00
|
|
|
function EventLoop({ thread, connection, hooks }) {
|
2013-08-16 21:59:04 +00:00
|
|
|
this._thread = thread;
|
|
|
|
this._hooks = hooks;
|
2013-12-09 20:09:15 +00:00
|
|
|
this._connection = connection;
|
2013-08-16 21:59:04 +00:00
|
|
|
|
|
|
|
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;
|
2014-06-17 19:51:43 +00:00
|
|
|
xpcInspector.enterNestedEventLoop(this);
|
2013-08-16 21:59:04 +00:00
|
|
|
|
|
|
|
// Keep exiting nested event loops while the last requestor is resolved.
|
2014-06-17 19:51:43 +00:00
|
|
|
if (xpcInspector.eventLoopNestLevel > 0) {
|
|
|
|
const { resolved } = xpcInspector.lastNestRequestor;
|
2013-08-16 21:59:04 +00:00
|
|
|
if (resolved) {
|
2014-06-17 19:51:43 +00:00
|
|
|
xpcInspector.exitNestedEventLoop();
|
2013-08-16 21:59:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2014-06-17 19:51:43 +00:00
|
|
|
if (this === xpcInspector.lastNestRequestor) {
|
|
|
|
xpcInspector.exitNestedEventLoop();
|
2013-08-16 21:59:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2012-02-07 17:22:30 +00:00
|
|
|
/**
|
|
|
|
* JSD2 actors.
|
|
|
|
*/
|
2014-07-28 13:01:00 +00:00
|
|
|
|
2012-02-07 17:22:30 +00:00
|
|
|
/**
|
|
|
|
* Creates a ThreadActor.
|
|
|
|
*
|
|
|
|
* ThreadActors manage a JSInspector object and manage execution/inspection
|
|
|
|
* of debuggees.
|
2012-01-23 08:29:15 +00:00
|
|
|
*
|
2014-07-28 13:01:00 +00:00
|
|
|
* @param aParent object
|
|
|
|
* This |ThreadActor|'s parent actor. It must implement the following
|
|
|
|
* properties:
|
|
|
|
* - url: The URL string of the debuggee.
|
|
|
|
* - window: The global window object.
|
|
|
|
* - preNest: Function called before entering a nested event loop.
|
|
|
|
* - postNest: Function called after exiting a nested event loop.
|
|
|
|
* - makeDebugger: A function that takes no arguments and instantiates
|
|
|
|
* a Debugger that manages its globals on its own.
|
2012-11-06 07:14:07 +00:00
|
|
|
* @param aGlobal object [optional]
|
|
|
|
* An optional (for content debugging only) reference to the content
|
|
|
|
* window.
|
2012-02-07 17:22:30 +00:00
|
|
|
*/
|
2014-07-28 13:01:00 +00:00
|
|
|
function ThreadActor(aParent, aGlobal)
|
2012-02-07 17:22:30 +00:00
|
|
|
{
|
|
|
|
this._state = "detached";
|
|
|
|
this._frameActors = [];
|
2014-07-28 13:01:00 +00:00
|
|
|
this._parent = aParent;
|
|
|
|
this._dbg = null;
|
|
|
|
this._gripDepth = 0;
|
|
|
|
this._threadLifetimePool = null;
|
|
|
|
this._tabClosed = false;
|
2014-12-19 22:40:58 +00:00
|
|
|
this._scripts = null;
|
2014-08-29 17:51:24 +00:00
|
|
|
this._pauseOnDOMEvents = null;
|
2013-04-15 21:07:00 +00:00
|
|
|
|
|
|
|
this._options = {
|
2014-07-03 13:44:00 +00:00
|
|
|
useSourceMaps: false,
|
|
|
|
autoBlackBox: false
|
2013-04-15 21:07:00 +00:00
|
|
|
};
|
2013-12-19 13:04:59 +00:00
|
|
|
|
2015-03-23 14:50:00 +00:00
|
|
|
this.breakpointActorMap = new BreakpointActorMap();
|
|
|
|
this.sourceActorStore = new SourceActorStore();
|
2014-10-01 05:45:00 +00:00
|
|
|
|
2014-07-28 13:01:00 +00:00
|
|
|
// A map of actorID -> actor for breakpoints created and managed by the
|
|
|
|
// server.
|
2015-03-23 14:50:00 +00:00
|
|
|
this._hiddenBreakpoints = new Map();
|
2014-07-28 13:01:00 +00:00
|
|
|
|
|
|
|
this.global = aGlobal;
|
|
|
|
|
|
|
|
this._allEventsListener = this._allEventsListener.bind(this);
|
|
|
|
this.onNewGlobal = this.onNewGlobal.bind(this);
|
|
|
|
this.onNewSource = this.onNewSource.bind(this);
|
|
|
|
this.uncaughtExceptionHook = this.uncaughtExceptionHook.bind(this);
|
|
|
|
this.onDebuggerStatement = this.onDebuggerStatement.bind(this);
|
|
|
|
this.onNewScript = this.onNewScript.bind(this);
|
2014-08-29 17:51:24 +00:00
|
|
|
this._onWindowReady = this._onWindowReady.bind(this);
|
|
|
|
events.on(this._parent, "window-ready", this._onWindowReady);
|
2014-11-28 23:40:58 +00:00
|
|
|
// Set a wrappedJSObject property so |this| can be sent via the observer svc
|
|
|
|
// for the xpcshell harness.
|
|
|
|
this.wrappedJSObject = this;
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ThreadActor.prototype = {
|
2013-12-19 13:04:59 +00:00
|
|
|
// Used by the ObjectActor to keep track of the depth of grip() calls.
|
|
|
|
_gripDepth: null,
|
|
|
|
|
2012-02-07 17:22:30 +00:00
|
|
|
actorPrefix: "context",
|
|
|
|
|
2014-07-28 13:01:00 +00:00
|
|
|
get dbg() {
|
|
|
|
if (!this._dbg) {
|
|
|
|
this._dbg = this._parent.makeDebugger();
|
|
|
|
this._dbg.uncaughtExceptionHook = this.uncaughtExceptionHook;
|
|
|
|
this._dbg.onDebuggerStatement = this.onDebuggerStatement;
|
|
|
|
this._dbg.onNewScript = this.onNewScript;
|
|
|
|
this._dbg.on("newGlobal", this.onNewGlobal);
|
|
|
|
// Keep the debugger disabled until a client attaches.
|
|
|
|
this._dbg.enabled = this._state != "detached";
|
|
|
|
}
|
|
|
|
return this._dbg;
|
|
|
|
},
|
|
|
|
|
|
|
|
get globalDebugObject() {
|
|
|
|
return this.dbg.makeGlobalObjectReference(this._parent.window);
|
|
|
|
},
|
|
|
|
|
2015-05-28 15:54:00 +00:00
|
|
|
get state() {
|
|
|
|
return this._state;
|
|
|
|
},
|
|
|
|
|
|
|
|
get attached() {
|
|
|
|
return this.state == "attached" ||
|
|
|
|
this.state == "running" ||
|
|
|
|
this.state == "paused";
|
|
|
|
},
|
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;
|
|
|
|
},
|
|
|
|
|
2014-12-19 22:40:58 +00:00
|
|
|
get scripts() {
|
|
|
|
if (!this._scripts) {
|
|
|
|
this._scripts = new ScriptStore();
|
|
|
|
this._scripts.addScripts(this.dbg.findScripts());
|
|
|
|
}
|
|
|
|
return this._scripts;
|
|
|
|
},
|
|
|
|
|
2013-04-15 21:07:00 +00:00
|
|
|
get sources() {
|
2015-03-23 14:50:00 +00:00
|
|
|
return this._parent.sources;
|
2013-04-15 21:07:00 +00:00
|
|
|
},
|
|
|
|
|
2013-10-11 21:35:51 +00:00
|
|
|
get youngestFrame() {
|
2014-01-07 01:21:53 +00:00
|
|
|
if (this.state != "paused") {
|
2013-10-11 21:35:51 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return this.dbg.getNewestFrame();
|
|
|
|
},
|
|
|
|
|
2013-10-01 21:25:19 +00:00
|
|
|
_prettyPrintWorker: null,
|
|
|
|
get prettyPrintWorker() {
|
|
|
|
if (!this._prettyPrintWorker) {
|
2015-05-21 16:06:32 +00:00
|
|
|
this._prettyPrintWorker = new DevToolsWorker(
|
|
|
|
"resource://gre/modules/devtools/server/actors/pretty-print-worker.js",
|
|
|
|
{ name: "pretty-print",
|
|
|
|
verbose: dumpn.wantLogging }
|
|
|
|
);
|
2013-10-01 21:25:19 +00:00
|
|
|
}
|
|
|
|
return this._prettyPrintWorker;
|
|
|
|
},
|
|
|
|
|
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,
|
2013-11-07 14:27:40 +00:00
|
|
|
_pushThreadPause: function () {
|
2013-08-16 21:59:04 +00:00
|
|
|
if (!this._threadPauseEventLoops) {
|
|
|
|
this._threadPauseEventLoops = [];
|
|
|
|
}
|
|
|
|
const eventLoop = this._nestedEventLoops.push();
|
|
|
|
this._threadPauseEventLoops.push(eventLoop);
|
|
|
|
eventLoop.enter();
|
|
|
|
},
|
2013-11-07 14:27:40 +00:00
|
|
|
_popThreadPause: function () {
|
2013-08-16 21:59:04 +00:00
|
|
|
const eventLoop = this._threadPauseEventLoops.pop();
|
|
|
|
dbg_assert(eventLoop, "Should have an event loop.");
|
|
|
|
eventLoop.resolve();
|
|
|
|
},
|
|
|
|
|
2013-12-06 00:33:53 +00:00
|
|
|
/**
|
|
|
|
* Remove all debuggees and clear out the thread's sources.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
clearDebuggees: function () {
|
2014-07-28 13:01:00 +00:00
|
|
|
if (this._dbg) {
|
2012-11-02 16:30:23 +00:00
|
|
|
this.dbg.removeAllDebuggees();
|
2012-08-24 07:41:02 +00:00
|
|
|
}
|
2013-04-15 21:07:00 +00:00
|
|
|
this._sources = null;
|
2014-12-19 22:40:58 +00:00
|
|
|
this._scripts = null;
|
2012-08-24 07:41:02 +00:00
|
|
|
},
|
|
|
|
|
2012-02-07 17:22:30 +00:00
|
|
|
/**
|
2014-07-28 13:01:00 +00:00
|
|
|
* Listener for our |Debugger|'s "newGlobal" event.
|
2012-10-31 16:31:55 +00:00
|
|
|
*/
|
2014-07-28 13:01:00 +00:00
|
|
|
onNewGlobal: function (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
|
|
|
|
});
|
2012-10-31 16:31:55 +00:00
|
|
|
},
|
|
|
|
|
2013-11-07 14:27:40 +00:00
|
|
|
disconnect: function () {
|
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();
|
|
|
|
}
|
|
|
|
|
2014-11-25 23:02:39 +00:00
|
|
|
// Blow away our source actor ID store because those IDs are only
|
|
|
|
// valid for this connection. This is ok because we never keep
|
|
|
|
// things like breakpoints across connections.
|
|
|
|
this._sourceActorStore = null;
|
|
|
|
|
2014-08-29 17:51:24 +00:00
|
|
|
events.off(this._parent, "window-ready", this._onWindowReady);
|
2012-08-24 07:41:02 +00:00
|
|
|
this.clearDebuggees();
|
2013-12-06 00:33:53 +00:00
|
|
|
this.conn.removeActorPool(this._threadLifetimePool);
|
|
|
|
this._threadLifetimePool = null;
|
2012-08-24 07:41:02 +00:00
|
|
|
|
2013-10-01 21:25:19 +00:00
|
|
|
if (this._prettyPrintWorker) {
|
2015-05-21 16:06:32 +00:00
|
|
|
this._prettyPrintWorker.destroy();
|
2013-10-01 21:25:19 +00:00
|
|
|
this._prettyPrintWorker = null;
|
|
|
|
}
|
|
|
|
|
2014-07-28 13:01:00 +00:00
|
|
|
if (!this._dbg) {
|
2012-08-24 07:41:02 +00:00
|
|
|
return;
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
2014-07-28 13:01:00 +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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
exit: function () {
|
2012-02-07 17:22:30 +00:00
|
|
|
this.disconnect();
|
Make the debugger frontend cope with an already connected target (bug 933212); r=jryans,fitzgen
* Made the DebuggerClient, which is actually the RootActor front, not consider one of the attached child fronts as "active". Since a single DebuggerClient (or RootFront) is kept around for the App Manager's lifetime, it makes sense to move the notion of "active" tab to the toolbox's target. As each toolbox gets destroyed, the fronts should be detaching from their actors (if they are stateful) so that the app is no longer in a debugging state. Debugging a new app (or reconnecting to a previous one) will create new fronts anyway.
* Slightly refactored the TabClient, ThreadClient, SourceClient and TracerClient towards a protocol.js-based architecture, by adding parent-child references and lifecycle management. Now a tab-scoped thread actor for instance has the tab as its parent, while a global-scoped thread actor (chrome debugger) has the DebuggerCLient (RootFront) as its parent. This lets parents reference their children, so that caching in the target object can work. It also allowed me to move some methods from the DebuggerClient to the actual front that should be responsible, like reconfigureTab, reconfigureThread and attachThread. These methods now use DebuggerClient.requester, too.
* Added some error handling in the debugger client requester around "before" and "after" callbacks, which exposed some errors in tests that are now fixed.
* Fixed the state handling in the thread actor so that merely detaching from a thread doesn't put it in the exited state. This is the part that what was necessary for Firebug's use case.
* Properly loading tracer and webgl actors now on b2g.
2014-01-14 15:39:40 +00:00
|
|
|
this._state = "exited";
|
2012-02-07 17:22:30 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Request handlers
|
2013-11-07 14:27:40 +00:00
|
|
|
onAttach: function (aRequest) {
|
2012-02-07 17:22:30 +00:00
|
|
|
if (this.state === "exited") {
|
|
|
|
return { type: "exited" };
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.state !== "detached") {
|
Make the debugger frontend cope with an already connected target (bug 933212); r=jryans,fitzgen
* Made the DebuggerClient, which is actually the RootActor front, not consider one of the attached child fronts as "active". Since a single DebuggerClient (or RootFront) is kept around for the App Manager's lifetime, it makes sense to move the notion of "active" tab to the toolbox's target. As each toolbox gets destroyed, the fronts should be detaching from their actors (if they are stateful) so that the app is no longer in a debugging state. Debugging a new app (or reconnecting to a previous one) will create new fronts anyway.
* Slightly refactored the TabClient, ThreadClient, SourceClient and TracerClient towards a protocol.js-based architecture, by adding parent-child references and lifecycle management. Now a tab-scoped thread actor for instance has the tab as its parent, while a global-scoped thread actor (chrome debugger) has the DebuggerCLient (RootFront) as its parent. This lets parents reference their children, so that caching in the target object can work. It also allowed me to move some methods from the DebuggerClient to the actual front that should be responsible, like reconfigureTab, reconfigureThread and attachThread. These methods now use DebuggerClient.requester, too.
* Added some error handling in the debugger client requester around "before" and "after" callbacks, which exposed some errors in tests that are now fixed.
* Fixed the state handling in the thread actor so that merely detaching from a thread doesn't put it in the exited state. This is the part that what was necessary for Firebug's use case.
* Properly loading tracer and webgl actors now on b2g.
2014-01-14 15:39:40 +00:00
|
|
|
return { error: "wrongState",
|
|
|
|
message: "Current state is " + this.state };
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this._state = "attached";
|
|
|
|
|
2015-01-03 03:06:12 +00:00
|
|
|
update(this._options, aRequest.options || {});
|
2015-03-23 14:50:00 +00:00
|
|
|
this.sources.reconfigure(this._options);
|
|
|
|
this.sources.on('newSource', (name, source) => {
|
|
|
|
this.onNewSource(source);
|
|
|
|
});
|
2013-04-15 21:07:00 +00:00
|
|
|
|
2013-12-09 20:09:15 +00:00
|
|
|
// Initialize an event loop stack. This can't be done in the constructor,
|
|
|
|
// because this.conn is not yet initialized by the actor pool at that time.
|
|
|
|
this._nestedEventLoops = new EventLoopStack({
|
2014-07-28 13:01:00 +00:00
|
|
|
hooks: this._parent,
|
2013-12-09 20:09:15 +00:00
|
|
|
connection: this.conn,
|
|
|
|
thread: this
|
|
|
|
});
|
|
|
|
|
2014-07-28 13:01:00 +00:00
|
|
|
this.dbg.addDebuggees();
|
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() };
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-11-07 14:27:40 +00:00
|
|
|
onDetach: function (aRequest) {
|
2012-02-07 17:22:30 +00:00
|
|
|
this.disconnect();
|
Make the debugger frontend cope with an already connected target (bug 933212); r=jryans,fitzgen
* Made the DebuggerClient, which is actually the RootActor front, not consider one of the attached child fronts as "active". Since a single DebuggerClient (or RootFront) is kept around for the App Manager's lifetime, it makes sense to move the notion of "active" tab to the toolbox's target. As each toolbox gets destroyed, the fronts should be detaching from their actors (if they are stateful) so that the app is no longer in a debugging state. Debugging a new app (or reconnecting to a previous one) will create new fronts anyway.
* Slightly refactored the TabClient, ThreadClient, SourceClient and TracerClient towards a protocol.js-based architecture, by adding parent-child references and lifecycle management. Now a tab-scoped thread actor for instance has the tab as its parent, while a global-scoped thread actor (chrome debugger) has the DebuggerCLient (RootFront) as its parent. This lets parents reference their children, so that caching in the target object can work. It also allowed me to move some methods from the DebuggerClient to the actual front that should be responsible, like reconfigureTab, reconfigureThread and attachThread. These methods now use DebuggerClient.requester, too.
* Added some error handling in the debugger client requester around "before" and "after" callbacks, which exposed some errors in tests that are now fixed.
* Fixed the state handling in the thread actor so that merely detaching from a thread doesn't put it in the exited state. This is the part that what was necessary for Firebug's use case.
* Properly loading tracer and webgl actors now on b2g.
2014-01-14 15:39:40 +00:00
|
|
|
this._state = "detached";
|
|
|
|
|
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-11-07 14:27:40 +00:00
|
|
|
onReconfigure: function (aRequest) {
|
2013-04-16 15:00:33 +00:00
|
|
|
if (this.state == "exited") {
|
|
|
|
return { error: "wrongState" };
|
|
|
|
}
|
|
|
|
|
2015-01-03 03:06:12 +00:00
|
|
|
update(this._options, aRequest.options || {});
|
2015-03-23 14:50:00 +00:00
|
|
|
// Update the global source store
|
|
|
|
this.sources.reconfigure(this._options);
|
2013-04-16 15:00:33 +00:00
|
|
|
|
|
|
|
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-11-07 14:27:40 +00:00
|
|
|
_pauseAndRespond: function (aFrame, aReason, 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
|
|
|
|
2015-02-23 08:36:58 +00:00
|
|
|
let generatedLocation = this.sources.getFrameLocation(aFrame);
|
|
|
|
this.sources.getOriginalLocation(generatedLocation)
|
|
|
|
.then((originalLocation) => {
|
|
|
|
if (!originalLocation.originalSourceActor) {
|
2014-11-25 23:02:39 +00:00
|
|
|
// The only time the source actor will be null is if there
|
|
|
|
// was a sourcemap and it tried to look up the original
|
|
|
|
// location but there was no original URL. This is a strange
|
|
|
|
// scenario so we simply don't pause.
|
|
|
|
DevToolsUtils.reportException(
|
|
|
|
'ThreadActor',
|
|
|
|
new Error('Attempted to pause in a script with a sourcemap but ' +
|
|
|
|
'could not find original location.')
|
|
|
|
);
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
packet.frame.where = {
|
2015-02-23 08:36:58 +00:00
|
|
|
source: originalLocation.originalSourceActor.form(),
|
|
|
|
line: originalLocation.originalLine,
|
|
|
|
column: originalLocation.originalColumn
|
2014-11-25 23:02:39 +00:00
|
|
|
};
|
2015-05-15 14:38:33 +00:00
|
|
|
resolve(onPacket(packet))
|
2013-07-25 00:46:49 +00:00
|
|
|
.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
|
|
|
|
2014-05-21 01:27:25 +00:00
|
|
|
// If the browser tab has been closed, terminate the debuggee script
|
|
|
|
// instead of continuing. Executing JS after the content window is gone is
|
|
|
|
// a bad idea.
|
|
|
|
return this._tabClosed ? null : 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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
_forceCompletion: function (aRequest) {
|
2013-09-09 21:55:19 +00:00
|
|
|
// TODO: remove this when Debugger.Frame.prototype.pop is implemented in
|
|
|
|
// bug 736733.
|
|
|
|
return {
|
|
|
|
error: "notImplemented",
|
|
|
|
message: "forced completion is not yet implemented."
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2013-11-07 14:27:40 +00:00
|
|
|
_makeOnEnterFrame: function ({ pauseAndRespond }) {
|
2013-09-09 21:55:19 +00:00
|
|
|
return aFrame => {
|
2015-02-12 04:40:52 +00:00
|
|
|
const generatedLocation = this.sources.getFrameLocation(aFrame);
|
2015-02-23 08:36:58 +00:00
|
|
|
let { originalSourceActor } = this.synchronize(this.sources.getOriginalLocation(
|
2013-09-09 21:55:19 +00:00
|
|
|
generatedLocation));
|
2015-02-23 08:36:58 +00:00
|
|
|
let url = originalSourceActor.url;
|
2013-09-09 21:55:19 +00:00
|
|
|
|
|
|
|
return this.sources.isBlackBoxed(url)
|
|
|
|
? undefined
|
|
|
|
: pauseAndRespond(aFrame);
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2013-11-07 14:27:40 +00:00
|
|
|
_makeOnPop: function ({ thread, pauseAndRespond, createValueGrip }) {
|
2013-09-09 21:55:19 +00:00
|
|
|
return function (aCompletion) {
|
|
|
|
// onPop is called with 'this' set to the current frame.
|
|
|
|
|
2015-02-12 04:40:52 +00:00
|
|
|
const generatedLocation = thread.sources.getFrameLocation(this);
|
2015-02-23 08:36:58 +00:00
|
|
|
const { originalSourceActor } = thread.synchronize(thread.sources.getOriginalLocation(
|
2013-09-09 21:55:19 +00:00
|
|
|
generatedLocation));
|
2015-02-23 08:36:58 +00:00
|
|
|
const url = originalSourceActor.url;
|
2013-09-09 21:55:19 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2013-11-07 14:27:40 +00:00
|
|
|
_makeOnStep: function ({ thread, pauseAndRespond, startFrame,
|
2014-05-21 01:27:25 +00:00
|
|
|
startLocation, steppingType }) {
|
|
|
|
// Breaking in place: we should always pause.
|
|
|
|
if (steppingType === "break") {
|
|
|
|
return function () {
|
|
|
|
return pauseAndRespond(this);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise take what a "step" means into consideration.
|
2013-09-09 21:55:19 +00:00
|
|
|
return function () {
|
|
|
|
// onStep is called with 'this' set to the current frame.
|
|
|
|
|
2015-02-12 04:40:52 +00:00
|
|
|
const generatedLocation = thread.sources.getFrameLocation(this);
|
2013-09-09 21:55:19 +00:00
|
|
|
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
|
2015-02-23 08:36:58 +00:00
|
|
|
if (newLocation.originalUrl == null
|
|
|
|
|| thread.sources.isBlackBoxed(newLocation.originalUrl)) {
|
2013-09-09 21:55:19 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cases 1.1, 1.2 and 1.3
|
|
|
|
if (this !== startFrame
|
2015-02-23 08:36:58 +00:00
|
|
|
|| startLocation.originalUrl !== newLocation.originalUrl
|
|
|
|
|| startLocation.originalLine !== newLocation.originalLine) {
|
2013-09-09 21:55:19 +00:00
|
|
|
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.
|
|
|
|
*/
|
2014-05-21 01:27:25 +00:00
|
|
|
_makeSteppingHooks: function (aStartLocation, steppingType) {
|
2013-09-09 21:55:19 +00:00
|
|
|
// 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 = {
|
2015-05-28 15:54:00 +00:00
|
|
|
pauseAndRespond: (aFrame, onPacket=k=>k) => {
|
2014-05-21 01:27:25 +00:00
|
|
|
return this._pauseAndRespond(aFrame, { type: "resumeLimit" }, onPacket);
|
2013-09-09 21:55:19 +00:00
|
|
|
},
|
|
|
|
createValueGrip: this.createValueGrip.bind(this),
|
|
|
|
thread: this,
|
|
|
|
startFrame: this.youngestFrame,
|
2014-05-21 01:27:25 +00:00
|
|
|
startLocation: aStartLocation,
|
|
|
|
steppingType: steppingType
|
2013-09-09 21:55:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
_handleResumeLimit: function (aRequest) {
|
2013-09-09 21:55:19 +00:00
|
|
|
let steppingType = aRequest.resumeLimit.type;
|
2014-05-21 01:27:25 +00:00
|
|
|
if (["break", "step", "next", "finish"].indexOf(steppingType) == -1) {
|
2015-05-15 14:38:33 +00:00
|
|
|
return reject({ error: "badParameterType",
|
|
|
|
message: "Unknown resumeLimit type" });
|
2013-09-09 21:55:19 +00:00
|
|
|
}
|
|
|
|
|
2015-02-12 04:40:52 +00:00
|
|
|
const generatedLocation = this.sources.getFrameLocation(this.youngestFrame);
|
2013-09-09 21:55:19 +00:00
|
|
|
return this.sources.getOriginalLocation(generatedLocation)
|
|
|
|
.then(originalLocation => {
|
2014-05-21 01:27:25 +00:00
|
|
|
const { onEnterFrame, onPop, onStep } = this._makeSteppingHooks(originalLocation,
|
|
|
|
steppingType);
|
2013-09-09 21:55:19 +00:00
|
|
|
|
|
|
|
// 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.
|
2014-05-21 01:27:25 +00:00
|
|
|
case "break":
|
2013-09-09 21:55:19 +00:00
|
|
|
case "next":
|
2013-09-12 16:56:03 +00:00
|
|
|
if (stepFrame.script) {
|
|
|
|
stepFrame.onStep = onStep;
|
|
|
|
}
|
2013-09-09 21:55:19 +00:00
|
|
|
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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
_clearSteppingHooks: function (aFrame) {
|
2014-06-23 10:58:00 +00:00
|
|
|
if (aFrame && aFrame.live) {
|
|
|
|
while (aFrame) {
|
|
|
|
aFrame.onStep = undefined;
|
|
|
|
aFrame.onPop = undefined;
|
|
|
|
aFrame = aFrame.older;
|
|
|
|
}
|
2013-09-09 21:55:19 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
_maybeListenToEvents: function (aRequest) {
|
2013-09-09 21:55:19 +00:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-08-29 17:51:24 +00:00
|
|
|
/**
|
|
|
|
* If we are tasked with breaking on the load event, we have to add the
|
|
|
|
* listener early enough.
|
|
|
|
*/
|
|
|
|
_onWindowReady: function () {
|
|
|
|
this._maybeListenToEvents({
|
|
|
|
pauseOnDOMEvents: this._pauseOnDOMEvents
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-03-18 06:50:43 +00:00
|
|
|
/**
|
|
|
|
* Handle a protocol request to resume execution of the debuggee.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
onResume: function (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-09-18 09:58:37 +00:00
|
|
|
if (this._nestedEventLoops.size && this._nestedEventLoops.lastPausedUrl
|
2014-07-28 13:01:00 +00:00
|
|
|
&& (this._nestedEventLoops.lastPausedUrl !== this._parent.url
|
|
|
|
|| this._nestedEventLoops.lastConnection !== this.conn)) {
|
2013-08-16 21:59:04 +00:00
|
|
|
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);
|
2015-05-15 14:38:33 +00:00
|
|
|
resumeLimitHandled = resolve(true);
|
2013-09-05 23:32:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2014-11-28 23:40:58 +00:00
|
|
|
// Tell anyone who cares of the resume (as of now, that's the xpcshell
|
|
|
|
// harness)
|
|
|
|
if (Services.obs) {
|
|
|
|
Services.obs.notifyObservers(this, "devtools-thread-resumed", null);
|
|
|
|
}
|
2013-09-05 23:32:27 +00:00
|
|
|
return packet;
|
|
|
|
}, error => {
|
|
|
|
return error instanceof Error
|
|
|
|
? { error: "unknownError",
|
2014-03-04 14:38:05 +00:00
|
|
|
message: DevToolsUtils.safeErrorString(error) }
|
2013-09-05 23:32:27 +00:00
|
|
|
// 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;
|
2014-06-12 14:18:09 +00:00
|
|
|
let listenerDO = this.globalDebugObject.makeDebuggeeValue(listener);
|
|
|
|
// If the listener is an object with a 'handleEvent' method, use that.
|
|
|
|
if (listenerDO.class == "Object" || listenerDO.class == "XULElement") {
|
|
|
|
// For some events we don't have permission to access the
|
|
|
|
// 'handleEvent' property when running in content scope.
|
|
|
|
if (!listenerDO.unwrap()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
let heDesc;
|
|
|
|
while (!heDesc && listenerDO) {
|
|
|
|
heDesc = listenerDO.getOwnPropertyDescriptor("handleEvent");
|
|
|
|
listenerDO = listenerDO.proto;
|
|
|
|
}
|
|
|
|
if (heDesc && heDesc.value) {
|
|
|
|
listenerDO = heDesc.value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// When the listener is a bound function, we are actually interested in
|
|
|
|
// the target function.
|
|
|
|
while (listenerDO.isBoundFunction) {
|
|
|
|
listenerDO = listenerDO.boundTargetFunction;
|
|
|
|
}
|
|
|
|
l.script = listenerDO.script;
|
2013-07-18 11:14:16 +00:00
|
|
|
// 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;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-01-23 11:39:24 +00:00
|
|
|
* Set a breakpoint on the first line of the given script that has an entry
|
|
|
|
* point.
|
2013-07-18 11:14:16 +00:00
|
|
|
*/
|
|
|
|
_breakOnEnter: function(script) {
|
|
|
|
let offsets = script.getAllOffsets();
|
|
|
|
for (let line = 0, n = offsets.length; line < n; line++) {
|
|
|
|
if (offsets[line]) {
|
2015-01-23 11:39:24 +00:00
|
|
|
// N.B. Hidden breakpoints do not have an original location, and are not
|
|
|
|
// stored in the breakpoint actor map.
|
|
|
|
let actor = new BreakpointActor(this);
|
|
|
|
this.threadLifetimePool.addActor(actor);
|
|
|
|
let scripts = this.scripts.getScriptsBySourceAndLine(script.source, line);
|
|
|
|
let entryPoints = findEntryPointsForLine(scripts, line);
|
2015-03-26 19:15:36 +00:00
|
|
|
setBreakpointAtEntryPoints(actor, entryPoints);
|
2015-01-23 11:39:24 +00:00
|
|
|
this._hiddenBreakpoints.set(actor.actorID, actor);
|
2013-07-18 11:14:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-03-18 06:50:43 +00:00
|
|
|
/**
|
|
|
|
* Helper method that returns the next frame when stepping.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
_getNextStepFrame: function (aFrame) {
|
2012-03-18 06:50:43 +00:00
|
|
|
let stepFrame = aFrame.reportedPop ? aFrame.older : aFrame;
|
|
|
|
if (!stepFrame || !stepFrame.script) {
|
|
|
|
stepFrame = null;
|
|
|
|
}
|
|
|
|
return stepFrame;
|
|
|
|
},
|
|
|
|
|
2013-11-07 14:27:40 +00:00
|
|
|
onClientEvaluate: function (aRequest) {
|
2012-02-07 17:22:30 +00:00
|
|
|
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
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
|
2013-11-07 14:27:40 +00:00
|
|
|
onFrames: function (aRequest) {
|
2012-02-07 17:22:30 +00:00
|
|
|
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
|
|
|
|
2015-02-23 08:36:58 +00:00
|
|
|
let promise = this.sources.getOriginalLocation(new GeneratedLocation(
|
|
|
|
this.sources.createNonSourceMappedActor(frame.script.source),
|
|
|
|
form.where.line,
|
|
|
|
form.where.column
|
|
|
|
)).then((originalLocation) => {
|
|
|
|
let sourceForm = originalLocation.originalSourceActor.form();
|
2014-11-25 23:02:39 +00:00
|
|
|
form.where = {
|
|
|
|
source: sourceForm,
|
2015-02-23 08:36:58 +00:00
|
|
|
line: originalLocation.originalLine,
|
|
|
|
column: originalLocation.originalColumn
|
2014-11-25 23:02:39 +00:00
|
|
|
};
|
|
|
|
form.source = sourceForm;
|
|
|
|
});
|
2013-04-15 21:07:00 +00:00
|
|
|
promises.push(promise);
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
|
|
|
|
2015-05-15 14:38:33 +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
|
|
|
},
|
|
|
|
|
2013-11-07 14:27:40 +00:00
|
|
|
onReleaseMany: function (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;
|
2015-05-28 15:54:00 +00:00
|
|
|
for (let actorID of aRequest.actors) {
|
2012-02-07 17:22:30 +00:00
|
|
|
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
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-11-25 23:02:39 +00:00
|
|
|
* Get the script and source lists from the debugger.
|
2012-02-07 17:22:30 +00:00
|
|
|
*/
|
2014-11-25 23:02:39 +00:00
|
|
|
_discoverSources: function () {
|
2014-12-19 22:40:58 +00:00
|
|
|
// Only get one script per Debugger.Source.
|
2014-11-25 23:02:39 +00:00
|
|
|
const sourcesToScripts = new Map();
|
2014-12-19 22:40:58 +00:00
|
|
|
const scripts = this.scripts.getAllScripts();
|
|
|
|
for (let i = 0, len = scripts.length; i < len; i++) {
|
|
|
|
let s = scripts[i];
|
2014-11-25 23:02:39 +00:00
|
|
|
if (s.source) {
|
|
|
|
sourcesToScripts.set(s.source, s);
|
2013-04-15 21:07:00 +00:00
|
|
|
}
|
2014-11-25 23:02:39 +00:00
|
|
|
}
|
2013-04-15 21:07:00 +00:00
|
|
|
|
2015-05-28 15:54:00 +00:00
|
|
|
return all([...sourcesToScripts.values()].map(script => {
|
|
|
|
return this.sources.createSourceActors(script.source);
|
|
|
|
}));
|
2012-06-03 13:39:50 +00:00
|
|
|
},
|
|
|
|
|
2014-11-25 23:02:39 +00:00
|
|
|
onSources: function (aRequest) {
|
|
|
|
return this._discoverSources().then(() => {
|
|
|
|
return {
|
2015-05-28 15:54:00 +00:00
|
|
|
sources: this.sources.iter().map(s => s.form())
|
2014-11-25 23:02:39 +00:00
|
|
|
};
|
|
|
|
});
|
2013-07-18 11:14:16 +00:00
|
|
|
},
|
|
|
|
|
2014-11-13 18:07:18 +00:00
|
|
|
/**
|
2014-11-25 23:02:39 +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.
|
2014-11-13 18:07:18 +00:00
|
|
|
*/
|
2014-11-25 23:02:39 +00:00
|
|
|
disableAllBreakpoints: function () {
|
2014-12-10 15:33:37 +00:00
|
|
|
for (let bpActor of this.breakpointActorMap.findActors()) {
|
2014-12-03 17:23:41 +00:00
|
|
|
bpActor.removeScripts();
|
2014-11-13 18:07:18 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-11-25 23:02:39 +00:00
|
|
|
|
2014-11-13 18:07:18 +00:00
|
|
|
/**
|
2014-11-25 23:02:39 +00:00
|
|
|
* Handle a protocol request to pause the debuggee.
|
2014-11-13 18:07:18 +00:00
|
|
|
*/
|
2014-11-25 23:02:39 +00:00
|
|
|
onInterrupt: function (aRequest) {
|
|
|
|
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." };
|
2014-11-13 18:07:18 +00:00
|
|
|
}
|
|
|
|
|
2014-11-25 23:02:39 +00:00
|
|
|
try {
|
|
|
|
// Put ourselves in the paused state.
|
|
|
|
let packet = this._paused();
|
|
|
|
if (!packet) {
|
|
|
|
return { error: "notInterrupted" };
|
2014-11-13 18:07:18 +00:00
|
|
|
}
|
2014-11-25 23:02:39 +00:00
|
|
|
packet.why = { type: "interrupted" };
|
2014-11-13 18:07:18 +00:00
|
|
|
|
2014-11-25 23:02:39 +00:00
|
|
|
// 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);
|
2014-11-13 18:07:18 +00:00
|
|
|
|
2014-11-25 23:02:39 +00:00
|
|
|
// Start a nested event loop.
|
|
|
|
this._pushThreadPause();
|
2014-11-13 18:07:18 +00:00
|
|
|
|
2014-11-25 23:02:39 +00:00
|
|
|
// We already sent a response to this request, don't send one
|
|
|
|
// now.
|
|
|
|
return null;
|
|
|
|
} catch (e) {
|
|
|
|
reportError(e);
|
|
|
|
return { error: "notInterrupted", message: e.toString() };
|
2014-11-13 18:07:18 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-06-03 13:39:50 +00:00
|
|
|
/**
|
2014-11-25 23:02:39 +00:00
|
|
|
* Handle a protocol request to retrieve all the event listeners on the page.
|
2012-06-03 13:39:50 +00:00
|
|
|
*/
|
2014-11-25 23:02:39 +00:00
|
|
|
onEventListeners: function (aRequest) {
|
|
|
|
// This request is only supported in content debugging.
|
|
|
|
if (!this.global) {
|
2013-03-14 22:21:00 +00:00
|
|
|
return {
|
2014-11-25 23:02:39 +00:00
|
|
|
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;
|
2014-01-29 09:23:10 +00:00
|
|
|
// Native event listeners don't provide any listenerObject or type and
|
|
|
|
// are not that useful to a JS debugger.
|
|
|
|
if (!listener || !handler.type) {
|
2013-07-18 11:14:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// There will be no tagName if the event listener is set on the window.
|
2014-05-09 14:58:26 +00:00
|
|
|
let selector = node.tagName ? CssLogic.findCssSelector(node) : "window";
|
2013-07-18 11:14:16 +00:00
|
|
|
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;
|
2014-06-12 14:18:09 +00:00
|
|
|
let handlerName = "on" + listenerForm.type;
|
|
|
|
listenerForm.isEventHandler = false;
|
|
|
|
if (typeof node.hasAttribute !== "undefined") {
|
|
|
|
listenerForm.isEventHandler = !!node.hasAttribute(handlerName);
|
|
|
|
}
|
|
|
|
if (!!node[handlerName]) {
|
|
|
|
listenerForm.isEventHandler = !!node[handlerName];
|
|
|
|
}
|
2013-07-18 11:14:16 +00:00
|
|
|
// Get the Debugger.Object for the listener object.
|
|
|
|
let listenerDO = this.globalDebugObject.makeDebuggeeValue(listener);
|
2014-06-12 14:18:09 +00:00
|
|
|
// If the listener is an object with a 'handleEvent' method, use that.
|
|
|
|
if (listenerDO.class == "Object" || listenerDO.class == "XULElement") {
|
2014-07-21 15:31:18 +00:00
|
|
|
// For some events we don't have permission to access the
|
|
|
|
// 'handleEvent' property when running in content scope.
|
|
|
|
if (!listenerDO.unwrap()) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-06-12 14:18:09 +00:00
|
|
|
let heDesc;
|
|
|
|
while (!heDesc && listenerDO) {
|
|
|
|
heDesc = listenerDO.getOwnPropertyDescriptor("handleEvent");
|
|
|
|
listenerDO = listenerDO.proto;
|
|
|
|
}
|
|
|
|
if (heDesc && heDesc.value) {
|
|
|
|
listenerDO = heDesc.value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// When the listener is a bound function, we are actually interested in
|
|
|
|
// the target function.
|
|
|
|
while (listenerDO.isBoundFunction) {
|
|
|
|
listenerDO = listenerDO.boundTargetFunction;
|
|
|
|
}
|
2013-07-18 11:14:16 +00:00
|
|
|
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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
_requestFrame: function (aFrameID) {
|
2012-02-07 17:22:30 +00:00
|
|
|
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-11-07 14:27:40 +00:00
|
|
|
_paused: function (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;
|
|
|
|
}
|
2014-07-28 13:01:00 +00:00
|
|
|
|
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.
|
2015-04-29 15:32:05 +00:00
|
|
|
if (this.global && !this.global.toString().includes("Sandbox")) {
|
2013-07-18 11:14:16 +00:00
|
|
|
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";
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
},
|
|
|
|
|
2013-11-07 14:27:40 +00:00
|
|
|
_resumed: function () {
|
2012-02-07 17:22:30 +00:00
|
|
|
this._state = "running";
|
|
|
|
|
|
|
|
// Drop the actors in the pause actor pool.
|
|
|
|
this.conn.removeActorPool(this._pausePool);
|
|
|
|
|
|
|
|
this._pausePool = null;
|
|
|
|
this._pauseActor = null;
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
_updateFrames: function () {
|
2012-02-07 17:22:30 +00:00
|
|
|
let popped = [];
|
|
|
|
|
|
|
|
// Create the actor pool that will hold the still-living frames.
|
|
|
|
let framePool = new ActorPool(this.conn);
|
|
|
|
let frameList = [];
|
|
|
|
|
2015-05-28 15:54:00 +00:00
|
|
|
for (let frameActor of this._frameActors) {
|
2012-02-07 17:22:30 +00:00
|
|
|
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;
|
|
|
|
},
|
|
|
|
|
2013-11-07 14:27:40 +00:00
|
|
|
_createFrameActor: function (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
|
|
|
*/
|
2014-03-07 19:06:28 +00:00
|
|
|
createEnvironmentActor: function (aEnvironment, aPool) {
|
2012-03-21 15:49:23 +00:00
|
|
|
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
|
|
|
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
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
createValueGrip: function (aValue, aPool=false) {
|
2012-09-27 08:30:00 +00:00
|
|
|
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;
|
2014-08-25 13:49:00 +00:00
|
|
|
|
2013-08-12 17:15:22 +00:00
|
|
|
case "string":
|
|
|
|
if (this._stringIsLong(aValue)) {
|
|
|
|
return this.longStringGrip(aValue, aPool);
|
|
|
|
}
|
|
|
|
return aValue;
|
2014-08-25 13:49:00 +00:00
|
|
|
|
2013-08-12 17:15:22 +00:00
|
|
|
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;
|
2014-08-25 13:49:00 +00:00
|
|
|
|
2013-08-12 17:15:22 +00:00
|
|
|
case "undefined":
|
|
|
|
return { type: "undefined" };
|
2014-08-25 13:49:00 +00:00
|
|
|
|
2013-08-12 17:15:22 +00:00
|
|
|
case "object":
|
|
|
|
if (aValue === null) {
|
|
|
|
return { type: "null" };
|
|
|
|
}
|
2015-01-14 18:51:00 +00:00
|
|
|
else if(aValue.optimizedOut ||
|
|
|
|
aValue.uninitialized ||
|
|
|
|
aValue.missingArguments) {
|
|
|
|
// The slot is optimized out, an uninitialized binding, or
|
|
|
|
// arguments on a dead scope
|
|
|
|
return {
|
|
|
|
type: "null",
|
|
|
|
optimizedOut: aValue.optimizedOut,
|
|
|
|
uninitialized: aValue.uninitialized,
|
|
|
|
missingArguments: aValue.missingArguments
|
|
|
|
};
|
|
|
|
}
|
2013-08-12 17:15:22 +00:00
|
|
|
return this.objectGrip(aValue, aPool);
|
2014-08-25 13:49:00 +00:00
|
|
|
|
|
|
|
case "symbol":
|
|
|
|
let form = {
|
|
|
|
type: "symbol"
|
|
|
|
};
|
|
|
|
let name = getSymbolName(aValue);
|
|
|
|
if (name !== undefined) {
|
|
|
|
form.name = this.createValueGrip(name);
|
|
|
|
}
|
|
|
|
return form;
|
|
|
|
|
2013-08-12 17:15:22 +00:00
|
|
|
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.
|
|
|
|
*/
|
2014-03-07 19:06:28 +00:00
|
|
|
createProtocolCompletionValue: function (aCompletion) {
|
2012-03-13 07:13:02 +00:00
|
|
|
let protoValue = {};
|
2014-07-15 16:20:38 +00:00
|
|
|
if (aCompletion == null) {
|
|
|
|
protoValue.terminated = true;
|
|
|
|
} else if ("return" in aCompletion) {
|
2012-03-13 07:13:02 +00:00
|
|
|
protoValue.return = this.createValueGrip(aCompletion.return);
|
|
|
|
} else if ("throw" in aCompletion) {
|
|
|
|
protoValue.throw = this.createValueGrip(aCompletion.throw);
|
|
|
|
} else {
|
2014-07-15 16:20:38 +00:00
|
|
|
protoValue.return = this.createValueGrip(aCompletion.yield);
|
2012-03-13 07:13:02 +00:00
|
|
|
}
|
|
|
|
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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
objectGrip: function (aValue, aPool) {
|
2012-02-07 17:22:30 +00:00
|
|
|
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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
pauseObjectGrip: function (aValue) {
|
2012-02-07 17:22:30 +00:00
|
|
|
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
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
threadObjectGrip: function (aActor) {
|
2012-10-12 08:26:49 +00:00
|
|
|
// 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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
onThreadGrips: function (aRequest) {
|
2012-11-14 08:00:57 +00:00
|
|
|
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
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
longStringGrip: function (aString, aPool) {
|
2012-09-27 08:29:00 +00:00
|
|
|
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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
pauseLongStringGrip: function (aString) {
|
2012-09-27 08:29:00 +00:00
|
|
|
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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
threadLongStringGrip: function (aString) {
|
2012-09-27 08:29:00 +00:00
|
|
|
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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
_stringIsLong: function (aString) {
|
2012-08-30 21:10:07 +00:00
|
|
|
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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
uncaughtExceptionHook: function (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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
onDebuggerStatement: function (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.
|
2015-02-12 04:40:52 +00:00
|
|
|
const generatedLocation = this.sources.getFrameLocation(aFrame);
|
2015-02-23 08:36:58 +00:00
|
|
|
const { originalSourceActor } = this.synchronize(this.sources.getOriginalLocation(
|
2013-09-05 23:51:23 +00:00
|
|
|
generatedLocation));
|
2015-02-23 08:36:58 +00:00
|
|
|
const url = originalSourceActor ? originalSourceActor.url : null;
|
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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
onExceptionUnwind: function (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;
|
|
|
|
}
|
|
|
|
|
2015-02-12 04:40:52 +00:00
|
|
|
const generatedLocation = this.sources.getFrameLocation(aFrame);
|
2014-11-25 23:02:39 +00:00
|
|
|
const { sourceActor } = this.synchronize(this.sources.getOriginalLocation(
|
2013-09-05 23:51:23 +00:00
|
|
|
generatedLocation));
|
2014-11-25 23:02:39 +00:00
|
|
|
const url = sourceActor ? sourceActor.url : null;
|
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
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
onNewScript: function (aScript, aGlobal) {
|
2014-12-19 22:40:58 +00:00
|
|
|
// XXX: The scripts must be added to the ScriptStore before restoring
|
|
|
|
// breakpoints in _addScript. If we try to add them to the ScriptStore
|
|
|
|
// inside _addScript, we can accidentally set a breakpoint in a top level
|
|
|
|
// script as a "closest match" because we wouldn't have added the child
|
|
|
|
// scripts to the ScriptStore yet.
|
2015-01-21 16:41:00 +00:00
|
|
|
this.scripts.addScripts(this.dbg.findScripts({ source: aScript.source }));
|
2014-12-19 22:40:58 +00:00
|
|
|
|
2015-04-28 14:41:00 +00:00
|
|
|
this._addSource(aScript.source);
|
2012-03-30 08:25:52 +00:00
|
|
|
},
|
|
|
|
|
2013-11-07 14:27:40 +00:00
|
|
|
onNewSource: function (aSource) {
|
2013-04-15 21:07:00 +00:00
|
|
|
this.conn.send({
|
|
|
|
from: this.actorID,
|
|
|
|
type: "newSource",
|
|
|
|
source: aSource.form()
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-06-11 07:58:57 +00:00
|
|
|
/**
|
2015-04-28 14:41:00 +00:00
|
|
|
* Restore any pre-existing breakpoints to the sources that we have access to.
|
2013-06-20 17:43:30 +00:00
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
_restoreBreakpoints: function () {
|
2014-12-10 15:33:37 +00:00
|
|
|
if (this.breakpointActorMap.size === 0) {
|
2014-02-18 22:35:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-28 14:41:00 +00:00
|
|
|
for (let s of this.scripts.getSources()) {
|
|
|
|
this._addSource(s);
|
2013-06-20 17:43:30 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-04-28 14:41:00 +00:00
|
|
|
* Add the provided source to the server cache.
|
2013-06-11 07:58:57 +00:00
|
|
|
*
|
2015-04-28 14:41:00 +00:00
|
|
|
* @param aSource Debugger.Source
|
|
|
|
* The source that will be stored.
|
|
|
|
* @returns true, if the source was added; false otherwise.
|
2013-06-11 07:58:57 +00:00
|
|
|
*/
|
2015-04-28 14:41:00 +00:00
|
|
|
_addSource: function (aSource) {
|
|
|
|
if (!this.sources.allowSource(aSource)) {
|
2013-06-11 07:58:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-05-08 17:50:49 +00:00
|
|
|
let sourceActor = this.sources.createNonSourceMappedActor(aSource);
|
|
|
|
|
|
|
|
// Go ahead and establish the source actors for this script, which
|
|
|
|
// fetches sourcemaps if available and sends onNewSource
|
|
|
|
// notifications.
|
|
|
|
//
|
|
|
|
// We need to use synchronize here because if the page is being reloaded,
|
|
|
|
// this call will replace the previous set of source actors for this source
|
|
|
|
// with a new one. If the source actors have not been replaced by the time
|
|
|
|
// we try to reset the breakpoints below, their location objects will still
|
|
|
|
// point to the old set of source actors, which point to different scripts.
|
|
|
|
this.synchronize(this.sources.createSourceActors(aSource));
|
|
|
|
|
2013-06-11 07:58:57 +00:00
|
|
|
// Set any stored breakpoints.
|
2015-02-23 15:14:57 +00:00
|
|
|
let promises = [];
|
2015-05-08 17:50:49 +00:00
|
|
|
|
2015-03-23 14:50:00 +00:00
|
|
|
for (let _actor of this.breakpointActorMap.findActors()) {
|
|
|
|
// XXX bug 1142115: We do async work in here, so we need to
|
|
|
|
// create a fresh binding because for/of does not yet do that in
|
|
|
|
// SpiderMonkey
|
|
|
|
let actor = _actor;
|
|
|
|
|
2015-03-11 14:15:40 +00:00
|
|
|
if (actor.isPending) {
|
2015-03-31 14:28:30 +00:00
|
|
|
promises.push(actor.originalLocation.originalSourceActor._setBreakpoint(actor));
|
2015-03-11 14:15:40 +00:00
|
|
|
} else {
|
2015-05-08 17:50:49 +00:00
|
|
|
promises.push(this.sources.getAllGeneratedLocations(actor.originalLocation)
|
|
|
|
.then((generatedLocations) => {
|
|
|
|
if (generatedLocations.length > 0 &&
|
|
|
|
generatedLocations[0].generatedSourceActor.actorID === sourceActor.actorID) {
|
|
|
|
sourceActor._setBreakpointAtAllGeneratedLocations(
|
2015-03-26 19:15:36 +00:00
|
|
|
actor,
|
2015-05-08 17:50:49 +00:00
|
|
|
generatedLocations
|
2015-03-26 19:15:36 +00:00
|
|
|
);
|
2015-03-11 14:15:40 +00:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
2015-02-23 15:14:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (promises.length > 0) {
|
|
|
|
this.synchronize(Promise.all(promises));
|
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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
onPrototypesAndProperties: function (aRequest) {
|
2013-08-20 12:32:04 +00:00
|
|
|
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,
|
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
|
|
|
};
|
|
|
|
|
2014-04-29 15:52:44 +00:00
|
|
|
exports.ThreadActor = ThreadActor;
|
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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
PauseScopedActor.withPaused = function (aMethod) {
|
2012-08-30 21:10:07 +00:00
|
|
|
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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
isPaused: function () {
|
2012-08-30 21:10:07 +00:00
|
|
|
// 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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
_wrongState: function () {
|
2012-08-30 21:10:07 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-03-31 17:19:15 +00:00
|
|
|
/**
|
|
|
|
* Resolve a URI back to physical file.
|
|
|
|
*
|
|
|
|
* Of course, this works only for URIs pointing to local resources.
|
|
|
|
*
|
|
|
|
* @param aURI
|
|
|
|
* URI to resolve
|
|
|
|
* @return
|
|
|
|
* resolved nsIURI
|
|
|
|
*/
|
|
|
|
function resolveURIToLocalPath(aURI) {
|
Bug 1001090 - Part 4: Fix errors in chrome code. (r=zombie,gavin,fitzgen,dcamp,bgrins,fabrice,gwagner,margaret,mrbkap,mak,njn,vicamo)
2014-09-15 23:30:46 +00:00
|
|
|
let resolved;
|
2014-03-31 17:19:15 +00:00
|
|
|
switch (aURI.scheme) {
|
|
|
|
case "jar":
|
|
|
|
case "file":
|
|
|
|
return aURI;
|
|
|
|
|
|
|
|
case "chrome":
|
Bug 1001090 - Part 4: Fix errors in chrome code. (r=zombie,gavin,fitzgen,dcamp,bgrins,fabrice,gwagner,margaret,mrbkap,mak,njn,vicamo)
2014-09-15 23:30:46 +00:00
|
|
|
resolved = Cc["@mozilla.org/chrome/chrome-registry;1"].
|
|
|
|
getService(Ci.nsIChromeRegistry).convertChromeURL(aURI);
|
2014-03-31 17:19:15 +00:00
|
|
|
return resolveURIToLocalPath(resolved);
|
|
|
|
|
|
|
|
case "resource":
|
|
|
|
resolved = Cc["@mozilla.org/network/protocol;1?name=resource"].
|
|
|
|
getService(Ci.nsIResProtocolHandler).resolveURI(aURI);
|
|
|
|
aURI = Services.io.newURI(resolved, null, null);
|
|
|
|
return resolveURIToLocalPath(aURI);
|
|
|
|
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2012-08-30 21:10:07 +00:00
|
|
|
|
2012-09-27 08:30:00 +00:00
|
|
|
/**
|
2014-11-25 23:02:39 +00:00
|
|
|
* A SourceActor provides information about the source of a script. There
|
|
|
|
* are two kinds of source actors: ones that represent real source objects,
|
|
|
|
* and ones that represent non-existant "original" sources when the real
|
|
|
|
* sources are sourcemapped. When a source is sourcemapped, actors are
|
|
|
|
* created for both the "generated" and "original" sources, and the client will
|
|
|
|
* only see the original sources. We separate these because there isn't
|
|
|
|
* a 1:1 mapping of generated to original sources; one generated source
|
|
|
|
* may represent N original sources, so we need to create N + 1 separate
|
|
|
|
* actors.
|
2012-09-27 08:30:00 +00:00
|
|
|
*
|
2014-11-25 23:02:39 +00:00
|
|
|
* There are 4 different scenarios for sources that you should
|
|
|
|
* understand:
|
|
|
|
*
|
|
|
|
* - A single non-sourcemapped source that is not inlined in HTML
|
|
|
|
* (separate JS file, eval'ed code, etc)
|
|
|
|
* - A single sourcemapped source which creates N original sources
|
|
|
|
* - An HTML page with multiple inline scripts, which are distinct
|
|
|
|
* sources, but should be represented as a single source
|
|
|
|
* - A pretty-printed source (which may or may not be an original
|
|
|
|
* sourcemapped source), which generates a sourcemap for itself
|
|
|
|
*
|
|
|
|
* The complexity of `SourceActor` and `ThreadSources` are to handle
|
|
|
|
* all of thise cases and hopefully internalize the complexities.
|
|
|
|
*
|
|
|
|
* @param Debugger.Source source
|
|
|
|
* The source object we are representing.
|
2013-09-12 23:39:53 +00:00
|
|
|
* @param ThreadActor thread
|
2012-09-27 08:30:00 +00:00
|
|
|
* The current thread actor.
|
2014-11-25 23:02:39 +00:00
|
|
|
* @param String originalUrl
|
|
|
|
* Optional. For sourcemapped urls, the original url this is representing.
|
|
|
|
* @param Debugger.Source generatedSource
|
2013-09-11 17:15:51 +00:00
|
|
|
* Optional, passed in when aSourceMap is also passed in. The generated
|
2014-11-25 23:02:39 +00:00
|
|
|
* source object that introduced this source.
|
2013-09-12 23:39:53 +00:00
|
|
|
* @param String contentType
|
|
|
|
* Optional. The content type of this source, if immediately available.
|
2012-09-27 08:30:00 +00:00
|
|
|
*/
|
2014-11-25 23:02:39 +00:00
|
|
|
function SourceActor({ source, thread, originalUrl, generatedSource,
|
2015-04-30 22:36:53 +00:00
|
|
|
isInlineSource, contentType }) {
|
2013-09-12 23:39:53 +00:00
|
|
|
this._threadActor = thread;
|
2014-11-25 23:02:39 +00:00
|
|
|
this._originalUrl = originalUrl;
|
|
|
|
this._source = source;
|
2013-09-12 23:39:53 +00:00
|
|
|
this._generatedSource = generatedSource;
|
|
|
|
this._contentType = contentType;
|
2015-04-30 22:36:53 +00:00
|
|
|
this._isInlineSource = isInlineSource;
|
2013-09-11 17:15:51 +00:00
|
|
|
|
|
|
|
this.onSource = this.onSource.bind(this);
|
|
|
|
this._invertSourceMap = this._invertSourceMap.bind(this);
|
2014-11-25 23:02:39 +00:00
|
|
|
this._encodeAndSetSourceMapURL = this._encodeAndSetSourceMapURL.bind(this);
|
2013-10-22 07:04:46 +00:00
|
|
|
this._getSourceText = this._getSourceText.bind(this);
|
|
|
|
|
2014-03-31 17:19:15 +00:00
|
|
|
this._mapSourceToAddon();
|
|
|
|
|
2013-10-22 07:04:46 +00:00
|
|
|
if (this.threadActor.sources.isPrettyPrinted(this.url)) {
|
|
|
|
this._init = this.onPrettyPrint({
|
|
|
|
indent: this.threadActor.sources.prettyPrintIndent(this.url)
|
|
|
|
}).then(null, error => {
|
|
|
|
DevToolsUtils.reportException("SourceActor", error);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this._init = null;
|
|
|
|
}
|
2012-09-27 08:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SourceActor.prototype = {
|
|
|
|
constructor: SourceActor,
|
|
|
|
actorPrefix: "source",
|
|
|
|
|
2013-10-22 07:04:46 +00:00
|
|
|
_oldSourceMap: null,
|
|
|
|
_init: null,
|
2014-03-31 17:19:15 +00:00
|
|
|
_addonID: null,
|
|
|
|
_addonPath: null,
|
2013-10-22 07:04:46 +00:00
|
|
|
|
2015-03-11 14:15:40 +00:00
|
|
|
get isSourceMapped() {
|
2015-04-30 22:36:53 +00:00
|
|
|
return !this.isInlineSource && (
|
|
|
|
this._originalURL || this._generatedSource ||
|
|
|
|
this.threadActor.sources.isPrettyPrinted(this.url)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
get isInlineSource() {
|
|
|
|
return this._isInlineSource;
|
2015-03-11 14:15:40 +00:00
|
|
|
},
|
|
|
|
|
2014-11-25 23:02:39 +00:00
|
|
|
get threadActor() { return this._threadActor; },
|
2015-03-26 19:15:36 +00:00
|
|
|
get sources() { return this._threadActor.sources; },
|
2014-11-25 23:02:39 +00:00
|
|
|
get dbg() { return this.threadActor.dbg; },
|
2014-12-19 22:40:58 +00:00
|
|
|
get scripts() { return this.threadActor.scripts; },
|
2014-11-25 23:02:39 +00:00
|
|
|
get source() { return this._source; },
|
|
|
|
get generatedSource() { return this._generatedSource; },
|
2014-12-10 15:33:37 +00:00
|
|
|
get breakpointActorMap() { return this.threadActor.breakpointActorMap; },
|
2014-11-25 23:02:39 +00:00
|
|
|
get url() {
|
|
|
|
if (this.source) {
|
2015-05-29 16:27:44 +00:00
|
|
|
return getSourceURL(this.source, this.threadActor._parent.window);
|
2014-11-25 23:02:39 +00:00
|
|
|
}
|
|
|
|
return this._originalUrl;
|
|
|
|
},
|
|
|
|
get addonID() { return this._addonID; },
|
|
|
|
get addonPath() { return this._addonPath; },
|
2012-09-27 08:30:00 +00:00
|
|
|
|
2013-10-01 21:25:19 +00:00
|
|
|
get prettyPrintWorker() {
|
|
|
|
return this.threadActor.prettyPrintWorker;
|
|
|
|
},
|
|
|
|
|
2013-11-07 14:27:40 +00:00
|
|
|
form: function () {
|
2014-11-25 23:02:39 +00:00
|
|
|
let source = this.source || this.generatedSource;
|
|
|
|
// This might not have a source or a generatedSource because we
|
|
|
|
// treat HTML pages with inline scripts as a special SourceActor
|
|
|
|
// that doesn't have either
|
|
|
|
let introductionUrl = null;
|
|
|
|
if (source && source.introductionScript) {
|
|
|
|
introductionUrl = source.introductionScript.source.url;
|
|
|
|
}
|
|
|
|
|
2013-02-28 12:02:00 +00:00
|
|
|
return {
|
|
|
|
actor: this.actorID,
|
2015-01-02 22:03:21 +00:00
|
|
|
url: this.url ? this.url.split(" -> ").pop() : null,
|
2014-03-31 17:19:15 +00:00
|
|
|
addonID: this._addonID,
|
|
|
|
addonPath: this._addonPath,
|
2013-10-22 07:04:46 +00:00
|
|
|
isBlackBoxed: this.threadActor.sources.isBlackBoxed(this.url),
|
2014-11-25 23:02:39 +00:00
|
|
|
isPrettyPrinted: this.threadActor.sources.isPrettyPrinted(this.url),
|
2015-01-02 22:03:21 +00:00
|
|
|
introductionUrl: introductionUrl ? introductionUrl.split(" -> ").pop() : null,
|
2014-11-25 23:02:39 +00:00
|
|
|
introductionType: source ? source.introductionType : null
|
2013-02-28 12:02:00 +00:00
|
|
|
};
|
2012-09-27 08:30:00 +00:00
|
|
|
},
|
|
|
|
|
2013-11-07 14:27:40 +00:00
|
|
|
disconnect: function () {
|
2012-09-27 08:30:00 +00:00
|
|
|
if (this.registeredPool && this.registeredPool.sourceActors) {
|
|
|
|
delete this.registeredPool.sourceActors[this.actorID];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-03-31 17:19:15 +00:00
|
|
|
_mapSourceToAddon: function() {
|
|
|
|
try {
|
2014-11-25 23:02:39 +00:00
|
|
|
var nsuri = Services.io.newURI(this.url.split(" -> ").pop(), null, null);
|
2014-03-31 17:19:15 +00:00
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
// We can't do anything with an invalid URI
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let localURI = resolveURIToLocalPath(nsuri);
|
|
|
|
|
|
|
|
let id = {};
|
|
|
|
if (localURI && mapURIToAddonID(localURI, id)) {
|
|
|
|
this._addonID = id.value;
|
|
|
|
|
|
|
|
if (localURI instanceof Ci.nsIJARURI) {
|
|
|
|
// The path in the add-on is easy for jar: uris
|
|
|
|
this._addonPath = localURI.JAREntry;
|
|
|
|
}
|
|
|
|
else if (localURI instanceof Ci.nsIFileURL) {
|
|
|
|
// For file: uris walk up to find the last directory that is part of the
|
|
|
|
// add-on
|
|
|
|
let target = localURI.file;
|
|
|
|
let path = target.leafName;
|
|
|
|
|
|
|
|
// We can assume that the directory containing the source file is part
|
|
|
|
// of the add-on
|
|
|
|
let root = target.parent;
|
|
|
|
let file = root.parent;
|
|
|
|
while (file && mapURIToAddonID(Services.io.newFileURI(file), {})) {
|
|
|
|
path = root.leafName + "/" + path;
|
|
|
|
root = file;
|
|
|
|
file = file.parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!file) {
|
2014-11-25 23:02:39 +00:00
|
|
|
const error = new Error("Could not find the root of the add-on for " + this.url);
|
2014-03-31 17:19:15 +00:00
|
|
|
DevToolsUtils.reportException("SourceActor.prototype._mapSourceToAddon", error)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._addonPath = path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-11-07 14:27:40 +00:00
|
|
|
_getSourceText: function () {
|
2014-11-25 23:02:39 +00:00
|
|
|
let toResolvedContent = t => ({
|
2013-09-12 23:39:53 +00:00
|
|
|
content: t,
|
|
|
|
contentType: this._contentType
|
|
|
|
});
|
|
|
|
|
2014-11-25 23:02:39 +00:00
|
|
|
let genSource = this.generatedSource || this.source;
|
|
|
|
return this.threadActor.sources.fetchSourceMap(genSource).then(map => {
|
|
|
|
let sc;
|
|
|
|
if (map && (sc = map.sourceContentFor(this.url))) {
|
|
|
|
return toResolvedContent(sc);
|
|
|
|
}
|
2013-05-13 11:16:00 +00:00
|
|
|
|
2014-11-25 23:02:39 +00:00
|
|
|
// Use `source.text` if it exists, is not the "no source"
|
|
|
|
// string, and the content type of the source is JavaScript. It
|
|
|
|
// will be "no source" if the Debugger API wasn't able to load
|
|
|
|
// the source because sources were discarded
|
|
|
|
// (javascript.options.discardSystemSource == true). Re-fetch
|
|
|
|
// non-JS sources to get the contentType from the headers.
|
|
|
|
if (this.source &&
|
|
|
|
this.source.text !== "[no source]" &&
|
|
|
|
this._contentType &&
|
|
|
|
this._contentType.indexOf('javascript') !== -1) {
|
|
|
|
return toResolvedContent(this.source.text);
|
|
|
|
}
|
|
|
|
else {
|
2015-04-30 22:36:53 +00:00
|
|
|
// Only load the HTML page source from cache (which exists when
|
|
|
|
// there are inline sources). Otherwise, we can't trust the
|
|
|
|
// cache because we are most likely here because we are
|
|
|
|
// fetching the original text for sourcemapped code, and the
|
|
|
|
// page hasn't requested it before (if it has, it was a
|
|
|
|
// previous debugging session).
|
|
|
|
let sourceFetched = fetch(this.url, { loadFromCache: this.isInlineSource });
|
2014-11-25 23:02:39 +00:00
|
|
|
|
|
|
|
// Record the contentType we just learned during fetching
|
2014-11-28 23:40:58 +00:00
|
|
|
return sourceFetched.then(result => {
|
|
|
|
this._contentType = result.contentType;
|
|
|
|
return result;
|
2014-11-25 23:02:39 +00:00
|
|
|
});
|
|
|
|
}
|
2014-02-11 21:35:11 +00:00
|
|
|
});
|
2013-09-11 17:15:51 +00:00
|
|
|
},
|
|
|
|
|
2014-10-01 16:57:49 +00:00
|
|
|
/**
|
|
|
|
* Get all executable lines from the current source
|
|
|
|
* @return Array - Executable lines of the current script
|
|
|
|
**/
|
|
|
|
getExecutableLines: function () {
|
|
|
|
// Check if the original source is source mapped
|
|
|
|
let packet = {
|
|
|
|
from: this.actorID
|
|
|
|
};
|
|
|
|
|
2014-11-25 23:02:39 +00:00
|
|
|
function sortLines(lines) {
|
|
|
|
// Converting the Set into an array
|
2015-05-28 15:54:00 +00:00
|
|
|
lines = [...lines];
|
2014-11-25 23:02:39 +00:00
|
|
|
lines.sort((a, b) => {
|
|
|
|
return a - b;
|
|
|
|
});
|
|
|
|
return lines;
|
|
|
|
}
|
2014-10-01 16:57:49 +00:00
|
|
|
|
2014-11-25 23:02:39 +00:00
|
|
|
if (this.generatedSource) {
|
|
|
|
return this.threadActor.sources.getSourceMap(this.generatedSource).then(sm => {
|
|
|
|
let lines = new Set();
|
2014-10-01 16:57:49 +00:00
|
|
|
|
2014-11-25 23:02:39 +00:00
|
|
|
// Position of executable lines in the generated source
|
|
|
|
let offsets = this.getExecutableOffsets(this.generatedSource, false);
|
|
|
|
for (let offset of offsets) {
|
|
|
|
let {line, source: sourceUrl} = sm.originalPositionFor({
|
|
|
|
line: offset.lineNumber,
|
|
|
|
column: offset.columnNumber
|
|
|
|
});
|
2014-10-01 16:57:49 +00:00
|
|
|
|
2014-11-25 23:02:39 +00:00
|
|
|
if (sourceUrl === this.url) {
|
|
|
|
lines.add(line);
|
|
|
|
}
|
2014-10-01 16:57:49 +00:00
|
|
|
}
|
|
|
|
|
2014-11-25 23:02:39 +00:00
|
|
|
packet.lines = sortLines(lines);
|
|
|
|
return packet;
|
|
|
|
});
|
|
|
|
}
|
2014-10-01 16:57:49 +00:00
|
|
|
|
2014-11-25 23:02:39 +00:00
|
|
|
let lines = this.getExecutableOffsets(this.source, true);
|
|
|
|
packet.lines = sortLines(lines);
|
2014-10-01 16:57:49 +00:00
|
|
|
return packet;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract all executable offsets from the given script
|
|
|
|
* @param String url - extract offsets of the script with this url
|
|
|
|
* @param Boolean onlyLine - will return only the line number
|
|
|
|
* @return Set - Executable offsets/lines of the script
|
|
|
|
**/
|
2014-11-25 23:02:39 +00:00
|
|
|
getExecutableOffsets: function (source, onlyLine) {
|
2014-10-01 16:57:49 +00:00
|
|
|
let offsets = new Set();
|
2014-12-19 22:40:58 +00:00
|
|
|
for (let s of this.threadActor.scripts.getScriptsBySource(source)) {
|
2014-11-25 23:02:39 +00:00
|
|
|
for (let offset of s.getAllColumnOffsets()) {
|
|
|
|
offsets.add(onlyLine ? offset.lineNumber : offset);
|
2014-10-01 16:57:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return offsets;
|
|
|
|
},
|
|
|
|
|
2013-09-11 17:15:51 +00:00
|
|
|
/**
|
|
|
|
* Handler for the "source" packet.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
onSource: function () {
|
2015-05-15 14:38:33 +00:00
|
|
|
return resolve(this._init)
|
2013-10-22 07:04:46 +00:00
|
|
|
.then(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
|
|
|
})
|
2013-10-22 07:04:46 +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,
|
2015-05-13 20:11:33 +00:00
|
|
|
"error": this.url,
|
2014-11-25 23:02:39 +00:00
|
|
|
"message": "Could not load the source for " + this.url + ".\n"
|
2014-03-04 14:38:05 +00:00
|
|
|
+ DevToolsUtils.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 }) {
|
2014-11-25 23:02:39 +00:00
|
|
|
this.threadActor.sources.prettyPrint(this.url, indent);
|
2013-09-11 17:15:51 +00:00
|
|
|
return this._getSourceText()
|
2013-10-01 21:25:19 +00:00
|
|
|
.then(this._sendToPrettyPrintWorker(indent))
|
2013-09-11 17:15:51 +00:00
|
|
|
.then(this._invertSourceMap)
|
2014-11-25 23:02:39 +00:00
|
|
|
.then(this._encodeAndSetSourceMapURL)
|
2013-10-22 07:04:46 +00:00
|
|
|
.then(() => {
|
|
|
|
// We need to reset `_init` now because we have already done the work of
|
|
|
|
// pretty printing, and don't want onSource to wait forever for
|
|
|
|
// initialization to complete.
|
|
|
|
this._init = null;
|
|
|
|
})
|
2013-09-11 17:15:51 +00:00
|
|
|
.then(this.onSource)
|
2013-10-22 07:04:46 +00:00
|
|
|
.then(null, error => {
|
|
|
|
this.onDisablePrettyPrint();
|
|
|
|
return {
|
|
|
|
from: this.actorID,
|
|
|
|
error: "prettyPrintError",
|
|
|
|
message: DevToolsUtils.safeErrorString(error)
|
|
|
|
};
|
|
|
|
});
|
2013-09-11 17:15:51 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-10-01 21:25:19 +00:00
|
|
|
* Return a function that sends a request to the pretty print worker, waits on
|
|
|
|
* the worker's response, and then returns the pretty printed code.
|
|
|
|
*
|
|
|
|
* @param Number aIndent
|
|
|
|
* The number of spaces to indent by the code by, when we send the
|
|
|
|
* request to the pretty print worker.
|
|
|
|
* @returns Function
|
|
|
|
* Returns a function which takes an AST, and returns a promise that
|
|
|
|
* is resolved with `{ code, mappings }` where `code` is the pretty
|
|
|
|
* printed code, and `mappings` is an array of source mappings.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
_sendToPrettyPrintWorker: function (aIndent) {
|
2013-11-06 06:49:22 +00:00
|
|
|
return ({ content }) => {
|
2015-05-21 16:06:32 +00:00
|
|
|
return this.prettyPrintWorker.performTask("pretty-print", {
|
2014-11-25 23:02:39 +00:00
|
|
|
url: this.url,
|
2013-10-01 21:25:19 +00:00
|
|
|
indent: aIndent,
|
2013-11-06 06:49:22 +00:00
|
|
|
source: content
|
2015-05-21 16:06:32 +00:00
|
|
|
})
|
2013-10-01 21:25:19 +00:00
|
|
|
};
|
2013-09-11 17:15:51 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
2013-09-24 23:01:01 +00:00
|
|
|
*
|
|
|
|
* Note that the source map is modified in place.
|
2013-09-11 17:15:51 +00:00
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
_invertSourceMap: function ({ code, mappings }) {
|
2014-11-25 23:02:39 +00:00
|
|
|
const generator = new SourceMapGenerator({ file: this.url });
|
2015-03-12 19:18:34 +00:00
|
|
|
return DevToolsUtils.yieldingEach(mappings._array, m => {
|
2013-10-01 21:25:19 +00:00
|
|
|
let mapping = {
|
|
|
|
generated: {
|
2015-04-01 09:03:57 +00:00
|
|
|
line: m.originalLine,
|
|
|
|
column: m.originalColumn
|
2013-10-01 21:25:19 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
if (m.source) {
|
|
|
|
mapping.source = m.source;
|
|
|
|
mapping.original = {
|
2015-04-01 09:03:57 +00:00
|
|
|
line: m.generatedLine,
|
|
|
|
column: m.generatedColumn
|
2013-10-01 21:25:19 +00:00
|
|
|
};
|
|
|
|
mapping.name = m.name;
|
|
|
|
}
|
|
|
|
generator.addMapping(mapping);
|
|
|
|
}).then(() => {
|
2014-11-25 23:02:39 +00:00
|
|
|
generator.setSourceContent(this.url, code);
|
2015-04-01 09:03:57 +00:00
|
|
|
let consumer = SourceMapConsumer.fromSourceMap(generator);
|
2014-11-25 23:02:39 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
code: code,
|
|
|
|
map: consumer
|
|
|
|
};
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
_encodeAndSetSourceMapURL: function ({ map: sm }) {
|
|
|
|
let source = this.generatedSource || this.source;
|
|
|
|
let sources = this.threadActor.sources;
|
|
|
|
|
|
|
|
return sources.getSourceMap(source).then(prevMap => {
|
|
|
|
if (prevMap) {
|
|
|
|
// Compose the source maps
|
|
|
|
this._oldSourceMapping = {
|
|
|
|
url: source.sourceMapURL,
|
|
|
|
map: prevMap
|
|
|
|
};
|
|
|
|
|
|
|
|
prevMap = SourceMapGenerator.fromSourceMap(prevMap);
|
|
|
|
prevMap.applySourceMap(sm, this.url);
|
|
|
|
sm = SourceMapConsumer.fromSourceMap(prevMap);
|
|
|
|
}
|
|
|
|
|
|
|
|
let sources = this.threadActor.sources;
|
|
|
|
sources.clearSourceMapCache(source.sourceMapURL);
|
|
|
|
sources.setSourceMapHard(source, null, sm);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for the "disablePrettyPrint" packet.
|
|
|
|
*/
|
|
|
|
onDisablePrettyPrint: function () {
|
|
|
|
let source = this.generatedSource || this.source;
|
|
|
|
let sources = this.threadActor.sources;
|
|
|
|
let sm = sources.getSourceMap(source);
|
|
|
|
|
|
|
|
sources.clearSourceMapCache(source.sourceMapURL, { hard: true });
|
|
|
|
|
|
|
|
if (this._oldSourceMapping) {
|
|
|
|
sources.setSourceMapHard(source,
|
|
|
|
this._oldSourceMapping.url,
|
|
|
|
this._oldSourceMapping.map);
|
|
|
|
this._oldSourceMapping = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.threadActor.sources.disablePrettyPrint(this.url);
|
|
|
|
return this.onSource();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for the "blackbox" packet.
|
|
|
|
*/
|
|
|
|
onBlackBox: function (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 (aRequest) {
|
|
|
|
this.threadActor.sources.unblackBox(this.url);
|
|
|
|
return {
|
|
|
|
from: this.actorID
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-03-11 14:15:40 +00:00
|
|
|
* Handle a request to set a breakpoint.
|
|
|
|
*
|
|
|
|
* @param JSON request
|
|
|
|
* A JSON object representing the request.
|
|
|
|
*
|
|
|
|
* @returns Promise
|
|
|
|
* A promise that resolves to a JSON object representing the
|
|
|
|
* response.
|
2014-11-25 23:02:39 +00:00
|
|
|
*/
|
2015-03-11 14:15:40 +00:00
|
|
|
onSetBreakpoint: function (request) {
|
2014-11-25 23:02:39 +00:00
|
|
|
if (this.threadActor.state !== "paused") {
|
2015-03-11 14:15:40 +00:00
|
|
|
return {
|
|
|
|
error: "wrongState",
|
|
|
|
message: "Cannot set breakpoint while debuggee is running."
|
|
|
|
};
|
2014-11-25 23:02:39 +00:00
|
|
|
}
|
|
|
|
|
2015-03-11 14:15:40 +00:00
|
|
|
let { location: { line, column }, condition } = request;
|
|
|
|
let location = new OriginalLocation(this, line, column);
|
2015-03-26 19:15:36 +00:00
|
|
|
return this._getOrCreateBreakpointActor(
|
|
|
|
location,
|
|
|
|
condition
|
|
|
|
).then((actor) => {
|
2015-03-31 14:28:17 +00:00
|
|
|
let response = {
|
|
|
|
actor: actor.actorID,
|
|
|
|
isPending: actor.isPending
|
|
|
|
};
|
2015-03-11 14:15:40 +00:00
|
|
|
|
2015-03-31 14:28:17 +00:00
|
|
|
let actualLocation = actor.originalLocation;
|
|
|
|
if (!actualLocation.equals(location)) {
|
|
|
|
response.actualLocation = actualLocation.toJSON();
|
2015-03-11 14:15:40 +00:00
|
|
|
}
|
2015-03-31 14:28:17 +00:00
|
|
|
|
|
|
|
return response;
|
2015-03-11 14:15:40 +00:00
|
|
|
});
|
2014-11-25 23:02:39 +00:00
|
|
|
},
|
|
|
|
|
2015-03-11 14:15:40 +00:00
|
|
|
/**
|
|
|
|
* Get or create a BreakpointActor for the given location in the original
|
|
|
|
* source, and ensure it is set as a breakpoint handler on all scripts that
|
|
|
|
* match the given location.
|
2014-11-25 23:02:39 +00:00
|
|
|
*
|
2015-02-23 15:14:57 +00:00
|
|
|
* @param OriginalLocation originalLocation
|
2015-03-11 14:15:40 +00:00
|
|
|
* An OriginalLocation representing the location of the breakpoint in
|
|
|
|
* the original source.
|
|
|
|
* @param String condition
|
|
|
|
* A string that is evaluated whenever the breakpoint is hit. If the
|
|
|
|
* string evaluates to false, the breakpoint is ignored.
|
|
|
|
*
|
2014-11-25 23:02:39 +00:00
|
|
|
* @returns BreakpointActor
|
2015-03-11 14:15:40 +00:00
|
|
|
* A BreakpointActor representing the breakpoint.
|
2014-11-25 23:02:39 +00:00
|
|
|
*/
|
2015-03-26 19:15:36 +00:00
|
|
|
_getOrCreateBreakpointActor: function (originalLocation, condition) {
|
2015-02-23 15:14:57 +00:00
|
|
|
let actor = this.breakpointActorMap.getActor(originalLocation);
|
2014-12-03 17:23:41 +00:00
|
|
|
if (!actor) {
|
2015-03-11 14:15:40 +00:00
|
|
|
actor = new BreakpointActor(this.threadActor, originalLocation);
|
2014-12-03 17:23:41 +00:00
|
|
|
this.threadActor.threadLifetimePool.addActor(actor);
|
2015-02-23 15:14:57 +00:00
|
|
|
this.breakpointActorMap.setActor(originalLocation, actor);
|
2014-11-25 23:02:39 +00:00
|
|
|
}
|
|
|
|
|
2015-01-22 08:39:28 +00:00
|
|
|
actor.condition = condition;
|
2014-11-25 23:02:39 +00:00
|
|
|
|
2015-03-26 19:15:36 +00:00
|
|
|
return this._setBreakpoint(actor);
|
2014-11-25 23:02:39 +00:00
|
|
|
},
|
|
|
|
|
2015-03-11 14:15:40 +00:00
|
|
|
/*
|
|
|
|
* Ensure the given BreakpointActor is set as a breakpoint handler on all
|
|
|
|
* scripts that match its location in the original source.
|
2015-01-19 13:44:26 +00:00
|
|
|
*
|
2015-03-23 13:13:03 +00:00
|
|
|
* If there are no scripts that match the location of the BreakpointActor,
|
|
|
|
* we slide its location to the next closest line (for line breakpoints) or
|
|
|
|
* column (for column breakpoint) that does.
|
2015-01-19 13:44:26 +00:00
|
|
|
*
|
2015-03-23 13:13:03 +00:00
|
|
|
* If breakpoint sliding fails, then either there are no scripts that contain
|
|
|
|
* any code for the given location, or they were all garbage collected before
|
|
|
|
* the debugger started running. We cannot distinguish between these two
|
|
|
|
* cases, so we insert the BreakpointActor in the BreakpointActorMap as
|
|
|
|
* a pending breakpoint. Whenever a new script is introduced, this method is
|
|
|
|
* called again for each pending breakpoint.
|
2014-11-25 23:02:39 +00:00
|
|
|
*
|
2015-03-11 14:15:40 +00:00
|
|
|
* @param BreakpointActor actor
|
|
|
|
* The BreakpointActor to be set as a breakpoint handler.
|
|
|
|
*
|
|
|
|
* @returns A Promise that resolves to the given BreakpointActor.
|
|
|
|
*/
|
2015-03-26 19:15:36 +00:00
|
|
|
_setBreakpoint: function (actor) {
|
2015-03-23 13:13:03 +00:00
|
|
|
let { originalLocation } = actor;
|
2015-03-27 06:49:16 +00:00
|
|
|
let { originalSourceActor, originalLine, originalColumn } = originalLocation;
|
2015-03-23 13:13:03 +00:00
|
|
|
|
2015-03-26 19:15:36 +00:00
|
|
|
return this._setBreakpointAtOriginalLocation(actor, originalLocation)
|
|
|
|
.then((actualLocation) => {
|
|
|
|
if (actualLocation) {
|
|
|
|
return actualLocation;
|
2015-03-23 13:13:03 +00:00
|
|
|
}
|
|
|
|
|
2015-04-01 13:54:53 +00:00
|
|
|
// There were no scripts that matched the given location, so we need to
|
|
|
|
// perform breakpoint sliding. We try to slide the breakpoint by column
|
|
|
|
// first, and if that fails, by line instead.
|
2015-03-26 19:15:36 +00:00
|
|
|
if (!this.isSourceMapped) {
|
2015-04-01 13:54:53 +00:00
|
|
|
if (originalColumn !== undefined) {
|
|
|
|
// To perform breakpoint sliding for column breakpoints, we need to
|
|
|
|
// build a map from column numbers to a list of entry points for each
|
|
|
|
// column, implemented as a sparse array. An entry point is a (script,
|
|
|
|
// offsets) pair, and represents all offsets in that script that are
|
|
|
|
// entry points for the corresponding column.
|
|
|
|
let columnToEntryPointsMap = [];
|
|
|
|
|
|
|
|
// Iterate over all scripts that correspond to this source actor and
|
|
|
|
// line number.
|
|
|
|
let scripts = this.scripts.getScriptsBySourceActor(this, originalLine);
|
2015-03-26 19:15:36 +00:00
|
|
|
for (let script of scripts) {
|
2015-04-01 13:54:53 +00:00
|
|
|
let columnToOffsetMap = script.getAllColumnOffsets()
|
|
|
|
.filter(({ lineNumber }) => {
|
|
|
|
return lineNumber === originalLine;
|
|
|
|
})
|
|
|
|
|
|
|
|
// Iterate over each column, and add their list of offsets to the
|
|
|
|
// map from column numbers to entry points by forming a (script,
|
|
|
|
// offsets) pair, where script is the current script, and offsets is
|
|
|
|
// the list of offsets for the current column.
|
|
|
|
for (let { columnNumber: column, offset } of columnToOffsetMap) {
|
|
|
|
let entryPoints = columnToEntryPointsMap[column];
|
|
|
|
if (!entryPoints) {
|
|
|
|
// We dont have a list of entry points for the current column
|
|
|
|
// number yet, so create it and add it to the map.
|
|
|
|
entryPoints = [];
|
|
|
|
columnToEntryPointsMap[column] = entryPoints;
|
2015-03-23 13:13:03 +00:00
|
|
|
}
|
2015-04-01 13:54:53 +00:00
|
|
|
entryPoints.push({ script, offsets: [offset] });
|
2015-03-23 13:13:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-01 13:54:53 +00:00
|
|
|
// Now that we have a map from column numbers to a list of entry points
|
|
|
|
// for each column, we can use it to perform breakpoint sliding. Start
|
|
|
|
// at the original column of the breakpoint actor, and keep
|
|
|
|
// incrementing it by one, until either we find a line that has at
|
|
|
|
// least one entry point, or we go past the last column in the map.
|
2015-03-26 19:15:36 +00:00
|
|
|
//
|
|
|
|
// Note that by computing the entire map up front, and implementing it
|
2015-04-01 13:54:53 +00:00
|
|
|
// as a sparse array, we can easily tell when we went past the last
|
|
|
|
// column in the map.
|
|
|
|
let actualColumn = originalColumn + 1;
|
|
|
|
while (actualColumn < columnToEntryPointsMap.length) {
|
|
|
|
let entryPoints = columnToEntryPointsMap[actualColumn];
|
2015-03-26 19:15:36 +00:00
|
|
|
if (entryPoints) {
|
|
|
|
setBreakpointAtEntryPoints(actor, entryPoints);
|
2015-04-01 13:54:53 +00:00
|
|
|
return new OriginalLocation(
|
|
|
|
originalSourceActor,
|
|
|
|
originalLine,
|
|
|
|
actualColumn
|
|
|
|
);
|
2015-03-26 19:15:36 +00:00
|
|
|
}
|
2015-04-01 13:54:53 +00:00
|
|
|
++actualColumn;
|
2015-03-26 19:15:36 +00:00
|
|
|
}
|
2015-04-01 13:54:53 +00:00
|
|
|
|
2015-04-03 12:46:27 +00:00
|
|
|
return originalLocation;
|
|
|
|
} else {
|
|
|
|
// To perform breakpoint sliding for line breakpoints, we need to
|
|
|
|
// build a map from line numbers to a list of entry points for each
|
|
|
|
// line, implemented as a sparse array. An entry point is a (script,
|
|
|
|
// offsets) pair, and represents all offsets in that script that are
|
|
|
|
// entry points for the corresponding line.
|
|
|
|
let lineToEntryPointsMap = [];
|
|
|
|
|
|
|
|
// Iterate over all scripts that correspond to this source actor.
|
|
|
|
let scripts = this.scripts.getScriptsBySourceActor(this);
|
|
|
|
for (let script of scripts) {
|
|
|
|
// Get all offsets for each line in the current script. This returns
|
|
|
|
// a map from line numbers fo a list of offsets for each line,
|
|
|
|
// implemented as a sparse array.
|
|
|
|
let lineToOffsetsMap = script.getAllOffsets();
|
|
|
|
|
|
|
|
// Iterate over each line, and add their list of offsets to the map
|
|
|
|
// from line numbers to entry points by forming a (script, offsets)
|
|
|
|
// pair, where script is the current script, and offsets is the list
|
|
|
|
// of offsets for the current line.
|
|
|
|
for (let line = 0; line < lineToOffsetsMap.length; ++line) {
|
|
|
|
let offsets = lineToOffsetsMap[line];
|
|
|
|
if (offsets) {
|
|
|
|
let entryPoints = lineToEntryPointsMap[line];
|
|
|
|
if (!entryPoints) {
|
|
|
|
// We dont have a list of entry points for the current line
|
|
|
|
// number yet, so create it and add it to the map.
|
|
|
|
entryPoints = [];
|
|
|
|
lineToEntryPointsMap[line] = entryPoints;
|
|
|
|
}
|
|
|
|
entryPoints.push({ script, offsets });
|
2015-04-01 13:54:53 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-23 13:13:03 +00:00
|
|
|
}
|
|
|
|
|
2015-04-03 12:46:27 +00:00
|
|
|
// Now that we have a map from line numbers to a list of entry points
|
|
|
|
// for each line, we can use it to perform breakpoint sliding. Start
|
|
|
|
// at the original line of the breakpoint actor, and keep incrementing
|
|
|
|
// it by one, until either we find a line that has at least one entry
|
|
|
|
// point, or we go past the last line in the map.
|
|
|
|
//
|
|
|
|
// Note that by computing the entire map up front, and implementing it
|
|
|
|
// as a sparse array, we can easily tell when we went past the last
|
|
|
|
// line in the map.
|
|
|
|
let actualLine = originalLine + 1;
|
|
|
|
while (actualLine < lineToEntryPointsMap.length) {
|
|
|
|
let entryPoints = lineToEntryPointsMap[actualLine];
|
|
|
|
if (entryPoints) {
|
|
|
|
setBreakpointAtEntryPoints(actor, entryPoints);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++actualLine;
|
|
|
|
}
|
|
|
|
if (actualLine >= lineToEntryPointsMap.length) {
|
|
|
|
// We went past the last line in the map, so breakpoint sliding
|
|
|
|
// failed. Keep the BreakpointActor in the BreakpointActorMap as a
|
|
|
|
// pending breakpoint, so we can try again whenever a new script is
|
|
|
|
// introduced.
|
|
|
|
return originalLocation;
|
2015-04-01 13:54:53 +00:00
|
|
|
}
|
|
|
|
|
2015-04-03 12:46:27 +00:00
|
|
|
return new OriginalLocation(
|
|
|
|
originalSourceActor,
|
|
|
|
actualLine
|
|
|
|
);
|
|
|
|
}
|
2015-03-23 13:13:03 +00:00
|
|
|
} else {
|
2015-04-01 09:03:57 +00:00
|
|
|
let slideByColumn = (actualColumn) => {
|
|
|
|
return this.sources.getAllGeneratedLocations(new OriginalLocation(
|
|
|
|
this,
|
|
|
|
originalLine,
|
|
|
|
actualColumn
|
|
|
|
)).then((generatedLocations) => {
|
|
|
|
// Because getAllGeneratedLocations will always return the list of
|
|
|
|
// generated locations for the closest column that is greater than
|
|
|
|
// the one we are searching for if no exact match can be found, if
|
|
|
|
// the list of generated locations is empty, we've reached the end
|
|
|
|
// of the original line, and sliding continues by line.
|
|
|
|
if (generatedLocations.length === 0) {
|
|
|
|
return slideByLine(originalLine + 1);
|
|
|
|
}
|
2015-03-27 06:49:16 +00:00
|
|
|
|
2015-04-01 09:03:57 +00:00
|
|
|
// If at least one script has an offset that matches one of the
|
|
|
|
// generated locations in the list, then breakpoint sliding
|
|
|
|
// succeeded.
|
|
|
|
if (this._setBreakpointAtAllGeneratedLocations(actor, generatedLocations)) {
|
|
|
|
return this.threadActor.sources.getOriginalLocation(generatedLocations[0]);
|
|
|
|
}
|
2015-03-27 06:49:16 +00:00
|
|
|
|
2015-04-01 09:03:57 +00:00
|
|
|
// Try the next column in the original source.
|
|
|
|
return slideByColumn(actualColumn + 1);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
let slideByLine = (actualLine) => {
|
|
|
|
return this.sources.getAllGeneratedLocations(new OriginalLocation(
|
|
|
|
this,
|
|
|
|
actualLine
|
|
|
|
)).then((generatedLocations) => {
|
|
|
|
// Because getAllGeneratedLocations will always return the list of
|
|
|
|
// generated locations for the closest line that is greater than
|
|
|
|
// the one we are searching for if no exact match can be found, if
|
|
|
|
// the list of generated locations is empty, we've reached the end
|
|
|
|
// of the original source, and breakpoint sliding failed.
|
|
|
|
if (generatedLocations.length === 0) {
|
|
|
|
return originalLocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If at least one script has an offset that matches one of the
|
|
|
|
// generated locations in the list, then breakpoint sliding
|
|
|
|
// succeeded.
|
|
|
|
if (this._setBreakpointAtAllGeneratedLocations(actor, generatedLocations)) {
|
|
|
|
return this.threadActor.sources.getOriginalLocation(generatedLocations[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try the next line in the original source.
|
|
|
|
return slideByLine(actualLine + 1);
|
|
|
|
});
|
|
|
|
};
|
2015-03-27 06:49:16 +00:00
|
|
|
|
2015-04-01 09:03:57 +00:00
|
|
|
if (originalColumn !== undefined) {
|
|
|
|
return slideByColumn(originalColumn + 1);
|
2015-03-27 06:49:16 +00:00
|
|
|
} else {
|
2015-04-01 09:03:57 +00:00
|
|
|
return slideByLine(originalLine + 1);
|
2015-03-27 06:49:16 +00:00
|
|
|
}
|
2015-03-23 13:13:03 +00:00
|
|
|
}
|
2015-03-26 19:15:36 +00:00
|
|
|
}).then((actualLocation) => {
|
|
|
|
// If the actual location on which the BreakpointActor ended up being
|
|
|
|
// set differs from the original line that was requested, both the
|
|
|
|
// BreakpointActor and the BreakpointActorMap need to be updated
|
|
|
|
// accordingly.
|
|
|
|
if (!actualLocation.equals(originalLocation)) {
|
|
|
|
let existingActor = this.breakpointActorMap.getActor(actualLocation);
|
|
|
|
if (existingActor) {
|
|
|
|
actor.onDelete();
|
|
|
|
this.breakpointActorMap.deleteActor(originalLocation);
|
|
|
|
actor = existingActor;
|
|
|
|
} else {
|
|
|
|
this.breakpointActorMap.deleteActor(originalLocation);
|
|
|
|
actor.originalLocation = actualLocation;
|
|
|
|
this.breakpointActorMap.setActor(actualLocation, actor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return actor;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_setBreakpointAtOriginalLocation: function (actor, originalLocation) {
|
|
|
|
if (!this.isSourceMapped) {
|
|
|
|
if (!this._setBreakpointAtGeneratedLocation(
|
|
|
|
actor,
|
|
|
|
GeneratedLocation.fromOriginalLocation(originalLocation)
|
|
|
|
)) {
|
|
|
|
return Promise.resolve(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.resolve(originalLocation);
|
|
|
|
} else {
|
|
|
|
return this.sources.getAllGeneratedLocations(originalLocation)
|
|
|
|
.then((generatedLocations) => {
|
|
|
|
if (!this._setBreakpointAtAllGeneratedLocations(
|
|
|
|
actor,
|
|
|
|
generatedLocations
|
|
|
|
)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.threadActor.sources.getOriginalLocation(generatedLocations[0]);
|
|
|
|
});
|
2015-03-03 16:09:26 +00:00
|
|
|
}
|
2015-02-03 09:48:25 +00:00
|
|
|
},
|
|
|
|
|
2015-03-26 19:15:36 +00:00
|
|
|
_setBreakpointAtAllGeneratedLocations: function (actor, generatedLocations) {
|
|
|
|
let success = false;
|
|
|
|
for (let generatedLocation of generatedLocations) {
|
|
|
|
if (this._setBreakpointAtGeneratedLocation(
|
|
|
|
actor,
|
|
|
|
generatedLocation
|
|
|
|
)) {
|
|
|
|
success = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return success;
|
|
|
|
},
|
|
|
|
|
2015-02-04 06:42:33 +00:00
|
|
|
/*
|
2015-02-23 15:14:57 +00:00
|
|
|
* Ensure the given BreakpointActor is set as breakpoint handler on all
|
2015-03-11 14:15:40 +00:00
|
|
|
* scripts that match the given location in the generated source.
|
2015-02-04 06:42:33 +00:00
|
|
|
*
|
|
|
|
* @param BreakpointActor actor
|
2015-03-11 14:15:40 +00:00
|
|
|
* The BreakpointActor to be set as a breakpoint handler.
|
2015-02-23 15:14:57 +00:00
|
|
|
* @param GeneratedLocation generatedLocation
|
2015-03-11 14:15:40 +00:00
|
|
|
* A GeneratedLocation representing the location in the generated
|
|
|
|
* source for which the given BreakpointActor is to be set as a
|
|
|
|
* breakpoint handler.
|
2015-03-23 13:13:03 +00:00
|
|
|
*
|
|
|
|
* @returns A Boolean that is true if the BreakpointActor was set as a
|
|
|
|
* breakpoint handler on at least one script, and false otherwise.
|
2015-02-04 06:42:33 +00:00
|
|
|
*/
|
2015-03-26 19:15:36 +00:00
|
|
|
_setBreakpointAtGeneratedLocation: function (actor, generatedLocation) {
|
2015-03-27 06:49:16 +00:00
|
|
|
let {
|
|
|
|
generatedSourceActor,
|
|
|
|
generatedLine,
|
|
|
|
generatedColumn,
|
|
|
|
generatedLastColumn
|
|
|
|
} = generatedLocation;
|
2015-03-23 13:13:03 +00:00
|
|
|
|
|
|
|
// Find all scripts that match the given source actor and line number.
|
|
|
|
let scripts = this.scripts.getScriptsBySourceActorAndLine(
|
2015-03-27 06:49:16 +00:00
|
|
|
generatedSourceActor,
|
2015-03-23 13:13:03 +00:00
|
|
|
generatedLine
|
2015-05-08 17:50:49 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
scripts = scripts.filter((script) => !actor.hasScript(script));
|
2015-03-23 13:13:03 +00:00
|
|
|
|
|
|
|
// Find all entry points that correspond to the given location.
|
|
|
|
let entryPoints = [];
|
|
|
|
if (generatedColumn === undefined) {
|
|
|
|
// This is a line breakpoint, so we are interested in all offsets
|
|
|
|
// that correspond to the given line number.
|
|
|
|
for (let script of scripts) {
|
|
|
|
let offsets = script.getLineOffsets(generatedLine);
|
|
|
|
if (offsets.length > 0) {
|
|
|
|
entryPoints.push({ script, offsets });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// This is a column breakpoint, so we are interested in all column
|
|
|
|
// offsets that correspond to the given line *and* column number.
|
|
|
|
for (let script of scripts) {
|
|
|
|
let columnToOffsetMap = script.getAllColumnOffsets()
|
|
|
|
.filter(({ lineNumber }) => {
|
|
|
|
return lineNumber === generatedLine;
|
|
|
|
});
|
|
|
|
for (let { columnNumber: column, offset } of columnToOffsetMap) {
|
2015-03-27 06:49:16 +00:00
|
|
|
if (column >= generatedColumn && column <= generatedLastColumn) {
|
2015-03-23 13:13:03 +00:00
|
|
|
entryPoints.push({ script, offsets: [offset] });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entryPoints.length === 0) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-03-26 19:15:36 +00:00
|
|
|
setBreakpointAtEntryPoints(actor, entryPoints);
|
2015-03-23 13:13:03 +00:00
|
|
|
return true;
|
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,
|
2013-10-22 07:04:46 +00:00
|
|
|
"prettyPrint": SourceActor.prototype.onPrettyPrint,
|
2014-10-01 16:57:49 +00:00
|
|
|
"disablePrettyPrint": SourceActor.prototype.onDisablePrettyPrint,
|
2014-11-25 23:02:39 +00:00
|
|
|
"getExecutableLines": SourceActor.prototype.getExecutableLines,
|
|
|
|
"setBreakpoint": SourceActor.prototype.onSetBreakpoint
|
2012-09-27 08:30:00 +00:00
|
|
|
};
|
|
|
|
|
2015-03-23 14:50:00 +00:00
|
|
|
exports.SourceActor = SourceActor;
|
2012-09-27 08:30:00 +00:00
|
|
|
|
2013-11-18 21:24:54 +00:00
|
|
|
/**
|
|
|
|
* Determine if a given value is non-primitive.
|
|
|
|
*
|
|
|
|
* @param Any aValue
|
|
|
|
* The value to test.
|
|
|
|
* @return Boolean
|
|
|
|
* Whether the value is non-primitive.
|
|
|
|
*/
|
|
|
|
function isObject(aValue) {
|
|
|
|
const type = typeof aValue;
|
|
|
|
return type == "object" ? aValue !== null : type == "function";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a function that can safely stringify Debugger.Objects of a given
|
|
|
|
* builtin type.
|
|
|
|
*
|
|
|
|
* @param Function aCtor
|
|
|
|
* The builtin class constructor.
|
|
|
|
* @return Function
|
|
|
|
* The stringifier for the class.
|
|
|
|
*/
|
|
|
|
function createBuiltinStringifier(aCtor) {
|
|
|
|
return aObj => aCtor.prototype.toString.call(aObj.unsafeDereference());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stringify a Debugger.Object-wrapped Error instance.
|
|
|
|
*
|
|
|
|
* @param Debugger.Object aObj
|
|
|
|
* The object to stringify.
|
|
|
|
* @return String
|
|
|
|
* The stringification of the object.
|
|
|
|
*/
|
|
|
|
function errorStringify(aObj) {
|
2013-12-03 13:32:41 +00:00
|
|
|
let name = DevToolsUtils.getProperty(aObj, "name");
|
2013-11-18 21:24:54 +00:00
|
|
|
if (name === "" || name === undefined) {
|
|
|
|
name = aObj.class;
|
|
|
|
} else if (isObject(name)) {
|
|
|
|
name = stringify(name);
|
|
|
|
}
|
|
|
|
|
2013-12-03 13:32:41 +00:00
|
|
|
let message = DevToolsUtils.getProperty(aObj, "message");
|
2013-11-18 21:24:54 +00:00
|
|
|
if (isObject(message)) {
|
|
|
|
message = stringify(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message === "" || message === undefined) {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
return name + ": " + message;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stringify a Debugger.Object based on its class.
|
|
|
|
*
|
|
|
|
* @param Debugger.Object aObj
|
|
|
|
* The object to stringify.
|
|
|
|
* @return String
|
|
|
|
* The stringification for the object.
|
|
|
|
*/
|
|
|
|
function stringify(aObj) {
|
2013-12-19 13:04:59 +00:00
|
|
|
if (aObj.class == "DeadObject") {
|
2013-11-18 21:24:54 +00:00
|
|
|
const error = new Error("Dead object encountered.");
|
|
|
|
DevToolsUtils.reportException("stringify", error);
|
|
|
|
return "<dead object>";
|
|
|
|
}
|
2014-10-23 13:52:00 +00:00
|
|
|
|
2013-11-18 21:24:54 +00:00
|
|
|
const stringifier = stringifiers[aObj.class] || stringifiers.Object;
|
2014-10-23 13:52:00 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
return stringifier(aObj);
|
|
|
|
} catch (e) {
|
|
|
|
DevToolsUtils.reportException("stringify", e);
|
|
|
|
return "<failed to stringify object>";
|
|
|
|
}
|
2013-11-18 21:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Used to prevent infinite recursion when an array is found inside itself.
|
|
|
|
let seen = null;
|
|
|
|
|
|
|
|
let stringifiers = {
|
|
|
|
Error: errorStringify,
|
|
|
|
EvalError: errorStringify,
|
|
|
|
RangeError: errorStringify,
|
|
|
|
ReferenceError: errorStringify,
|
|
|
|
SyntaxError: errorStringify,
|
|
|
|
TypeError: errorStringify,
|
|
|
|
URIError: errorStringify,
|
|
|
|
Boolean: createBuiltinStringifier(Boolean),
|
|
|
|
Function: createBuiltinStringifier(Function),
|
|
|
|
Number: createBuiltinStringifier(Number),
|
|
|
|
RegExp: createBuiltinStringifier(RegExp),
|
|
|
|
String: createBuiltinStringifier(String),
|
|
|
|
Object: obj => "[object " + obj.class + "]",
|
|
|
|
Array: obj => {
|
|
|
|
// If we're at the top level then we need to create the Set for tracking
|
|
|
|
// previously stringified arrays.
|
|
|
|
const topLevel = !seen;
|
|
|
|
if (topLevel) {
|
|
|
|
seen = new Set();
|
|
|
|
} else if (seen.has(obj)) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
seen.add(obj);
|
|
|
|
|
2013-12-03 13:32:41 +00:00
|
|
|
const len = DevToolsUtils.getProperty(obj, "length");
|
2013-11-18 21:24:54 +00:00
|
|
|
let string = "";
|
|
|
|
|
|
|
|
// The following check is only required because the debuggee could possibly
|
|
|
|
// be a Proxy and return any value. For normal objects, array.length is
|
|
|
|
// always a non-negative integer.
|
|
|
|
if (typeof len == "number" && len > 0) {
|
|
|
|
for (let i = 0; i < len; i++) {
|
|
|
|
const desc = obj.getOwnPropertyDescriptor(i);
|
|
|
|
if (desc) {
|
|
|
|
const { value } = desc;
|
|
|
|
if (value != null) {
|
|
|
|
string += isObject(value) ? stringify(value) : value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i < len - 1) {
|
|
|
|
string += ",";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (topLevel) {
|
|
|
|
seen = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return string;
|
|
|
|
},
|
|
|
|
DOMException: obj => {
|
2013-12-03 13:32:41 +00:00
|
|
|
const message = DevToolsUtils.getProperty(obj, "message") || "<no message>";
|
|
|
|
const result = (+DevToolsUtils.getProperty(obj, "result")).toString(16);
|
|
|
|
const code = DevToolsUtils.getProperty(obj, "code");
|
|
|
|
const name = DevToolsUtils.getProperty(obj, "name") || "<unknown>";
|
2013-11-18 21:24:54 +00:00
|
|
|
|
|
|
|
return '[Exception... "' + message + '" ' +
|
|
|
|
'code: "' + code +'" ' +
|
|
|
|
'nsresult: "0x' + result + ' (' + name + ')"]';
|
2014-10-23 13:52:00 +00:00
|
|
|
},
|
|
|
|
Promise: obj => {
|
2014-12-22 15:48:00 +00:00
|
|
|
const { state, value, reason } = getPromiseState(obj);
|
2014-10-23 13:52:00 +00:00
|
|
|
let statePreview = state;
|
|
|
|
if (state != "pending") {
|
|
|
|
const settledValue = state === "fulfilled" ? value : reason;
|
|
|
|
statePreview += ": " + (typeof settledValue === "object" && settledValue !== null
|
|
|
|
? stringify(settledValue)
|
|
|
|
: settledValue);
|
|
|
|
}
|
|
|
|
return "Promise (" + statePreview + ")";
|
|
|
|
},
|
2013-11-18 21:24:54 +00:00
|
|
|
};
|
|
|
|
|
2015-05-25 18:11:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an actor to iterate over an object's property names and values.
|
|
|
|
*
|
|
|
|
* @param aObjectActor ObjectActor
|
|
|
|
* The object actor.
|
|
|
|
* @param aOptions Object
|
|
|
|
* A dictionary object with various boolean attributes:
|
|
|
|
* - ignoreSafeGetters Boolean
|
|
|
|
* If true, do not iterate over safe getters.
|
|
|
|
* - ignoreIndexedProperties Boolean
|
|
|
|
* If true, filters out Array items.
|
|
|
|
* e.g. properties names between `0` and `object.length`.
|
|
|
|
* - ignoreNonIndexedProperties Boolean
|
|
|
|
* If true, filters out items that aren't array items
|
|
|
|
* e.g. properties names that are not a number between `0`
|
|
|
|
* and `object.length`.
|
|
|
|
* - sort Boolean
|
|
|
|
* If true, the iterator will sort the properties by name
|
|
|
|
* before dispatching them.
|
|
|
|
* - query String
|
|
|
|
* If non-empty, will filter the properties by names containing
|
|
|
|
* this query string. The match is not case-sensitive.
|
|
|
|
*/
|
|
|
|
function PropertyIteratorActor(aObjectActor, aOptions)
|
|
|
|
{
|
|
|
|
this.objectActor = aObjectActor;
|
|
|
|
|
|
|
|
let ownProperties = Object.create(null);
|
|
|
|
let names = [];
|
|
|
|
try {
|
|
|
|
names = this.objectActor.obj.getOwnPropertyNames();
|
|
|
|
} catch (ex) {}
|
|
|
|
|
|
|
|
|
|
|
|
let safeGetterValues = {};
|
|
|
|
let safeGetterNames = [];
|
|
|
|
if (!aOptions.ignoreSafeGetters) {
|
|
|
|
// Merge the safe getter values into the existing properties list.
|
|
|
|
safeGetterValues = this.objectActor._findSafeGetterValues(names);
|
|
|
|
safeGetterNames = Object.keys(safeGetterValues);
|
|
|
|
for (let name of safeGetterNames) {
|
|
|
|
if (names.indexOf(name) === -1) {
|
|
|
|
names.push(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aOptions.ignoreIndexedProperties || aOptions.ignoreNonIndexedProperties) {
|
|
|
|
let length = DevToolsUtils.getProperty(this.objectActor.obj, "length");
|
|
|
|
if (typeof(length) !== "number") {
|
|
|
|
// Pseudo arrays are flagged as ArrayLike if they have
|
|
|
|
// subsequent indexed properties without having any length attribute.
|
|
|
|
length = 0;
|
|
|
|
for (let key of names) {
|
|
|
|
if (isNaN(key) || key != length++) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aOptions.ignoreIndexedProperties) {
|
|
|
|
names = names.filter(i => {
|
|
|
|
// Use parseFloat in order to reject floats...
|
|
|
|
// (parseInt converts floats to integer)
|
|
|
|
// (Number(str) converts spaces to 0)
|
|
|
|
i = parseFloat(i);
|
|
|
|
return !Number.isInteger(i) || i < 0 || i >= length;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aOptions.ignoreNonIndexedProperties) {
|
|
|
|
names = names.filter(i => {
|
|
|
|
i = parseFloat(i);
|
|
|
|
return Number.isInteger(i) && i >= 0 && i < length;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aOptions.query) {
|
|
|
|
let { query } = aOptions;
|
|
|
|
query = query.toLowerCase();
|
|
|
|
names = names.filter(name => {
|
|
|
|
return name.toLowerCase().includes(query);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aOptions.sort) {
|
|
|
|
names.sort();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now build the descriptor list
|
|
|
|
for (let name of names) {
|
|
|
|
let desc = this.objectActor._propertyDescriptor(name);
|
|
|
|
if (!desc) {
|
|
|
|
desc = safeGetterValues[name];
|
|
|
|
}
|
|
|
|
else if (name in safeGetterValues) {
|
|
|
|
// Merge the safe getter values into the existing properties list.
|
|
|
|
let { getterValue, getterPrototypeLevel } = safeGetterValues[name];
|
|
|
|
desc.getterValue = getterValue;
|
|
|
|
desc.getterPrototypeLevel = getterPrototypeLevel;
|
|
|
|
}
|
|
|
|
ownProperties[name] = desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.names = names;
|
|
|
|
this.ownProperties = ownProperties;
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyIteratorActor.prototype = {
|
|
|
|
actorPrefix: "propertyIterator",
|
|
|
|
|
|
|
|
grip: function () {
|
|
|
|
return {
|
|
|
|
type: "propertyIterator",
|
|
|
|
actor: this.actorID,
|
|
|
|
count: this.names.length
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
names: function ({ indexes }) {
|
|
|
|
let list = [];
|
|
|
|
for (let idx of indexes) {
|
|
|
|
list.push(this.names[idx]);
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
names: list
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
slice: function ({ start, count }) {
|
|
|
|
let names = this.names.slice(start, start + count);
|
|
|
|
let props = Object.create(null);
|
|
|
|
for (let name of names) {
|
|
|
|
props[name] = this.ownProperties[name];
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
ownProperties: props
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
all: function () {
|
|
|
|
return {
|
|
|
|
ownProperties: this.ownProperties
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
PropertyIteratorActor.prototype.requestTypes = {
|
|
|
|
"names": PropertyIteratorActor.prototype.names,
|
|
|
|
"slice": PropertyIteratorActor.prototype.slice,
|
|
|
|
"all": PropertyIteratorActor.prototype.all,
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.PropertyIteratorActor = PropertyIteratorActor;
|
|
|
|
|
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)
|
|
|
|
{
|
2014-05-07 00:36:18 +00:00
|
|
|
dbg_assert(!aObj.optimizedOut, "Should not create object actors for optimized out values!");
|
2012-02-07 17:22:30 +00:00
|
|
|
this.obj = aObj;
|
|
|
|
this.threadActor = aThreadActor;
|
2015-05-25 18:11:59 +00:00
|
|
|
this.iterators = new Set();
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
grip: function () {
|
2013-12-19 13:04:59 +00:00
|
|
|
this.threadActor._gripDepth++;
|
|
|
|
|
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
|
|
|
|
2013-12-19 13:04:59 +00:00
|
|
|
if (this.obj.class != "DeadObject") {
|
2014-10-23 13:52:00 +00:00
|
|
|
// Expose internal Promise state.
|
|
|
|
if (this.obj.class == "Promise") {
|
2014-12-22 15:48:00 +00:00
|
|
|
const { state, value, reason } = getPromiseState(this.obj);
|
2014-10-23 13:52:00 +00:00
|
|
|
g.promiseState = { state };
|
|
|
|
if (state == "fulfilled") {
|
|
|
|
g.promiseState.value = this.threadActor.createValueGrip(value);
|
|
|
|
} else if (state == "rejected") {
|
|
|
|
g.promiseState.reason = this.threadActor.createValueGrip(reason);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-25 18:11:59 +00:00
|
|
|
// FF40+: Allow to know how many properties an object has
|
|
|
|
// to lazily display them when there is a bunch.
|
|
|
|
// Throws on some MouseEvent object in tests.
|
|
|
|
try {
|
|
|
|
// Bug 1163520: Assert on internal functions
|
|
|
|
if (this.obj.class != "Function") {
|
|
|
|
g.ownPropertyLength = this.obj.getOwnPropertyNames().length;
|
|
|
|
}
|
|
|
|
} catch(e) {}
|
|
|
|
|
2014-05-30 14:42:55 +00:00
|
|
|
let raw = this.obj.unsafeDereference();
|
|
|
|
|
|
|
|
// If Cu is not defined, we are running on a worker thread, where xrays
|
|
|
|
// don't exist.
|
|
|
|
if (Cu) {
|
|
|
|
raw = Cu.unwaiveXrays(raw);
|
|
|
|
}
|
|
|
|
|
2013-12-19 13:04:59 +00:00
|
|
|
if (!DevToolsUtils.isSafeJSObject(raw)) {
|
|
|
|
raw = null;
|
2012-12-14 18:26:47 +00:00
|
|
|
}
|
|
|
|
|
2013-12-19 13:04:59 +00:00
|
|
|
let previewers = DebuggerServer.ObjectActorPreviewers[this.obj.class] ||
|
|
|
|
DebuggerServer.ObjectActorPreviewers.Object;
|
|
|
|
for (let fn of previewers) {
|
2014-03-25 00:32:00 +00:00
|
|
|
try {
|
|
|
|
if (fn(this, g, raw)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
DevToolsUtils.reportException("ObjectActor.prototype.grip previewer function", e);
|
2013-10-04 07:33:08 +00:00
|
|
|
}
|
2012-12-14 18:26:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-19 13:04:59 +00:00
|
|
|
this.threadActor._gripDepth--;
|
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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
release: function () {
|
2013-03-30 11:31:10 +00:00
|
|
|
if (this.registeredPool.objectActors) {
|
|
|
|
this.registeredPool.objectActors.delete(this.obj);
|
|
|
|
}
|
2015-05-25 18:11:59 +00:00
|
|
|
this.iterators.forEach(actor => this.registeredPool.removeActor(actor));
|
|
|
|
this.iterators.clear();
|
2012-10-12 08:26:49 +00:00
|
|
|
this.registeredPool.removeActor(this);
|
2012-02-07 17:22:30 +00:00
|
|
|
},
|
|
|
|
|
2013-11-06 00:40:00 +00:00
|
|
|
/**
|
|
|
|
* Handle a protocol request to provide the definition site of this function
|
|
|
|
* object.
|
|
|
|
*
|
|
|
|
* @param aRequest object
|
|
|
|
* The protocol request object.
|
|
|
|
*/
|
|
|
|
onDefinitionSite: function OA_onDefinitionSite(aRequest) {
|
|
|
|
if (this.obj.class != "Function") {
|
|
|
|
return {
|
|
|
|
from: this.actorID,
|
|
|
|
error: "objectNotFunction",
|
|
|
|
message: this.actorID + " is not a function."
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.obj.script) {
|
|
|
|
return {
|
|
|
|
from: this.actorID,
|
|
|
|
error: "noScript",
|
|
|
|
message: this.actorID + " has no Debugger.Script"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-02-23 08:36:58 +00:00
|
|
|
return this.threadActor.sources.getOriginalLocation(new GeneratedLocation(
|
|
|
|
this.threadActor.sources.createNonSourceMappedActor(this.obj.script.source),
|
|
|
|
this.obj.script.startLine,
|
|
|
|
0 // TODO bug 901138: use Debugger.Script.prototype.startColumn
|
|
|
|
)).then((originalLocation) => {
|
|
|
|
return {
|
|
|
|
source: originalLocation.originalSourceActor.form(),
|
|
|
|
line: originalLocation.originalLine,
|
|
|
|
column: originalLocation.originalColumn
|
|
|
|
};
|
|
|
|
});
|
2013-11-06 00:40:00 +00:00
|
|
|
},
|
|
|
|
|
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-11-07 14:27:40 +00:00
|
|
|
onOwnPropertyNames: function (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
|
|
|
|
2015-05-25 18:11:59 +00:00
|
|
|
/**
|
|
|
|
* Creates an actor to iterate over an object property names and values.
|
|
|
|
* See PropertyIteratorActor constructor for more info about options param.
|
|
|
|
*
|
|
|
|
* @param aRequest object
|
|
|
|
* The protocol request object.
|
|
|
|
*/
|
|
|
|
onEnumProperties: function (aRequest) {
|
|
|
|
let actor = new PropertyIteratorActor(this, aRequest.options);
|
|
|
|
this.registeredPool.addActor(actor);
|
|
|
|
this.iterators.add(actor);
|
|
|
|
return { iterator: actor.grip() };
|
|
|
|
},
|
|
|
|
|
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-11-07 14:27:40 +00:00
|
|
|
onPrototypeAndProperties: function (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,
|
2015-05-25 18:11:59 +00:00
|
|
|
safeGetterValues: this._findSafeGetterValues(names) };
|
2013-05-11 09:05:21 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find the safe getter values for the current Debugger.Object, |this.obj|.
|
|
|
|
*
|
|
|
|
* @private
|
2015-05-25 18:11:59 +00:00
|
|
|
* @param array aOwnProperties
|
|
|
|
* The array that holds the list of known ownProperties names for
|
2013-05-11 09:05:21 +00:00
|
|
|
* |this.obj|.
|
2013-12-19 13:04:59 +00:00
|
|
|
* @param number [aLimit=0]
|
|
|
|
* Optional limit of getter values to find.
|
2013-05-11 09:05:21 +00:00
|
|
|
* @return object
|
|
|
|
* An object that maps property names to safe getter descriptors as
|
|
|
|
* defined by the remote debugging protocol.
|
|
|
|
*/
|
2013-12-19 13:04:59 +00:00
|
|
|
_findSafeGetterValues: function (aOwnProperties, aLimit = 0)
|
2013-05-11 09:05:21 +00:00
|
|
|
{
|
|
|
|
let safeGetterValues = Object.create(null);
|
|
|
|
let obj = this.obj;
|
2013-12-19 13:04:59 +00:00
|
|
|
let level = 0, i = 0;
|
2013-05-11 09:05:21 +00:00
|
|
|
|
|
|
|
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 ||
|
2015-05-25 18:11:59 +00:00
|
|
|
(obj != this.obj && aOwnProperties.indexOf(name) !== -1)) {
|
2013-05-11 09:05:21 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-03-19 16:42:15 +00:00
|
|
|
// Ignore __proto__ on Object.prototye.
|
|
|
|
if (!obj.proto && name == "__proto__") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-05-11 09:05:21 +00:00
|
|
|
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-12-19 13:04:59 +00:00
|
|
|
if (aLimit && ++i == aLimit) {
|
|
|
|
break;
|
|
|
|
}
|
2013-05-16 15:42:15 +00:00
|
|
|
}
|
2013-05-11 09:05:21 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-19 13:04:59 +00:00
|
|
|
if (aLimit && i == aLimit) {
|
|
|
|
break;
|
|
|
|
}
|
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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
_findSafeGetters: function (aObject)
|
2013-05-11 09:05:21 +00:00
|
|
|
{
|
|
|
|
if (aObject._safeGetters) {
|
|
|
|
return aObject._safeGetters;
|
|
|
|
}
|
|
|
|
|
|
|
|
let getters = new Set();
|
2013-12-19 13:04:59 +00:00
|
|
|
let names = [];
|
|
|
|
try {
|
|
|
|
names = aObject.getOwnPropertyNames()
|
|
|
|
} catch (ex) {
|
|
|
|
// Calling getOwnPropertyNames() on some wrapped native prototypes is not
|
|
|
|
// allowed: "cannot modify properties of a WrappedNative". See bug 952093.
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let name of names) {
|
2013-05-11 09:05:21 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-12-03 13:32:41 +00:00
|
|
|
if (DevToolsUtils.hasSafeGetter(desc)) {
|
2013-05-11 09:05:21 +00:00
|
|
|
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-11-07 14:27:40 +00:00
|
|
|
onPrototype: function (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-11-07 14:27:40 +00:00
|
|
|
onProperty: function (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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
onDisplayString: function (aRequest) {
|
2013-11-18 21:24:54 +00:00
|
|
|
const string = stringify(this.obj);
|
2013-07-23 16:58:27 +00:00
|
|
|
return { from: this.actorID,
|
2013-11-18 21:24:54 +00:00
|
|
|
displayString: this.threadActor.createValueGrip(string) };
|
2013-07-23 16:58:27 +00:00
|
|
|
},
|
|
|
|
|
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-12-19 13:04:59 +00:00
|
|
|
* @private
|
2013-02-12 08:38:24 +00:00
|
|
|
* @param string aName
|
|
|
|
* The property that the descriptor is generated for.
|
2013-12-19 13:04:59 +00:00
|
|
|
* @param boolean [aOnlyEnumerable]
|
|
|
|
* Optional: true if you want a descriptor only for an enumerable
|
|
|
|
* property, false otherwise.
|
|
|
|
* @return object|undefined
|
|
|
|
* The property descriptor, or undefined if this is not an enumerable
|
|
|
|
* property and aOnlyEnumerable=true.
|
2012-02-07 17:22:30 +00:00
|
|
|
*/
|
2013-12-19 13:04:59 +00:00
|
|
|
_propertyDescriptor: function (aName, aOnlyEnumerable) {
|
2013-02-12 08:38:24 +00:00
|
|
|
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-12-19 13:04:59 +00:00
|
|
|
if (!desc || aOnlyEnumerable && !desc.enumerable) {
|
2013-07-23 16:58:27 +00:00
|
|
|
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-11-07 14:27:40 +00:00
|
|
|
onDecompile: function (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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
onParameterNames: function (aRequest) {
|
2013-03-30 11:31:10 +00:00
|
|
|
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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
onRelease: function (aRequest) {
|
2013-03-30 11:31:10 +00:00
|
|
|
this.release();
|
|
|
|
return {};
|
|
|
|
},
|
2013-09-25 16:03:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a protocol request to provide the lexical scope of a function.
|
|
|
|
*
|
|
|
|
* @param aRequest object
|
|
|
|
* The protocol request object.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
onScope: function (aRequest) {
|
2013-09-25 16:03:17 +00:00
|
|
|
if (this.obj.class !== "Function") {
|
|
|
|
return { error: "objectNotFunction",
|
|
|
|
message: "scope request is only valid for object grips with a" +
|
|
|
|
" 'Function' class." };
|
|
|
|
}
|
|
|
|
|
|
|
|
let envActor = this.threadActor.createEnvironmentActor(this.obj.environment,
|
|
|
|
this.registeredPool);
|
|
|
|
if (!envActor) {
|
|
|
|
return { error: "notDebuggee",
|
|
|
|
message: "cannot access the environment of this function." };
|
|
|
|
}
|
|
|
|
|
|
|
|
return { from: this.actorID, scope: envActor.form() };
|
|
|
|
}
|
2013-03-30 11:31:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ObjectActor.prototype.requestTypes = {
|
2013-11-06 00:40:00 +00:00
|
|
|
"definitionSite": ObjectActor.prototype.onDefinitionSite,
|
2013-03-30 11:31:10 +00:00
|
|
|
"parameterNames": ObjectActor.prototype.onParameterNames,
|
|
|
|
"prototypeAndProperties": ObjectActor.prototype.onPrototypeAndProperties,
|
2015-05-25 18:11:59 +00:00
|
|
|
"enumProperties": ObjectActor.prototype.onEnumProperties,
|
2013-03-30 11:31:10 +00:00
|
|
|
"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-09-25 16:03:17 +00:00
|
|
|
"scope": ObjectActor.prototype.onScope,
|
2013-03-30 11:31:10 +00:00
|
|
|
};
|
|
|
|
|
2014-04-29 15:52:44 +00:00
|
|
|
exports.ObjectActor = ObjectActor;
|
2013-03-30 11:31:10 +00:00
|
|
|
|
2013-12-19 13:04:59 +00:00
|
|
|
/**
|
|
|
|
* Functions for adding information to ObjectActor grips for the purpose of
|
|
|
|
* having customized output. This object holds arrays mapped by
|
|
|
|
* Debugger.Object.prototype.class.
|
|
|
|
*
|
|
|
|
* In each array you can add functions that take two
|
|
|
|
* arguments:
|
|
|
|
* - the ObjectActor instance to make a preview for,
|
|
|
|
* - the grip object being prepared for the client,
|
|
|
|
* - the raw JS object after calling Debugger.Object.unsafeDereference(). This
|
|
|
|
* argument is only provided if the object is safe for reading properties and
|
|
|
|
* executing methods. See DevToolsUtils.isSafeJSObject().
|
|
|
|
*
|
|
|
|
* Functions must return false if they cannot provide preview
|
|
|
|
* information for the debugger object, or true otherwise.
|
|
|
|
*/
|
|
|
|
DebuggerServer.ObjectActorPreviewers = {
|
2014-03-04 19:59:00 +00:00
|
|
|
String: [function({obj, threadActor}, aGrip) {
|
|
|
|
let result = genericObjectPreviewer("String", String, obj, threadActor);
|
2014-07-21 14:24:00 +00:00
|
|
|
let length = DevToolsUtils.getProperty(obj, "length");
|
|
|
|
|
|
|
|
if (!result || typeof length != "number") {
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-04 19:59:00 +00:00
|
|
|
|
2014-07-21 14:24:00 +00:00
|
|
|
aGrip.preview = {
|
|
|
|
kind: "ArrayLike",
|
|
|
|
length: length
|
|
|
|
};
|
|
|
|
|
|
|
|
if (threadActor._gripDepth > 1) {
|
2014-03-04 19:59:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-21 14:24:00 +00:00
|
|
|
let items = aGrip.preview.items = [];
|
|
|
|
|
|
|
|
const max = Math.min(result.value.length, OBJECT_PREVIEW_MAX_ITEMS);
|
|
|
|
for (let i = 0; i < max; i++) {
|
|
|
|
let value = threadActor.createValueGrip(result.value[i]);
|
|
|
|
items.push(value);
|
|
|
|
}
|
|
|
|
|
2014-03-04 19:59:00 +00:00
|
|
|
return true;
|
|
|
|
}],
|
|
|
|
|
|
|
|
Boolean: [function({obj, threadActor}, aGrip) {
|
|
|
|
let result = genericObjectPreviewer("Boolean", Boolean, obj, threadActor);
|
|
|
|
if (result) {
|
|
|
|
aGrip.preview = result;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}],
|
|
|
|
|
|
|
|
Number: [function({obj, threadActor}, aGrip) {
|
|
|
|
let result = genericObjectPreviewer("Number", Number, obj, threadActor);
|
|
|
|
if (result) {
|
|
|
|
aGrip.preview = result;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}],
|
|
|
|
|
2013-12-19 13:04:59 +00:00
|
|
|
Function: [function({obj, threadActor}, aGrip) {
|
|
|
|
if (obj.name) {
|
|
|
|
aGrip.name = obj.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obj.displayName) {
|
|
|
|
aGrip.displayName = obj.displayName.substr(0, 500);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obj.parameterNames) {
|
|
|
|
aGrip.parameterNames = obj.parameterNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the developer has added a de-facto standard displayName
|
|
|
|
// property for us to use.
|
|
|
|
let userDisplayName;
|
|
|
|
try {
|
|
|
|
userDisplayName = obj.getOwnPropertyDescriptor("displayName");
|
|
|
|
} catch (e) {
|
|
|
|
// Calling getOwnPropertyDescriptor with displayName might throw
|
|
|
|
// with "permission denied" errors for some functions.
|
|
|
|
dumpn(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (userDisplayName && typeof userDisplayName.value == "string" &&
|
|
|
|
userDisplayName.value) {
|
|
|
|
aGrip.userDisplayName = threadActor.createValueGrip(userDisplayName.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}],
|
|
|
|
|
|
|
|
RegExp: [function({obj, threadActor}, aGrip) {
|
|
|
|
// Avoid having any special preview for the RegExp.prototype itself.
|
|
|
|
if (!obj.proto || obj.proto.class != "RegExp") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
let str = RegExp.prototype.toString.call(obj.unsafeDereference());
|
|
|
|
aGrip.displayString = threadActor.createValueGrip(str);
|
|
|
|
return true;
|
|
|
|
}],
|
|
|
|
|
|
|
|
Date: [function({obj, threadActor}, aGrip) {
|
|
|
|
let time = Date.prototype.getTime.call(obj.unsafeDereference());
|
|
|
|
|
|
|
|
aGrip.preview = {
|
|
|
|
timestamp: threadActor.createValueGrip(time),
|
|
|
|
};
|
|
|
|
return true;
|
|
|
|
}],
|
|
|
|
|
|
|
|
Array: [function({obj, threadActor}, aGrip) {
|
|
|
|
let length = DevToolsUtils.getProperty(obj, "length");
|
|
|
|
if (typeof length != "number") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aGrip.preview = {
|
|
|
|
kind: "ArrayLike",
|
|
|
|
length: length,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (threadActor._gripDepth > 1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
let raw = obj.unsafeDereference();
|
|
|
|
let items = aGrip.preview.items = [];
|
|
|
|
|
2014-06-11 22:16:06 +00:00
|
|
|
for (let i = 0; i < length; ++i) {
|
|
|
|
// Array Xrays filter out various possibly-unsafe properties (like
|
|
|
|
// functions, and claim that the value is undefined instead. This
|
|
|
|
// is generally the right thing for privileged code accessing untrusted
|
|
|
|
// objects, but quite confusing for Object previews. So we manually
|
|
|
|
// override this protection by waiving Xrays on the array, and re-applying
|
|
|
|
// Xrays on any indexed value props that we pull off of it.
|
|
|
|
let desc = Object.getOwnPropertyDescriptor(Cu.waiveXrays(raw), i);
|
|
|
|
if (desc && !desc.get && !desc.set) {
|
|
|
|
let value = Cu.unwaiveXrays(desc.value);
|
2013-12-19 13:04:59 +00:00
|
|
|
value = makeDebuggeeValueIfNeeded(obj, value);
|
|
|
|
items.push(threadActor.createValueGrip(value));
|
|
|
|
} else {
|
|
|
|
items.push(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (items.length == OBJECT_PREVIEW_MAX_ITEMS) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}], // Array
|
|
|
|
|
|
|
|
Set: [function({obj, threadActor}, aGrip) {
|
|
|
|
let size = DevToolsUtils.getProperty(obj, "size");
|
|
|
|
if (typeof size != "number") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aGrip.preview = {
|
|
|
|
kind: "ArrayLike",
|
|
|
|
length: size,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Avoid recursive object grips.
|
|
|
|
if (threadActor._gripDepth > 1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
let raw = obj.unsafeDereference();
|
|
|
|
let items = aGrip.preview.items = [];
|
2014-05-28 18:14:27 +00:00
|
|
|
// We currently lack XrayWrappers for Set, so when we iterate over
|
|
|
|
// the values, the temporary iterator objects get created in the target
|
|
|
|
// compartment. However, we _do_ have Xrays to Object now, so we end up
|
|
|
|
// Xraying those temporary objects, and filtering access to |it.value|
|
|
|
|
// based on whether or not it's Xrayable and/or callable, which breaks
|
|
|
|
// the for/of iteration.
|
|
|
|
//
|
|
|
|
// This code is designed to handle untrusted objects, so we can safely
|
|
|
|
// waive Xrays on the iterable, and relying on the Debugger machinery to
|
|
|
|
// make sure we handle the resulting objects carefully.
|
|
|
|
for (let item of Cu.waiveXrays(Set.prototype.values.call(raw))) {
|
|
|
|
item = Cu.unwaiveXrays(item);
|
2013-12-19 13:04:59 +00:00
|
|
|
item = makeDebuggeeValueIfNeeded(obj, item);
|
|
|
|
items.push(threadActor.createValueGrip(item));
|
|
|
|
if (items.length == OBJECT_PREVIEW_MAX_ITEMS) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}], // Set
|
|
|
|
|
|
|
|
Map: [function({obj, threadActor}, aGrip) {
|
|
|
|
let size = DevToolsUtils.getProperty(obj, "size");
|
|
|
|
if (typeof size != "number") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aGrip.preview = {
|
|
|
|
kind: "MapLike",
|
|
|
|
size: size,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (threadActor._gripDepth > 1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
let raw = obj.unsafeDereference();
|
|
|
|
let entries = aGrip.preview.entries = [];
|
2014-07-14 17:09:06 +00:00
|
|
|
// Iterating over a Map via .entries goes through various intermediate
|
|
|
|
// objects - an Iterator object, then a 2-element Array object, then the
|
|
|
|
// actual values we care about. We don't have Xrays to Iterator objects,
|
|
|
|
// so we get Opaque wrappers for them. And even though we have Xrays to
|
|
|
|
// Arrays, the semantics often deny access to the entires based on the
|
|
|
|
// nature of the values. So we need waive Xrays for the iterator object
|
|
|
|
// and the tupes, and then re-apply them on the underlying values until
|
|
|
|
// we fix bug 1023984.
|
2014-06-11 22:16:06 +00:00
|
|
|
//
|
|
|
|
// Even then though, we might want to continue waiving Xrays here for the
|
|
|
|
// same reason we do so for Arrays above - this filtering behavior is likely
|
|
|
|
// to be more confusing than beneficial in the case of Object previews.
|
2014-07-14 17:09:06 +00:00
|
|
|
for (let keyValuePair of Cu.waiveXrays(Map.prototype.entries.call(raw))) {
|
|
|
|
let key = Cu.unwaiveXrays(keyValuePair[0]);
|
|
|
|
let value = Cu.unwaiveXrays(keyValuePair[1]);
|
2013-12-19 13:04:59 +00:00
|
|
|
key = makeDebuggeeValueIfNeeded(obj, key);
|
|
|
|
value = makeDebuggeeValueIfNeeded(obj, value);
|
|
|
|
entries.push([threadActor.createValueGrip(key),
|
|
|
|
threadActor.createValueGrip(value)]);
|
|
|
|
if (entries.length == OBJECT_PREVIEW_MAX_ITEMS) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}], // Map
|
|
|
|
|
|
|
|
DOMStringMap: [function({obj, threadActor}, aGrip, aRawObj) {
|
|
|
|
if (!aRawObj) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
let keys = obj.getOwnPropertyNames();
|
|
|
|
aGrip.preview = {
|
|
|
|
kind: "MapLike",
|
|
|
|
size: keys.length,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (threadActor._gripDepth > 1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
let entries = aGrip.preview.entries = [];
|
|
|
|
for (let key of keys) {
|
|
|
|
let value = makeDebuggeeValueIfNeeded(obj, aRawObj[key]);
|
|
|
|
entries.push([key, threadActor.createValueGrip(value)]);
|
|
|
|
if (entries.length == OBJECT_PREVIEW_MAX_ITEMS) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}], // DOMStringMap
|
2014-10-23 13:52:00 +00:00
|
|
|
|
2013-12-19 13:04:59 +00:00
|
|
|
}; // DebuggerServer.ObjectActorPreviewers
|
|
|
|
|
2014-03-04 19:59:00 +00:00
|
|
|
/**
|
|
|
|
* Generic previewer for "simple" classes like String, Number and Boolean.
|
|
|
|
*
|
|
|
|
* @param string aClassName
|
|
|
|
* Class name to expect.
|
|
|
|
* @param object aClass
|
|
|
|
* The class to expect, eg. String. The valueOf() method of the class is
|
|
|
|
* invoked on the given object.
|
|
|
|
* @param Debugger.Object aObj
|
|
|
|
* The debugger object we need to preview.
|
|
|
|
* @param object aThreadActor
|
|
|
|
* The thread actor to use to create a value grip.
|
|
|
|
* @return object|null
|
|
|
|
* An object with one property, "value", which holds the value grip that
|
|
|
|
* represents the given object. Null is returned if we cant preview the
|
|
|
|
* object.
|
|
|
|
*/
|
|
|
|
function genericObjectPreviewer(aClassName, aClass, aObj, aThreadActor) {
|
|
|
|
if (!aObj.proto || aObj.proto.class != aClassName) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
let raw = aObj.unsafeDereference();
|
|
|
|
let v = null;
|
|
|
|
try {
|
|
|
|
v = aClass.prototype.valueOf.call(raw);
|
|
|
|
} catch (ex) {
|
|
|
|
// valueOf() can throw if the raw JS object is "misbehaved".
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (v !== null) {
|
|
|
|
v = aThreadActor.createValueGrip(makeDebuggeeValueIfNeeded(aObj, v));
|
|
|
|
return { value: v };
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-12-19 13:04:59 +00:00
|
|
|
// Preview functions that do not rely on the object class.
|
|
|
|
DebuggerServer.ObjectActorPreviewers.Object = [
|
|
|
|
function TypedArray({obj, threadActor}, aGrip) {
|
|
|
|
if (TYPED_ARRAY_CLASSES.indexOf(obj.class) == -1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
let length = DevToolsUtils.getProperty(obj, "length");
|
|
|
|
if (typeof length != "number") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aGrip.preview = {
|
|
|
|
kind: "ArrayLike",
|
|
|
|
length: length,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (threadActor._gripDepth > 1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
let raw = obj.unsafeDereference();
|
|
|
|
let global = Cu.getGlobalForObject(DebuggerServer);
|
|
|
|
let classProto = global[obj.class].prototype;
|
2014-06-11 22:16:06 +00:00
|
|
|
// The Xray machinery for TypedArrays denies indexed access on the grounds
|
|
|
|
// that it's slow, and advises callers to do a structured clone instead.
|
|
|
|
let safeView = Cu.cloneInto(classProto.subarray.call(raw, 0, OBJECT_PREVIEW_MAX_ITEMS), global);
|
2013-12-19 13:04:59 +00:00
|
|
|
let items = aGrip.preview.items = [];
|
|
|
|
for (let i = 0; i < safeView.length; i++) {
|
|
|
|
items.push(safeView[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
function Error({obj, threadActor}, aGrip) {
|
|
|
|
switch (obj.class) {
|
|
|
|
case "Error":
|
|
|
|
case "EvalError":
|
|
|
|
case "RangeError":
|
|
|
|
case "ReferenceError":
|
|
|
|
case "SyntaxError":
|
|
|
|
case "TypeError":
|
|
|
|
case "URIError":
|
|
|
|
let name = DevToolsUtils.getProperty(obj, "name");
|
|
|
|
let msg = DevToolsUtils.getProperty(obj, "message");
|
|
|
|
let stack = DevToolsUtils.getProperty(obj, "stack");
|
|
|
|
let fileName = DevToolsUtils.getProperty(obj, "fileName");
|
|
|
|
let lineNumber = DevToolsUtils.getProperty(obj, "lineNumber");
|
|
|
|
let columnNumber = DevToolsUtils.getProperty(obj, "columnNumber");
|
|
|
|
aGrip.preview = {
|
|
|
|
kind: "Error",
|
|
|
|
name: threadActor.createValueGrip(name),
|
|
|
|
message: threadActor.createValueGrip(msg),
|
|
|
|
stack: threadActor.createValueGrip(stack),
|
|
|
|
fileName: threadActor.createValueGrip(fileName),
|
|
|
|
lineNumber: threadActor.createValueGrip(lineNumber),
|
|
|
|
columnNumber: threadActor.createValueGrip(columnNumber),
|
|
|
|
};
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
function CSSMediaRule({obj, threadActor}, aGrip, aRawObj) {
|
2014-06-17 19:51:43 +00:00
|
|
|
if (isWorker || !aRawObj || !(aRawObj instanceof Ci.nsIDOMCSSMediaRule)) {
|
2013-12-19 13:04:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aGrip.preview = {
|
|
|
|
kind: "ObjectWithText",
|
|
|
|
text: threadActor.createValueGrip(aRawObj.conditionText),
|
|
|
|
};
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
function CSSStyleRule({obj, threadActor}, aGrip, aRawObj) {
|
2014-06-17 19:51:43 +00:00
|
|
|
if (isWorker || !aRawObj || !(aRawObj instanceof Ci.nsIDOMCSSStyleRule)) {
|
2013-12-19 13:04:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aGrip.preview = {
|
|
|
|
kind: "ObjectWithText",
|
|
|
|
text: threadActor.createValueGrip(aRawObj.selectorText),
|
|
|
|
};
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
function ObjectWithURL({obj, threadActor}, aGrip, aRawObj) {
|
2014-06-17 19:51:43 +00:00
|
|
|
if (isWorker || !aRawObj || !(aRawObj instanceof Ci.nsIDOMCSSImportRule ||
|
|
|
|
aRawObj instanceof Ci.nsIDOMCSSStyleSheet ||
|
|
|
|
aRawObj instanceof Ci.nsIDOMLocation ||
|
|
|
|
aRawObj instanceof Ci.nsIDOMWindow)) {
|
2013-12-19 13:04:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
let url;
|
2014-06-17 19:51:43 +00:00
|
|
|
if (aRawObj instanceof Ci.nsIDOMWindow && aRawObj.location) {
|
2013-12-19 13:04:59 +00:00
|
|
|
url = aRawObj.location.href;
|
2014-03-22 08:02:13 +00:00
|
|
|
} else if (aRawObj.href) {
|
2013-12-19 13:04:59 +00:00
|
|
|
url = aRawObj.href;
|
2014-03-22 08:02:13 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
2013-12-19 13:04:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aGrip.preview = {
|
|
|
|
kind: "ObjectWithURL",
|
|
|
|
url: threadActor.createValueGrip(url),
|
|
|
|
};
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
function ArrayLike({obj, threadActor}, aGrip, aRawObj) {
|
2014-06-17 19:51:43 +00:00
|
|
|
if (isWorker || !aRawObj ||
|
2013-07-09 17:54:21 +00:00
|
|
|
obj.class != "DOMStringList" &&
|
2013-12-19 13:04:59 +00:00
|
|
|
obj.class != "DOMTokenList" &&
|
2014-06-17 19:51:43 +00:00
|
|
|
!(aRawObj instanceof Ci.nsIDOMMozNamedAttrMap ||
|
|
|
|
aRawObj instanceof Ci.nsIDOMCSSRuleList ||
|
|
|
|
aRawObj instanceof Ci.nsIDOMCSSValueList ||
|
|
|
|
aRawObj instanceof Ci.nsIDOMFileList ||
|
|
|
|
aRawObj instanceof Ci.nsIDOMFontFaceList ||
|
|
|
|
aRawObj instanceof Ci.nsIDOMMediaList ||
|
|
|
|
aRawObj instanceof Ci.nsIDOMNodeList ||
|
|
|
|
aRawObj instanceof Ci.nsIDOMStyleSheetList)) {
|
2013-12-19 13:04:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof aRawObj.length != "number") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aGrip.preview = {
|
|
|
|
kind: "ArrayLike",
|
|
|
|
length: aRawObj.length,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (threadActor._gripDepth > 1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
let items = aGrip.preview.items = [];
|
|
|
|
|
|
|
|
for (let i = 0; i < aRawObj.length &&
|
|
|
|
items.length < OBJECT_PREVIEW_MAX_ITEMS; i++) {
|
|
|
|
let value = makeDebuggeeValueIfNeeded(obj, aRawObj[i]);
|
|
|
|
items.push(threadActor.createValueGrip(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}, // ArrayLike
|
|
|
|
|
|
|
|
function CSSStyleDeclaration({obj, threadActor}, aGrip, aRawObj) {
|
2014-06-17 19:51:43 +00:00
|
|
|
if (isWorker || !aRawObj || !(aRawObj instanceof Ci.nsIDOMCSSStyleDeclaration)) {
|
2013-12-19 13:04:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aGrip.preview = {
|
|
|
|
kind: "MapLike",
|
|
|
|
size: aRawObj.length,
|
|
|
|
};
|
|
|
|
|
|
|
|
let entries = aGrip.preview.entries = [];
|
|
|
|
|
|
|
|
for (let i = 0; i < OBJECT_PREVIEW_MAX_ITEMS &&
|
|
|
|
i < aRawObj.length; i++) {
|
|
|
|
let prop = aRawObj[i];
|
|
|
|
let value = aRawObj.getPropertyValue(prop);
|
|
|
|
entries.push([prop, threadActor.createValueGrip(value)]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
function DOMNode({obj, threadActor}, aGrip, aRawObj) {
|
2014-06-17 19:51:43 +00:00
|
|
|
if (isWorker || obj.class == "Object" || !aRawObj ||
|
|
|
|
!(aRawObj instanceof Ci.nsIDOMNode)) {
|
2013-12-19 13:04:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
let preview = aGrip.preview = {
|
|
|
|
kind: "DOMNode",
|
|
|
|
nodeType: aRawObj.nodeType,
|
|
|
|
nodeName: aRawObj.nodeName,
|
|
|
|
};
|
|
|
|
|
2014-06-17 19:51:43 +00:00
|
|
|
if (aRawObj instanceof Ci.nsIDOMDocument && aRawObj.location) {
|
2013-12-19 13:04:59 +00:00
|
|
|
preview.location = threadActor.createValueGrip(aRawObj.location.href);
|
2014-06-17 19:51:43 +00:00
|
|
|
} else if (aRawObj instanceof Ci.nsIDOMDocumentFragment) {
|
2013-12-19 13:04:59 +00:00
|
|
|
preview.childNodesLength = aRawObj.childNodes.length;
|
|
|
|
|
|
|
|
if (threadActor._gripDepth < 2) {
|
|
|
|
preview.childNodes = [];
|
|
|
|
for (let node of aRawObj.childNodes) {
|
|
|
|
let actor = threadActor.createValueGrip(obj.makeDebuggeeValue(node));
|
|
|
|
preview.childNodes.push(actor);
|
|
|
|
if (preview.childNodes.length == OBJECT_PREVIEW_MAX_ITEMS) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-17 19:51:43 +00:00
|
|
|
} else if (aRawObj instanceof Ci.nsIDOMElement) {
|
2013-12-19 13:04:59 +00:00
|
|
|
// Add preview for DOM element attributes.
|
|
|
|
if (aRawObj instanceof Ci.nsIDOMHTMLElement) {
|
|
|
|
preview.nodeName = preview.nodeName.toLowerCase();
|
|
|
|
}
|
|
|
|
|
|
|
|
let i = 0;
|
|
|
|
preview.attributes = {};
|
|
|
|
preview.attributesLength = aRawObj.attributes.length;
|
|
|
|
for (let attr of aRawObj.attributes) {
|
|
|
|
preview.attributes[attr.nodeName] = threadActor.createValueGrip(attr.value);
|
|
|
|
if (++i == OBJECT_PREVIEW_MAX_ITEMS) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-06-17 19:51:43 +00:00
|
|
|
} else if (aRawObj instanceof Ci.nsIDOMAttr) {
|
2013-12-19 13:04:59 +00:00
|
|
|
preview.value = threadActor.createValueGrip(aRawObj.value);
|
2014-06-17 19:51:43 +00:00
|
|
|
} else if (aRawObj instanceof Ci.nsIDOMText ||
|
|
|
|
aRawObj instanceof Ci.nsIDOMComment) {
|
2013-12-19 13:04:59 +00:00
|
|
|
preview.textContent = threadActor.createValueGrip(aRawObj.textContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}, // DOMNode
|
|
|
|
|
|
|
|
function DOMEvent({obj, threadActor}, aGrip, aRawObj) {
|
2014-06-17 19:51:43 +00:00
|
|
|
if (isWorker || !aRawObj || !(aRawObj instanceof Ci.nsIDOMEvent)) {
|
2013-12-19 13:04:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
let preview = aGrip.preview = {
|
|
|
|
kind: "DOMEvent",
|
|
|
|
type: aRawObj.type,
|
|
|
|
properties: Object.create(null),
|
|
|
|
};
|
|
|
|
|
|
|
|
if (threadActor._gripDepth < 2) {
|
|
|
|
let target = obj.makeDebuggeeValue(aRawObj.target);
|
|
|
|
preview.target = threadActor.createValueGrip(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
let props = [];
|
2014-06-17 19:51:43 +00:00
|
|
|
if (aRawObj instanceof Ci.nsIDOMMouseEvent) {
|
2013-12-19 13:04:59 +00:00
|
|
|
props.push("buttons", "clientX", "clientY", "layerX", "layerY");
|
2014-06-17 19:51:43 +00:00
|
|
|
} else if (aRawObj instanceof Ci.nsIDOMKeyEvent) {
|
2013-12-19 13:04:59 +00:00
|
|
|
let modifiers = [];
|
|
|
|
if (aRawObj.altKey) {
|
|
|
|
modifiers.push("Alt");
|
|
|
|
}
|
|
|
|
if (aRawObj.ctrlKey) {
|
|
|
|
modifiers.push("Control");
|
|
|
|
}
|
|
|
|
if (aRawObj.metaKey) {
|
|
|
|
modifiers.push("Meta");
|
|
|
|
}
|
|
|
|
if (aRawObj.shiftKey) {
|
|
|
|
modifiers.push("Shift");
|
|
|
|
}
|
|
|
|
preview.eventKind = "key";
|
|
|
|
preview.modifiers = modifiers;
|
|
|
|
|
|
|
|
props.push("key", "charCode", "keyCode");
|
2014-08-29 23:04:26 +00:00
|
|
|
} else if (aRawObj instanceof Ci.nsIDOMTransitionEvent) {
|
|
|
|
props.push("propertyName", "pseudoElement");
|
|
|
|
} else if (aRawObj instanceof Ci.nsIDOMAnimationEvent) {
|
2013-12-19 13:04:59 +00:00
|
|
|
props.push("animationName", "pseudoElement");
|
2014-06-17 19:51:43 +00:00
|
|
|
} else if (aRawObj instanceof Ci.nsIDOMClipboardEvent) {
|
2013-12-19 13:04:59 +00:00
|
|
|
props.push("clipboardData");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add event-specific properties.
|
|
|
|
for (let prop of props) {
|
|
|
|
let value = aRawObj[prop];
|
|
|
|
if (value && (typeof value == "object" || typeof value == "function")) {
|
|
|
|
// Skip properties pointing to objects.
|
|
|
|
if (threadActor._gripDepth > 1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
value = obj.makeDebuggeeValue(value);
|
|
|
|
}
|
|
|
|
preview.properties[prop] = threadActor.createValueGrip(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add any properties we find on the event object.
|
|
|
|
if (!props.length) {
|
|
|
|
let i = 0;
|
|
|
|
for (let prop in aRawObj) {
|
|
|
|
let value = aRawObj[prop];
|
|
|
|
if (prop == "target" || prop == "type" || value === null ||
|
|
|
|
typeof value == "function") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (value && typeof value == "object") {
|
|
|
|
if (threadActor._gripDepth > 1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
value = obj.makeDebuggeeValue(value);
|
|
|
|
}
|
|
|
|
preview.properties[prop] = threadActor.createValueGrip(value);
|
|
|
|
if (++i == OBJECT_PREVIEW_MAX_ITEMS) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}, // DOMEvent
|
|
|
|
|
|
|
|
function DOMException({obj, threadActor}, aGrip, aRawObj) {
|
2014-06-17 19:51:43 +00:00
|
|
|
if (isWorker || !aRawObj || !(aRawObj instanceof Ci.nsIDOMDOMException)) {
|
2013-12-19 13:04:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aGrip.preview = {
|
|
|
|
kind: "DOMException",
|
|
|
|
name: threadActor.createValueGrip(aRawObj.name),
|
|
|
|
message: threadActor.createValueGrip(aRawObj.message),
|
|
|
|
code: threadActor.createValueGrip(aRawObj.code),
|
|
|
|
result: threadActor.createValueGrip(aRawObj.result),
|
|
|
|
filename: threadActor.createValueGrip(aRawObj.filename),
|
|
|
|
lineNumber: threadActor.createValueGrip(aRawObj.lineNumber),
|
|
|
|
columnNumber: threadActor.createValueGrip(aRawObj.columnNumber),
|
|
|
|
};
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2015-02-24 01:27:05 +00:00
|
|
|
function PseudoArray({obj, threadActor}, aGrip, aRawObj) {
|
|
|
|
let length = 0;
|
|
|
|
|
|
|
|
// Making sure all keys are numbers from 0 to length-1
|
|
|
|
let keys = obj.getOwnPropertyNames();
|
|
|
|
if (keys.length == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (let key of keys) {
|
|
|
|
if (isNaN(key) || key != length++) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aGrip.preview = {
|
|
|
|
kind: "ArrayLike",
|
|
|
|
length: length,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Avoid recursive object grips.
|
|
|
|
if (threadActor._gripDepth > 1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
let items = aGrip.preview.items = [];
|
|
|
|
|
|
|
|
let i = 0;
|
|
|
|
for (let key of keys) {
|
|
|
|
if (aRawObj.hasOwnProperty(key) && i++ < OBJECT_PREVIEW_MAX_ITEMS) {
|
|
|
|
let value = makeDebuggeeValueIfNeeded(obj, aRawObj[key]);
|
|
|
|
items.push(threadActor.createValueGrip(value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}, // PseudoArray
|
|
|
|
|
2013-12-19 13:04:59 +00:00
|
|
|
function GenericObject(aObjectActor, aGrip) {
|
|
|
|
let {obj, threadActor} = aObjectActor;
|
|
|
|
if (aGrip.preview || aGrip.displayString || threadActor._gripDepth > 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
let i = 0, names = [];
|
|
|
|
let preview = aGrip.preview = {
|
|
|
|
kind: "Object",
|
|
|
|
ownProperties: Object.create(null),
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
|
|
|
names = obj.getOwnPropertyNames();
|
|
|
|
} catch (ex) {
|
|
|
|
// Calling getOwnPropertyNames() on some wrapped native prototypes is not
|
|
|
|
// allowed: "cannot modify properties of a WrappedNative". See bug 952093.
|
|
|
|
}
|
|
|
|
|
|
|
|
preview.ownPropertiesLength = names.length;
|
|
|
|
|
|
|
|
for (let name of names) {
|
|
|
|
let desc = aObjectActor._propertyDescriptor(name, true);
|
|
|
|
if (!desc) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
preview.ownProperties[name] = desc;
|
|
|
|
if (++i == OBJECT_PREVIEW_MAX_ITEMS) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i < OBJECT_PREVIEW_MAX_ITEMS) {
|
|
|
|
preview.safeGetterValues = aObjectActor.
|
2015-05-25 18:11:59 +00:00
|
|
|
_findSafeGetterValues(Object.keys(preview.ownProperties),
|
2013-12-19 13:04:59 +00:00
|
|
|
OBJECT_PREVIEW_MAX_ITEMS - i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}, // GenericObject
|
|
|
|
]; // DebuggerServer.ObjectActorPreviewers.Object
|
|
|
|
|
2013-03-30 11:31:10 +00:00
|
|
|
/**
|
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);
|
|
|
|
|
2015-01-03 03:06:12 +00:00
|
|
|
update(PauseScopedObjectActor.prototype, ObjectActor.prototype);
|
2013-03-30 11:31:10 +00:00
|
|
|
|
2015-01-03 03:06:12 +00:00
|
|
|
update(PauseScopedObjectActor.prototype, {
|
2013-03-30 11:31:10 +00:00
|
|
|
constructor: PauseScopedObjectActor,
|
2013-09-25 16:03:17 +00:00
|
|
|
actorPrefix: "pausedobj",
|
2013-03-30 11:31:10 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
onThreadGrip: PauseScopedActor.withPaused(function (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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
onRelease: PauseScopedActor.withPaused(function (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
|
|
|
|
2015-01-03 03:06:12 +00:00
|
|
|
update(PauseScopedObjectActor.prototype.requestTypes, {
|
2013-03-30 11:31:10 +00:00
|
|
|
"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",
|
|
|
|
|
2013-11-07 14:27:40 +00:00
|
|
|
disconnect: function () {
|
2012-08-30 21:10:07 +00:00
|
|
|
// 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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
grip: function () {
|
2012-08-30 21:10:07 +00:00
|
|
|
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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
onSubstring: function (aRequest) {
|
2012-08-30 21:10:07 +00:00
|
|
|
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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
onRelease: function () {
|
2012-11-05 16:41:59 +00:00
|
|
|
// 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
|
|
|
};
|
|
|
|
|
2014-04-29 15:52:44 +00:00
|
|
|
exports.LongStringActor = LongStringActor;
|
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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
disconnect: function () {
|
2012-02-07 17:22:30 +00:00
|
|
|
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
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
form: function () {
|
2014-11-25 23:02:39 +00:00
|
|
|
let threadActor = this.threadActor;
|
2012-03-13 07:13:02 +00:00
|
|
|
let form = { actor: this.actorID,
|
2012-02-07 17:22:30 +00:00
|
|
|
type: this.frame.type };
|
|
|
|
if (this.frame.type === "call") {
|
2014-11-25 23:02:39 +00:00
|
|
|
form.callee = 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) {
|
2014-11-25 23:02:39 +00:00
|
|
|
let envActor = threadActor.createEnvironmentActor(
|
|
|
|
this.frame.environment,
|
|
|
|
this.frameLifetimePool
|
|
|
|
);
|
2013-01-15 00:15:58 +00:00
|
|
|
form.environment = envActor.form();
|
|
|
|
}
|
2014-11-25 23:02:39 +00:00
|
|
|
form.this = threadActor.createValueGrip(this.frame.this);
|
2012-03-13 07:13:02 +00:00
|
|
|
form.arguments = this._args();
|
2012-02-11 09:44:20 +00:00
|
|
|
if (this.frame.script) {
|
2015-02-23 08:36:58 +00:00
|
|
|
var generatedLocation = this.threadActor.sources.getFrameLocation(this.frame);
|
2015-02-12 04:40:52 +00:00
|
|
|
form.where = {
|
2015-02-23 08:36:58 +00:00
|
|
|
source: generatedLocation.generatedSourceActor.form(),
|
|
|
|
line: generatedLocation.generatedLine,
|
|
|
|
column: generatedLocation.generatedColumn
|
2015-02-12 04:40:52 +00:00
|
|
|
};
|
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
|
|
|
},
|
|
|
|
|
2013-11-07 14:27:40 +00:00
|
|
|
_args: function () {
|
2012-03-13 07:13:02 +00:00
|
|
|
if (!this.frame.arguments) {
|
2012-02-07 17:22:30 +00:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2015-05-28 15:54:00 +00:00
|
|
|
return this.frame.arguments.map(arg => this.threadActor.createValueGrip(arg));
|
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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
onPop: function (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.
|
2015-03-03 16:09:26 +00:00
|
|
|
* @param OriginalLocation aOriginalLocation
|
2015-02-23 15:14:57 +00:00
|
|
|
* The original location of the breakpoint.
|
2012-02-07 17:22:30 +00:00
|
|
|
*/
|
2015-03-03 16:09:26 +00:00
|
|
|
function BreakpointActor(aThreadActor, aOriginalLocation)
|
2012-02-07 17:22:30 +00:00
|
|
|
{
|
2014-11-07 14:21:00 +00:00
|
|
|
// The set of Debugger.Script instances that this breakpoint has been set
|
|
|
|
// upon.
|
|
|
|
this.scripts = new Set();
|
|
|
|
|
2012-02-07 17:22:30 +00:00
|
|
|
this.threadActor = aThreadActor;
|
2015-02-10 09:43:13 +00:00
|
|
|
this.originalLocation = aOriginalLocation;
|
2015-03-03 16:09:26 +00:00
|
|
|
this.condition = null;
|
2015-03-11 14:15:40 +00:00
|
|
|
this.isPending = true;
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BreakpointActor.prototype = {
|
|
|
|
actorPrefix: "breakpoint",
|
2014-03-24 13:37:24 +00:00
|
|
|
condition: null,
|
2012-02-07 17:22:30 +00:00
|
|
|
|
2015-05-05 09:55:46 +00:00
|
|
|
disconnect: function () {
|
|
|
|
this.removeScripts();
|
|
|
|
},
|
|
|
|
|
2015-01-19 13:44:26 +00:00
|
|
|
hasScript: function (aScript) {
|
|
|
|
return this.scripts.has(aScript);
|
|
|
|
},
|
|
|
|
|
2012-06-03 13:39:50 +00:00
|
|
|
/**
|
|
|
|
* Called when this same breakpoint is added to another Debugger.Script
|
2014-11-07 14:21:00 +00:00
|
|
|
* instance.
|
2012-06-03 13:39:50 +00:00
|
|
|
*
|
|
|
|
* @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.
|
|
|
|
*/
|
2015-01-23 11:39:24 +00:00
|
|
|
addScript: function (aScript) {
|
2014-11-07 14:21:00 +00:00
|
|
|
this.scripts.add(aScript);
|
2015-03-11 14:15:40 +00:00
|
|
|
this.isPending = false;
|
2012-06-03 13:39:50 +00:00
|
|
|
},
|
|
|
|
|
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);
|
|
|
|
}
|
2014-11-07 14:21:00 +00:00
|
|
|
this.scripts.clear();
|
2013-05-01 15:29:33 +00:00
|
|
|
},
|
|
|
|
|
2014-04-04 12:27:57 +00:00
|
|
|
/**
|
|
|
|
* Check if this breakpoint has a condition that doesn't error and
|
2015-03-06 03:41:54 +00:00
|
|
|
* evaluates to true in aFrame.
|
2014-04-04 12:27:57 +00:00
|
|
|
*
|
|
|
|
* @param aFrame Debugger.Frame
|
|
|
|
* The frame to evaluate the condition in
|
2015-03-06 03:41:54 +00:00
|
|
|
* @returns Object
|
|
|
|
* - result: boolean|undefined
|
|
|
|
* True when the conditional breakpoint should trigger a pause, false otherwise.
|
|
|
|
* If the condition evaluation failed/killed, `result` will be `undefined`.
|
|
|
|
* - message: string
|
|
|
|
* The thrown message converted to a string, when the condition throws.
|
2014-04-04 12:27:57 +00:00
|
|
|
*/
|
2015-02-09 13:43:17 +00:00
|
|
|
checkCondition: function(aFrame) {
|
|
|
|
let completion = aFrame.eval(this.condition);
|
|
|
|
if (completion) {
|
|
|
|
if (completion.throw) {
|
2015-03-06 03:41:54 +00:00
|
|
|
// The evaluation failed and threw
|
|
|
|
let message = "Unknown exception";
|
|
|
|
try {
|
|
|
|
if (completion.throw.getOwnPropertyDescriptor) {
|
|
|
|
message = completion.throw.getOwnPropertyDescriptor("message").value;
|
|
|
|
} else if (completion.toString) {
|
|
|
|
message = completion.toString();
|
|
|
|
}
|
|
|
|
} catch (ex) {}
|
|
|
|
return {
|
|
|
|
result: true,
|
|
|
|
message: message
|
|
|
|
};
|
2015-02-09 13:43:17 +00:00
|
|
|
} else if (completion.yield) {
|
|
|
|
dbg_assert(false,
|
|
|
|
"Shouldn't ever get yield completions from an eval");
|
|
|
|
} else {
|
2015-03-06 03:41:54 +00:00
|
|
|
return { result: completion.return ? true : false };
|
2015-02-09 13:43:17 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// The evaluation was killed (possibly by the slow script dialog)
|
2015-03-06 03:41:54 +00:00
|
|
|
return { result: undefined };
|
2014-03-24 13:37:24 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
hit: function (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.
|
2015-02-23 08:36:58 +00:00
|
|
|
let generatedLocation = this.threadActor.sources.getFrameLocation(aFrame);
|
|
|
|
let { originalSourceActor } = this.threadActor.synchronize(
|
|
|
|
this.threadActor.sources.getOriginalLocation(generatedLocation));
|
|
|
|
let url = originalSourceActor.url;
|
2013-08-16 21:59:04 +00:00
|
|
|
|
2014-03-24 13:37:24 +00:00
|
|
|
if (this.threadActor.sources.isBlackBoxed(url)
|
2015-02-09 13:43:17 +00:00
|
|
|
|| aFrame.onStep) {
|
2013-06-11 14:23:00 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2013-07-18 11:14:16 +00:00
|
|
|
let reason = {};
|
2015-02-09 13:43:17 +00:00
|
|
|
|
2013-07-18 11:14:16 +00:00
|
|
|
if (this.threadActor._hiddenBreakpoints.has(this.actorID)) {
|
|
|
|
reason.type = "pauseOnDOMEvents";
|
2015-03-06 03:41:54 +00:00
|
|
|
} else if (!this.condition) {
|
2013-07-18 11:14:16 +00:00
|
|
|
reason.type = "breakpoint";
|
|
|
|
// TODO: add the rest of the breakpoints on that line (bug 676602).
|
|
|
|
reason.actors = [ this.actorID ];
|
2015-02-09 13:43:17 +00:00
|
|
|
} else {
|
2015-03-06 03:41:54 +00:00
|
|
|
let { result, message } = this.checkCondition(aFrame)
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
if (!message) {
|
|
|
|
reason.type = "breakpoint";
|
|
|
|
} else {
|
|
|
|
reason.type = "breakpointConditionThrown";
|
|
|
|
reason.message = message;
|
|
|
|
}
|
|
|
|
reason.actors = [ this.actorID ];
|
|
|
|
} else {
|
|
|
|
return undefined;
|
|
|
|
}
|
2013-07-18 11:14:16 +00:00
|
|
|
}
|
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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
onDelete: function (aRequest) {
|
2012-06-03 13:39:50 +00:00
|
|
|
// Remove from the breakpoint store.
|
2015-02-23 15:14:57 +00:00
|
|
|
if (this.originalLocation) {
|
|
|
|
this.threadActor.breakpointActorMap.deleteActor(this.originalLocation);
|
2015-01-23 11:39:24 +00:00
|
|
|
}
|
2013-12-06 17:25:58 +00:00
|
|
|
this.threadActor.threadLifetimePool.removeActor(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.
|
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
form: function () {
|
2013-01-15 00:15:58 +00:00
|
|
|
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-11-07 14:27:40 +00:00
|
|
|
_bindings: function () {
|
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;
|
2015-05-28 15:54:00 +00:00
|
|
|
} else {
|
|
|
|
parameterNames = [];
|
2012-03-21 15:49:23 +00:00
|
|
|
}
|
2015-05-28 15:54:00 +00:00
|
|
|
for (let name of parameterNames) {
|
2012-03-13 07:13:02 +00:00
|
|
|
let arg = {};
|
2014-05-07 00:36:18 +00:00
|
|
|
let value = this.obj.getVariable(name);
|
|
|
|
|
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 = {
|
2014-05-07 00:36:18 +00:00
|
|
|
value: value,
|
2012-03-21 15:49:23 +00:00
|
|
|
configurable: false,
|
2015-01-14 18:51:00 +00:00
|
|
|
writable: !(value && value.optimizedOut),
|
2012-03-21 15:49:23 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-05-28 15:54:00 +00:00
|
|
|
for (let name of this.obj.names()) {
|
2012-03-13 07:13:02 +00:00
|
|
|
if (bindings.arguments.some(function exists(element) {
|
|
|
|
return !!element[name];
|
|
|
|
})) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-05-09 04:30:50 +00:00
|
|
|
let value = this.obj.getVariable(name);
|
2014-05-07 00:36:18 +00:00
|
|
|
|
|
|
|
// TODO: this part should be removed in favor of the commented-out part
|
|
|
|
// below when getVariableDescriptor lands.
|
|
|
|
let desc = {
|
|
|
|
value: value,
|
|
|
|
configurable: false,
|
2015-01-14 18:51:00 +00:00
|
|
|
writable: !(value &&
|
|
|
|
(value.optimizedOut ||
|
|
|
|
value.uninitialized ||
|
|
|
|
value.missingArguments)),
|
2014-05-07 00:36:18 +00:00
|
|
|
enumerable: true
|
|
|
|
};
|
|
|
|
|
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 {
|
2014-05-15 14:36:03 +00:00
|
|
|
descForm.get = this.threadActor.createValueGrip(desc.get || undefined);
|
|
|
|
descForm.set = this.threadActor.createValueGrip(desc.set || undefined);
|
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
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
onAssign: function (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);
|
2015-05-28 15:54:00 +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" };
|
2015-05-28 15:54:00 +00:00
|
|
|
} else {
|
|
|
|
throw e;
|
|
|
|
}
|
2012-02-07 17:22:30 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
*/
|
2013-11-07 14:27:40 +00:00
|
|
|
onBindings: function (aRequest) {
|
2012-02-07 17:22:30 +00:00
|
|
|
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
|
|
|
|
2014-04-29 15:52:44 +00:00
|
|
|
exports.EnvironmentActor = EnvironmentActor;
|
|
|
|
|
2014-12-22 15:48:00 +00:00
|
|
|
function hackDebugger(Debugger) {
|
|
|
|
// TODO: Improve native code instead of hacking on top of it
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.staticLevel != "undefined") {
|
|
|
|
output += ":L" + this.staticLevel;
|
|
|
|
}
|
|
|
|
if (typeof this.startLine != "undefined") {
|
|
|
|
output += ":" + this.startLine;
|
|
|
|
if (this.lineCount && this.lineCount > 1) {
|
|
|
|
output += "-" + (this.startLine + this.lineCount - 1);
|
|
|
|
}
|
2012-11-01 15:34:10 +00:00
|
|
|
}
|
2014-12-22 15:48:00 +00:00
|
|
|
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;
|
|
|
|
};
|
2012-11-01 15:34:10 +00:00
|
|
|
|
2014-12-22 15:48:00 +00:00
|
|
|
/**
|
|
|
|
* 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-11-01 15:34:10 +00:00
|
|
|
}
|
2014-12-22 15:48:00 +00:00
|
|
|
});
|
|
|
|
}
|
2012-11-01 15:34:10 +00:00
|
|
|
|
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.)
|
|
|
|
*
|
2014-07-28 13:01:00 +00:00
|
|
|
* @param aParent object
|
|
|
|
* This actor's parent actor. See ThreadActor for a list of expected
|
|
|
|
* properties.
|
2012-10-31 16:31:55 +00:00
|
|
|
*/
|
2014-07-28 13:01:00 +00:00
|
|
|
function ChromeDebuggerActor(aConnection, aParent)
|
2012-10-31 16:31:55 +00:00
|
|
|
{
|
2014-07-28 13:01:00 +00:00
|
|
|
ThreadActor.call(this, aParent);
|
2012-10-31 16:31:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ChromeDebuggerActor.prototype = Object.create(ThreadActor.prototype);
|
|
|
|
|
2015-01-03 03:06:12 +00:00
|
|
|
update(ChromeDebuggerActor.prototype, {
|
2012-10-31 16:31:55 +00:00
|
|
|
constructor: ChromeDebuggerActor,
|
|
|
|
|
|
|
|
// A constant prefix that will be used to form the actor ID by the server.
|
2014-12-02 06:03:51 +00:00
|
|
|
actorPrefix: "chromeDebugger"
|
2012-10-31 16:31:55 +00:00
|
|
|
});
|
|
|
|
|
2014-04-29 15:52:44 +00:00
|
|
|
exports.ChromeDebuggerActor = ChromeDebuggerActor;
|
|
|
|
|
2014-03-07 08:09:14 +00:00
|
|
|
/**
|
|
|
|
* Creates an actor for handling add-on debugging. AddonThreadActor is
|
|
|
|
* a thin wrapper over ThreadActor.
|
|
|
|
*
|
|
|
|
* @param aConnection object
|
|
|
|
* The DebuggerServerConnection with which this AddonThreadActor
|
|
|
|
* is associated. (Currently unused, but required to make this
|
|
|
|
* constructor usable with addGlobalActor.)
|
|
|
|
*
|
2014-07-28 13:01:00 +00:00
|
|
|
* @param aParent object
|
|
|
|
* This actor's parent actor. See ThreadActor for a list of expected
|
|
|
|
* properties.
|
2014-03-07 08:09:14 +00:00
|
|
|
*/
|
2014-07-28 13:01:00 +00:00
|
|
|
function AddonThreadActor(aConnect, aParent) {
|
|
|
|
ThreadActor.call(this, aParent);
|
2014-03-07 08:09:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AddonThreadActor.prototype = Object.create(ThreadActor.prototype);
|
|
|
|
|
2015-01-03 03:06:12 +00:00
|
|
|
update(AddonThreadActor.prototype, {
|
2014-03-07 08:09:14 +00:00
|
|
|
constructor: AddonThreadActor,
|
|
|
|
|
|
|
|
// A constant prefix that will be used to form the actor ID by the server.
|
2015-03-23 14:50:00 +00:00
|
|
|
actorPrefix: "addonThread"
|
2014-03-07 08:09:14 +00:00
|
|
|
});
|
2012-10-31 16:31:55 +00:00
|
|
|
|
2014-04-29 15:52:44 +00:00
|
|
|
exports.AddonThreadActor = AddonThreadActor;
|
|
|
|
|
2012-10-31 16:31:55 +00:00
|
|
|
// Utility functions.
|
|
|
|
|
2013-04-15 21:07:00 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
*/
|
2014-05-30 14:42:55 +00:00
|
|
|
let oldReportError = reportError;
|
|
|
|
reportError = function(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;
|
2014-05-30 14:42:55 +00:00
|
|
|
oldReportError(msg);
|
2013-07-03 21:10:52 +00:00
|
|
|
dumpn(msg);
|
2013-04-15 21:07:00 +00:00
|
|
|
}
|
2013-07-18 11:14:16 +00:00
|
|
|
|
2013-12-19 13:04:59 +00:00
|
|
|
/**
|
|
|
|
* Make a debuggee value for the given object, if needed. Primitive values
|
|
|
|
* are left the same.
|
|
|
|
*
|
|
|
|
* Use case: you have a raw JS object (after unsafe dereference) and you want to
|
|
|
|
* send it to the client. In that case you need to use an ObjectActor which
|
|
|
|
* requires a debuggee value. The Debugger.Object.prototype.makeDebuggeeValue()
|
|
|
|
* method works only for JS objects and functions.
|
|
|
|
*
|
|
|
|
* @param Debugger.Object obj
|
|
|
|
* @param any value
|
|
|
|
* @return object
|
|
|
|
*/
|
|
|
|
function makeDebuggeeValueIfNeeded(obj, value) {
|
|
|
|
if (value && (typeof value == "object" || typeof value == "function")) {
|
|
|
|
return obj.makeDebuggeeValue(value);
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
2014-01-28 07:21:31 +00:00
|
|
|
|
2015-02-05 13:44:10 +00:00
|
|
|
const symbolProtoToString = Symbol.prototype.toString;
|
2014-08-25 13:49:00 +00:00
|
|
|
|
|
|
|
function getSymbolName(symbol) {
|
|
|
|
const name = symbolProtoToString.call(symbol).slice("Symbol(".length, -1);
|
|
|
|
return name || undefined;
|
|
|
|
}
|
2014-11-25 23:02:39 +00:00
|
|
|
|
2014-12-09 20:00:00 +00:00
|
|
|
function isEvalSource(source) {
|
2014-11-25 23:02:39 +00:00
|
|
|
let introType = source.introductionType;
|
|
|
|
// These are all the sources that are essentially eval-ed (either
|
|
|
|
// by calling eval or passing a string to one of these functions).
|
2014-12-09 20:00:00 +00:00
|
|
|
return (introType === 'eval' ||
|
|
|
|
introType === 'Function' ||
|
|
|
|
introType === 'eventHandler' ||
|
|
|
|
introType === 'setTimeout' ||
|
|
|
|
introType === 'setInterval');
|
|
|
|
}
|
2015-03-23 14:50:00 +00:00
|
|
|
exports.isEvalSource = isEvalSource;
|
2014-12-09 20:00:00 +00:00
|
|
|
|
2015-05-29 16:27:44 +00:00
|
|
|
function getSourceURL(source, window) {
|
|
|
|
if (isEvalSource(source)) {
|
2014-12-09 20:00:00 +00:00
|
|
|
// Eval sources have no urls, but they might have a `displayURL`
|
|
|
|
// created with the sourceURL pragma. If the introduction script
|
|
|
|
// is a non-eval script, generate an full absolute URL relative to it.
|
|
|
|
|
2015-05-29 16:27:44 +00:00
|
|
|
if (source.displayURL && source.introductionScript &&
|
2014-12-09 20:00:00 +00:00
|
|
|
!isEvalSource(source.introductionScript.source)) {
|
2015-05-29 16:27:44 +00:00
|
|
|
|
|
|
|
if (source.introductionScript.source.url === 'debugger eval code') {
|
|
|
|
if (window) {
|
|
|
|
// If this is a named eval script created from the console, make it
|
|
|
|
// relative to the current page. window is only available
|
|
|
|
// when we care about this.
|
|
|
|
return joinURI(window.location.href, source.displayURL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return joinURI(dirname(source.introductionScript.source.url),
|
|
|
|
source.displayURL);
|
|
|
|
}
|
2014-12-09 20:00:00 +00:00
|
|
|
}
|
|
|
|
|
2014-11-25 23:02:39 +00:00
|
|
|
return source.displayURL;
|
|
|
|
}
|
2015-05-29 16:27:44 +00:00
|
|
|
else if (source.url === 'debugger eval code') {
|
2015-05-28 16:39:56 +00:00
|
|
|
// Treat code evaluated by the console as unnamed eval scripts
|
|
|
|
return null;
|
|
|
|
}
|
2014-11-25 23:02:39 +00:00
|
|
|
return source.url;
|
|
|
|
}
|
2015-03-23 14:50:00 +00:00
|
|
|
exports.getSourceURL = getSourceURL;
|
2015-01-23 11:39:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Find the scripts which contain offsets that are an entry point to the given
|
|
|
|
* line.
|
|
|
|
*
|
|
|
|
* @param Array scripts
|
|
|
|
* The set of Debugger.Scripts to consider.
|
|
|
|
* @param Number line
|
|
|
|
* The line we are searching for entry points into.
|
|
|
|
* @returns Array of objects of the form { script, offsets } where:
|
|
|
|
* - script is a Debugger.Script
|
|
|
|
* - offsets is an array of offsets that are entry points into the
|
|
|
|
* given line.
|
|
|
|
*/
|
|
|
|
function findEntryPointsForLine(scripts, line) {
|
|
|
|
const entryPoints = [];
|
|
|
|
for (let script of scripts) {
|
|
|
|
const offsets = script.getLineOffsets(line);
|
|
|
|
if (offsets.length) {
|
|
|
|
entryPoints.push({ script, offsets });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return entryPoints;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set breakpoints on all the given entry points with the given
|
|
|
|
* BreakpointActor as the handler.
|
|
|
|
*
|
|
|
|
* @param BreakpointActor actor
|
|
|
|
* The actor handling the breakpoint hits.
|
|
|
|
* @param Array entryPoints
|
|
|
|
* An array of objects of the form `{ script, offsets }`.
|
|
|
|
*/
|
2015-03-26 19:15:36 +00:00
|
|
|
function setBreakpointAtEntryPoints(actor, entryPoints) {
|
2015-01-23 11:39:24 +00:00
|
|
|
for (let { script, offsets } of entryPoints) {
|
2015-03-11 14:15:40 +00:00
|
|
|
actor.addScript(script);
|
2015-01-23 11:39:24 +00:00
|
|
|
for (let offset of offsets) {
|
|
|
|
script.setBreakpoint(offset, actor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-06 12:20:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unwrap a global that is wrapped in a |Debugger.Object|, or if the global has
|
|
|
|
* become a dead object, return |undefined|.
|
|
|
|
*
|
|
|
|
* @param Debugger.Object wrappedGlobal
|
|
|
|
* The |Debugger.Object| which wraps a global.
|
|
|
|
*
|
|
|
|
* @returns {Object|undefined}
|
|
|
|
* Returns the unwrapped global object or |undefined| if unwrapping
|
|
|
|
* failed.
|
|
|
|
*/
|
|
|
|
exports.unwrapDebuggerObjectGlobal = wrappedGlobal => {
|
|
|
|
try {
|
|
|
|
// Because of bug 991399 we sometimes get nuked window references here. We
|
|
|
|
// just bail out in that case.
|
|
|
|
//
|
|
|
|
// Note that addon sandboxes have a DOMWindow as their prototype. So make
|
|
|
|
// sure that we can touch the prototype too (whatever it is), in case _it_
|
|
|
|
// is it a nuked window reference. We force stringification to make sure
|
|
|
|
// that any dead object proxies make themselves known.
|
|
|
|
let global = wrappedGlobal.unsafeDereference();
|
|
|
|
Object.getPrototypeOf(global) + "";
|
|
|
|
return global;
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
};
|