Bug 1108310 - Remove deprecated for-each-in loop and let blocks and fix strict mode warnings in webapprt/content/downloads/downloads. r=Unfocused
authorChris Peterson <cpeterson@mozilla.com>
Sun, 30 Nov 2014 00:29:07 -0800
changeset 219052 824d26fdcb28fe553b3efa43026a7ca8d37f107c
parent 219051 d5fb8084657a577d5ea04a24fe945344a73dba00
child 219053 350917941d640cc9841e76771c823698bb9f6ec8
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 webapprt/content/downloads/downloads. r=Unfocused
webapprt/content/downloads/downloads.js
--- a/webapprt/content/downloads/downloads.js
+++ b/webapprt/content/downloads/downloads.js
@@ -1,12 +1,14 @@
 /* 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";
+
 const { interfaces: Ci, utils: Cu, classes: Cc } = Components;
 
 const nsIDM = Ci.nsIDownloadManager;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/Task.jsm");
 Cu.import("resource://gre/modules/osfile.jsm");
@@ -349,39 +351,39 @@ DownloadItem.prototype = {
         break;
 
       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] = () => {
-            // Display the file size, but show "Unknown" for negative sizes.
-            let sizeText = gStr.doneSizeUnknown;
-            if (this.maxBytes >= 0) {
-              let [size, unit] = DownloadUtils.convertByteUnits(this.maxBytes);
-              sizeText = gStr.doneSize.replace("#1", size);
-              sizeText = sizeText.replace("#2", unit);
-            }
-            return sizeText;
-          };
-          stateSize[nsIDM.DOWNLOAD_FAILED] = () => gStr.stateFailed;
-          stateSize[nsIDM.DOWNLOAD_CANCELED] = () => gStr.stateCanceled;
-          stateSize[nsIDM.DOWNLOAD_BLOCKED_PARENTAL] = () => gStr.stateBlocked;
-          stateSize[nsIDM.DOWNLOAD_BLOCKED_POLICY] = () => gStr.stateBlockedPolicy;
-          stateSize[nsIDM.DOWNLOAD_DIRTY] = () => gStr.stateDirty;
+        let stateSize = {};
+        stateSize[nsIDM.DOWNLOAD_FINISHED] = () => {
+          // Display the file size, but show "Unknown" for negative sizes.
+          let sizeText = gStr.doneSizeUnknown;
+          if (this.maxBytes >= 0) {
+            let [size, unit] = DownloadUtils.convertByteUnits(this.maxBytes);
+            sizeText = gStr.doneSize.replace("#1", size);
+            sizeText = sizeText.replace("#2", unit);
+          }
+          return sizeText;
+        };
+        stateSize[nsIDM.DOWNLOAD_FAILED] = () => gStr.stateFailed;
+        stateSize[nsIDM.DOWNLOAD_CANCELED] = () => gStr.stateCanceled;
+        stateSize[nsIDM.DOWNLOAD_BLOCKED_PARENTAL] = () => gStr.stateBlocked;
+        stateSize[nsIDM.DOWNLOAD_BLOCKED_POLICY] = () => gStr.stateBlockedPolicy;
+        stateSize[nsIDM.DOWNLOAD_DIRTY] = () => gStr.stateDirty;
 
-          // Insert 1 is the download size or download state.
-          status = gStr.doneStatus.replace("#1", stateSize[this.state]());
-        }
+        // Insert 1 is the download size or download state.
+        status = gStr.doneStatus.replace("#1", stateSize[this.state]());
 
         let [displayHost, fullHost] =
           DownloadUtils.getURIHost(this.referrer || this.uri);
+
         // Insert 2 is the eTLD + 1 or other variations of the host.
         status = status.replace("#2", displayHost);
         // Set the tooltip to be the full host.
         statusTip = fullHost;
 
         break;
     }
 
@@ -716,22 +718,21 @@ let gDownloadList = {
     this.searchTerms = this.searchBox.value.trim().toLowerCase().split(/\s+/);
 
     // Unless forced, don't rebuild the download list if the search didn't change.
     if (!aForceBuild && this.searchTerms.join(" ") == prevSearch) {
       return;
     }
 
     // Clear the list before adding items by replacing with a shallow copy.
-    let (empty = this.downloadView.cloneNode(false)) {
-      this.downloadView.parentNode.replaceChild(empty, this.downloadView);
-      this.downloadView = empty;
-    }
+    let empty = this.downloadView.cloneNode(false);
+    this.downloadView.parentNode.replaceChild(empty, this.downloadView);
+    this.downloadView = empty;
 
-    for each (let downloadItem in this.downloadItems) {
+    for (let downloadItem of this.downloadItems) {
       if (downloadItem.inProgress ||
           downloadItem.matchesSearch(this.searchTerms, this.searchAttributes)) {
         this.downloadView.appendChild(downloadItem.element);
 
         // Because of the joys of XBL, we can't update the buttons until the
         // download object is in the document.
         downloadItem.updateView();
       }
@@ -767,17 +768,17 @@ let gDownloadList = {
   /**
    * Update the disabled state of the clear list button based on whether or not
    * there are items in the list that can potentially be removed.
    */
   updateClearListButton: function() {
     let button = document.getElementById("clearListButton");
 
     // The button is enabled if we have items in the list that we can clean up.
-    for each (let downloadItem in this.downloadItems) {
+    for (let downloadItem of this.downloadItems) {
       if (!downloadItem.inProgress &&
           downloadItem.matchesSearch(this.searchTerms, this.searchAttributes)) {
         button.disabled = false;
         return;
       }
     }
 
     button.disabled = true;
@@ -871,17 +872,17 @@ let gDownloadList = {
    *        a DOM node that is.
    */
   performCommand: function(aCmd, aItem) {
     if (!aItem) {
       // Convert the nodelist into an array to keep a copy of the download items.
       let items = Array.from(this.downloadView.selectedItems);
 
       // Do the command for each download item.
-      for each (let item in items) {
+      for (let item of items) {
         this.performCommand(aCmd, item);
       }
 
       return;
     }
 
     let elm = aItem;
 
@@ -977,17 +978,17 @@ let gDownloadList = {
     this.downloadView.selectAll();
   },
 
   onUpdateProgress: function() {
     let numActive = 0;
     let totalSize = 0;
     let totalTransferred = 0;
 
-    for each (let downloadItem in this.downloadItems) {
+    for (let downloadItem of this.downloadItems) {
       if (!downloadItem.inProgress) {
         continue;
       }
 
       numActive++;
 
       // Only add to total values if we actually know the download size.
       if (downloadItem.maxBytes > 0 &&
@@ -1104,25 +1105,24 @@ let gDownloadList = {
 
     // We might have removed the last item, so update the clear list button.
     this.updateClearListButton();
   },
 };
 
 function Startup() {
   // Convert strings to those in the string bundle.
-  let (sb = document.getElementById("downloadStrings")) {
-    let strings = ["paused", "cannotPause", "doneStatus", "doneSize",
-                   "doneSizeUnknown", "stateFailed", "stateCanceled",
-                   "stateBlocked", "stateBlockedPolicy", "stateDirty",
-                   "downloadsTitleFiles", "downloadsTitlePercent",];
+  let sb = document.getElementById("downloadStrings");
+  let strings = ["paused", "cannotPause", "doneStatus", "doneSize",
+                 "doneSizeUnknown", "stateFailed", "stateCanceled",
+                 "stateBlocked", "stateBlockedPolicy", "stateDirty",
+                 "downloadsTitleFiles", "downloadsTitlePercent",];
 
-    for each (let name in strings) {
-      gStr[name] = sb.getString(name);
-    }
+  for (let name of strings) {
+    gStr[name] = sb.getString(name);
   }
 
   gDownloadList.init();
 
   let DownloadTaskbarProgress =
     Cu.import("resource://gre/modules/DownloadTaskbarProgress.jsm", {}).DownloadTaskbarProgress;
   DownloadTaskbarProgress.onDownloadWindowLoad(window);
 }