2013-03-13 04:51:30 +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/. */
|
2013-05-13 07:01:00 +00:00
|
|
|
|
2014-04-13 06:47:27 +00:00
|
|
|
"use strict";
|
2013-03-13 04:51:30 +00:00
|
|
|
|
2014-04-13 06:47:27 +00:00
|
|
|
const { Cc, Ci, Cu } = require("chrome");
|
|
|
|
const gcli = require("gcli/index");
|
2013-03-13 04:51:30 +00:00
|
|
|
|
2014-04-13 06:47:27 +00:00
|
|
|
loader.lazyImporter(this, "gDevTools", "resource:///modules/devtools/gDevTools.jsm");
|
2013-03-13 04:51:30 +00:00
|
|
|
|
2014-04-13 06:47:27 +00:00
|
|
|
/**
|
|
|
|
* The commands and converters that are exported to GCLI
|
|
|
|
*/
|
|
|
|
exports.items = [];
|
2013-03-13 04:51:30 +00:00
|
|
|
|
2013-05-21 09:18:55 +00:00
|
|
|
/**
|
2013-09-13 13:23:13 +00:00
|
|
|
* Utility to get access to the current breakpoint list.
|
|
|
|
*
|
|
|
|
* @param DebuggerPanel dbg
|
|
|
|
* The debugger panel.
|
|
|
|
* @return array
|
|
|
|
* An array of objects, one for each breakpoint, where each breakpoint
|
|
|
|
* object has the following properties:
|
|
|
|
* - url: the URL of the source file.
|
|
|
|
* - label: a unique string identifier designed to be user visible.
|
|
|
|
* - lineNumber: the line number of the breakpoint in the source file.
|
|
|
|
* - lineText: the text of the line at the breakpoint.
|
|
|
|
* - truncatedLineText: lineText truncated to MAX_LINE_TEXT_LENGTH.
|
2013-05-21 09:18:55 +00:00
|
|
|
*/
|
|
|
|
function getAllBreakpoints(dbg) {
|
|
|
|
let breakpoints = [];
|
2013-09-13 13:23:13 +00:00
|
|
|
let sources = dbg._view.Sources;
|
2013-09-13 13:23:13 +00:00
|
|
|
let { trimUrlLength: trim } = dbg.panelWin.SourceUtils;
|
2013-05-21 09:18:55 +00:00
|
|
|
|
2013-11-07 21:23:55 +00:00
|
|
|
for (let source of sources) {
|
|
|
|
for (let { attachment: breakpoint } of source) {
|
2013-05-21 09:18:55 +00:00
|
|
|
breakpoints.push({
|
2014-11-25 23:02:39 +00:00
|
|
|
url: source.attachment.source.url,
|
2014-01-03 21:42:16 +00:00
|
|
|
label: source.attachment.label + ":" + breakpoint.line,
|
2013-09-13 13:23:13 +00:00
|
|
|
lineNumber: breakpoint.line,
|
|
|
|
lineText: breakpoint.text,
|
|
|
|
truncatedLineText: trim(breakpoint.text, MAX_LINE_TEXT_LENGTH, "end")
|
2013-05-21 09:18:55 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return breakpoints;
|
|
|
|
}
|
|
|
|
|
2014-11-25 23:02:39 +00:00
|
|
|
function getAllSources(dbg) {
|
|
|
|
if (!dbg) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
let items = dbg._view.Sources.items;
|
|
|
|
return items
|
|
|
|
.filter(item => !!item.attachment.source.url)
|
|
|
|
.map(item => ({
|
|
|
|
name: item.attachment.source.url,
|
|
|
|
value: item.attachment.source.actor
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2013-03-13 04:51:30 +00:00
|
|
|
/**
|
|
|
|
* 'break' command
|
|
|
|
*/
|
2014-04-13 06:47:27 +00:00
|
|
|
exports.items.push({
|
2013-03-13 04:51:30 +00:00
|
|
|
name: "break",
|
|
|
|
description: gcli.lookup("breakDesc"),
|
|
|
|
manual: gcli.lookup("breakManual")
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 'break list' command
|
|
|
|
*/
|
2014-04-13 06:47:27 +00:00
|
|
|
exports.items.push({
|
2013-03-13 04:51:30 +00:00
|
|
|
name: "break list",
|
|
|
|
description: gcli.lookup("breaklistDesc"),
|
2013-04-03 16:55:00 +00:00
|
|
|
returnType: "breakpoints",
|
2013-03-13 04:51:30 +00:00
|
|
|
exec: function(args, context) {
|
2013-09-13 13:23:13 +00:00
|
|
|
let dbg = getPanel(context, "jsdebugger", { ensureOpened: true });
|
|
|
|
return dbg.then(getAllBreakpoints);
|
2013-04-03 16:55:00 +00:00
|
|
|
}
|
|
|
|
});
|
2013-03-13 04:51:30 +00:00
|
|
|
|
2014-04-13 06:47:27 +00:00
|
|
|
exports.items.push({
|
|
|
|
item: "converter",
|
2013-04-03 16:55:00 +00:00
|
|
|
from: "breakpoints",
|
|
|
|
to: "view",
|
|
|
|
exec: function(breakpoints, context) {
|
|
|
|
let dbg = getPanel(context, "jsdebugger");
|
|
|
|
if (dbg && breakpoints.length) {
|
|
|
|
return context.createView({
|
|
|
|
html: breakListHtml,
|
|
|
|
data: {
|
2013-05-21 09:18:55 +00:00
|
|
|
breakpoints: breakpoints,
|
|
|
|
onclick: context.update,
|
|
|
|
ondblclick: context.updateExec
|
2013-04-03 16:55:00 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return context.createView({
|
|
|
|
html: "<p>${message}</p>",
|
|
|
|
data: { message: gcli.lookup("breaklistNone") }
|
|
|
|
});
|
2013-03-13 04:51:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-04-03 16:55:00 +00:00
|
|
|
var breakListHtml = "" +
|
|
|
|
"<table>" +
|
|
|
|
" <thead>" +
|
|
|
|
" <th>Source</th>" +
|
|
|
|
" <th>Line</th>" +
|
|
|
|
" <th>Actions</th>" +
|
|
|
|
" </thead>" +
|
|
|
|
" <tbody>" +
|
|
|
|
" <tr foreach='breakpoint in ${breakpoints}'>" +
|
|
|
|
" <td class='gcli-breakpoint-label'>${breakpoint.label}</td>" +
|
|
|
|
" <td class='gcli-breakpoint-lineText'>" +
|
|
|
|
" ${breakpoint.truncatedLineText}" +
|
|
|
|
" </td>" +
|
|
|
|
" <td>" +
|
|
|
|
" <span class='gcli-out-shortcut'" +
|
2013-05-21 09:18:55 +00:00
|
|
|
" data-command='break del ${breakpoint.label}'" +
|
2013-04-03 16:55:00 +00:00
|
|
|
" onclick='${onclick}'" +
|
2013-05-13 07:01:00 +00:00
|
|
|
" ondblclick='${ondblclick}'>" +
|
|
|
|
" " + gcli.lookup("breaklistOutRemove") + "</span>" +
|
2013-04-03 16:55:00 +00:00
|
|
|
" </td>" +
|
|
|
|
" </tr>" +
|
|
|
|
" </tbody>" +
|
|
|
|
"</table>" +
|
|
|
|
"";
|
|
|
|
|
|
|
|
var MAX_LINE_TEXT_LENGTH = 30;
|
|
|
|
var MAX_LABEL_LENGTH = 20;
|
|
|
|
|
2013-03-13 04:51:30 +00:00
|
|
|
/**
|
|
|
|
* 'break add' command
|
|
|
|
*/
|
2014-04-13 06:47:27 +00:00
|
|
|
exports.items.push({
|
2013-03-13 04:51:30 +00:00
|
|
|
name: "break add",
|
|
|
|
description: gcli.lookup("breakaddDesc"),
|
|
|
|
manual: gcli.lookup("breakaddManual")
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 'break add line' command
|
|
|
|
*/
|
2014-04-13 06:47:27 +00:00
|
|
|
exports.items.push({
|
2013-03-13 04:51:30 +00:00
|
|
|
name: "break add line",
|
|
|
|
description: gcli.lookup("breakaddlineDesc"),
|
|
|
|
params: [
|
|
|
|
{
|
|
|
|
name: "file",
|
|
|
|
type: {
|
|
|
|
name: "selection",
|
2014-11-25 23:02:39 +00:00
|
|
|
lookup: function(context) {
|
|
|
|
return getAllSources(getPanel(context, "jsdebugger"));
|
2013-03-13 04:51:30 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
description: gcli.lookup("breakaddlineFileDesc")
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "line",
|
|
|
|
type: { name: "number", min: 1, step: 10 },
|
|
|
|
description: gcli.lookup("breakaddlineLineDesc")
|
|
|
|
}
|
|
|
|
],
|
2013-05-09 14:15:22 +00:00
|
|
|
returnType: "string",
|
2013-03-13 04:51:30 +00:00
|
|
|
exec: function(args, context) {
|
|
|
|
let dbg = getPanel(context, "jsdebugger");
|
|
|
|
if (!dbg) {
|
|
|
|
return gcli.lookup("debuggerStopped");
|
|
|
|
}
|
2013-05-13 07:01:00 +00:00
|
|
|
|
|
|
|
let deferred = context.defer();
|
2014-11-25 23:02:39 +00:00
|
|
|
let item = dbg._view.Sources.getItemForAttachment(a => {
|
|
|
|
return a.source && a.source.actor === args.file;
|
|
|
|
})
|
|
|
|
let position = { actor: item.value, line: args.line };
|
2013-09-13 13:23:13 +00:00
|
|
|
|
|
|
|
dbg.addBreakpoint(position).then(() => {
|
2013-03-13 04:51:30 +00:00
|
|
|
deferred.resolve(gcli.lookup("breakaddAdded"));
|
2013-09-13 13:23:13 +00:00
|
|
|
}, aError => {
|
|
|
|
deferred.resolve(gcli.lookupFormat("breakaddFailed", [aError]));
|
2013-03-13 04:51:30 +00:00
|
|
|
});
|
2013-09-13 13:23:13 +00:00
|
|
|
|
2013-03-13 04:51:30 +00:00
|
|
|
return deferred.promise;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 'break del' command
|
|
|
|
*/
|
2014-04-13 06:47:27 +00:00
|
|
|
exports.items.push({
|
2013-03-13 04:51:30 +00:00
|
|
|
name: "break del",
|
|
|
|
description: gcli.lookup("breakdelDesc"),
|
|
|
|
params: [
|
|
|
|
{
|
2013-05-21 09:18:55 +00:00
|
|
|
name: "breakpoint",
|
2013-03-13 04:51:30 +00:00
|
|
|
type: {
|
2013-05-21 09:18:55 +00:00
|
|
|
name: "selection",
|
|
|
|
lookup: function(context) {
|
2013-03-13 04:51:30 +00:00
|
|
|
let dbg = getPanel(context, "jsdebugger");
|
2013-09-13 13:23:13 +00:00
|
|
|
if (!dbg) {
|
2013-05-21 09:18:55 +00:00
|
|
|
return [];
|
|
|
|
}
|
2013-09-13 13:23:13 +00:00
|
|
|
return getAllBreakpoints(dbg).map(breakpoint => ({
|
|
|
|
name: breakpoint.label,
|
|
|
|
value: breakpoint,
|
|
|
|
description: breakpoint.truncatedLineText
|
|
|
|
}));
|
2013-05-21 09:18:55 +00:00
|
|
|
}
|
2013-03-13 04:51:30 +00:00
|
|
|
},
|
|
|
|
description: gcli.lookup("breakdelBreakidDesc")
|
|
|
|
}
|
|
|
|
],
|
2013-05-09 14:15:22 +00:00
|
|
|
returnType: "string",
|
2013-03-13 04:51:30 +00:00
|
|
|
exec: function(args, context) {
|
|
|
|
let dbg = getPanel(context, "jsdebugger");
|
|
|
|
if (!dbg) {
|
|
|
|
return gcli.lookup("debuggerStopped");
|
|
|
|
}
|
|
|
|
|
2014-11-25 23:02:39 +00:00
|
|
|
let source = dbg._view.Sources.getItemForAttachment(a => {
|
|
|
|
return a.source && a.source.url === args.breakpoint.url
|
|
|
|
});
|
|
|
|
|
2013-03-13 04:51:30 +00:00
|
|
|
let deferred = context.defer();
|
2014-11-25 23:02:39 +00:00
|
|
|
let position = { actor: source.attachment.source.actor,
|
|
|
|
line: args.breakpoint.lineNumber };
|
2013-09-13 13:23:13 +00:00
|
|
|
|
|
|
|
dbg.removeBreakpoint(position).then(() => {
|
2013-03-13 04:51:30 +00:00
|
|
|
deferred.resolve(gcli.lookup("breakdelRemoved"));
|
2013-09-13 13:23:13 +00:00
|
|
|
}, () => {
|
|
|
|
deferred.resolve(gcli.lookup("breakNotFound"));
|
|
|
|
});
|
|
|
|
|
2013-03-13 04:51:30 +00:00
|
|
|
return deferred.promise;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 'dbg' command
|
|
|
|
*/
|
2014-04-13 06:47:27 +00:00
|
|
|
exports.items.push({
|
2013-03-13 04:51:30 +00:00
|
|
|
name: "dbg",
|
|
|
|
description: gcli.lookup("dbgDesc"),
|
|
|
|
manual: gcli.lookup("dbgManual")
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 'dbg open' command
|
|
|
|
*/
|
2014-04-13 06:47:27 +00:00
|
|
|
exports.items.push({
|
2013-03-13 04:51:30 +00:00
|
|
|
name: "dbg open",
|
|
|
|
description: gcli.lookup("dbgOpen"),
|
|
|
|
params: [],
|
|
|
|
exec: function(args, context) {
|
2013-09-13 13:23:13 +00:00
|
|
|
let target = context.environment.target;
|
|
|
|
return gDevTools.showToolbox(target, "jsdebugger").then(() => null);
|
2013-03-13 04:51:30 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 'dbg close' command
|
|
|
|
*/
|
2014-04-13 06:47:27 +00:00
|
|
|
exports.items.push({
|
2013-03-13 04:51:30 +00:00
|
|
|
name: "dbg close",
|
|
|
|
description: gcli.lookup("dbgClose"),
|
|
|
|
params: [],
|
|
|
|
exec: function(args, context) {
|
2013-09-13 13:23:13 +00:00
|
|
|
if (!getPanel(context, "jsdebugger")) {
|
2013-06-19 17:09:28 +00:00
|
|
|
return;
|
2013-09-13 13:23:13 +00:00
|
|
|
}
|
|
|
|
let target = context.environment.target;
|
|
|
|
return gDevTools.closeToolbox(target).then(() => null);
|
2013-03-13 04:51:30 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 'dbg interrupt' command
|
|
|
|
*/
|
2014-04-13 06:47:27 +00:00
|
|
|
exports.items.push({
|
2013-03-13 04:51:30 +00:00
|
|
|
name: "dbg interrupt",
|
|
|
|
description: gcli.lookup("dbgInterrupt"),
|
|
|
|
params: [],
|
|
|
|
exec: function(args, context) {
|
|
|
|
let dbg = getPanel(context, "jsdebugger");
|
|
|
|
if (!dbg) {
|
|
|
|
return gcli.lookup("debuggerStopped");
|
|
|
|
}
|
|
|
|
|
|
|
|
let controller = dbg._controller;
|
|
|
|
let thread = controller.activeThread;
|
|
|
|
if (!thread.paused) {
|
|
|
|
thread.interrupt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 'dbg continue' command
|
|
|
|
*/
|
2014-04-13 06:47:27 +00:00
|
|
|
exports.items.push({
|
2013-03-13 04:51:30 +00:00
|
|
|
name: "dbg continue",
|
|
|
|
description: gcli.lookup("dbgContinue"),
|
|
|
|
params: [],
|
|
|
|
exec: function(args, context) {
|
|
|
|
let dbg = getPanel(context, "jsdebugger");
|
|
|
|
if (!dbg) {
|
|
|
|
return gcli.lookup("debuggerStopped");
|
|
|
|
}
|
|
|
|
|
|
|
|
let controller = dbg._controller;
|
|
|
|
let thread = controller.activeThread;
|
|
|
|
if (thread.paused) {
|
|
|
|
thread.resume();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 'dbg step' command
|
|
|
|
*/
|
2014-04-13 06:47:27 +00:00
|
|
|
exports.items.push({
|
2013-03-13 04:51:30 +00:00
|
|
|
name: "dbg step",
|
|
|
|
description: gcli.lookup("dbgStepDesc"),
|
|
|
|
manual: gcli.lookup("dbgStepManual")
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 'dbg step over' command
|
|
|
|
*/
|
2014-04-13 06:47:27 +00:00
|
|
|
exports.items.push({
|
2013-03-13 04:51:30 +00:00
|
|
|
name: "dbg step over",
|
|
|
|
description: gcli.lookup("dbgStepOverDesc"),
|
|
|
|
params: [],
|
|
|
|
exec: function(args, context) {
|
|
|
|
let dbg = getPanel(context, "jsdebugger");
|
|
|
|
if (!dbg) {
|
|
|
|
return gcli.lookup("debuggerStopped");
|
|
|
|
}
|
|
|
|
|
|
|
|
let controller = dbg._controller;
|
|
|
|
let thread = controller.activeThread;
|
|
|
|
if (thread.paused) {
|
|
|
|
thread.stepOver();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 'dbg step in' command
|
|
|
|
*/
|
2014-04-13 06:47:27 +00:00
|
|
|
exports.items.push({
|
2013-03-13 04:51:30 +00:00
|
|
|
name: 'dbg step in',
|
|
|
|
description: gcli.lookup("dbgStepInDesc"),
|
|
|
|
params: [],
|
|
|
|
exec: function(args, context) {
|
|
|
|
let dbg = getPanel(context, "jsdebugger");
|
|
|
|
if (!dbg) {
|
|
|
|
return gcli.lookup("debuggerStopped");
|
|
|
|
}
|
|
|
|
|
|
|
|
let controller = dbg._controller;
|
|
|
|
let thread = controller.activeThread;
|
|
|
|
if (thread.paused) {
|
|
|
|
thread.stepIn();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 'dbg step over' command
|
|
|
|
*/
|
2014-04-13 06:47:27 +00:00
|
|
|
exports.items.push({
|
2013-03-13 04:51:30 +00:00
|
|
|
name: 'dbg step out',
|
|
|
|
description: gcli.lookup("dbgStepOutDesc"),
|
|
|
|
params: [],
|
|
|
|
exec: function(args, context) {
|
|
|
|
let dbg = getPanel(context, "jsdebugger");
|
|
|
|
if (!dbg) {
|
|
|
|
return gcli.lookup("debuggerStopped");
|
|
|
|
}
|
|
|
|
|
|
|
|
let controller = dbg._controller;
|
|
|
|
let thread = controller.activeThread;
|
|
|
|
if (thread.paused) {
|
|
|
|
thread.stepOut();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 'dbg list' command
|
|
|
|
*/
|
2014-04-13 06:47:27 +00:00
|
|
|
exports.items.push({
|
2013-03-13 04:51:30 +00:00
|
|
|
name: "dbg list",
|
|
|
|
description: gcli.lookup("dbgListSourcesDesc"),
|
|
|
|
params: [],
|
2013-05-09 14:15:22 +00:00
|
|
|
returnType: "dom",
|
2013-03-13 04:51:30 +00:00
|
|
|
exec: function(args, context) {
|
|
|
|
let dbg = getPanel(context, "jsdebugger");
|
|
|
|
if (!dbg) {
|
|
|
|
return gcli.lookup("debuggerClosed");
|
|
|
|
}
|
2013-05-13 07:01:00 +00:00
|
|
|
|
2014-11-25 23:02:39 +00:00
|
|
|
let sources = getAllSources(dbg);
|
2013-09-13 13:23:13 +00:00
|
|
|
let doc = context.environment.chromeDocument;
|
2013-03-13 04:51:30 +00:00
|
|
|
let div = createXHTMLElement(doc, "div");
|
|
|
|
let ol = createXHTMLElement(doc, "ol");
|
2013-09-13 13:23:13 +00:00
|
|
|
|
2013-09-13 13:23:13 +00:00
|
|
|
sources.forEach(source => {
|
2013-03-13 04:51:30 +00:00
|
|
|
let li = createXHTMLElement(doc, "li");
|
2014-11-25 23:02:39 +00:00
|
|
|
li.textContent = source.name;
|
2013-03-13 04:51:30 +00:00
|
|
|
ol.appendChild(li);
|
|
|
|
});
|
|
|
|
div.appendChild(ol);
|
|
|
|
|
|
|
|
return div;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-07-27 17:50:57 +00:00
|
|
|
/**
|
|
|
|
* Define the 'dbg blackbox' and 'dbg unblackbox' commands.
|
|
|
|
*/
|
|
|
|
[
|
|
|
|
{
|
|
|
|
name: "blackbox",
|
|
|
|
clientMethod: "blackBox",
|
|
|
|
l10nPrefix: "dbgBlackBox"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unblackbox",
|
|
|
|
clientMethod: "unblackBox",
|
|
|
|
l10nPrefix: "dbgUnBlackBox"
|
|
|
|
}
|
2013-09-13 13:23:13 +00:00
|
|
|
].forEach(function(cmd) {
|
|
|
|
const lookup = function(id) {
|
2013-07-27 17:50:57 +00:00
|
|
|
return gcli.lookup(cmd.l10nPrefix + id);
|
|
|
|
};
|
|
|
|
|
2014-04-13 06:47:27 +00:00
|
|
|
exports.items.push({
|
2013-07-27 17:50:57 +00:00
|
|
|
name: "dbg " + cmd.name,
|
|
|
|
description: lookup("Desc"),
|
|
|
|
params: [
|
|
|
|
{
|
|
|
|
name: "source",
|
|
|
|
type: {
|
|
|
|
name: "selection",
|
2014-11-25 23:02:39 +00:00
|
|
|
lookup: function(context) {
|
|
|
|
return getAllSources(getPanel(context, "jsdebugger"));
|
2013-07-27 17:50:57 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
description: lookup("SourceDesc"),
|
|
|
|
defaultValue: null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "glob",
|
|
|
|
type: "string",
|
|
|
|
description: lookup("GlobDesc"),
|
|
|
|
defaultValue: null
|
2013-08-12 20:58:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invert",
|
|
|
|
type: "boolean",
|
|
|
|
description: lookup("InvertDesc")
|
2013-07-27 17:50:57 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
returnType: "dom",
|
2013-09-13 13:23:13 +00:00
|
|
|
exec: function(args, context) {
|
2013-07-27 17:50:57 +00:00
|
|
|
const dbg = getPanel(context, "jsdebugger");
|
|
|
|
const doc = context.environment.chromeDocument;
|
|
|
|
if (!dbg) {
|
|
|
|
throw new Error(gcli.lookup("debuggerClosed"));
|
|
|
|
}
|
|
|
|
|
|
|
|
const { promise, resolve, reject } = context.defer();
|
|
|
|
const { activeThread } = dbg._controller;
|
2013-09-13 13:23:13 +00:00
|
|
|
const globRegExp = args.glob ? globToRegExp(args.glob) : null;
|
2013-07-27 17:50:57 +00:00
|
|
|
|
|
|
|
// Filter the sources down to those that we will need to black box.
|
|
|
|
|
|
|
|
function shouldBlackBox(source) {
|
2013-08-12 20:58:22 +00:00
|
|
|
var value = globRegExp && globRegExp.test(source.url)
|
2014-11-25 23:02:39 +00:00
|
|
|
|| args.source && source.actor == args.source;
|
2013-08-12 20:58:22 +00:00
|
|
|
return args.invert ? !value : value;
|
2013-07-27 17:50:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const toBlackBox = [s.attachment.source
|
|
|
|
for (s of dbg._view.Sources.items)
|
|
|
|
if (shouldBlackBox(s.attachment.source))];
|
|
|
|
|
|
|
|
// If we aren't black boxing any sources, bail out now.
|
|
|
|
|
|
|
|
if (toBlackBox.length === 0) {
|
|
|
|
const empty = createXHTMLElement(doc, "div");
|
|
|
|
empty.textContent = lookup("EmptyDesc");
|
|
|
|
return void resolve(empty);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send the black box request to each source we are black boxing. As we
|
|
|
|
// get responses, accumulate the results in `blackBoxed`.
|
|
|
|
|
|
|
|
const blackBoxed = [];
|
|
|
|
|
|
|
|
for (let source of toBlackBox) {
|
2013-09-13 13:23:13 +00:00
|
|
|
activeThread.source(source)[cmd.clientMethod](function({ error }) {
|
2013-07-27 17:50:57 +00:00
|
|
|
if (error) {
|
2013-09-13 13:23:13 +00:00
|
|
|
blackBoxed.push(lookup("ErrorDesc") + " " + source.url);
|
2013-07-27 17:50:57 +00:00
|
|
|
} else {
|
2013-09-13 13:23:13 +00:00
|
|
|
blackBoxed.push(source.url);
|
2013-07-27 17:50:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (toBlackBox.length === blackBoxed.length) {
|
|
|
|
displayResults();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// List the results for the user.
|
|
|
|
|
|
|
|
function displayResults() {
|
|
|
|
const results = doc.createElement("div");
|
|
|
|
results.textContent = lookup("NonEmptyDesc");
|
2013-09-13 13:23:13 +00:00
|
|
|
|
2013-07-27 17:50:57 +00:00
|
|
|
const list = createXHTMLElement(doc, "ul");
|
|
|
|
results.appendChild(list);
|
2013-09-13 13:23:13 +00:00
|
|
|
|
2013-07-27 17:50:57 +00:00
|
|
|
for (let result of blackBoxed) {
|
|
|
|
const item = createXHTMLElement(doc, "li");
|
|
|
|
item.textContent = result;
|
|
|
|
list.appendChild(item);
|
|
|
|
}
|
|
|
|
resolve(results);
|
|
|
|
}
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-03-13 04:51:30 +00:00
|
|
|
/**
|
2013-09-13 13:23:13 +00:00
|
|
|
* A helper to create xhtml namespaced elements.
|
2013-03-13 04:51:30 +00:00
|
|
|
*/
|
|
|
|
function createXHTMLElement(document, tagname) {
|
|
|
|
return document.createElementNS("http://www.w3.org/1999/xhtml", tagname);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-13 13:23:13 +00:00
|
|
|
* A helper to go from a command context to a debugger panel.
|
2013-03-13 04:51:30 +00:00
|
|
|
*/
|
2013-05-13 07:01:00 +00:00
|
|
|
function getPanel(context, id, options = {}) {
|
2013-09-13 13:23:13 +00:00
|
|
|
if (!context) {
|
2013-03-13 04:51:30 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2013-04-03 16:55:00 +00:00
|
|
|
let target = context.environment.target;
|
2013-09-13 13:23:13 +00:00
|
|
|
|
|
|
|
if (options.ensureOpened) {
|
2013-09-13 13:23:13 +00:00
|
|
|
return gDevTools.showToolbox(target, id).then(toolbox => {
|
2013-04-03 16:55:00 +00:00
|
|
|
return toolbox.getPanel(id);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
let toolbox = gDevTools.getToolbox(target);
|
2013-05-13 07:01:00 +00:00
|
|
|
if (toolbox) {
|
|
|
|
return toolbox.getPanel(id);
|
|
|
|
} else {
|
|
|
|
return undefined;
|
|
|
|
}
|
2013-04-03 16:55:00 +00:00
|
|
|
}
|
2013-03-13 04:51:30 +00:00
|
|
|
}
|
2013-07-27 17:50:57 +00:00
|
|
|
|
|
|
|
/**
|
2013-09-13 13:23:13 +00:00
|
|
|
* Converts a glob to a regular expression.
|
2013-07-27 17:50:57 +00:00
|
|
|
*/
|
|
|
|
function globToRegExp(glob) {
|
|
|
|
const reStr = glob
|
2013-09-13 13:23:13 +00:00
|
|
|
// Escape existing regular expression syntax.
|
2013-07-27 17:50:57 +00:00
|
|
|
.replace(/\\/g, "\\\\")
|
|
|
|
.replace(/\//g, "\\/")
|
|
|
|
.replace(/\^/g, "\\^")
|
|
|
|
.replace(/\$/g, "\\$")
|
|
|
|
.replace(/\+/g, "\\+")
|
|
|
|
.replace(/\?/g, "\\?")
|
|
|
|
.replace(/\./g, "\\.")
|
|
|
|
.replace(/\(/g, "\\(")
|
|
|
|
.replace(/\)/g, "\\)")
|
|
|
|
.replace(/\=/g, "\\=")
|
|
|
|
.replace(/\!/g, "\\!")
|
|
|
|
.replace(/\|/g, "\\|")
|
|
|
|
.replace(/\{/g, "\\{")
|
|
|
|
.replace(/\}/g, "\\}")
|
|
|
|
.replace(/\,/g, "\\,")
|
|
|
|
.replace(/\[/g, "\\[")
|
|
|
|
.replace(/\]/g, "\\]")
|
|
|
|
.replace(/\-/g, "\\-")
|
2013-09-13 13:23:13 +00:00
|
|
|
// Turn * into the match everything wildcard.
|
2013-07-27 17:50:57 +00:00
|
|
|
.replace(/\*/g, ".*")
|
|
|
|
return new RegExp("^" + reStr + "$");
|
|
|
|
}
|