gecko/browser/devtools/profiler/commands.js
Joe Walker 6fd91a613d Bug 933727 - Split gcli.jsm and use JS directly from gcli project; r=mratcliffe
* * *
Bug 933727 - Update Developer Toolbar to use promises and split out GCLI; r=mratcliffe
* * *
Bug 933727 - Update GCLI tests to use Task.spawn; r=mratcliffe
* * *
Bug 933727 - Update the Inspector to use split out GCLI; r=pbrosset
* * *
Bug 933727 - Update style editor to use split out GCLI; r=harth
* * *
Bug 933727 - Update Debugger to use split out GCLI; r=past
* * *
Bug 933727 - Update Profiler/Tilt/Scratchpad to use split out GCLI; r=valueof

--HG--
rename : browser/devtools/commandline/test/browser_cmd_pref.js => browser/devtools/commandline/test/browser_cmd_pref1.js
rename : browser/devtools/commandline/test/browser_cmd_pref.js => browser/devtools/commandline/test/browser_cmd_pref2.js
rename : browser/devtools/commandline/test/browser_gcli_cli.js => browser/devtools/commandline/test/browser_gcli_cli1.js
rename : browser/devtools/commandline/test/browser_gcli_cli.js => browser/devtools/commandline/test/browser_gcli_cli2.js
rename : browser/devtools/commandline/test/browser_gcli_completion.js => browser/devtools/commandline/test/browser_gcli_completion1.js
rename : browser/devtools/commandline/test/browser_gcli_completion.js => browser/devtools/commandline/test/browser_gcli_completion2.js
2013-09-03 12:20:27 +01:00

182 lines
4.0 KiB
JavaScript

/* 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/. */
const { Cu } = require("chrome");
module.exports = [];
var gcli = require('gcli/index');
loader.lazyGetter(this, "gDevTools",
() => Cu.import("resource:///modules/devtools/gDevTools.jsm", {}).gDevTools);
var { Promise: promise } = Cu.import("resource://gre/modules/Promise.jsm", {});
/*
* 'profiler' command. Doesn't do anything.
*/
gcli.addCommand({
name: "profiler",
description: gcli.lookup("profilerDesc"),
manual: gcli.lookup("profilerManual")
});
/*
* 'profiler open' command
*/
gcli.addCommand({
name: "profiler open",
description: gcli.lookup("profilerOpenDesc"),
params: [],
exec: function (args, context) {
return gDevTools.showToolbox(context.environment.target, "jsprofiler")
.then(function () null);
}
});
/*
* 'profiler close' command
*/
gcli.addCommand({
name: "profiler close",
description: gcli.lookup("profilerCloseDesc"),
params: [],
exec: function (args, context) {
if (!getPanel(context, "jsprofiler"))
return;
return gDevTools.closeToolbox(context.environment.target)
.then(function () null);
}
});
/*
* 'profiler start' command
*/
gcli.addCommand({
name: "profiler start",
description: gcli.lookup("profilerStartDesc"),
returnType: "string",
params: [],
exec: function (args, context) {
function start() {
let panel = getPanel(context, "jsprofiler");
if (panel.recordingProfile)
throw gcli.lookup("profilerAlreadyStarted2");
panel.toggleRecording();
return gcli.lookup("profilerStarted2");
}
return gDevTools.showToolbox(context.environment.target, "jsprofiler")
.then(start);
}
});
/*
* 'profiler stop' command
*/
gcli.addCommand({
name: "profiler stop",
description: gcli.lookup("profilerStopDesc"),
returnType: "string",
params: [],
exec: function (args, context) {
function stop() {
let panel = getPanel(context, "jsprofiler");
if (!panel.recordingProfile)
throw gcli.lookup("profilerNotStarted3");
panel.toggleRecording();
return gcli.lookup("profilerStopped");
}
return gDevTools.showToolbox(context.environment.target, "jsprofiler")
.then(stop);
}
});
/*
* 'profiler list' command
*/
gcli.addCommand({
name: "profiler list",
description: gcli.lookup("profilerListDesc"),
returnType: "dom",
params: [],
exec: function (args, context) {
let panel = getPanel(context, "jsprofiler");
if (!panel) {
throw gcli.lookup("profilerNotReady");
}
let doc = panel.document;
let div = createXHTMLElement(doc, "div");
let ol = createXHTMLElement(doc, "ol");
for ([ uid, profile] of panel.profiles) {
let li = createXHTMLElement(doc, "li");
li.textContent = profile.name;
if (profile.isStarted) {
li.textContent += " *";
}
ol.appendChild(li);
}
div.appendChild(ol);
return div;
}
});
/*
* 'profiler show' command
*/
gcli.addCommand({
name: "profiler show",
description: gcli.lookup("profilerShowDesc"),
params: [
{
name: "name",
type: "string",
manual: gcli.lookup("profilerShowManual")
}
],
exec: function (args, context) {
let panel = getPanel(context, "jsprofiler");
if (!panel) {
throw gcli.lookup("profilerNotReady");
}
let profile = panel.getProfileByName(args.name);
if (!profile) {
throw gcli.lookup("profilerNotFound");
}
panel.sidebar.selectedItem = panel.sidebar.getItemByProfile(profile);
}
});
function getPanel(context, id) {
if (context == null) {
return undefined;
}
let toolbox = gDevTools.getToolbox(context.environment.target);
return toolbox == null ? undefined : toolbox.getPanel(id);
}
function createXHTMLElement(document, tagname) {
return document.createElementNS("http://www.w3.org/1999/xhtml", tagname);
}