Bug 1151475 - Part 1: Remove use of expression closure from mail/base/. r=mkmelin
authorTooru Fujisawa <arai_a@mac.com>
Mon, 20 Apr 2015 00:16:23 +0900
changeset 22475 07a6ec81889a816f9d850c6f68567cbe074228e5
parent 22474 db3e708b2267baff9b6a85daa51e209dc2a0ae6a
child 22476 1f40bc6a4a87b41a019be9d0f174ab64d0d7cf96
push idunknown
push userunknown
push dateunknown
reviewersmkmelin
bugs1151475
Bug 1151475 - Part 1: Remove use of expression closure from mail/base/. r=mkmelin
mail/base/content/folderPane.js
mail/base/content/glodaFacetBindings.xml
mail/base/content/glodaFacetView.js
mail/base/content/glodaFacetVis.js
mail/base/content/mailWidgets.xml
mail/base/content/msgHdrViewOverlay.js
mail/base/content/msgMail3PaneWindow.js
mail/base/content/specialTabs.js
mail/base/modules/Windows8WindowFrameColor.jsm
mail/base/modules/oauth.jsm
--- a/mail/base/content/folderPane.js
+++ b/mail/base/content/folderPane.js
@@ -1129,17 +1129,17 @@ let gFolderTreeView = {
                                                      flag, folderName, position)
   {
     // If there's only one subFolder, just put it at the root.
     let subFolders = gFolderTreeView._allSmartFolders(accounts, flag, folderName, false);
     if (flag && subFolders.length == 1) {
       let folderItem = new ftvItem(subFolders[0]);
       folderItem._level = 0;
       if (flag & nsMsgFolderFlags.Inbox)
-        folderItem.__defineGetter__("children", function() []);
+        folderItem.__defineGetter__("children", () => []);
       if (position == undefined)
         map.push(folderItem);
       else
         map[position] = folderItem;
       // No smart folder was added
       return null;
     }
 
@@ -1178,17 +1178,17 @@ let gFolderTreeView = {
     let prevChild = null;
     // Each child is a level one below the smartFolder
     for each (let child in smartFolderItem._children) {
       child._level = smartFolderItem._level + 1;
       child._parent = smartFolderItem;
       // don't show sub-folders of the inbox, but I think Archives/Sent, etc
       // should have the sub-folders.
       if (flag & nsMsgFolderFlags.Inbox)
-        child.__defineGetter__("children", function() []);
+        child.__defineGetter__("children", () => []);
       // If we have consecutive children with the same server, then both
       // should display as folder - server.
       if (prevChild && (child._folder.server == prevChild._folder.server)) {
         child.addServerName = true;
         prevChild.addServerName = true;
         prevChild.useServerNameOnly = false;
       }
       else if (flag)
@@ -1502,17 +1502,17 @@ let gFolderTreeView = {
           if (!folder.isSpecialFolder(outFolderFlagMask, true) &&
               (!folder.isServer && folder.getNumUnread(false) > 0) ||
               (folder == currentFolder))
             map.push(new ftvItem(folder));
         }
 
         // There are no children in this view!
         for (let folder of map) {
-          folder.__defineGetter__("children", function() []);
+          folder.__defineGetter__("children", () => []);
           folder.addServerName = true;
         }
         sortFolderItems(map);
         return map;
       },
 
       getParentOfFolder: function(aFolder) {
         // This is a flat view, so no folders have parents.
@@ -1597,17 +1597,17 @@ let gFolderTreeView = {
           } else {
             uniqueNames.add(name);
           }
         }
 
         // There are no children in this view!
         for (let item of faves) {
           let name = item._folder.abbreviatedName.toLocaleLowerCase();
-          item.__defineGetter__("children", function() []);
+          item.__defineGetter__("children", () => []);
           item.addServerName = dupeNames.has(name);
         }
         sortFolderItems(faves);
         return faves;
       },
 
       getParentOfFolder: function(aFolder) {
         // This is a flat view, so no folders have parents.
@@ -1650,17 +1650,17 @@ let gFolderTreeView = {
         });
 
         let items = [new ftvItem(f) for (f of recentFolders)];
 
         // There are no children in this view!
         // And we want to display the account name to distinguish folders w/
         // the same name.
         for (let folder of items) {
-          folder.__defineGetter__("children", function() []);
+          folder.__defineGetter__("children", () => []);
           folder.addServerName = true;
         }
 
         return items;
       },
 
       getParentOfFolder: function(aFolder) {
         // This is a flat view, so no folders have parents.
@@ -1750,26 +1750,26 @@ let gFolderTreeView = {
       },
 
       /**
        * All the flags above, bitwise ORed.
        */
       get _allSmartFlags() {
         delete this._allSmartFlags;
         return this._allSmartFlags = this._flagNameList.reduce(
-          function (res, [flag,, isDeep,]) res | flag, 0);
+          (res, [flag,, isDeep,]) => res | flag, 0);
       },
 
       /**
        * All the "shallow" flags above (isDeep set to false), bitwise ORed.
        */
       get _allShallowFlags() {
         delete this._allShallowFlags;
         return this._allShallowFlags = this._flagNameList.reduce(
-          function (res, [flag,, isDeep,]) isDeep ? res : (res | flag), 0);
+          (res, [flag,, isDeep,]) => isDeep ? res : (res | flag), 0);
       },
 
       /**
        * Returns an array of 4 elements describing the smart folder
        * if the given folder is a special folder, else returns null.
        */
       _getSmartFolderType: function ftv_smart__getSmartFolderType(aFolder) {
         let smartFolderName = getSmartFolderName(aFolder);
@@ -2018,17 +2018,17 @@ let gFolderTreeView = {
       newChild = new ftv_SmartItem(aItem);
       parent.children.push(newChild);
       newChild._level = parent._level + 1;
       newChild._parent = parent;
       sortFolderItems(parent._children);
       newChild.useServerNameOnly = true;
     }
     if (aItem.flags & nsMsgFolderFlags.Inbox)
-      newChild.__defineGetter__("children", function() []);
+      newChild.__defineGetter__("children", () => []);
     if (parent)
       this._addChildToView(parent, parentIndex, newChild);
     else {
       this._rowMap.splice(newChildIndex, 0, newChild);
       this._tree.rowCountChanged(newChildIndex, 1);
     }
   },
   /**
--- a/mail/base/content/glodaFacetBindings.xml
+++ b/mail/base/content/glodaFacetBindings.xml
@@ -1650,17 +1650,17 @@
               // i+2 is the *byte* offset at which the term is in the string.
               // i+3 is the term's length.
               matches.push([offsetNums[i + 2], offsetNums[i + 3]]);
             }
 
             // Sort the matches by index, just to be sure.
             // They are probably already sorted, but if they aren't it could
             // mess things up at the next step.
-            matches.sort(function(a, b) a[0] - b[0]);
+            matches.sort((a, b) => a[0] - b[0]);
 
             // Convert the byte offsets and lengths into character indexes.
             let charCodeToByteCount = function(c) {
               // UTF-8 stores:
               // - code points below U+0080 on 1 byte,
               // - code points below U+0800 on 2 bytes,
               // - code points U+D800 through U+DFFF are UTF-16 surrogate halves
               // (they indicate that JS has split a 4 bytes UTF-8 character
--- a/mail/base/content/glodaFacetView.js
+++ b/mail/base/content/glodaFacetView.js
@@ -338,21 +338,21 @@ var FacetContext = {
 
   set fullSet(items) {
     let scores;
     if (this.searcher && this.searcher.scores)
       scores = this.searcher.scores;
     else
       scores = Gloda.scoreNounItems(items);
     let scoredItems = items.map(function(item, index) { return [scores[index], item]; });
-    scoredItems.sort(function(a,b) b[0]-a[0]);
+    scoredItems.sort((a, b) => b[0]-a[0]);
     this._relevantSortedItems = scoredItems.map(scoredItem => scoredItem[1]);
 
     this._dateSortedItems =
-      this._relevantSortedItems.concat().sort(function(a,b) b.date-a.date);
+      this._relevantSortedItems.concat().sort((a, b) => b.date-a.date);
   },
 
   initialBuild: function() {
     let queryExplanation = document.getElementById("query-explanation");
     if (this.searcher)
       queryExplanation.setFulltext(this.searcher);
     else
       queryExplanation.setQuery(this.collection.query);
--- a/mail/base/content/glodaFacetVis.js
+++ b/mail/base/content/glodaFacetVis.js
@@ -260,65 +260,64 @@ DateFacetVis.prototype = {
       .bottom(totalAxisLabelHeight);
 
     let faceter = this.faceter;
     let dis = this;
     // bin bars...
     vis.add(pv.Bar)
       .data(bins)
       .bottom(0)
-      .height(function (d) Math.floor(d.items.length * binScale))
-      .width(function() barWidth)
-      .left(function() isRTL ? null : (this.index * barPix))
-      .right(function() isRTL ? (this.index * barPix) : null)
+      .height(d => Math.floor(d.items.length * binScale))
+      .width(() => barWidth)
+      .left(function() { return isRTL ? null : (this.index * barPix); })
+      .right(function() { return isRTL ? (this.index * barPix) : null; })
       .fillStyle("#add2fb")
-      .event("mouseover", function(d) this.fillStyle("#3465a4"))
-      .event("mouseout", function(d) this.fillStyle("#add2fb"))
+      .event("mouseover", function(d) { return this.fillStyle("#3465a4"); })
+      .event("mouseout", function(d) { return this.fillStyle("#add2fb"); })
       .event("click", function(d) {
           dis.constraints = [[d.startDate, d.endDate]];
           dis.binding.setAttribute("zoomedout", "false");
           FacetContext.addFacetConstraint(faceter, true, dis.constraints,
                                           true, true);
         }
       );
 
     this.hotBars = vis.add(pv.Bar)
       .data(this.emptyBins)
       .bottom(0)
-      .height(function (d) Math.floor(d * binScale))
-      .width(function() barWidth)
-      .left(function() this.index * barPix)
+      .height(d => Math.floor(d * binScale))
+      .width(() => barWidth)
+      .left(function() { return this.index * barPix; })
       .fillStyle("#3465a4");
 
     for (let labelTier of labelTiers) {
       let labelBar = vis.add(pv.Bar)
         .data(labelTier.displayValues)
         .bottom(-totalAxisLabelHeight + labelTier.vertOffset)
         .height(labelTier.vertHeight)
-        .left(function(d) isRTL ? null : Math.floor(width * d[0]))
-        .right(function(d) isRTL ? Math.floor(width * d[0]) : null)
-        .width(function(d)
-                 Math.floor(width * d[1]) - Math.floor(width * d[0]) - 1)
+        .left(d => isRTL ? null : Math.floor(width * d[0]))
+        .right(d => isRTL ? Math.floor(width * d[0]) : null)
+        .width(d => Math.floor(width * d[1]) - Math.floor(width * d[0]) - 1)
         .fillStyle("#dddddd")
-        .event("mouseover", function(d) this.fillStyle("#3465a4"))
-        .event("mouseout", function(d) this.fillStyle("#dddddd"))
+        .event("mouseover", function(d) { return this.fillStyle("#3465a4"); })
+        .event("mouseout", function(d) { return this.fillStyle("#dddddd"); })
         .event("click", function(d) {
           dis.constraints = [[d[3], d[4]]];
           dis.binding.setAttribute("zoomedout", "false");
           FacetContext.addFacetConstraint(faceter, true, dis.constraints,
                                           true, true)
         });
 
       if (labelTier.displayLabel) {
         labelBar.anchor("top").add(pv.Label)
           .font(this._AXIS_FONT)
           .textAlign("center")
           .textBaseline("top")
           .textStyle("black")
-          .text(function(d) d[2]);
+          .text(d => d[2]);
       }
     }
 
 
     vis.render();
   },
 
   hoverItems: function(aItems) {
--- a/mail/base/content/mailWidgets.xml
+++ b/mail/base/content/mailWidgets.xml
@@ -20,22 +20,22 @@
   <!-- dummy widget to force this file to load -->
   <binding id="dummy" extends="xul:box"/>
 
   <binding id="attachmentlist-base" extends="chrome://global/content/bindings/listbox.xml#listbox-base">
     <implementation>
       <constructor><![CDATA[
         let children = Array.slice(this._childNodes);
 
-        children.filter(function(aChild) aChild.getAttribute("selected") == "true")
+        children.filter(aChild => aChild.getAttribute("selected") == "true")
                 .forEach(this.selectedItems.push, this.selectedItems);
 
-        children.filter(function(aChild) !aChild.hasAttribute("context"))
-                .forEach(function(aChild) aChild.setAttribute("context",
-                         this.getAttribute("itemcontext")), this);
+        children.filter(aChild => !aChild.hasAttribute("context"))
+                .forEach(aChild => aChild.setAttribute("context",
+                           this.getAttribute("itemcontext")));
 
         this.sizes = {small: 16, large: 32, tile: 32};
         this.messenger = Components.classes["@mozilla.org/messenger;1"]
                                    .createInstance(Components.interfaces.nsIMessenger);
 
       ]]></constructor>
 
       <!-- ///////////////// public members ///////////////// -->
--- a/mail/base/content/msgHdrViewOverlay.js
+++ b/mail/base/content/msgHdrViewOverlay.js
@@ -1168,17 +1168,17 @@ function HideMessageHeaderPane()
  * mail-newsgroups-headerfield element.
  *
  * @param headerEntry  the entry data structure for this header
  * @param headerValue  the string value for the header from the message
  */
 function OutputNewsgroups(headerEntry, headerValue)
 {
   headerValue.split(",").forEach(
-    function(newsgroup) headerEntry.enclosingBox.addNewsgroupView(newsgroup));
+    newsgroup => headerEntry.enclosingBox.addNewsgroupView(newsgroup));
 
   headerEntry.enclosingBox.buildViews();
 }
 
 /**
  * Take string of message-ids separated by whitespace, split it
  * into message-ids and send them together with the index number
  * to the corresponding mail-messageids-headerfield element.
--- a/mail/base/content/msgMail3PaneWindow.js
+++ b/mail/base/content/msgMail3PaneWindow.js
@@ -1792,19 +1792,19 @@ let TabsInTitlebar = {
   _readPref: function () {
     // check is only true when drawInTitlebar=true and autoHide=false
     let check = Services.prefs.getBoolPref(this._drawInTitlePref) &&
                 !Services.prefs.getBoolPref(this._autoHidePref);
     this.allowedBy("pref", check);
   },
 
   _update: function (aForce=false) {
-    function $(id) document.getElementById(id);
-    function rect(ele) ele.getBoundingClientRect();
-    function verticalMargins(cstyle) parseFloat(cstyle.marginBottom) + parseFloat(cstyle.marginTop);
+    function $(id) { return document.getElementById(id); }
+    function rect(ele) { return ele.getBoundingClientRect(); }
+    function verticalMargins(cstyle) { return parseFloat(cstyle.marginBottom) + parseFloat(cstyle.marginTop); }
 
     if (!this._initialized || window.fullScreen)
       return;
 
     let allowed = true;
 
     if (!aForce) {
       // _update is called on resize events, because the window is not ready
--- a/mail/base/content/specialTabs.js
+++ b/mail/base/content/specialTabs.js
@@ -980,17 +980,17 @@ var specialTabs = {
 
     modes: {
       chromeTab: {
         type: "chromeTab",
         maxTabs: 10
       }
     },
 
-    shouldSwitchTo: function ({ chromePage: x })
+    shouldSwitchTo: ({ chromePage: x }) =>
       contentTabBaseType.shouldSwitchTo({ contentPage: x }),
 
     /**
      * This is the internal function used by chrome tabs to open a new tab. To
      * open a chromeTab, use specialTabs.openTab("chromeTab", aArgs)
      *
      * @param aArgs The options that chrome tabs accept.
      * @param aArgs.chromePage A string that holds the URL that is to be opened
--- a/mail/base/modules/Windows8WindowFrameColor.jsm
+++ b/mail/base/modules/Windows8WindowFrameColor.jsm
@@ -26,17 +26,17 @@ const Windows8WindowFrameColor = {
       // Seems to be the default color (hardcoded because of bug 1065998, bug 1107902)
       return [158, 158, 158];
     }
     // The color returned from the Registry is in decimal form.
     let customizationColorHex = customizationColor.toString(16);
     // Zero-pad the number just to make sure that it is 8 digits.
     customizationColorHex = ("00000000" + customizationColorHex).substr(-8);
     let customizationColorArray = customizationColorHex.match(/../g);
-    let [unused, fgR, fgG, fgB] = customizationColorArray.map(function(val) parseInt(val, 16));
+    let [unused, fgR, fgG, fgB] = customizationColorArray.map(val => parseInt(val, 16));
     let colorizationColorBalance = Registry.readRegKey(HKCU, dwmKey,
                                                        "ColorizationColorBalance") || 78;
      // Window frame base color when Color Intensity is at 0, see bug 1004576.
     let frameBaseColor = 217;
     let alpha = colorizationColorBalance / 100;
 
     // Alpha-blend the foreground color with the frame base color.
     let r = Math.round(fgR * alpha + frameBaseColor * (1 - alpha));
--- a/mail/base/modules/oauth.jsm
+++ b/mail/base/modules/oauth.jsm
@@ -107,29 +107,29 @@ OAuth.prototype = {
 
     let dataParams = [];
     let url = /^https?:/.test(aUrl) ? aUrl : this.baseURI + aUrl;
     let urlSpec = url;
     let queryIndex = url.indexOf("?");
     if (queryIndex != -1) {
       urlSpec = url.slice(0, queryIndex);
       dataParams = url.slice(queryIndex + 1).split("&")
-                      .map(function(p) p.split("=").map(percentEncode));
+                      .map(p => p.split("=").map(percentEncode));
     }
     this.log.info("in sign and send url = " + url + "\nurlSpec = " + urlSpec);
     this.log.info("dataParams = " + dataParams);
 
     let signature;
     if (this.signatureMethod === "HMAC-SHA1") {
       let signatureKey = this.consumerSecret + "&" + this.tokenSecret;
       let signatureBase =
         aMethod + "&" + encodeURIComponent(urlSpec) + "&" +
         params.concat(dataParams)
-              .sort(function(a,b) (a[0] < b[0]) ? -1 : (a[0] > b[0]) ? 1 : 0)
-              .map(function(p) p.map(percentEncode).join("%3D"))
+              .sort((a, b) => (a[0] < b[0]) ? -1 : (a[0] > b[0]) ? 1 : 0)
+              .map(p => p.map(percentEncode).join("%3D"))
               .join("%26");
 
       this.log.info("sig base = " + signatureBase);
       let keyFactory = Cc["@mozilla.org/security/keyobjectfactory;1"]
                        .getService(Ci.nsIKeyObjectFactory);
       let hmac =
         Cc["@mozilla.org/security/hmac;1"].createInstance(Ci.nsICryptoHMAC);
       hmac.init(hmac.SHA1,
@@ -145,17 +145,17 @@ OAuth.prototype = {
     }
     else {
       throw Cr.NS_ERROR_NOT_IMPLEMENTED;
     }
 
     params.push(["oauth_signature", signature]);
 
     let authorization =
-      "OAuth " + params.map(function (p) p[0] + "=\"" + p[1] + "\"").join(", ");
+      "OAuth " + params.map(p => p[0] + "=\"" + p[1] + "\"").join(", ");
     let options = {
       headers: (aHeaders || []).concat([["Authorization", authorization]]),
       postData: aPOSTData,
       method: aMethod,
       onLoad: aOnLoad.bind(aThis),
       onError: aOnError.bind(aThis)
     };
     return httpRequest(url, options);