2013-05-13 00:01:00 -07:00
|
|
|
/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
2013-03-12 21:51:30 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2013-05-13 00:01:00 -07:00
|
|
|
"use strict";
|
2013-03-12 21:51:30 -07:00
|
|
|
|
|
|
|
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
2013-05-13 00:01:00 -07:00
|
|
|
|
2013-03-12 21:51:30 -07:00
|
|
|
this.EXPORTED_SYMBOLS = [ ];
|
|
|
|
|
2013-05-09 07:15:22 -07:00
|
|
|
Cu.import("resource://gre/modules/devtools/gcli.jsm");
|
2013-03-12 21:51:30 -07:00
|
|
|
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "gDevTools",
|
2013-05-13 00:01:00 -07:00
|
|
|
"resource:///modules/devtools/gDevTools.jsm");
|
2013-03-12 21:51:30 -07:00
|
|
|
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "console",
|
2013-05-13 00:01:00 -07:00
|
|
|
"resource://gre/modules/devtools/Console.jsm");
|
2013-03-12 21:51:30 -07:00
|
|
|
|
2013-05-21 02:18:55 -07:00
|
|
|
/**
|
|
|
|
* Utility to get access to the current breakpoint list
|
|
|
|
* @param dbg The debugger panel
|
|
|
|
* @returns an array of object, one for each breakpoint, where each breakpoint
|
|
|
|
* object has the following properties:
|
|
|
|
* - id: A unique identifier for the breakpoint. This is not designed to be
|
|
|
|
* shown to the user.
|
|
|
|
* - label: A unique string identifier designed to be user visible. In theory
|
|
|
|
* the label of a breakpoint could change
|
|
|
|
* - url: The URL of the source file
|
|
|
|
* - 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
|
|
|
|
*/
|
|
|
|
function getAllBreakpoints(dbg) {
|
|
|
|
let breakpoints = [];
|
2013-06-21 07:33:56 -07:00
|
|
|
let sources = dbg.panelWin.DebuggerView.Sources;
|
|
|
|
let { trimUrlLength: tr } = dbg.panelWin.SourceUtils;
|
2013-05-21 02:18:55 -07:00
|
|
|
|
2013-06-21 07:33:56 -07:00
|
|
|
for (let source in sources) {
|
2013-05-21 02:18:55 -07:00
|
|
|
for (let { attachment: breakpoint } in source) {
|
|
|
|
breakpoints.push({
|
|
|
|
id: source.value + ":" + breakpoint.lineNumber,
|
|
|
|
label: source.label + ":" + breakpoint.lineNumber,
|
|
|
|
url: source.value,
|
|
|
|
lineNumber: breakpoint.lineNumber,
|
|
|
|
lineText: breakpoint.lineText,
|
2013-06-21 07:33:56 -07:00
|
|
|
truncatedLineText: tr(breakpoint.lineText, MAX_LINE_TEXT_LENGTH, "end")
|
2013-05-21 02:18:55 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return breakpoints;
|
|
|
|
}
|
|
|
|
|
2013-03-12 21:51:30 -07:00
|
|
|
/**
|
|
|
|
* 'break' command
|
|
|
|
*/
|
|
|
|
gcli.addCommand({
|
|
|
|
name: "break",
|
|
|
|
description: gcli.lookup("breakDesc"),
|
|
|
|
manual: gcli.lookup("breakManual")
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 'break list' command
|
|
|
|
*/
|
|
|
|
gcli.addCommand({
|
|
|
|
name: "break list",
|
|
|
|
description: gcli.lookup("breaklistDesc"),
|
2013-04-03 09:55:00 -07:00
|
|
|
returnType: "breakpoints",
|
2013-03-12 21:51:30 -07:00
|
|
|
exec: function(args, context) {
|
2013-05-13 00:01:00 -07:00
|
|
|
let dbg = getPanel(context, "jsdebugger", { ensure_opened: true });
|
|
|
|
return dbg.then(function(dbg) {
|
2013-05-21 02:18:55 -07:00
|
|
|
return getAllBreakpoints(dbg);
|
2013-04-03 09:55:00 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2013-03-12 21:51:30 -07:00
|
|
|
|
2013-04-03 09:55:00 -07:00
|
|
|
gcli.addConverter({
|
|
|
|
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 02:18:55 -07:00
|
|
|
breakpoints: breakpoints,
|
|
|
|
onclick: context.update,
|
|
|
|
ondblclick: context.updateExec
|
2013-04-03 09:55:00 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return context.createView({
|
|
|
|
html: "<p>${message}</p>",
|
|
|
|
data: { message: gcli.lookup("breaklistNone") }
|
|
|
|
});
|
2013-03-12 21:51:30 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-04-03 09:55:00 -07: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 02:18:55 -07:00
|
|
|
" data-command='break del ${breakpoint.label}'" +
|
2013-04-03 09:55:00 -07:00
|
|
|
" onclick='${onclick}'" +
|
2013-05-13 00:01:00 -07:00
|
|
|
" ondblclick='${ondblclick}'>" +
|
|
|
|
" " + gcli.lookup("breaklistOutRemove") + "</span>" +
|
2013-04-03 09:55:00 -07:00
|
|
|
" </td>" +
|
|
|
|
" </tr>" +
|
|
|
|
" </tbody>" +
|
|
|
|
"</table>" +
|
|
|
|
"";
|
|
|
|
|
|
|
|
var MAX_LINE_TEXT_LENGTH = 30;
|
|
|
|
var MAX_LABEL_LENGTH = 20;
|
|
|
|
|
2013-03-12 21:51:30 -07:00
|
|
|
/**
|
|
|
|
* 'break add' command
|
|
|
|
*/
|
|
|
|
gcli.addCommand({
|
|
|
|
name: "break add",
|
|
|
|
description: gcli.lookup("breakaddDesc"),
|
|
|
|
manual: gcli.lookup("breakaddManual")
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 'break add line' command
|
|
|
|
*/
|
|
|
|
gcli.addCommand({
|
|
|
|
name: "break add line",
|
|
|
|
description: gcli.lookup("breakaddlineDesc"),
|
|
|
|
params: [
|
|
|
|
{
|
|
|
|
name: "file",
|
|
|
|
type: {
|
|
|
|
name: "selection",
|
2013-05-21 02:18:55 -07:00
|
|
|
data: function(context) {
|
2013-03-12 21:51:30 -07:00
|
|
|
let dbg = getPanel(context, "jsdebugger");
|
|
|
|
if (dbg) {
|
2013-05-13 00:01:00 -07:00
|
|
|
return dbg.panelWin.DebuggerView.Sources.values;
|
2013-03-12 21:51:30 -07:00
|
|
|
}
|
2013-05-13 00:01:00 -07:00
|
|
|
return [];
|
2013-03-12 21:51:30 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
description: gcli.lookup("breakaddlineFileDesc")
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "line",
|
|
|
|
type: { name: "number", min: 1, step: 10 },
|
|
|
|
description: gcli.lookup("breakaddlineLineDesc")
|
|
|
|
}
|
|
|
|
],
|
2013-05-09 07:15:22 -07:00
|
|
|
returnType: "string",
|
2013-03-12 21:51:30 -07:00
|
|
|
exec: function(args, context) {
|
|
|
|
args.type = "line";
|
|
|
|
|
|
|
|
let dbg = getPanel(context, "jsdebugger");
|
|
|
|
if (!dbg) {
|
|
|
|
return gcli.lookup("debuggerStopped");
|
|
|
|
}
|
2013-05-13 00:01:00 -07:00
|
|
|
|
|
|
|
let deferred = context.defer();
|
2013-03-12 21:51:30 -07:00
|
|
|
let position = { url: args.file, line: args.line };
|
|
|
|
dbg.addBreakpoint(position, function(aBreakpoint, aError) {
|
|
|
|
if (aError) {
|
|
|
|
deferred.resolve(gcli.lookupFormat("breakaddFailed", [aError]));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
deferred.resolve(gcli.lookup("breakaddAdded"));
|
|
|
|
});
|
|
|
|
return deferred.promise;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 'break del' command
|
|
|
|
*/
|
|
|
|
gcli.addCommand({
|
|
|
|
name: "break del",
|
|
|
|
description: gcli.lookup("breakdelDesc"),
|
|
|
|
params: [
|
|
|
|
{
|
2013-05-21 02:18:55 -07:00
|
|
|
name: "breakpoint",
|
2013-03-12 21:51:30 -07:00
|
|
|
type: {
|
2013-05-21 02:18:55 -07:00
|
|
|
name: "selection",
|
|
|
|
lookup: function(context) {
|
2013-03-12 21:51:30 -07:00
|
|
|
let dbg = getPanel(context, "jsdebugger");
|
2013-05-21 02:18:55 -07:00
|
|
|
if (dbg == null) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
return getAllBreakpoints(dbg).map(breakpoint => {
|
|
|
|
return {
|
|
|
|
name: breakpoint.label,
|
|
|
|
value: breakpoint,
|
|
|
|
description: breakpoint.truncatedLineText
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
2013-03-12 21:51:30 -07:00
|
|
|
},
|
|
|
|
description: gcli.lookup("breakdelBreakidDesc")
|
|
|
|
}
|
|
|
|
],
|
2013-05-09 07:15:22 -07:00
|
|
|
returnType: "string",
|
2013-03-12 21:51:30 -07:00
|
|
|
exec: function(args, context) {
|
|
|
|
let dbg = getPanel(context, "jsdebugger");
|
|
|
|
if (!dbg) {
|
|
|
|
return gcli.lookup("debuggerStopped");
|
|
|
|
}
|
|
|
|
|
2013-06-21 07:33:56 -07:00
|
|
|
let breakpoint = dbg.getBreakpoint(
|
|
|
|
args.breakpoint.url, args.breakpoint.lineNumber);
|
2013-05-21 02:18:55 -07:00
|
|
|
|
|
|
|
if (breakpoint == null) {
|
2013-03-12 21:51:30 -07:00
|
|
|
return gcli.lookup("breakNotFound");
|
|
|
|
}
|
|
|
|
|
|
|
|
let deferred = context.defer();
|
|
|
|
try {
|
2013-05-21 02:18:55 -07:00
|
|
|
dbg.removeBreakpoint(breakpoint, function() {
|
2013-03-12 21:51:30 -07:00
|
|
|
deferred.resolve(gcli.lookup("breakdelRemoved"));
|
|
|
|
});
|
|
|
|
} catch (ex) {
|
2013-05-21 02:18:55 -07:00
|
|
|
console.error('Error removing breakpoint, already removed?', ex);
|
2013-03-12 21:51:30 -07:00
|
|
|
// If the debugger has been closed already, don't scare the user.
|
|
|
|
deferred.resolve(gcli.lookup("breakdelRemoved"));
|
|
|
|
}
|
|
|
|
return deferred.promise;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 'dbg' command
|
|
|
|
*/
|
|
|
|
gcli.addCommand({
|
|
|
|
name: "dbg",
|
|
|
|
description: gcli.lookup("dbgDesc"),
|
|
|
|
manual: gcli.lookup("dbgManual")
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 'dbg open' command
|
|
|
|
*/
|
|
|
|
gcli.addCommand({
|
|
|
|
name: "dbg open",
|
|
|
|
description: gcli.lookup("dbgOpen"),
|
|
|
|
params: [],
|
|
|
|
exec: function(args, context) {
|
2013-05-21 02:18:55 -07:00
|
|
|
return gDevTools.showToolbox(context.environment.target, "jsdebugger")
|
|
|
|
.then(() => null);
|
2013-03-12 21:51:30 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 'dbg close' command
|
|
|
|
*/
|
|
|
|
gcli.addCommand({
|
|
|
|
name: "dbg close",
|
|
|
|
description: gcli.lookup("dbgClose"),
|
|
|
|
params: [],
|
|
|
|
exec: function(args, context) {
|
2013-06-19 10:09:28 -07:00
|
|
|
if (!getPanel(context, "jsdebugger"))
|
|
|
|
return;
|
|
|
|
|
2013-05-21 02:18:55 -07:00
|
|
|
return gDevTools.closeToolbox(context.environment.target)
|
|
|
|
.then(() => null);
|
2013-03-12 21:51:30 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 'dbg interrupt' command
|
|
|
|
*/
|
|
|
|
gcli.addCommand({
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
gcli.addCommand({
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
gcli.addCommand({
|
|
|
|
name: "dbg step",
|
|
|
|
description: gcli.lookup("dbgStepDesc"),
|
|
|
|
manual: gcli.lookup("dbgStepManual")
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 'dbg step over' command
|
|
|
|
*/
|
|
|
|
gcli.addCommand({
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
gcli.addCommand({
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
gcli.addCommand({
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
gcli.addCommand({
|
|
|
|
name: "dbg list",
|
|
|
|
description: gcli.lookup("dbgListSourcesDesc"),
|
|
|
|
params: [],
|
2013-05-09 07:15:22 -07:00
|
|
|
returnType: "dom",
|
2013-03-12 21:51:30 -07:00
|
|
|
exec: function(args, context) {
|
|
|
|
let dbg = getPanel(context, "jsdebugger");
|
|
|
|
let doc = context.environment.chromeDocument;
|
|
|
|
if (!dbg) {
|
|
|
|
return gcli.lookup("debuggerClosed");
|
|
|
|
}
|
2013-05-13 00:01:00 -07:00
|
|
|
|
2013-03-12 21:51:30 -07:00
|
|
|
let sources = dbg._view.Sources.values;
|
|
|
|
let div = createXHTMLElement(doc, "div");
|
|
|
|
let ol = createXHTMLElement(doc, "ol");
|
|
|
|
sources.forEach(function(src) {
|
|
|
|
let li = createXHTMLElement(doc, "li");
|
|
|
|
li.textContent = src;
|
|
|
|
ol.appendChild(li);
|
|
|
|
});
|
|
|
|
div.appendChild(ol);
|
|
|
|
|
|
|
|
return div;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-07-27 10:50:57 -07:00
|
|
|
/**
|
|
|
|
* Define the 'dbg blackbox' and 'dbg unblackbox' commands.
|
|
|
|
*/
|
|
|
|
[
|
|
|
|
{
|
|
|
|
name: "blackbox",
|
|
|
|
clientMethod: "blackBox",
|
|
|
|
l10nPrefix: "dbgBlackBox"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unblackbox",
|
|
|
|
clientMethod: "unblackBox",
|
|
|
|
l10nPrefix: "dbgUnBlackBox"
|
|
|
|
}
|
|
|
|
].forEach(function (cmd) {
|
|
|
|
const lookup = function (id) {
|
|
|
|
return gcli.lookup(cmd.l10nPrefix + id);
|
|
|
|
};
|
|
|
|
|
|
|
|
gcli.addCommand({
|
|
|
|
name: "dbg " + cmd.name,
|
|
|
|
description: lookup("Desc"),
|
|
|
|
params: [
|
|
|
|
{
|
|
|
|
name: "source",
|
|
|
|
type: {
|
|
|
|
name: "selection",
|
|
|
|
data: function (context) {
|
|
|
|
let dbg = getPanel(context, "jsdebugger");
|
|
|
|
return dbg
|
|
|
|
? [s for (s of dbg._view.Sources.values)]
|
|
|
|
: [];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
description: lookup("SourceDesc"),
|
|
|
|
defaultValue: null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "glob",
|
|
|
|
type: "string",
|
|
|
|
description: lookup("GlobDesc"),
|
|
|
|
defaultValue: null
|
|
|
|
}
|
|
|
|
],
|
|
|
|
returnType: "dom",
|
|
|
|
exec: function (args, context) {
|
|
|
|
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;
|
|
|
|
const globRegExp = args.glob
|
|
|
|
? globToRegExp(args.glob)
|
|
|
|
: null;
|
|
|
|
|
|
|
|
// Filter the sources down to those that we will need to black box.
|
|
|
|
|
|
|
|
function shouldBlackBox(source) {
|
|
|
|
return globRegExp && globRegExp.test(source.url)
|
|
|
|
|| args.source && source.url == args.source;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-08-02 17:09:37 -07:00
|
|
|
let { url } = source;
|
2013-07-27 10:50:57 -07:00
|
|
|
activeThread.source(source)[cmd.clientMethod](function ({ error }) {
|
|
|
|
if (error) {
|
2013-08-02 17:09:37 -07:00
|
|
|
blackBoxed.push(lookup("ErrorDesc") + " " + url);
|
2013-07-27 10:50:57 -07:00
|
|
|
} else {
|
2013-08-02 17:09:37 -07:00
|
|
|
blackBoxed.push(url);
|
2013-07-27 10:50:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (toBlackBox.length === blackBoxed.length) {
|
|
|
|
displayResults();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// List the results for the user.
|
|
|
|
|
|
|
|
function displayResults() {
|
|
|
|
const results = doc.createElement("div");
|
|
|
|
results.textContent = lookup("NonEmptyDesc");
|
|
|
|
const list = createXHTMLElement(doc, "ul");
|
|
|
|
results.appendChild(list);
|
|
|
|
for (let result of blackBoxed) {
|
|
|
|
const item = createXHTMLElement(doc, "li");
|
|
|
|
item.textContent = result;
|
|
|
|
list.appendChild(item);
|
|
|
|
}
|
|
|
|
resolve(results);
|
|
|
|
}
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-03-12 21:51:30 -07:00
|
|
|
/**
|
|
|
|
* A helper to create xhtml namespaced elements
|
|
|
|
*/
|
|
|
|
function createXHTMLElement(document, tagname) {
|
|
|
|
return document.createElementNS("http://www.w3.org/1999/xhtml", tagname);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A helper to go from a command context to a debugger panel
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
function getPanel(context, id, options = {}) {
|
2013-03-12 21:51:30 -07:00
|
|
|
if (context == null) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2013-04-03 09:55:00 -07:00
|
|
|
let target = context.environment.target;
|
2013-05-13 00:01:00 -07:00
|
|
|
if (options.ensure_opened) {
|
2013-04-03 09:55:00 -07:00
|
|
|
return gDevTools.showToolbox(target, id).then(function(toolbox) {
|
|
|
|
return toolbox.getPanel(id);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
let toolbox = gDevTools.getToolbox(target);
|
2013-05-13 00:01:00 -07:00
|
|
|
if (toolbox) {
|
|
|
|
return toolbox.getPanel(id);
|
|
|
|
} else {
|
|
|
|
return undefined;
|
|
|
|
}
|
2013-04-03 09:55:00 -07:00
|
|
|
}
|
2013-03-12 21:51:30 -07:00
|
|
|
}
|
2013-07-27 10:50:57 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a glob to a regular expression
|
|
|
|
*/
|
|
|
|
function globToRegExp(glob) {
|
|
|
|
const reStr = glob
|
|
|
|
// Escape existing regular expression syntax
|
|
|
|
.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, "\\-")
|
|
|
|
// Turn * into the match everything wildcard
|
|
|
|
.replace(/\*/g, ".*")
|
|
|
|
return new RegExp("^" + reStr + "$");
|
|
|
|
}
|