Bug 1108310 - Remove deprecated for-each-in loop and let blocks and fix strict mode warnings in toolkit/mozapps/downloads. r=Unfocused
authorChris Peterson <cpeterson@mozilla.com>
Sat, 29 Nov 2014 23:31:33 -0800
changeset 219049 f12d02a53b0a9124c3e961ad7267d1858094de5e
parent 219048 0a6dbb9910a1b2d0533700a676bde4be989d3a01
child 219050 af29bc3f9660a423e7e06bf1e05d1fa33ba666b3
push id27954
push userryanvm@gmail.com
push dateWed, 10 Dec 2014 21:10:24 +0000
treeherdermozilla-central@0cf461e62ce5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersUnfocused
bugs1108310
milestone37.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 1108310 - Remove deprecated for-each-in loop and let blocks and fix strict mode warnings in toolkit/mozapps/downloads. r=Unfocused
toolkit/mozapps/downloads/DownloadUtils.jsm
toolkit/mozapps/downloads/content/downloads.js
--- a/toolkit/mozapps/downloads/DownloadUtils.jsm
+++ b/toolkit/mozapps/downloads/DownloadUtils.jsm
@@ -1,13 +1,15 @@
 /* vim: sw=2 ts=2 sts=2 expandtab filetype=javascript
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+"use strict";
+
 this.EXPORTED_SYMBOLS = [ "DownloadUtils" ];
 
 /**
  * This module provides the DownloadUtils object which contains useful methods
  * for downloads such as displaying file sizes, transfer times, and download
  * locations.
  *
  * List of methods:
@@ -71,17 +73,17 @@ let gStr = {
   units: ["bytes", "kilobyte", "megabyte", "gigabyte"],
   // Update timeSize in convertTimeUnits if changing the length of this array
   timeUnits: ["seconds", "minutes", "hours", "days"],
   infiniteRate: "infiniteRate",
 };
 
 // This lazily initializes the string bundle upon first use.
 this.__defineGetter__("gBundle", function() {
-  delete gBundle;
+  delete this.gBundle;
   return this.gBundle = Cc["@mozilla.org/intl/stringbundle;1"].
                         getService(Ci.nsIStringBundleService).
                         createBundle(kDownloadProperties);
 });
 
 // Keep track of at most this many second/lastSec pairs so that multiple calls
 // to getTimeLeft produce the same time left
 const kCachedLastMaxSize = 10;
@@ -265,23 +267,21 @@ this.DownloadUtils = {
       gCachedLast.shift();
 
     // Apply smoothing only if the new time isn't a huge change -- e.g., if the
     // new time is more than half the previous time; this is useful for
     // downloads that start/resume slowly
     if (aSeconds > aLastSec / 2) {
       // Apply hysteresis to favor downward over upward swings
       // 30% of down and 10% of up (exponential smoothing)
-      let (diff = aSeconds - aLastSec) {
-        aSeconds = aLastSec + (diff < 0 ? .3 : .1) * diff;
-      }
+      let diff = aSeconds - aLastSec;
+      aSeconds = aLastSec + (diff < 0 ? .3 : .1) * diff;
 
       // If the new time is similar, reuse something close to the last seconds,
       // but subtract a little to provide forward progress
-      let diff = aSeconds - aLastSec;
       let diffPct = diff / aLastSec * 100;
       if (Math.abs(diff) < 5 || Math.abs(diffPct) < 5)
         aSeconds = aLastSec - (diff < 0 ? .4 : .2);
     }
 
     // Decide what text to show for the time
     let timeLeft;
     if (aSeconds < 4) {
--- a/toolkit/mozapps/downloads/content/downloads.js
+++ b/toolkit/mozapps/downloads/content/downloads.js
@@ -1,13 +1,15 @@
 # -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
+"use strict";
+
 ////////////////////////////////////////////////////////////////////////////////
 //// Globals
 
 const PREF_BDM_CLOSEWHENDONE = "browser.download.manager.closeWhenDone";
 const PREF_BDM_ALERTONEXEOPEN = "browser.download.manager.alertOnEXEOpen";
 const PREF_BDM_SCANWHENDONE = "browser.download.manager.scanWhenDone";
 
 const nsLocalFile = Components.Constructor("@mozilla.org/file/local;1",
@@ -406,21 +408,20 @@ function onUpdateProgress()
 //// Startup, Shutdown
 
 function Startup()
 {
   gDownloadsView = document.getElementById("downloadView");
   gSearchBox = document.getElementById("searchbox");
 
   // convert strings to those in the string bundle
-  let (sb = document.getElementById("downloadStrings")) {
-    let getStr = function(string) sb.getString(string);
-    for (let [name, value] in Iterator(gStr))
-      gStr[name] = typeof value == "string" ? getStr(value) : value.map(getStr);
-  }
+  let sb = document.getElementById("downloadStrings");
+  let getStr = function(string) sb.getString(string);
+  for (let [name, value] in Iterator(gStr))
+    gStr[name] = typeof value == "string" ? getStr(value) : value.map(getStr);
 
   initStatement();
   buildDownloadList(true);
 
   // The DownloadProgressListener (DownloadProgressListener.js) handles progress
   // notifications.
   gDownloadListener = new DownloadProgressListener();
   gDownloadManager.addListener(gDownloadListener);
@@ -818,17 +819,17 @@ function performCommand(aCmd, aItem)
     gPerformAllCallback = null;
 
     // Convert the nodelist into an array to keep a copy of the download items
     let items = [];
     for (let i = gDownloadsView.selectedItems.length; --i >= 0; )
       items.unshift(gDownloadsView.selectedItems[i]);
 
     // Do the command for each download item
-    for each (let item in items)
+    for (let item of items)
       performCommand(aCmd, item);
 
     // Call the callback with no arguments and reset because we're done
     if (typeof gPerformAllCallback == "function")
       gPerformAllCallback();
     gPerformAllCallback = undefined;
 
     return;
@@ -968,40 +969,40 @@ function updateStatus(aItem, aDownload) 
     }
     case nsIDM.DOWNLOAD_FINISHED:
     case nsIDM.DOWNLOAD_FAILED:
     case nsIDM.DOWNLOAD_CANCELED:
     case nsIDM.DOWNLOAD_BLOCKED_PARENTAL:
     case nsIDM.DOWNLOAD_BLOCKED_POLICY:
     case nsIDM.DOWNLOAD_DIRTY:
     {
-      let (stateSize = {}) {
-        stateSize[nsIDM.DOWNLOAD_FINISHED] = function() {
-          // Display the file size, but show "Unknown" for negative sizes
-          let fileSize = Number(aItem.getAttribute("maxBytes"));
-          let sizeText = gStr.doneSizeUnknown;
-          if (fileSize >= 0) {
-            let [size, unit] = DownloadUtils.convertByteUnits(fileSize);
-            sizeText = replaceInsert(gStr.doneSize, 1, size);
-            sizeText = replaceInsert(sizeText, 2, unit);
-          }
-          return sizeText;
-        };
-        stateSize[nsIDM.DOWNLOAD_FAILED] = function() gStr.stateFailed;
-        stateSize[nsIDM.DOWNLOAD_CANCELED] = function() gStr.stateCanceled;
-        stateSize[nsIDM.DOWNLOAD_BLOCKED_PARENTAL] = function() gStr.stateBlockedParentalControls;
-        stateSize[nsIDM.DOWNLOAD_BLOCKED_POLICY] = function() gStr.stateBlockedPolicy;
-        stateSize[nsIDM.DOWNLOAD_DIRTY] = function() gStr.stateDirty;
+      let stateSize = {};
+      stateSize[nsIDM.DOWNLOAD_FINISHED] = function() {
+        // Display the file size, but show "Unknown" for negative sizes
+        let fileSize = Number(aItem.getAttribute("maxBytes"));
+        let sizeText = gStr.doneSizeUnknown;
+        if (fileSize >= 0) {
+          let [size, unit] = DownloadUtils.convertByteUnits(fileSize);
+          sizeText = replaceInsert(gStr.doneSize, 1, size);
+          sizeText = replaceInsert(sizeText, 2, unit);
+        }
+        return sizeText;
+      };
+      stateSize[nsIDM.DOWNLOAD_FAILED] = function() gStr.stateFailed;
+      stateSize[nsIDM.DOWNLOAD_CANCELED] = function() gStr.stateCanceled;
+      stateSize[nsIDM.DOWNLOAD_BLOCKED_PARENTAL] = function() gStr.stateBlockedParentalControls;
+      stateSize[nsIDM.DOWNLOAD_BLOCKED_POLICY] = function() gStr.stateBlockedPolicy;
+      stateSize[nsIDM.DOWNLOAD_DIRTY] = function() gStr.stateDirty;
 
-        // Insert 1 is the download size or download state
-        status = replaceInsert(gStr.doneStatus, 1, stateSize[state]());
-      }
+      // Insert 1 is the download size or download state
+      status = replaceInsert(gStr.doneStatus, 1, stateSize[state]());
 
       let [displayHost, fullHost] =
         DownloadUtils.getURIHost(getReferrerOrSource(aItem));
+
       // Insert 2 is the eTLD + 1 or other variations of the host
       status = replaceInsert(status, 2, displayHost);
       // Set the tooltip to be the full host
       statusTip = fullHost;
 
       break;
     }
   }
@@ -1105,20 +1106,19 @@ function buildDownloadList(aForceBuild)
   if (!aForceBuild && gSearchTerms.join(" ") == prevSearch)
     return;
 
   // Clear out values before using them
   clearTimeout(gBuilder);
   gStmt.reset();
 
   // Clear the list before adding items by replacing with a shallow copy
-  let (empty = gDownloadsView.cloneNode(false)) {
-    gDownloadsView.parentNode.replaceChild(empty, gDownloadsView);
-    gDownloadsView = empty;
-  }
+  let empty = gDownloadsView.cloneNode(false);
+  gDownloadsView.parentNode.replaceChild(empty, gDownloadsView);
+  gDownloadsView = empty;
 
   try {
     gStmt.bindByIndex(0, nsIDM.DOWNLOAD_NOTSTARTED);
     gStmt.bindByIndex(1, nsIDM.DOWNLOAD_DOWNLOADING);
     gStmt.bindByIndex(2, nsIDM.DOWNLOAD_PAUSED);
     gStmt.bindByIndex(3, nsIDM.DOWNLOAD_QUEUED);
     gStmt.bindByIndex(4, nsIDM.DOWNLOAD_SCANNING);
   } catch (e) {
@@ -1167,32 +1167,31 @@ function stepListBuilder(aNumItems) {
       state: gStmt.getInt32(4),
       startTime: Math.round(gStmt.getInt64(5) / 1000),
       endTime: Math.round(gStmt.getInt64(6) / 1000),
       currBytes: gStmt.getInt64(8),
       maxBytes: gStmt.getInt64(9)
     };
 
     // Only add the referrer if it's not null
-    let (referrer = gStmt.getString(7)) {
-      if (referrer)
-        attrs.referrer = referrer;
-    }
+    let referrer = gStmt.getString(7);
+    if (referrer)
+      attrs.referrer = referrer;
 
     // If the download is active, grab the real progress, otherwise default 100
     let isActive = gStmt.getInt32(10);
     attrs.progress = isActive ? gDownloadManager.getDownload(attrs.dlid).
       percentComplete : 100;
 
     // Make the item and add it to the end if it's active or matches the search
     let item = createDownloadItem(attrs);
     if (item && (isActive || downloadMatchesSearch(item))) {
       // Add item to the end
       gDownloadsView.appendChild(item);
-    
+
       // Because of the joys of XBL, we can't update the buttons until the
       // download object is in the document.
       updateButtons(item);
     } else {
       // We didn't add an item, so bump up the number of items to process, but
       // not a whole number so that we eventually do pause for a chunk break
       aNumItems += .9;
     }
@@ -1258,21 +1257,21 @@ function prependList(aDownload)
  *        Download richlistitem to check if it matches the current search
  * @return Boolean true if it matches the search; false otherwise
  */
 function downloadMatchesSearch(aItem)
 {
   // Search through the download attributes that are shown to the user and
   // make it into one big string for easy combined searching
   let combinedSearch = "";
-  for each (let attr in gSearchAttributes)
+  for (let attr of gSearchAttributes)
     combinedSearch += aItem.getAttribute(attr).toLowerCase() + " ";
 
   // Make sure each of the terms are found
-  for each (let term in gSearchTerms)
+  for (let term of gSearchTerms)
     if (combinedSearch.indexOf(term) == -1)
       return false;
 
   return true;
 }
 
 // we should be using real URLs all the time, but until
 // bug 239948 is fully fixed, this will do...