Bug 1499906 (attempt 2) - Use template literals where suitable. r=erahm
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 19 Oct 2018 15:11:43 +1100
changeset 490396 f35ac5e55bb4ea3a74c53b964bec3627c984961b
parent 490395 1752794d80abffc53fe6ffa689fcd1648195b6af
child 490397 25594c3013c4852ee5441321b340983c2a8d6364
child 490438 18859d2fec94f35e924e9093a99169623e0b2d78
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewerserahm
bugs1499906
milestone64.0a1
Bug 1499906 (attempt 2) - Use template literals where suitable. r=erahm
toolkit/components/aboutmemory/content/aboutMemory.js
--- a/toolkit/components/aboutmemory/content/aboutMemory.js
+++ b/toolkit/components/aboutmemory/content/aboutMemory.js
@@ -79,17 +79,17 @@ function assert(aCond, aMsg) {
     reportAssertionFailure(aMsg);
     throw new Error(gAssertionFailureMsgPrefix + aMsg);
   }
 }
 
 // This is used for malformed input from memory reporters.
 function assertInput(aCond, aMsg) {
   if (!aCond) {
-    throw new Error("Invalid memory report(s): " + aMsg);
+    throw new Error(`Invalid memory report(s): ${aMsg}`);
   }
 }
 
 function handleException(aEx) {
   let str = "" + aEx;
   if (str.startsWith(gAssertionFailureMsgPrefix)) {
     // Argh, assertion failure within this file!  Give up.
     throw aEx;
@@ -138,17 +138,17 @@ const SHOW_FOOTER = 1;
 // Values for the |aShowTimestamp| argument to updateTitleMainAndFooter.
 const NO_TIMESTAMP = 0;
 const SHOW_TIMESTAMP = 1;
 
 function updateTitleMainAndFooter(aTitleNote, aMsg, aShowTimestamp,
                                   aFooterAction, aClassName) {
   document.title = gPageName;
   if (aTitleNote) {
-    document.title += " (" + aTitleNote + ")";
+    document.title += ` (${aTitleNote})`;
   }
 
   // Clear gMain by replacing it with an empty node.
   let tmp = gMain.cloneNode(false);
   gMain.parentNode.replaceChild(tmp, gMain);
   gMain = tmp;
 
   gMain.classList.remove("hidden");
@@ -163,17 +163,17 @@ function updateTitleMainAndFooter(aTitle
     let className = "section";
     if (aClassName) {
       className = className + " " + aClassName;
     }
     if (aShowTimestamp == SHOW_TIMESTAMP) {
       // JS has many options for pretty-printing timestamps. We use
       // toISOString() because it has sub-second granularity, which is useful
       // if you quickly and repeatedly click one of the buttons.
-      aMsg += " (" + (new Date()).toISOString() + ")";
+      aMsg += ` (${(new Date()).toISOString()})`;
     }
     msgElement = appendElementWithText(gMain, "div", className, aMsg);
   }
 
   switch (aFooterAction) {
    case HIDE_FOOTER: gFooter.classList.add("hidden"); break;
    case SHOW_FOOTER: gFooter.classList.remove("hidden"); break;
    default: assert(false, "bad footer action in updateTitleMainAndFooter");
@@ -676,17 +676,17 @@ function updateAboutMemoryFromFile(aFile
  * diffs them.
  *
  * @param aFilename1
  *        The name of the first file being read from.
  * @param aFilename2
  *        The name of the first file being read from.
  */
 function updateAboutMemoryFromTwoFiles(aFilename1, aFilename2) {
-  let titleNote = "diff of " + aFilename1 + " and " + aFilename2;
+  let titleNote = `diff of ${aFilename1} and ${aFilename2}`;
   loadMemoryReportsFromFile(aFilename1, titleNote, function(aStr1) {
     loadMemoryReportsFromFile(aFilename2, titleNote, function(aStr2) {
       try {
         let obj1 = parseAndUnwrapIfCrashDump(aStr1);
         let obj2 = parseAndUnwrapIfCrashDump(aStr2);
         gIsDiff = true;
         updateAboutMemoryFromJSONObject(diffJSONObjects(obj1, obj2));
         gIsDiff = false;
@@ -1000,18 +1000,18 @@ function appendAboutMemoryMain(aProcessR
     }
   }
 
   function displayReports() {
     // Sort the processes.
     let processes = Object.keys(pcollsByProcess);
     processes.sort(function(aProcessA, aProcessB) {
       assert(aProcessA != aProcessB,
-             "Elements of Object.keys() should be unique, but " +
-             "saw duplicate '" + aProcessA + "' elem.");
+             `Elements of Object.keys() should be unique, but ` +
+             `saw duplicate '${aProcessA}' elem.`);
 
       // Always put the main process first.
       if (aProcessA == gUnnamedProcessStr) {
         return -1;
       }
       if (aProcessB == gUnnamedProcessStr) {
         return 1;
       }
@@ -1306,17 +1306,17 @@ function sortTreeAndInsertAggregateNodes
   for (i = 0; i < aT._kids.length - 1; i++) {
     if (isInsignificant(aT._kids[i])) {
       // This child is below the significance threshold.  If there are other
       // (smaller) children remaining, move them under an aggregate node.
       let i0 = i;
       let nAgg = aT._kids.length - i0;
       // Create an aggregate node.  Inherit units from the parent;  everything
       // in the tree should have the same units anyway (we test this later).
-      let aggT = new TreeNode("(" + nAgg + " tiny)", aT._units);
+      let aggT = new TreeNode(`(${nAgg} tiny)`, aT._units);
       aggT._kids = [];
       let aggBytes = 0;
       for ( ; i < aT._kids.length; i++) {
         aggBytes += aT._kids[i]._amount;
         aggT._kids.push(aT._kids[i]);
       }
       aggT._hideKids = true;
       aggT._amount = aggBytes;
@@ -1410,17 +1410,17 @@ function appendWarningElements(aP, aHasK
  */
 function appendProcessAboutMemoryElements(aP, aN, aProcess, aTrees,
                                           aDegenerates, aHeapTotal,
                                           aHasMozMallocUsableSize) {
   let appendLink = function(aHere, aThere, aArrow) {
     let link = appendElementWithText(aP, "a", "upDownArrow", aArrow);
     link.href = "#" + aThere + aN;
     link.id = aHere + aN;
-    link.title = "Go to the " + aThere + " of " + aProcess;
+    link.title = `Go to the ${aThere} of ${aProcess}`;
     link.style = "text-decoration: none";
 
     // This gives nice spacing when we copy and paste.
     appendElementWithText(aP, "span", "", "\n");
   };
 
   appendElementWithText(aP, "h1", "", aProcess);
   appendLink("start", "end", "↓");
@@ -1613,17 +1613,17 @@ function appendMrNameSpan(aP, aDescripti
     }
     let noteSpan = appendElementWithText(aP, "span", "mrNote", noteText);
     noteSpan.title =
       "Warning: this value is invalid and indicates a bug in one or more " +
       "memory reporters. ";
   }
 
   if (aNMerged) {
-    let noteText = " [" + aNMerged + "]";
+    let noteText = ` [${aNMerged}]`;
     if (!aPresence) {
       noteText += "\n";
     }
     let noteSpan = appendElementWithText(aP, "span", "mrNote", noteText);
     noteSpan.title =
       "This value is the sum of " + aNMerged +
       " memory reports that all have the same path.";
   }
@@ -1643,18 +1643,17 @@ function appendMrNameSpan(aP, aDescripti
       c = "!";
       title = "One of the sets of memory reports lacked children for this " +
               "node's parent. This is a fake child node added to make the " +
               "two memory sets comparable.";
       break;
      default: assert(false, "bad presence");
       break;
     }
-    let noteSpan = appendElementWithText(aP, "span", "mrNote",
-                                         " [" + c + "]\n");
+    let noteSpan = appendElementWithText(aP, "span", "mrNote", ` [${c}]\n`);
     noteSpan.title = title;
   }
 }
 
 // This is used to record the (safe) IDs of which sub-trees have been manually
 // expanded (marked as true) and collapsed (marked as false).  It's used to
 // replicate the collapsed/expanded state when the page is updated.  It can end
 // up holding IDs of nodes that no longer exist, e.g. for compartments that
@@ -1785,31 +1784,31 @@ function appendTreeElements(aP, aRoot, a
     // we expect negative values in that case.
     assertInput(aRoot._units === aT._units,
                 "units within a tree are inconsistent");
     let tIsInvalid = false;
     if (!gIsDiff && !(0 <= aT._amount && aT._amount <= aRoot._amount)) {
       tIsInvalid = true;
       let unsafePath = aUnsafeNames.join("/");
       gUnsafePathsWithInvalidValuesForThisProcess.push(unsafePath);
-      reportAssertionFailure("Invalid value (" + aT._amount + " / " +
-                             aRoot._amount + ") for " +
-                             flipBackslashes(unsafePath));
+      reportAssertionFailure(
+        `Invalid value (${aT._amount} / ${aRoot._amount}) for ` +
+        flipBackslashes(unsafePath));
     }
 
     // For non-leaf nodes, the entire sub-tree is put within a span so it can
     // be collapsed if the node is clicked on.
     let d;
     let sep;
     let showSubtrees;
     if (aT._kids) {
       // Determine if we should show the sub-tree below this entry;  this
       // involves reinstating any previous toggling of the sub-tree.
       let unsafePath = aUnsafeNames.join("/");
-      let safeTreeId = aProcess + ":" + flipBackslashes(unsafePath);
+      let safeTreeId = `${aProcess}:${flipBackslashes(unsafePath)}`;
       showSubtrees = !aT._hideKids;
       if (gShowSubtreesBySafeTreeId[safeTreeId] !== undefined) {
         showSubtrees = gShowSubtreesBySafeTreeId[safeTreeId];
       }
       d = appendElement(aP, "span", "hasKids");
       d.id = safeTreeId;
       d.onclick = toggle;
       sep = showSubtrees ? kShowKidsSep : kHideKidsSep;