Bug 1467713 - Part 4 - Replace "var" with "let" and remove the parameter prefix. r=jaws
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Tue, 05 Jun 2018 17:30:43 +0100
changeset 476237 2ebd60198511bd7465b04740c4a1b514dd039c34
parent 476236 cd9e34c79fdb5bb215f7175baa04c6c54bc519a3
child 476238 6bc3fc83fceae397dc3bb0941b12ee43d1124340
push id9374
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:43:20 +0000
treeherdermozilla-beta@160e085dfb0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1467713
milestone62.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 1467713 - Part 4 - Replace "var" with "let" and remove the parameter prefix. r=jaws MozReview-Commit-ID: 61k7xS2MlKr
browser/components/preferences/permissions.js
--- a/browser/components/preferences/permissions.js
+++ b/browser/components/preferences/permissions.js
@@ -56,83 +56,83 @@ var gPermissionManager = {
   _tree: null,
   _observerRemoved: false,
 
   _view: {
     _rowCount: 0,
     get rowCount() {
       return this._rowCount;
     },
-    getCellText(aRow, aColumn) {
-      if (aColumn.id == "siteCol")
-        return gPermissionManager._permissions[aRow].origin;
-      else if (aColumn.id == "statusCol")
-        return gPermissionManager._permissions[aRow].capability;
+    getCellText(row, column) {
+      if (column.id == "siteCol")
+        return gPermissionManager._permissions[row].origin;
+      else if (column.id == "statusCol")
+        return gPermissionManager._permissions[row].capability;
       return "";
     },
 
-    isSeparator(aIndex) { return false; },
+    isSeparator(index) { return false; },
     isSorted() { return false; },
-    isContainer(aIndex) { return false; },
-    setTree(aTree) {},
-    getImageSrc(aRow, aColumn) {},
-    getCellValue(aRow, aColumn) {},
+    isContainer(index) { return false; },
+    setTree(tree) {},
+    getImageSrc(row, column) {},
+    getCellValue(row, column) {},
     cycleHeader(column) {},
     getRowProperties(row) { return ""; },
     getColumnProperties(column) { return ""; },
     getCellProperties(row, column) {
       if (column.element.getAttribute("id") == "siteCol")
         return "ltr";
 
       return "";
     }
   },
 
   onLoad() {
     this._bundle = document.getElementById("bundlePreferences");
-    var params = window.arguments[0];
+    let params = window.arguments[0];
     document.mozSubdialogReady = this.init(params);
   },
 
-  async init(aParams) {
+  async init(params) {
     if (this._type) {
       // reusing an open dialog, clear the old observer
       this.uninit();
     }
 
-    this._type = aParams.permissionType;
-    this._manageCapability = aParams.manageCapability;
+    this._type = params.permissionType;
+    this._manageCapability = params.manageCapability;
 
     const l10n = permissionExceptionsL10n[this._type];
     let permissionsText = document.getElementById("permissionsText");
     document.l10n.setAttributes(permissionsText, l10n.description);
 
     document.l10n.setAttributes(document.documentElement, l10n.window);
 
     await document.l10n.translateElements([
       document.documentElement,
       permissionsText,
     ]);
 
-    document.getElementById("btnBlock").hidden    = !aParams.blockVisible;
-    document.getElementById("btnSession").hidden  = !aParams.sessionVisible;
-    document.getElementById("btnAllow").hidden    = !aParams.allowVisible;
+    document.getElementById("btnBlock").hidden    = !params.blockVisible;
+    document.getElementById("btnSession").hidden  = !params.sessionVisible;
+    document.getElementById("btnAllow").hidden    = !params.allowVisible;
 
-    var urlFieldVisible = (aParams.blockVisible || aParams.sessionVisible || aParams.allowVisible);
+    let urlFieldVisible = (params.blockVisible || params.sessionVisible || params.allowVisible);
 
-    var urlField = document.getElementById("url");
-    urlField.value = aParams.prefilledHost;
+    let urlField = document.getElementById("url");
+    urlField.value = params.prefilledHost;
     urlField.hidden = !urlFieldVisible;
 
     this.onHostInput(urlField);
 
-    var urlLabel = document.getElementById("urlLabel");
+    let urlLabel = document.getElementById("urlLabel");
     urlLabel.hidden = !urlFieldVisible;
 
-    if (aParams.hideStatusColumn) {
+    if (params.hideStatusColumn) {
       document.getElementById("statusCol").hidden = true;
     }
 
     let treecols = document.getElementsByTagName("treecols")[0];
     treecols.addEventListener("click", event => {
       if (event.target.nodeName != "treecol" || event.button != 0) {
         return;
       }
@@ -156,35 +156,35 @@ var gPermissionManager = {
   uninit() {
     if (!this._observerRemoved) {
       Services.obs.removeObserver(this, "perm-changed");
 
       this._observerRemoved = true;
     }
   },
 
-  observe(aSubject, aTopic, aData) {
-    if (aTopic == "perm-changed") {
-      var permission = aSubject.QueryInterface(Ci.nsIPermission);
+  observe(subject, topic, data) {
+    if (topic == "perm-changed") {
+      let permission = subject.QueryInterface(Ci.nsIPermission);
 
       // Ignore unrelated permission types.
       if (permission.type != this._type)
         return;
 
-      if (aData == "added") {
+      if (data == "added") {
         this._addPermission(permission);
-      } else if (aData == "changed") {
-        for (var i = 0; i < this._permissions.length; ++i) {
+      } else if (data == "changed") {
+        for (let i = 0; i < this._permissions.length; ++i) {
           if (permission.matches(this._permissions[i].principal, true)) {
             this._permissions[i].capability = this._getCapabilityString(permission.capability);
             break;
           }
         }
         this._handleCapabilityChange();
-      } else if (aData == "deleted") {
+      } else if (data == "deleted") {
         this._removePermissionFromList(permission.principal);
       }
     }
   },
 
   _resortPermissions() {
     gTreeUtils.sort(this._tree, this._view, this._permissions,
                     this._lastPermissionSortColumn,
@@ -198,60 +198,60 @@ var gPermissionManager = {
     // or vice versa, since if we're sorted on status, we may no
     // longer be in order.
     if (this._lastPermissionSortColumn == "statusCol") {
       this._resortPermissions();
     }
     this._tree.treeBoxObject.invalidate();
   },
 
-  _getCapabilityString(aCapability) {
-    var stringKey = null;
-    switch (aCapability) {
+  _getCapabilityString(capability) {
+    let stringKey = null;
+    switch (capability) {
     case nsIPermissionManager.ALLOW_ACTION:
       stringKey = "can";
       break;
     case nsIPermissionManager.DENY_ACTION:
       stringKey = "cannot";
       break;
     case nsICookiePermission.ACCESS_ALLOW_FIRST_PARTY_ONLY:
       stringKey = "canAccessFirstParty";
       break;
     case nsICookiePermission.ACCESS_SESSION:
       stringKey = "canSession";
       break;
     }
     return this._bundle.getString(stringKey);
   },
 
-  _addPermission(aPermission) {
-    this._addPermissionToList(aPermission);
+  _addPermission(permission) {
+    this._addPermissionToList(permission);
     ++this._view._rowCount;
     this._tree.treeBoxObject.rowCountChanged(this._view.rowCount - 1, 1);
     // Re-do the sort, since we inserted this new item at the end.
     this._resortPermissions();
   },
 
-  _addPermissionToList(aPermission) {
-    if (aPermission.type == this._type &&
+  _addPermissionToList(permission) {
+    if (permission.type == this._type &&
         (!this._manageCapability ||
-         (aPermission.capability == this._manageCapability))) {
+         (permission.capability == this._manageCapability))) {
 
-      var principal = aPermission.principal;
-      var capabilityString = this._getCapabilityString(aPermission.capability);
-      var p = new Permission(principal,
-                             aPermission.type,
+      let principal = permission.principal;
+      let capabilityString = this._getCapabilityString(permission.capability);
+      let p = new Permission(principal,
+                             permission.type,
                              capabilityString);
       this._permissions.push(p);
     }
   },
 
-  addPermission(aCapability) {
-    var textbox = document.getElementById("url");
-    var input_url = textbox.value.replace(/^\s*/, ""); // trim any leading space
+  addPermission(capability) {
+    let textbox = document.getElementById("url");
+    let input_url = textbox.value.replace(/^\s*/, ""); // trim any leading space
     let principal;
     try {
       // The origin accessor on the principal object will throw if the
       // principal doesn't have a canonical origin representation. This will
       // help catch cases where the URI parser parsed something like
       // `localhost:8080` as having the scheme `localhost`, rather than being
       // an invalid URI. A canonical origin representation is required by the
       // permission manager for storage, so this won't prevent any valid
@@ -274,33 +274,33 @@ var gPermissionManager = {
         {id: "permissions-invalid-uri-title"},
         {id: "permissions-invalid-uri-label"}
       ]).then(([title, message]) => {
         Services.prompt.alert(window, title, message);
       });
       return;
     }
 
-    var capabilityString = this._getCapabilityString(aCapability);
+    let capabilityString = this._getCapabilityString(capability);
 
     // check whether the permission already exists, if not, add it
     let permissionExists = false;
     let capabilityExists = false;
-    for (var i = 0; i < this._permissions.length; ++i) {
+    for (let i = 0; i < this._permissions.length; ++i) {
       if (this._permissions[i].principal.equals(principal)) {
         permissionExists = true;
         capabilityExists = this._permissions[i].capability == capabilityString;
         if (!capabilityExists) {
           this._permissions[i].capability = capabilityString;
         }
         break;
       }
     }
 
-    let permissionParams = {principal, type: this._type, capability: aCapability};
+    let permissionParams = {principal, type: this._type, capability};
     if (!permissionExists) {
       this._permissionsToAdd.set(principal.origin, permissionParams);
       this._addPermission(permissionParams);
     } else if (!capabilityExists) {
       this._permissionsToAdd.set(principal.origin, permissionParams);
       this._handleCapabilityChange();
     }
 
@@ -309,118 +309,118 @@ var gPermissionManager = {
 
     // covers a case where the site exists already, so the buttons don't disable
     this.onHostInput(textbox);
 
     // enable "remove all" button as needed
     document.getElementById("removeAllPermissions").disabled = this._permissions.length == 0;
   },
 
-  _removePermission(aPermission) {
-    this._removePermissionFromList(aPermission.principal);
+  _removePermission(permission) {
+    this._removePermissionFromList(permission.principal);
 
     // If this permission was added during this session, let's remove
     // it from the pending adds list to prevent calls to the
     // permission manager.
-    let isNewPermission = this._permissionsToAdd.delete(aPermission.principal.origin);
+    let isNewPermission = this._permissionsToAdd.delete(permission.principal.origin);
 
     if (!isNewPermission) {
-      this._permissionsToDelete.set(aPermission.principal.origin, aPermission);
+      this._permissionsToDelete.set(permission.principal.origin, permission);
     }
 
   },
 
-  _removePermissionFromList(aPrincipal) {
+  _removePermissionFromList(principal) {
     for (let i = 0; i < this._permissions.length; ++i) {
-      if (this._permissions[i].principal.equals(aPrincipal)) {
+      if (this._permissions[i].principal.equals(principal)) {
         this._permissions.splice(i, 1);
         this._view._rowCount--;
         this._tree.treeBoxObject.rowCountChanged(this._view.rowCount - 1, -1);
         this._tree.treeBoxObject.invalidate();
         break;
       }
     }
   },
 
   _loadPermissions() {
     this._tree = document.getElementById("permissionsTree");
     this._permissions = [];
 
     // load permissions into a table
-    var enumerator = Services.perms.enumerator;
+    let enumerator = Services.perms.enumerator;
     while (enumerator.hasMoreElements()) {
-      var nextPermission = enumerator.getNext().QueryInterface(Ci.nsIPermission);
+      let nextPermission = enumerator.getNext().QueryInterface(Ci.nsIPermission);
       this._addPermissionToList(nextPermission);
     }
 
     this._view._rowCount = this._permissions.length;
 
     // sort and display the table
     this._tree.view = this._view;
     this.onPermissionSort("origin");
 
     // disable "remove all" button if there are none
     document.getElementById("removeAllPermissions").disabled = this._permissions.length == 0;
   },
 
-  onWindowKeyPress(aEvent) {
-    if (aEvent.keyCode == KeyEvent.DOM_VK_ESCAPE)
+  onWindowKeyPress(event) {
+    if (event.keyCode == KeyEvent.DOM_VK_ESCAPE)
       window.close();
   },
 
-  onPermissionKeyPress(aEvent) {
-    if (aEvent.keyCode == KeyEvent.DOM_VK_DELETE) {
+  onPermissionKeyPress(event) {
+    if (event.keyCode == KeyEvent.DOM_VK_DELETE) {
       this.onPermissionDelete();
     } else if (AppConstants.platform == "macosx" &&
-               aEvent.keyCode == KeyEvent.DOM_VK_BACK_SPACE) {
+               event.keyCode == KeyEvent.DOM_VK_BACK_SPACE) {
       this.onPermissionDelete();
-      aEvent.preventDefault();
+      event.preventDefault();
     }
   },
 
-  onHostKeyPress(aEvent) {
-    if (aEvent.keyCode == KeyEvent.DOM_VK_RETURN)
+  onHostKeyPress(event) {
+    if (event.keyCode == KeyEvent.DOM_VK_RETURN)
       document.getElementById("btnAllow").click();
   },
 
-  onHostInput(aSiteField) {
-    document.getElementById("btnSession").disabled = !aSiteField.value;
-    document.getElementById("btnBlock").disabled = !aSiteField.value;
-    document.getElementById("btnAllow").disabled = !aSiteField.value;
+  onHostInput(siteField) {
+    document.getElementById("btnSession").disabled = !siteField.value;
+    document.getElementById("btnBlock").disabled = !siteField.value;
+    document.getElementById("btnAllow").disabled = !siteField.value;
   },
 
   onPermissionDelete() {
     if (!this._view.rowCount)
       return;
-    var removedPermissions = [];
+    let removedPermissions = [];
     gTreeUtils.deleteSelectedItems(this._tree, this._view, this._permissions, removedPermissions);
-    for (var i = 0; i < removedPermissions.length; ++i) {
-      var p = removedPermissions[i];
+    for (let i = 0; i < removedPermissions.length; ++i) {
+      let p = removedPermissions[i];
       this._removePermission(p);
     }
     document.getElementById("removePermission").disabled = !this._permissions.length;
     document.getElementById("removeAllPermissions").disabled = !this._permissions.length;
   },
 
   onAllPermissionsDelete() {
     if (!this._view.rowCount)
       return;
-    var removedPermissions = [];
+    let removedPermissions = [];
     gTreeUtils.deleteAll(this._tree, this._view, this._permissions, removedPermissions);
-    for (var i = 0; i < removedPermissions.length; ++i) {
-      var p = removedPermissions[i];
+    for (let i = 0; i < removedPermissions.length; ++i) {
+      let p = removedPermissions[i];
       this._removePermission(p);
     }
     document.getElementById("removePermission").disabled = true;
     document.getElementById("removeAllPermissions").disabled = true;
   },
 
   onPermissionSelect() {
-    var hasSelection = this._tree.view.selection.count > 0;
-    var hasRows = this._tree.view.rowCount > 0;
+    let hasSelection = this._tree.view.selection.count > 0;
+    let hasRows = this._tree.view.rowCount > 0;
     document.getElementById("removePermission").disabled = !hasRows || !hasSelection;
     document.getElementById("removeAllPermissions").disabled = !hasRows;
   },
 
   onApplyChanges() {
     // Stop observing permission changes since we are about
     // to write out the pending adds/deletes and don't need
     // to update the UI
@@ -438,28 +438,28 @@ var gPermissionManager = {
   },
 
   _lastPermissionSortColumn: "",
   _lastPermissionSortAscending: false,
   _permissionsComparator(a, b) {
     return a.toLowerCase().localeCompare(b.toLowerCase());
   },
 
-  onPermissionSort(aColumn) {
+  onPermissionSort(column) {
     this._lastPermissionSortAscending = gTreeUtils.sort(this._tree,
                                                         this._view,
                                                         this._permissions,
-                                                        aColumn,
+                                                        column,
                                                         this._permissionsComparator,
                                                         this._lastPermissionSortColumn,
                                                         this._lastPermissionSortAscending);
-    this._lastPermissionSortColumn = aColumn;
+    this._lastPermissionSortColumn = column;
     let sortDirection = this._lastPermissionSortAscending ? "descending" : "ascending";
     let cols = document.querySelectorAll("treecol");
     cols.forEach(c => c.removeAttribute("sortDirection"));
-    let column = document.querySelector(`treecol[data-field-name=${aColumn}]`);
-    column.setAttribute("sortDirection", sortDirection);
+    document.querySelector(`treecol[data-field-name=${column}]`)
+            .setAttribute("sortDirection", sortDirection);
   },
 };
 
-function initWithParams(aParams) {
-  gPermissionManager.init(aParams);
+function initWithParams(params) {
+  gPermissionManager.init(params);
 }