Bug 1288558 - Part 2: Replace var with let. r=MattN
authorSteve Chung <schung@mozilla.com>
Wed, 07 Sep 2016 17:50:06 -0700
changeset 354418 6f18e82e0ccdf068a2ddf1a826f654ab66535ceb
parent 354417 ad1252b88e460a400583dc43720f0e540afccfdc
child 354419 5db2cc28a8ff880a980fbf799a9a4b0bd0d4e52d
push id6570
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:26:13 +0000
treeherdermozilla-beta@f455459b2ae5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs1288558
milestone51.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 1288558 - Part 2: Replace var with let. r=MattN MozReview-Commit-ID: 9zOEOWmk9Hq
toolkit/components/passwordmgr/content/passwordManager.js
--- a/toolkit/components/passwordmgr/content/passwordManager.js
+++ b/toolkit/components/passwordmgr/content/passwordManager.js
@@ -1,38 +1,38 @@
 /* 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/. */
 
 /*** =================== SAVED SIGNONS CODE =================== ***/
-var { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
+const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
 
 Cu.import("resource://gre/modules/AppConstants.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "DeferredTask",
                                   "resource://gre/modules/DeferredTask.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
                                   "resource://gre/modules/PlacesUtils.jsm");
 
-var kSignonBundle;
-var kObserverService;
+let kSignonBundle;
+let kObserverService;
 
 // interface variables
-var passwordmanager = null;
+let passwordmanager = null;
 
-var showingPasswords = false;
+let showingPasswords = false;
 
 // password-manager lists
-var signons = [];
-var deletedSignons = [];
+let signons = [];
+let deletedSignons = [];
 
-var signonsTree;
-var signonReloadDisplay = {
+let signonsTree;
+let signonReloadDisplay = {
   observe: function(subject, topic, data) {
     if (topic == "passwordmgr-storage-changed") {
       switch (data) {
         case "addLogin":
         case "modifyLogin":
         case "removeLogin":
         case "removeAllLogins":
           if (!signonsTree) {
@@ -47,19 +47,19 @@ var signonReloadDisplay = {
           break;
       }
       kObserverService.notifyObservers(null, "passwordmgr-dialog-updated", null);
     }
   }
 }
 
 // Formatter for localization.
-var dateFormatter = new Intl.DateTimeFormat(undefined,
+let dateFormatter = new Intl.DateTimeFormat(undefined,
                       { day: "numeric", month: "short", year: "numeric" });
-var dateAndTimeFormatter = new Intl.DateTimeFormat(undefined,
+let dateAndTimeFormatter = new Intl.DateTimeFormat(undefined,
                              { day: "numeric", month: "short", year: "numeric",
                                hour: "numeric", minute: "numeric" });
 
 function Startup() {
   // xpconnect to password manager interfaces
   passwordmanager = Components.classes["@mozilla.org/login-manager;1"]
                         .getService(Components.interfaces.nsILoginManager);
 
@@ -115,17 +115,17 @@ function Shutdown() {
   kObserverService.removeObserver(signonReloadDisplay, "passwordmgr-storage-changed");
 }
 
 function setFilter(aFilterString) {
   document.getElementById("filter").value = aFilterString;
   _filterPasswords();
 }
 
-var signonsTreeView = {
+let signonsTreeView = {
   // Keep track of which favicons we've fetched or started fetching.
   // Maps a login origin to a favicon URL.
   _faviconMap: new Map(),
   _filterSet: [],
   // Coalesce invalidations to avoid repeated flickering.
   _invalidateTask: new DeferredTask(() => {
     signonsTree.treeBoxObject.invalidateColumn(signonsTree.columns.siteCol);
   }, 10),
@@ -156,18 +156,18 @@ var signonsTreeView = {
         this._invalidateTask.arm();
       }).catch(Cu.reportError);
 
     return "";
   },
   getProgressMode(row, column) {},
   getCellValue(row, column) {},
   getCellText(row, column) {
-    var time;
-    var signon = this._filterSet.length ? this._filterSet[row] : signons[row];
+    let time;
+    let signon = this._filterSet.length ? this._filterSet[row] : signons[row];
     switch (column.id) {
       case "siteCol":
         return signon.httpRealm ?
                (signon.hostname + " (" + signon.httpRealm + ")"):
                signon.hostname;
       case "userCol":
         return signon.username || "";
       case "passwordCol":
@@ -229,28 +229,28 @@ var signonsTreeView = {
       _editLogin("password");
     }
   },
 };
 
 function SortTree(tree, view, table, column, lastSortColumn, lastSortAscending, updateSelection) {
 
   // remember which item was selected so we can restore it after the sort
-  var selections = GetTreeSelections(tree);
-  var selectedNumber = selections.length ? table[selections[0]].number : -1;
+  let selections = GetTreeSelections(tree);
+  let selectedNumber = selections.length ? table[selections[0]].number : -1;
 
   // determine if sort is to be ascending or descending
-  var ascending = (column == lastSortColumn) ? !lastSortAscending : true;
+  let ascending = (column == lastSortColumn) ? !lastSortAscending : true;
 
   function compareFunc(a, b) {
-    var valA, valB;
+    let valA, valB;
     switch (column) {
       case "hostname":
-        var realmA = a.httpRealm;
-        var realmB = b.httpRealm;
+        let realmA = a.httpRealm;
+        let realmB = b.httpRealm;
         realmA = realmA == null ? "" : realmA.toLowerCase();
         realmB = realmB == null ? "" : realmB.toLowerCase();
 
         valA = a[column].toLowerCase() + realmA;
         valB = b[column].toLowerCase() + realmB;
         break;
       case "username":
       case "password":
@@ -271,19 +271,19 @@ function SortTree(tree, view, table, col
   }
 
   // do the sort
   table.sort(compareFunc);
   if (!ascending)
     table.reverse();
 
   // restore the selection
-  var selectedRow = -1;
+  let selectedRow = -1;
   if (selectedNumber>=0 && updateSelection) {
-    for (var s=0; s<table.length; s++) {
+    for (let s=0; s<table.length; s++) {
       if (table[s].number == selectedNumber) {
         // update selection
         // note: we need to deselect before reselecting in order to trigger ...Selected()
         tree.view.selection.select(-1);
         tree.view.selection.select(s);
         selectedRow = s;
         break;
       }
@@ -313,144 +313,144 @@ function LoadSignons() {
   signonsTree.view = signonsTreeView;
   // The sort column didn't change. SortTree (called by
   // SignonColumnSort) assumes we want to toggle the sort
   // direction but here we don't so we have to trick it
   lastSignonSortAscending = !lastSignonSortAscending;
   SignonColumnSort(lastSignonSortColumn);
 
   // disable "remove all signons" button if there are no signons
-  var element = document.getElementById("removeAllSignons");
-  var toggle = document.getElementById("togglePasswords");
+  let element = document.getElementById("removeAllSignons");
+  let toggle = document.getElementById("togglePasswords");
   if (signons.length == 0) {
     element.setAttribute("disabled", "true");
     toggle.setAttribute("disabled", "true");
   } else {
     element.removeAttribute("disabled");
     toggle.removeAttribute("disabled");
   }
 
   return true;
 }
 
 function GetTreeSelections(tree) {
-  var selections = [];
-  var select = tree.view.selection;
+  let selections = [];
+  let select = tree.view.selection;
   if (select) {
-    var count = select.getRangeCount();
-    var min = new Object();
-    var max = new Object();
-    for (var i=0; i<count; i++) {
+    let count = select.getRangeCount();
+    let min = new Object();
+    let max = new Object();
+    for (let i=0; i<count; i++) {
       select.getRangeAt(i, min, max);
-      for (var k=min.value; k<=max.value; k++) {
+      for (let k=min.value; k<=max.value; k++) {
         if (k != -1) {
           selections[selections.length] = k;
         }
       }
     }
   }
   return selections;
 }
 
 function SignonSelected() {
-  var selections = GetTreeSelections(signonsTree);
+  let selections = GetTreeSelections(signonsTree);
   if (selections.length) {
     document.getElementById("removeSignon").removeAttribute("disabled");
   } else {
     document.getElementById("removeSignon").setAttribute("disabled", true);
   }
 }
 
 function DeleteSelectedItemFromTree
     (tree, view, table, deletedTable, removeButton, removeAllButton) {
 
   // Turn off tree selection notifications during the deletion
   tree.view.selection.selectEventsSuppressed = true;
 
   // remove selected items from list (by setting them to null) and place in deleted list
-  var selections = GetTreeSelections(tree);
-  for (var s=selections.length-1; s>= 0; s--) {
-    var i = selections[s];
+  let selections = GetTreeSelections(tree);
+  for (let s=selections.length-1; s>= 0; s--) {
+    let i = selections[s];
     deletedTable[deletedTable.length] = table[i];
     table[i] = null;
   }
 
   // collapse list by removing all the null entries
-  for (var j=0; j<table.length; j++) {
+  for (let j=0; j<table.length; j++) {
     if (table[j] == null) {
-      var k = j;
+      let k = j;
       while ((k < table.length) && (table[k] == null)) {
         k++;
       }
       table.splice(j, k-j);
       view.rowCount -= k - j;
       tree.treeBoxObject.rowCountChanged(j, j - k);
     }
   }
 
   // update selection and/or buttons
   if (table.length) {
     // update selection
-    var nextSelection = (selections[0] < table.length) ? selections[0] : table.length-1;
+    let nextSelection = (selections[0] < table.length) ? selections[0] : table.length-1;
     tree.view.selection.select(nextSelection);
     tree.treeBoxObject.ensureRowIsVisible(nextSelection);
   } else {
     // disable buttons
     document.getElementById(removeButton).setAttribute("disabled", "true")
     document.getElementById(removeAllButton).setAttribute("disabled", "true");
   }
   tree.view.selection.selectEventsSuppressed = false;
 }
 
 function DeleteSignon() {
-  var syncNeeded = (signonsTreeView._filterSet.length != 0);
+  let syncNeeded = (signonsTreeView._filterSet.length != 0);
   DeleteSelectedItemFromTree(signonsTree, signonsTreeView,
                              signonsTreeView._filterSet.length ? signonsTreeView._filterSet : signons,
                              deletedSignons, "removeSignon", "removeAllSignons");
   FinalizeSignonDeletions(syncNeeded);
 }
 
 function DeleteAllFromTree(tree, view, table, deletedTable, removeButton, removeAllButton) {
 
   // remove all items from table and place in deleted table
-  for (var i=0; i<table.length; i++) {
+  for (let i=0; i<table.length; i++) {
     deletedTable[deletedTable.length] = table[i];
   }
   table.length = 0;
 
   // clear out selections
   view.selection.select(-1);
 
   // update the tree view and notify the tree
   view.rowCount = 0;
 
-  var box = tree.treeBoxObject;
+  let box = tree.treeBoxObject;
   box.rowCountChanged(0, -deletedTable.length);
   box.invalidate();
 
 
   // disable buttons
   document.getElementById(removeButton).setAttribute("disabled", "true")
   document.getElementById(removeAllButton).setAttribute("disabled", "true");
 }
 
 function DeleteAllSignons() {
-  var prompter = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
+  let prompter = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
                            .getService(Components.interfaces.nsIPromptService);
 
   // Confirm the user wants to remove all passwords
-  var dummy = { value: false };
+  let dummy = { value: false };
   if (prompter.confirmEx(window,
                          kSignonBundle.getString("removeAllPasswordsTitle"),
                          kSignonBundle.getString("removeAllPasswordsPrompt"),
                          prompter.STD_YES_NO_BUTTONS + prompter.BUTTON_POS_1_DEFAULT,
                          null, null, null, null, dummy) == 1) // 1 == "No" button
     return;
 
-  var syncNeeded = (signonsTreeView._filterSet.length != 0);
+  let syncNeeded = (signonsTreeView._filterSet.length != 0);
   DeleteAllFromTree(signonsTree, signonsTreeView,
                         signonsTreeView._filterSet.length ? signonsTreeView._filterSet : signons,
                         deletedSignons, "removeSignon", "removeAllSignons");
   FinalizeSignonDeletions(syncNeeded);
   Services.telemetry.getHistogramById("PWMGR_MANAGE_DELETED_ALL").add(1);
 }
 
 function TogglePasswordVisible() {
@@ -464,28 +464,28 @@ function TogglePasswordVisible() {
 
   // Notify observers that the password visibility toggling is
   // completed.  (Mostly useful for tests)
   kObserverService.notifyObservers(null, "passwordmgr-password-toggle-complete", null);
   Services.telemetry.getHistogramById("PWMGR_MANAGE_VISIBILITY_TOGGLED").add(showingPasswords);
 }
 
 function AskUserShowPasswords() {
-  var prompter = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
-  var dummy = { value: false };
+  let prompter = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
+  let dummy = { value: false };
 
   // Confirm the user wants to display passwords
   return prompter.confirmEx(window,
           null,
           kSignonBundle.getString("noMasterPasswordPrompt"), prompter.STD_YES_NO_BUTTONS,
           null, null, null, null, dummy) == 0;    // 0=="Yes" button
 }
 
 function FinalizeSignonDeletions(syncNeeded) {
-  for (var s = 0; s < deletedSignons.length; s++) {
+  for (let s = 0; s < deletedSignons.length; s++) {
     passwordmanager.removeLogin(deletedSignons[s]);
     Services.telemetry.getHistogramById("PWMGR_MANAGE_DELETED").add(1);
   }
   // If the deletion has been performed in a filtered view, reflect the deletion in the unfiltered table.
   // See bug 405389.
   if (syncNeeded) {
     try {
       signons = passwordmanager.getAllLogins();
@@ -524,66 +524,66 @@ function getColumnByName(column) {
     case "timePasswordChanged":
       return document.getElementById("timePasswordChangedCol");
     case "timesUsed":
       return document.getElementById("timesUsedCol");
   }
   return undefined;
 }
 
-var lastSignonSortColumn = "hostname";
-var lastSignonSortAscending = true;
+let lastSignonSortColumn = "hostname";
+let lastSignonSortAscending = true;
 
 function SignonColumnSort(column) {
   // clear out the sortDirection attribute on the old column
-  var lastSortedCol = getColumnByName(lastSignonSortColumn);
+  let lastSortedCol = getColumnByName(lastSignonSortColumn);
   lastSortedCol.removeAttribute("sortDirection");
 
   // sort
   lastSignonSortAscending =
     SortTree(signonsTree, signonsTreeView,
                  signonsTreeView._filterSet.length ? signonsTreeView._filterSet : signons,
                  column, lastSignonSortColumn, lastSignonSortAscending);
   lastSignonSortColumn = column;
 
   // set the sortDirection attribute to get the styling going
   // first we need to get the right element
-  var sortedCol = getColumnByName(column);
+  let sortedCol = getColumnByName(column);
   sortedCol.setAttribute("sortDirection", lastSignonSortAscending ?
                                           "ascending" : "descending");
 }
 
 function SignonClearFilter() {
-  var singleSelection = (signonsTreeView.selection.count == 1);
+  let singleSelection = (signonsTreeView.selection.count == 1);
 
   // Clear the Tree Display
   signonsTreeView.rowCount = 0;
   signonsTree.treeBoxObject.rowCountChanged(0, -signonsTreeView._filterSet.length);
   signonsTreeView._filterSet = [];
 
   // Just reload the list to make sure deletions are respected
   LoadSignons();
 
   // Restore selection
   if (singleSelection) {
     signonsTreeView.selection.clearSelection();
     for (let i = 0; i < signonsTreeView._lastSelectedRanges.length; ++i) {
-      var range = signonsTreeView._lastSelectedRanges[i];
+      let range = signonsTreeView._lastSelectedRanges[i];
       signonsTreeView.selection.rangedSelect(range.min, range.max, true);
     }
   } else {
     signonsTreeView.selection.select(0);
   }
   signonsTreeView._lastSelectedRanges = [];
 
   document.getElementById("signonsIntro").textContent = kSignonBundle.getString("loginsDescriptionAll");
 }
 
 function FocusFilterBox() {
-  var filterBox = document.getElementById("filter");
+  let filterBox = document.getElementById("filter");
   if (filterBox.getAttribute("focused") != "true")
     filterBox.focus();
 }
 
 function SignonMatchesFilter(aSignon, aFilterValue) {
   if (aSignon.hostname.toLowerCase().indexOf(aFilterValue) != -1)
     return true;
   if (aSignon.username &&
@@ -601,34 +601,34 @@ function SignonMatchesFilter(aSignon, aF
 
 function FilterPasswords(aFilterValue, view) {
   aFilterValue = aFilterValue.toLowerCase();
   return signons.filter(s => SignonMatchesFilter(s, aFilterValue));
 }
 
 function SignonSaveState() {
   // Save selection
-  var seln = signonsTreeView.selection;
+  let seln = signonsTreeView.selection;
   signonsTreeView._lastSelectedRanges = [];
-  var rangeCount = seln.getRangeCount();
-  for (var i = 0; i < rangeCount; ++i) {
-    var min = {}; var max = {};
+  let rangeCount = seln.getRangeCount();
+  for (let i = 0; i < rangeCount; ++i) {
+    let min = {}; let max = {};
     seln.getRangeAt(i, min, max);
     signonsTreeView._lastSelectedRanges.push({ min: min.value, max: max.value });
   }
 }
 
 function _filterPasswords() {
-  var filter = document.getElementById("filter").value;
+  let filter = document.getElementById("filter").value;
   if (filter == "") {
     SignonClearFilter();
     return;
   }
 
-  var newFilterSet = FilterPasswords(filter, signonsTreeView);
+  let newFilterSet = FilterPasswords(filter, signonsTreeView);
   if (!signonsTreeView._filterSet.length) {
     // Save Display Info for the Non-Filtered mode when we first
     // enter Filtered mode.
     SignonSaveState();
   }
   signonsTreeView._filterSet = newFilterSet;
 
   // Clear the display
@@ -647,30 +647,30 @@ function _filterPasswords() {
 }
 
 function CopyPassword() {
   // Don't copy passwords if we aren't already showing the passwords & a master
   // password hasn't been entered.
   if (!showingPasswords && !masterPasswordLogin())
     return;
   // Copy selected signon's password to clipboard
-  var clipboard = Components.classes["@mozilla.org/widget/clipboardhelper;1"].
+  let clipboard = Components.classes["@mozilla.org/widget/clipboardhelper;1"].
                   getService(Components.interfaces.nsIClipboardHelper);
-  var row = document.getElementById("signonsTree").currentIndex;
-  var password = signonsTreeView.getCellText(row, {id : "passwordCol" });
+  let row = document.getElementById("signonsTree").currentIndex;
+  let password = signonsTreeView.getCellText(row, {id : "passwordCol" });
   clipboard.copyString(password);
   Services.telemetry.getHistogramById("PWMGR_MANAGE_COPIED_PASSWORD").add(1);
 }
 
 function CopyUsername() {
   // Copy selected signon's username to clipboard
-  var clipboard = Components.classes["@mozilla.org/widget/clipboardhelper;1"].
+  let clipboard = Components.classes["@mozilla.org/widget/clipboardhelper;1"].
                   getService(Components.interfaces.nsIClipboardHelper);
-  var row = document.getElementById("signonsTree").currentIndex;
-  var username = signonsTreeView.getCellText(row, {id : "userCol" });
+  let row = document.getElementById("signonsTree").currentIndex;
+  let username = signonsTreeView.getCellText(row, {id : "userCol" });
   clipboard.copyString(username);
   Services.telemetry.getHistogramById("PWMGR_MANAGE_COPIED_USERNAME").add(1);
 }
 
 function EditCellInSelectedRow(columnName) {
   let row = signonsTree.currentIndex;
   let columnElement = getColumnByName(columnName);
   signonsTree.startEditing(row, signonsTree.columns.getColumnFor(columnElement));
@@ -708,19 +708,19 @@ function UpdateContextMenu() {
     menuItems.get("context-editpassword").removeAttribute("disabled");
   } else {
     menuItems.get("context-editpassword").setAttribute("disabled", "true");
   }
 }
 
 function masterPasswordLogin(noPasswordCallback) {
   // This doesn't harm if passwords are not encrypted
-  var tokendb = Components.classes["@mozilla.org/security/pk11tokendb;1"]
+  let tokendb = Components.classes["@mozilla.org/security/pk11tokendb;1"]
                     .createInstance(Components.interfaces.nsIPK11TokenDB);
-  var token = tokendb.getInternalKeyToken();
+  let token = tokendb.getInternalKeyToken();
 
   // If there is no master password, still give the user a chance to opt-out of displaying passwords
   if (token.checkPassword(""))
     return noPasswordCallback ? noPasswordCallback() : true;
 
   // So there's a master password. But since checkPassword didn't succeed, we're logged out (per nsIPK11Token.idl).
   try {
     // Relogin and ask for the master password.