Bug 1547581 - use arrow functions when calling methods from addEventListener to use 'this' from the enclosing lexical scope. r=darktrojan
authoraceman <acelists@atlas.sk>
Tue, 21 May 2019 14:56:00 +0200
changeset 35661 423c3668781ba823426e3b90850fc34dd9560f2f
parent 35660 db23151240208013bc4bc45357a5915c033a1855
child 35662 f6a39b92a2336dfeafbed1167897c0374abfeaeb
push id392
push userclokep@gmail.com
push dateMon, 02 Sep 2019 20:17:19 +0000
reviewersdarktrojan
bugs1547581
Bug 1547581 - use arrow functions when calling methods from addEventListener to use 'this' from the enclosing lexical scope. r=darktrojan
mail/base/content/sanitizeDialog.js
mail/components/preferences/advanced.js
mail/components/preferences/applicationManager.js
mail/components/preferences/applicationManager.xul
mail/components/preferences/applications.js
mail/components/preferences/attachmentReminder.js
mail/components/preferences/compose.js
mail/components/preferences/fonts.js
mailnews/base/content/msgSelectOfflineFolders.js
mailnews/base/content/virtualFolderListEdit.js
--- a/mail/base/content/sanitizeDialog.js
+++ b/mail/base/content/sanitizeDialog.js
@@ -226,9 +226,9 @@ var gSanitizePromptDialog = {
 
     if (itemList.collapsed)
       this.showItemList();
     else
       this.hideItemList();
   },
 };
 
-document.addEventListener("dialogaccept", gSanitizePromptDialog.sanitize);
+document.addEventListener("dialogaccept", () => gSanitizePromptDialog.sanitize());
--- a/mail/components/preferences/advanced.js
+++ b/mail/components/preferences/advanced.js
@@ -697,17 +697,17 @@ var gAdvancedPane = {
 
       let description = document.createXULElement("description");
       description.classList.add("message-bar-description");
       description.setAttribute("flex", "1");
       description.textContent = messages[i];
       messageContainer.appendChild(description);
 
       let button = document.createXULElement("button");
-      button.addEventListener("command", gAdvancedPane.confirmLanguageChange);
+      button.addEventListener("command", () => gAdvancedPane.confirmLanguageChange());
       button.classList.add("message-bar-button");
       button.setAttribute("locales", locales.join(","));
       button.setAttribute("label", buttonLabels[i]);
       messageContainer.appendChild(button);
 
       contentContainer.appendChild(messageContainer);
     }
 
--- a/mail/components/preferences/applicationManager.js
+++ b/mail/components/preferences/applicationManager.js
@@ -93,9 +93,9 @@ var gAppManagerDialog = {
     document.getElementById("appLocation").value = address;
     var bundle = document.getElementById("appManagerBundle");
     var appType = (app instanceof Ci.nsILocalHandlerApp) ?
                     "descriptionLocalApp" : "descriptionWebApp";
     document.getElementById("appType").value = bundle.getString(appType);
   },
 };
 
-document.addEventListener("dialogaccept", gAppManagerDialog.onOK);
+document.addEventListener("dialogaccept", () => gAppManagerDialog.onOK());
--- a/mail/components/preferences/applicationManager.xul
+++ b/mail/components/preferences/applicationManager.xul
@@ -10,16 +10,17 @@
 <dialog id="appManager"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
         buttons="accept,cancel"
         onload="gAppManagerDialog.init();"
         title="&appManager.title;"
         style="&appManager.style;"
         persist="screenX screenY">
 
+  <script src="chrome://global/content/preferencesBindings.js"/>
   <script src="chrome://messenger/content/preferences/applications.js"/>
   <script src="chrome://messenger/content/preferences/applicationManager.js"/>
 
   <commandset id="appManagerCommandSet">
     <command id="cmd_delete"
              oncommand="gAppManagerDialog.remove();"
              disabled="true"/>
   </commandset>
--- a/mail/components/preferences/applications.js
+++ b/mail/components/preferences/applications.js
@@ -2,16 +2,17 @@
  * 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";
 
 /* import-globals-from preferences.js */
 /* import-globals-from subdialogs.js */
+/* import-globals-from ../../../../toolkit/content/preferencesBindings.js */
 
 // applications.inc.xul
 /* globals ICON_URL_APP */
 
 // ------------------------------
 // Constants & Enumeration Values
 
 // For CSS. Can be one of "ask", "save", or "feed". If absent, the icon URL
@@ -32,18 +33,19 @@ XPCOMUtils.defineLazyServiceGetters(this
 });
 
 Preferences.addAll([
   { id: "mail.preferences.applications.selectedTabIndex", type: "int" },
   { id: "mail.compose.big_attachments.notify", type: "bool" },
   { id: "mail.compose.big_attachments.threshold_kb", type: "int" },
 ]);
 
-document.getElementById("paneApplications")
-        .addEventListener("paneload", function() { gApplicationsTabController.init(); });
+if (document.getElementById("paneApplications"))
+  document.getElementById("paneApplications")
+          .addEventListener("paneload", () => gApplicationsTabController.init());
 
 // ---------
 // Utilities
 
 function getDisplayNameForFile(aFile) {
   if (AppConstants.platform == "win") {
     if (aFile instanceof Ci.nsILocalFileWin) {
       try {
@@ -475,17 +477,16 @@ var gApplicationsTabController = {
       // Hide the tab selector
       let tabs = document.getElementById("attachmentPrefsTabs");
       tabs.hidden = true;
       this.mInitialized = true;
       return;
     }
 
     gCloudFileTab.init();
-    this.paneSelectionChanged = this.paneSelectionChanged.bind(this);
     window.addEventListener("paneSelected", this.paneSelectionChanged);
 
     if (!(("arguments" in window) && window.arguments[1])) {
       // If no tab was specified, select the last used tab.
       let preference = Preferences.get("mail.preferences.applications.selectedTabIndex");
       this.mTabBox.selectedIndex = preference.value != null ? preference.value : this.mDefaultIndex;
     }
 
--- a/mail/components/preferences/attachmentReminder.js
+++ b/mail/components/preferences/attachmentReminder.js
@@ -73,9 +73,9 @@ var gAttachmentReminderOptionsDialog = {
         keywordList += ",";
     }
 
     Services.prefs.setStringPref("mail.compose.attachment_reminder_keywords",
                                  keywordList);
   },
 };
 
-document.addEventListener("dialogaccept", gAttachmentReminderOptionsDialog.saveKeywords);
+document.addEventListener("dialogaccept", () => gAttachmentReminderOptionsDialog.saveKeywords());
--- a/mail/components/preferences/compose.js
+++ b/mail/components/preferences/compose.js
@@ -275,17 +275,17 @@ var gComposePane = {
       // If the default startup directory prefs have changed,
       // reinitialize the default startup dir picker to show the new value.
       gComposePane.initAbDefaultStartupDir();
     },
     load() {
       // Observe changes of our prefs.
       Services.prefs.addObserver(this.domain, this);
       // Unload the pref observer when preferences window is closed.
-      window.addEventListener("unload", this.unload, true);
+      window.addEventListener("unload", () => this.unload(), true);
       this.inited = true;
     },
 
     unload(event) {
       Services.prefs.removeObserver(gComposePane.startupDirListener.domain,
                                     gComposePane.startupDirListener);
     },
   },
--- a/mail/components/preferences/fonts.js
+++ b/mail/components/preferences/fonts.js
@@ -124,9 +124,9 @@ var gFontsDialog = {
       Services.prefs.clearUserPref("mailnews.send_default_charset");
 
     if (viewCharsetStr === defaultPrefs.getComplexValue(
           "view_default_charset", Ci.nsIPrefLocalizedString).data)
       Services.prefs.clearUserPref("mailnews.view_default_charset");
   },
 };
 
-document.addEventListener("dialogaccept", gFontsDialog.ondialogaccept);
+document.addEventListener("dialogaccept", () => gFontsDialog.ondialogaccept());
--- a/mailnews/base/content/msgSelectOfflineFolders.js
+++ b/mailnews/base/content/msgSelectOfflineFolders.js
@@ -99,10 +99,10 @@ var gSelectOffline = {
     gFolderTreeView.unload();
     for (let [folder, value] of this._rollbackMap) {
       if (value != folder.getFlag(Ci.nsMsgFolderFlags.Offline))
         folder.toggleFlag(Ci.nsMsgFolderFlags.Offline);
     }
   },
 };
 
-document.addEventListener("dialogaccept", gSelectOffline.onAccept);
-document.addEventListener("dialogcancel", gSelectOffline.onCancel);
+document.addEventListener("dialogaccept", () => gSelectOffline.onAccept());
+document.addEventListener("dialogcancel", () => gSelectOffline.onCancel());
--- a/mailnews/base/content/virtualFolderListEdit.js
+++ b/mailnews/base/content/virtualFolderListEdit.js
@@ -101,10 +101,10 @@ var gSelectVirtual = {
       window.arguments[0].okCallback(uris);
   },
 
   onCancel() {
     gFolderTreeView.unload();
   },
 };
 
-document.addEventListener("dialogaccept", gSelectVirtual.onAccept);
-document.addEventListener("dialogcancel", gSelectVirtual.onCancel);
+document.addEventListener("dialogaccept", () => gSelectVirtual.onAccept());
+document.addEventListener("dialogcancel", () => gSelectVirtual.onCancel());