Skip to content

Instantly share code, notes, and snippets.

@joewalker
joewalker / hello.mozcmd
Created June 22, 2012 11:02
Basic 'hello' command using mozcmd
[
{
name: 'hello',
description: 'Show a message',
params: [
{
name: 'name',
type: 'string',
description: 'Who to say hello to',
}
Components.utils.import("resource:///modules/devtools/gcli.jsm");
gcli.addCommand({
name: 'foo',
params: [
{
name: 'letters',
type: {
name: 'selection',
@joewalker
joewalker / gist:2995951
Created June 26, 2012 14:01
createView
Basic use of createView
gcli.addCommand({
name: 'foo',
exec: function(args, context) {
return context.createView({
html: '<div>${name}</div>',
data: { name: 'joe' }
});
Components.utils.import("resource:///modules/devtools/gcli.jsm");
gcli.addCommand({
name: 'foo',
params: [
{
name: 'letters',
type: {
name: 'selection',
@joewalker
joewalker / xulcommand.js
Created July 4, 2012 18:31
Bug 767900 - GCLI needs a command to enable execution of XUL Commands
Components.utils.import("resource:///modules/devtools/gcli.jsm");
gcli.addCommand({
name: 'xulcommand',
description: 'Run a XUL Command',
params: [
{
name: 'command',
type: {
@joewalker
joewalker / promise.js
Last active December 11, 2015 13:38
Logging errors in promises
let console = (Cu.import("resource://gre/modules/devtools/Console.jsm", {})).console;
// ...
/**
* Internal utility: Decorates given `f` function, so that on exception promise
* rejected with thrown error is returned.
*/
function attempt(f) {
return function effort(input) {
@joewalker
joewalker / helpers.audit.js
Last active December 11, 2015 16:08
An example of the new way to write GCLI tests
/**
* An example of the new way to write GCLI tests
*/
var promise = helpers.audit([ // Tests can be async. They're done when the promise resolves
{
name: 'a test', // Optional test name, we'll use the 'setup' string if there is no name
setup: 'help search', // A string to type (which can include control chars like <TAB>),
// or a function to do custom setup. return a promise to be async
skipIf: function() { ... }, // If you need to skip tests in some cases e.g. private browsing
check: { // Some stuff to check ...
XPCOMUtils.defineLazyGetter(this, "require", function() {
let { require } = Cu.import("resource://gre/modules/devtools/Require.jsm", {});
Cu.import("resource://gre/modules/devtools/gcli.jsm", {});
return require;
});
XPCOMUtils.defineLazyGetter(this, "Requisition", () => require("gcli/cli").Requisition);
function execGcliCommand(command) {
let foo = new Set;
foo.add("jsonable");
console.log(JSON.stringify(foo)); // "{}"