Bug 886848 - Update debugger commands to use the new breakpoint APIs, r=past
authorVictor Porof <vporof@mozilla.com>
Fri, 13 Sep 2013 16:23:13 +0300
changeset 159972 10b1453a6d9da71a86786b5a012fb70673c65cd6
parent 159971 a926ec1e9582408f57803901ea36e5472d21da4a
child 159973 628a2db4b46b063e50429e976b0631e851778332
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspast
bugs886848
milestone26.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 886848 - Update debugger commands to use the new breakpoint APIs, r=past
browser/devtools/debugger/CmdDebugger.jsm
--- a/browser/devtools/debugger/CmdDebugger.jsm
+++ b/browser/devtools/debugger/CmdDebugger.jsm
@@ -14,43 +14,42 @@ Cu.import('resource://gre/modules/XPCOMU
 
 XPCOMUtils.defineLazyModuleGetter(this, "gDevTools",
   "resource:///modules/devtools/gDevTools.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "console",
   "resource://gre/modules/devtools/Console.jsm");
 
 /**
- * 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
+ * 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.
  */
 function getAllBreakpoints(dbg) {
   let breakpoints = [];
   let sources = dbg.panelWin.DebuggerView.Sources;
-  let { trimUrlLength: tr } = dbg.panelWin.SourceUtils;
+  let { trimUrlLength: trim } = dbg.panelWin.SourceUtils;
 
   for (let source in sources) {
     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,
-        truncatedLineText: tr(breakpoint.lineText, MAX_LINE_TEXT_LENGTH, "end")
+        label: source.label + ":" + breakpoint.line,
+        lineNumber: breakpoint.line,
+        lineText: breakpoint.text,
+        truncatedLineText: trim(breakpoint.text, MAX_LINE_TEXT_LENGTH, "end")
       });
     }
   }
 
   return breakpoints;
 }
 
 /**
@@ -65,20 +64,18 @@ gcli.addCommand({
 /**
  * 'break list' command
  */
 gcli.addCommand({
   name: "break list",
   description: gcli.lookup("breaklistDesc"),
   returnType: "breakpoints",
   exec: function(args, context) {
-    let dbg = getPanel(context, "jsdebugger", { ensure_opened: true });
-    return dbg.then(function(dbg) {
-      return getAllBreakpoints(dbg);
-    });
+    let dbg = getPanel(context, "jsdebugger", { ensureOpened: true });
+    return dbg.then(getAllBreakpoints);
   }
 });
 
 gcli.addConverter({
   from: "breakpoints",
   to: "view",
   exec: function(breakpoints, context) {
     let dbg = getPanel(context, "jsdebugger");
@@ -161,32 +158,30 @@ gcli.addCommand({
     {
       name: "line",
       type: { name: "number", min: 1, step: 10 },
       description: gcli.lookup("breakaddlineLineDesc")
     }
   ],
   returnType: "string",
   exec: function(args, context) {
-    args.type = "line";
-
     let dbg = getPanel(context, "jsdebugger");
     if (!dbg) {
       return gcli.lookup("debuggerStopped");
     }
 
     let deferred = context.defer();
     let position = { url: args.file, line: args.line };
-    dbg.addBreakpoint(position, function(aBreakpoint, aError) {
-      if (aError) {
-        deferred.resolve(gcli.lookupFormat("breakaddFailed", [aError]));
-        return;
-      }
+
+    dbg.addBreakpoint(position).then(() => {
       deferred.resolve(gcli.lookup("breakaddAdded"));
+    }, aError => {
+      deferred.resolve(gcli.lookupFormat("breakaddFailed", [aError]));
     });
+
     return deferred.promise;
   }
 });
 
 /**
  * 'break del' command
  */
 gcli.addCommand({
@@ -197,52 +192,42 @@ gcli.addCommand({
       name: "breakpoint",
       type: {
         name: "selection",
         lookup: function(context) {
           let dbg = getPanel(context, "jsdebugger");
           if (dbg == null) {
             return [];
           }
-          return getAllBreakpoints(dbg).map(breakpoint => {
-            return {
-              name: breakpoint.label,
-              value: breakpoint,
-              description: breakpoint.truncatedLineText
-            };
-          });
+          return getAllBreakpoints(dbg).map(breakpoint => ({
+            name: breakpoint.label,
+            value: breakpoint,
+            description: breakpoint.truncatedLineText
+          }));
         }
       },
       description: gcli.lookup("breakdelBreakidDesc")
     }
   ],
   returnType: "string",
   exec: function(args, context) {
     let dbg = getPanel(context, "jsdebugger");
     if (!dbg) {
       return gcli.lookup("debuggerStopped");
     }
 
-    let breakpoint = dbg.getBreakpoint(
-      args.breakpoint.url, args.breakpoint.lineNumber);
-
-    if (breakpoint == null) {
-      return gcli.lookup("breakNotFound");
-    }
+    let deferred = context.defer();
+    let position = { url: args.breakpoint.url, line: args.breakpoint.lineNumber };
 
-    let deferred = context.defer();
-    try {
-      dbg.removeBreakpoint(breakpoint, function() {
-        deferred.resolve(gcli.lookup("breakdelRemoved"));
-      });
-    } catch (ex) {
-      console.error('Error removing breakpoint, already removed?', ex);
-      // If the debugger has been closed already, don't scare the user.
+    dbg.removeBreakpoint(position).then(() => {
       deferred.resolve(gcli.lookup("breakdelRemoved"));
-    }
+    }, () => {
+      deferred.resolve(gcli.lookup("breakNotFound"));
+    });
+
     return deferred.promise;
   }
 });
 
 /**
  * 'dbg' command
  */
 gcli.addCommand({
@@ -407,16 +392,17 @@ gcli.addCommand({
     let doc = context.environment.chromeDocument;
     if (!dbg) {
       return gcli.lookup("debuggerClosed");
     }
 
     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;
@@ -552,22 +538,23 @@ gcli.addCommand({
 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
  */
 function getPanel(context, id, options = {}) {
-  if (context == null) {
+  if (!context) {
     return undefined;
   }
 
   let target = context.environment.target;
-  if (options.ensure_opened) {
+
+  if (options.ensureOpened) {
     return gDevTools.showToolbox(target, id).then(function(toolbox) {
       return toolbox.getPanel(id);
     });
   } else {
     let toolbox = gDevTools.getToolbox(target);
     if (toolbox) {
       return toolbox.getPanel(id);
     } else {