Bug 856002 - GCLI requisition update/exec methods should take a DOM node; r=harth
authorJoe Walker <jwalker@mozilla.com>
Tue, 21 May 2013 10:18:55 +0100
changeset 143912 231636fc32319c1f4edc9c9d247d3af9212e38e8
parent 143911 873bf55af0cdab648bc85945d02e3bbc23304f26
child 143913 3b90dbff58096d79c8c32343e8c0b1df8b0fe250
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersharth
bugs856002
milestone24.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 856002 - GCLI requisition update/exec methods should take a DOM node; r=harth
browser/devtools/commandline/BuiltinCommands.jsm
--- a/browser/devtools/commandline/BuiltinCommands.jsm
+++ b/browser/devtools/commandline/BuiltinCommands.jsm
@@ -9,17 +9,17 @@ const BRAND_SHORT_NAME = Cc["@mozilla.or
                            .createBundle("chrome://branding/locale/brand.properties")
                            .GetStringFromName("brandShortName");
 
 this.EXPORTED_SYMBOLS = [ "CmdAddonFlags", "CmdCommands", "DEFAULT_DEBUG_PORT", "connect" ];
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js");
-Cu.import("resource://gre/modules/osfile.jsm")
+Cu.import("resource://gre/modules/osfile.jsm");
 
 Cu.import("resource://gre/modules/devtools/gcli.jsm");
 Cu.import("resource:///modules/devtools/shared/event-emitter.js");
 
 XPCOMUtils.defineLazyModuleGetter(this, "gDevTools",
                                   "resource:///modules/devtools/gDevTools.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "devtools",
                                   "resource://gre/modules/devtools/Loader.jsm");
@@ -169,18 +169,18 @@ XPCOMUtils.defineLazyModuleGetter(this, 
                  + ")") :
                 "",
               toggleActionName: isActiveForToggle(addon) ? "disable": "enable",
               toggleActionMessage: isActiveForToggle(addon) ?
                 gcli.lookup("addonListOutDisable") :
                 gcli.lookup("addonListOutEnable")
             };
           }),
-          onclick: createUpdateHandler(context),
-          ondblclick: createExecuteHandler(context)
+          onclick: context.update,
+          ondblclick: context.updateExec
         }
       });
     }
   });
 
   var addonsListHtml = "" +
         "<table>" +
         " <caption>${header}</caption>" +
@@ -339,66 +339,16 @@ XPCOMUtils.defineLazyModuleGetter(this, 
         AddonManager.getAllAddons(disable.bind(deferred, aArgs.name));
         return deferred.promise;
       }
     });
     module.CmdAddonFlags.addonsLoaded = true;
     Services.obs.notifyObservers(null, "gcli_addon_commands_ready", null);
   });
 
-  /**
-   * Helper to find the 'data-command' attribute and call some action on it.
-   * @see |updateCommand()| and |executeCommand()|
-   */
-  function withCommand(element, action) {
-    var command = element.getAttribute("data-command");
-    if (!command) {
-      command = element.querySelector("*[data-command]")
-        .getAttribute("data-command");
-    }
-
-    if (command) {
-      action(command);
-    }
-    else {
-      console.warn("Missing data-command for " + util.findCssSelector(element));
-    }
-  }
-
-  /**
-   * Create a handler to update the requisition to contain the text held in the
-   * first matching data-command attribute under the currentTarget of the event.
-   * @param context Either a Requisition or an ExecutionContext or another object
-   * that contains an |update()| function that follows a similar contract.
-   */
-  function createUpdateHandler(context) {
-    return function(ev) {
-      withCommand(ev.currentTarget, function(command) {
-        context.update(command);
-      });
-    }
-  }
-
-  /**
-   * Create a handler to execute the text held in the data-command attribute
-   * under the currentTarget of the event.
-   * @param context Either a Requisition or an ExecutionContext or another object
-   * that contains an |update()| function that follows a similar contract.
-   */
-  function createExecuteHandler(context) {
-    return function(ev) {
-      withCommand(ev.currentTarget, function(command) {
-        context.exec({
-          visible: true,
-          typed: command
-        });
-      });
-    }
-  }
-
 }(this));
 
 /* CmdCalllog -------------------------------------------------------------- */
 
 (function(module) {
   XPCOMUtils.defineLazyGetter(this, "Debugger", function() {
     let JsDebugger = {};
     Components.utils.import("resource://gre/modules/jsdebugger.jsm", JsDebugger);
@@ -921,18 +871,18 @@ XPCOMUtils.defineLazyModuleGetter(this, 
                        (noAttrs ? gcli.lookup("cookieListOutNone") : ' ');
       }
 
       return context.createView({
         html: cookieListHtml,
         data: {
           options: { allowEval: true },
           cookies: cookies,
-          onclick: createUpdateHandler(context),
-          ondblclick: createExecuteHandler(context),
+          onclick: context.update,
+          ondblclick: context.updateExec
         }
       });
     }
   });
 
   /**
    * The cookie 'expires' value needs converting into something more readable
    */
@@ -1100,66 +1050,16 @@ XPCOMUtils.defineLazyModuleGetter(this, 
                     args.name,
                     args.value,
                     args.secure,
                     args.httpOnly,
                     args.session,
                     time);
     }
   });
-
-  /**
-   * Helper to find the 'data-command' attribute and call some action on it.
-   * @see |updateCommand()| and |executeCommand()|
-   */
-  function withCommand(element, action) {
-    let command = element.getAttribute("data-command");
-    if (!command) {
-      command = element.querySelector("*[data-command]")
-              .getAttribute("data-command");
-    }
-
-    if (command) {
-      action(command);
-    }
-    else {
-      console.warn("Missing data-command for " + util.findCssSelector(element));
-    }
-  }
-
-  /**
-   * Create a handler to update the requisition to contain the text held in the
-   * first matching data-command attribute under the currentTarget of the event.
-   * @param context Either a Requisition or an ExecutionContext or another object
-   * that contains an |update()| function that follows a similar contract.
-   */
-  function createUpdateHandler(context) {
-    return function(ev) {
-      withCommand(ev.currentTarget, function(command) {
-        context.update(command);
-      });
-    }
-  }
-
-  /**
-   * Create a handler to execute the text held in the data-command attribute
-   * under the currentTarget of the event.
-   * @param context Either a Requisition or an ExecutionContext or another object
-   * that contains an |update()| function that follows a similar contract.
-   */
-  function createExecuteHandler(context) {
-    return function(ev) {
-      withCommand(ev.currentTarget, function(command) {
-        context.exec({
-          visible: true,
-          typed: command
-        });
-      });
-    }
-  }
 }(this));
 
 /* CmdExport --------------------------------------------------------------- */
 
 (function(module) {
   /**
    * 'export' command
    */
@@ -2202,18 +2102,18 @@ gcli.addCommand({
   gcli.addConverter({
     from: "appcacheentries",
     to: "view",
     exec: function(entries, context) {
       return context.createView({
         html: appcacheListEntries,
         data: {
           entries: entries,
-          onclick: createUpdateHandler(context),
-          ondblclick: createExecuteHandler(context),
+          onclick: context.update,
+          ondblclick: context.updateExec
         }
       });
     }
   });
 
   gcli.addCommand({
     name: 'appcache list',
     description: gcli.lookup('appCacheListDesc'),
@@ -2248,59 +2148,9 @@ gcli.addCommand({
         defaultValue: null,
       }
     ],
     exec: function(args, context) {
       let utils = new AppCacheUtils();
       return utils.viewEntry(args.key);
     }
   });
-
-  /**
-   * Helper to find the 'data-command' attribute and call some action on it.
-   * @see |updateCommand()| and |executeCommand()|
-   */
-  function withCommand(element, action) {
-    let command = element.getAttribute("data-command");
-    if (!command) {
-      command = element.querySelector("*[data-command]")
-              .getAttribute("data-command");
-    }
-
-    if (command) {
-      action(command);
-    }
-    else {
-      console.warn("Missing data-command for " + util.findCssSelector(element));
-    }
-  }
-
-  /**
-   * Create a handler to update the requisition to contain the text held in the
-   * first matching data-command attribute under the currentTarget of the event.
-   * @param context Either a Requisition or an ExecutionContext or another object
-   * that contains an |update()| function that follows a similar contract.
-   */
-  function createUpdateHandler(context) {
-    return function(ev) {
-      withCommand(ev.currentTarget, function(command) {
-        context.update(command);
-      });
-    }
-  }
-
-  /**
-   * Create a handler to execute the text held in the data-command attribute
-   * under the currentTarget of the event.
-   * @param context Either a Requisition or an ExecutionContext or another object
-   * that contains an |update()| function that follows a similar contract.
-   */
-  function createExecuteHandler(context) {
-    return function(ev) {
-      withCommand(ev.currentTarget, function(command) {
-        context.exec({
-          visible: true,
-          typed: command
-        });
-      });
-    }
-  }
 }(this));