Bug 698928 - Use debug.assertion if about:memory hits a problem. r=nnethercote.
authorJesse Ruderman <jruderman@gmail.com>
Mon, 20 Feb 2012 18:17:30 -0800
changeset 88786 49140e63962f19e807cb0e0db630aabbb198be18
parent 88785 5dab4b89eabc665297df1e51d7f38f5ca01da589
child 88787 c3e591a5b8678663501c1d99b8ba0153c9591107
push id975
push userffxbld
push dateTue, 13 Mar 2012 21:39:16 +0000
treeherdermozilla-aurora@99faebf9dc36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnnethercote
bugs698928
milestone13.0a1
Bug 698928 - Use debug.assertion if about:memory hits a problem. r=nnethercote.
toolkit/components/aboutmemory/content/aboutMemory.js
--- a/toolkit/components/aboutmemory/content/aboutMemory.js
+++ b/toolkit/components/aboutmemory/content/aboutMemory.js
@@ -75,17 +75,26 @@ String.prototype.startsWith =
 function flipBackslashes(aUnsafeStr)
 {
   return aUnsafeStr.replace(/\\/g, '/');
 }
 
 function assert(aCond, aMsg)
 {
   if (!aCond) {
-    throw("assertion failed: " + aMsg);
+    reportAssertionFailure(aMsg)
+    throw("aboutMemory.js assertion failed: " + aMsg);
+  }
+}
+
+function reportAssertionFailure(aMsg)
+{
+  var debug = Cc["@mozilla.org/xpcom/debug;1"].getService(Ci.nsIDebug2);
+  if (debug.isDebugBuild) {
+    debug.assertion(aMsg, "false", "aboutMemory.js", 0);
   }
 }
 
 function debug(x)
 {
   appendElementWithText(document.body, "div", "legend", JSON.stringify(x));
 }
 
@@ -571,17 +580,17 @@ function buildTree(aReports, aTreeName)
   let foundReport = false;
   for (let unsafePath in aReports) {
     if (aReports[unsafePath].treeNameMatches(aTreeName)) {
       foundReport = true;
       break;
     }
   }
   if (!foundReport) {
-    assert(aTreeName !== 'explicit');
+    assert(aTreeName !== 'explicit', "aTreeName !== 'explicit'");
     return null;
   }
 
   let t = new TreeNode("falseRoot");
   for (let unsafePath in aReports) {
     // Add any missing nodes in the tree implied by the unsafePath.
     let r = aReports[unsafePath];
     if (r.treeNameMatches(aTreeName)) {
@@ -1249,20 +1258,21 @@ function appendTreeElements(aPOuter, aT,
 
     // Generate the percentage;  detect and record invalid values at the same
     // time.
     let percText = "";
     let tIsInvalid = false;
     if (aT._amount === treeBytes) {
       percText = "100.0";
     } else {
-      let perc = (100 * aT._amount / treeBytes);
-      if (!(0 <= perc && perc <= 100)) {
+      if (!(0 <= aT._amount && aT._amount <= treeBytes)) {
         tIsInvalid = true;
         gUnsafePathsWithInvalidValuesForThisProcess.push(unsafePath);
+        reportAssertionFailure("Invalid value for " +
+                               flipBackslashes(unsafePath));
       }
       percText = (100 * aT._amount / treeBytes).toFixed(2);
       percText = pad(percText, 5, '0');
     }
     percText = " (" + percText + "%)";
 
     // For non-leaf nodes, the entire sub-tree is put within a span so it can
     // be collapsed if the node is clicked on.
@@ -1411,17 +1421,17 @@ function appendOtherElements(aP, aReport
   // widest element, so we can format things nicely.
   let maxStringLength = 0;
   let otherReports = [];
   for (let unsafePath in aReportsByProcess) {
     let r = aReportsByProcess[unsafePath];
     if (!r._done) {
       assert(r._kind === KIND_OTHER,
              "_kind !== KIND_OTHER for " + flipBackslashes(r._unsafePath));
-      assert(r._nMerged === undefined);  // we don't allow dup'd OTHER Reports
+      assert(r._nMerged === undefined, "dup'd OTHER report");
       let o = new OtherReport(r._unsafePath, r._units, r._amount,
                               r._description);
       otherReports.push(o);
       if (o._asString.length > maxStringLength) {
         maxStringLength = o._asString.length;
       }
     }
   }
@@ -1429,16 +1439,18 @@ function appendOtherElements(aP, aReport
 
   // Generate text for the not-yet-printed values.
   let text = "";
   for (let i = 0; i < otherReports.length; i++) {
     let o = otherReports[i];
     let oIsInvalid = o.isInvalid();
     if (oIsInvalid) {
       gUnsafePathsWithInvalidValuesForThisProcess.push(o._unsafePath);
+      reportAssertionFailure("Invalid value for " +
+                             flipBackslashes(o._unsafePath));
     }
     appendMrValueSpan(pre, pad(o._asString, maxStringLength, ' '), oIsInvalid);
     appendMrNameSpan(pre, KIND_OTHER, kNoKids, o._description, o._unsafePath,
                      o._isUnknown, oIsInvalid);
     appendTextNode(pre, "\n");
   }
 
   appendTextNode(aP, "\n");  // gives nice spacing when we cut and paste