Bug 883908 - Fix padding in Console.jsm's trace method. r=jwalker
authorDave Camp <dcamp@mozilla.com>
Mon, 17 Jun 2013 06:52:54 -0700
changeset 147511 19a51caf7582121d8799d102d5ed604e4365b2cd
parent 147510 4de2ded917f1aa191be6f1f7f3d8b13834a53b32
child 147512 e84338c0a9ca6d9a6385153316d9d6de3d6872ef
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)
reviewersjwalker
bugs883908
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 883908 - Fix padding in Console.jsm's trace method. r=jwalker
toolkit/devtools/Console.jsm
--- a/toolkit/devtools/Console.jsm
+++ b/toolkit/devtools/Console.jsm
@@ -30,30 +30,32 @@ Cu.import("resource://gre/modules/Consol
 XPCOMUtils.defineLazyModuleGetter(this, "Services",
                                   "resource://gre/modules/Services.jsm");
 
 let gTimerRegistry = new Map();
 
 /**
  * String utility to ensure that strings are a specified length. Strings
  * that are too long are truncated to the max length and the last char is
- * set to "_". Strings that are too short are left padded with spaces.
+ * set to "_". Strings that are too short are padded with spaces.
  *
  * @param {string} aStr
  *        The string to format to the correct length
  * @param {number} aMaxLen
  *        The maximum allowed length of the returned string
  * @param {number} aMinLen (optional)
  *        The minimum allowed length of the returned string. If undefined,
  *        then aMaxLen will be used
  * @param {object} aOptions (optional)
- *        An object allowing format customization. The only customization
- *        allowed currently is 'truncate' which can take the value "start" to
- *        truncate strings from the start as opposed to the end or "center" to
- *        truncate strings in the center
+ *        An object allowing format customization. Allowed customizations:
+ *          'truncate' - can take the value "start" to truncate strings from
+ *             the start as opposed to the end or "center" to truncate
+ *             strings in the center.
+ *          'align' - takes an alignment when padding is needed for MinLen,
+ *             either "start" or "end".  Defaults to "start".
  * @return {string}
  *        The original string formatted to fit the specified lengths
  */
 function fmt(aStr, aMaxLen, aMinLen, aOptions) {
   if (aMinLen == null) {
     aMinLen = aMaxLen;
   }
   if (aStr == null) {
@@ -69,17 +71,18 @@ function fmt(aStr, aMaxLen, aMinLen, aOp
       let end = aStr.substring((aStr.length - (aMaxLen / 2)) + 1);
       return start + "_" + end;
     }
     else {
       return aStr.substring(0, aMaxLen - 1) + "_";
     }
   }
   if (aStr.length < aMinLen) {
-    return Array(aMinLen - aStr.length + 1).join(" ") + aStr;
+    let padding = Array(aMinLen - aStr.length + 1).join(" ");
+    aStr = (aOptions.align === "end") ? padding + aStr : aStr + padding;
   }
   return aStr;
 }
 
 /**
  * Utility to extract the constructor name of an object.
  * Object.toString gives: "[object ?????]"; we want the "?????".
  *
@@ -374,17 +377,17 @@ function getStack(aFrame, aMaxDepth = 0)
  *        Array of trace objects as created by parseStack()
  * @return {string} Multi line report of the stack trace
  */
 function formatTrace(aTrace) {
   let reply = "";
   aTrace.forEach(function(frame) {
     reply += fmt(frame.filename, 20, 20, { truncate: "start" }) + " " +
              fmt(frame.lineNumber, 5, 5) + " " +
-             fmt(frame.functionName, 75, 75, { truncate: "center" }) + "\n";
+             fmt(frame.functionName, 0, 75, { truncate: "center" }) + "\n";
   });
   return reply;
 }
 
 /**
  * Create a new timer by recording the current time under the specified name.
  *
  * @param {string} aName