Bug 1394820 - Enable ESLint for DownloadIntegration.jsm r?Standard8 draft
authorDan Banner <dbugs@thebanners.uk>
Tue, 29 Aug 2017 18:57:11 +0100
changeset 655190 f7c35f473e7fa7feb62ea6e87c890723444f4231
parent 654592 1b4c59eef820b46eb0037aca68f83a15088db45f
child 728757 46f32611c2fc7a4521ccd79c582dbc3f40320663
push id76789
push userbmo:dbugs@thebanners.uk
push dateTue, 29 Aug 2017 17:57:38 +0000
reviewersStandard8
bugs1394820
milestone57.0a1
Bug 1394820 - Enable ESLint for DownloadIntegration.jsm r?Standard8 MozReview-Commit-ID: INwMSXSJ31f
.eslintignore
toolkit/components/jsdownloads/src/DownloadIntegration.jsm
--- a/.eslintignore
+++ b/.eslintignore
@@ -343,17 +343,16 @@ toolkit/modules/tests/xpcshell/test_task
 # External code:
 toolkit/components/microformats/test/**
 toolkit/components/microformats/microformat-shiv.js
 toolkit/components/reader/Readability.js
 toolkit/components/reader/JSDOMParser.js
 
 # Uses preprocessing
 toolkit/content/widgets/wizard.xml
-toolkit/components/jsdownloads/src/DownloadIntegration.jsm
 toolkit/components/osfile/osfile.jsm
 toolkit/components/urlformatter/nsURLFormatter.js
 toolkit/modules/AppConstants.jsm
 toolkit/mozapps/downloads/nsHelperAppDlg.js
 toolkit/mozapps/update/tests/data/xpcshellConstantsPP.js
 
 # Third party
 toolkit/modules/third_party/**
--- a/toolkit/components/jsdownloads/src/DownloadIntegration.jsm
+++ b/toolkit/components/jsdownloads/src/DownloadIntegration.jsm
@@ -75,16 +75,17 @@ XPCOMUtils.defineLazyServiceGetter(this,
            Ci.nsIApplicationReputationService);
 
 XPCOMUtils.defineLazyServiceGetter(this, "volumeService",
                                    "@mozilla.org/telephony/volume-service;1",
                                    "nsIVolumeService");
 
 // We have to use the gCombinedDownloadIntegration identifier because, in this
 // module only, the DownloadIntegration identifier refers to the base version.
+/* global gCombinedDownloadIntegration:false */
 Integration.downloads.defineModuleGetter(this, "gCombinedDownloadIntegration",
             "resource://gre/modules/DownloadIntegration.jsm",
             "DownloadIntegration");
 
 const Timer = Components.Constructor("@mozilla.org/timer;1", "nsITimer",
                                      "initWithCallback");
 
 /**
@@ -271,17 +272,17 @@ this.DownloadIntegration = {
       this._downloadsDirectory = gEnvironment.get("DOWNLOADS_DIRECTORY");
       if (!this._downloadsDirectory) {
         throw new Components.Exception("DOWNLOADS_DIRECTORY is not set.",
                                        Cr.NS_ERROR_FILE_UNRECOGNIZED_PATH);
       }
     } else {
       try {
         this._downloadsDirectory = this._getDirectory("DfltDwnld");
-      } catch(e) {
+      } catch (e) {
         this._downloadsDirectory = await this._createDownloadsDirectory("Home");
       }
     }
 
     return this._downloadsDirectory;
   },
   _downloadsDirectory: null,
 
@@ -290,38 +291,38 @@ this.DownloadIntegration = {
    *
    * @return {Promise}
    * @resolves The downloads directory string path.
    */
   async getPreferredDownloadsDirectory() {
     let directoryPath = null;
     let prefValue = Services.prefs.getIntPref("browser.download.folderList", 1);
 
-    switch(prefValue) {
+    switch (prefValue) {
       case 0: // Desktop
         directoryPath = this._getDirectory("Desk");
         break;
       case 1: // Downloads
         directoryPath = await this.getSystemDownloadsDirectory();
         break;
       case 2: // Custom
         try {
           let directory = Services.prefs.getComplexValue("browser.download.dir",
                                                          Ci.nsIFile);
           directoryPath = directory.path;
           await OS.File.makeDir(directoryPath, { ignoreExisting: true });
-        } catch(ex) {
+        } catch (ex) {
           // Either the preference isn't set or the directory cannot be created.
           directoryPath = await this.getSystemDownloadsDirectory();
         }
         break;
       case 3: // Cloud Storage
         try {
           directoryPath = await CloudStorage.getDownloadFolder();
-        } catch(ex) {}
+        } catch (ex) {}
         if (!directoryPath) {
           directoryPath = await this.getSystemDownloadsDirectory();
         }
         break;
       default:
         directoryPath = await this.getSystemDownloadsDirectory();
     }
     return directoryPath;
@@ -672,17 +673,17 @@ this.DownloadIntegration = {
    * Asks for confirmation for launching the specified executable file. This
    * can be overridden by regression tests to avoid the interactive prompt.
    */
   async confirmLaunchExecutable(path) {
     // We don't anchor the prompt to a specific window intentionally, not
     // only because this is the same behavior as the system-level prompt,
     // but also because the most recently active window is the right choice
     // in basically all cases.
-    return await DownloadUIHelper.getPrompter().confirmLaunchExecutable(path);
+    return DownloadUIHelper.getPrompter().confirmLaunchExecutable(path);
   },
 
   /**
    * Launches the specified file, unless overridden by regression tests.
    */
   launchFile(file, mimeInfo) {
     if (mimeInfo) {
       mimeInfo.launchWithFile(file);
@@ -957,20 +958,18 @@ this.DownloadObserver = {
         }
         for (let download of this._privateInProgressDownloads) {
           download.cancel();
           this._canceledOfflineDownloads.add(download);
         }
         break;
       case "wake_notification":
       case "resume_process_notification":
-        let wakeDelay = 10000;
-        try {
-          wakeDelay = Services.prefs.getIntPref("browser.download.manager.resumeOnWakeDelay");
-        } catch(e) {}
+        let wakeDelay =
+          Services.prefs.getIntPref("browser.download.manager.resumeOnWakeDelay", 10000);
 
         if (wakeDelay >= 0) {
           this._wakeTimer = new Timer(this._resumeOfflineDownloads.bind(this), wakeDelay,
                                       Ci.nsITimer.TYPE_ONE_SHOT);
         }
         break;
       case "network:offline-status-changed":
         if (aData == "online") {
@@ -999,18 +998,17 @@ this.DownloadObserver = {
  * reflected on the provided list of downloads.
  *
  * You do not need to keep a reference to this object in order to keep it alive,
  * because the history service already keeps a strong reference to it.
  *
  * @param aList
  *        DownloadList object linked to this observer.
  */
-this.DownloadHistoryObserver = function (aList)
-{
+this.DownloadHistoryObserver = function(aList) {
   this._list = aList;
   PlacesUtils.history.addObserver(this);
 }
 
 this.DownloadHistoryObserver.prototype = {
   /**
    * DownloadList object linked to this observer.
    */
@@ -1024,40 +1022,39 @@ this.DownloadHistoryObserver.prototype =
                                                       download.source.url)));
   },
 
   // nsINavHistoryObserver
   onClearHistory: function DL_onClearHistory() {
     this._list.removeFinished();
   },
 
-  onTitleChanged: function () {},
-  onBeginUpdateBatch: function () {},
-  onEndUpdateBatch: function () {},
-  onVisit: function () {},
-  onPageChanged: function () {},
-  onDeleteVisits: function () {},
+  onTitleChanged() {},
+  onBeginUpdateBatch() {},
+  onEndUpdateBatch() {},
+  onVisit() {},
+  onPageChanged() {},
+  onDeleteVisits() {},
 };
 
 /**
  * This view can be added to a DownloadList object to trigger a save operation
  * in the given DownloadStore object when a relevant change occurs.  You should
  * call the "initialize" method in order to register the view and load the
  * current state from disk.
  *
  * You do not need to keep a reference to this object in order to keep it alive,
  * because the DownloadList object already keeps a strong reference to it.
  *
  * @param aList
  *        The DownloadList object on which the view should be registered.
  * @param aStore
  *        The DownloadStore object used for saving.
  */
-this.DownloadAutoSaveView = function (aList, aStore)
-{
+this.DownloadAutoSaveView = function(aList, aStore) {
   this._list = aList;
   this._store = aStore;
   this._downloadsMap = new Map();
   this._writer = new DeferredTask(() => this._store.save(), kSaveDelayMs);
   AsyncShutdown.profileBeforeChange.addBlocker("DownloadAutoSaveView: writing data",
                                                () => this._writer.finalize());
 }
 
@@ -1079,18 +1076,17 @@ this.DownloadAutoSaveView.prototype = {
 
   /**
    * Registers the view and loads the current state from disk.
    *
    * @return {Promise}
    * @resolves When the view has been registered.
    * @rejects JavaScript exception.
    */
-  initialize: function ()
-  {
+  initialize() {
     // We set _initialized to true after adding the view, so that
     // onDownloadAdded doesn't cause a save to occur.
     return this._list.addView(this).then(() => this._initialized = true);
   },
 
   /**
    * This map contains only Download objects that should be saved to disk, and
    * associates them with the result of their getSerializationHash function, for
@@ -1102,51 +1098,47 @@ this.DownloadAutoSaveView.prototype = {
    * DeferredTask for the save operation.
    */
   _writer: null,
 
   /**
    * Called when the list of downloads changed, this triggers the asynchronous
    * serialization of the list of downloads.
    */
-  saveSoon: function ()
-  {
+  saveSoon() {
     this._writer.arm();
   },
 
   // DownloadList callback
-  onDownloadAdded: function (aDownload)
-  {
+  onDownloadAdded(aDownload) {
     if (gCombinedDownloadIntegration.shouldPersistDownload(aDownload)) {
       this._downloadsMap.set(aDownload, aDownload.getSerializationHash());
       if (this._initialized) {
         this.saveSoon();
       }
     }
   },
 
   // DownloadList callback
-  onDownloadChanged: function (aDownload)
-  {
+  onDownloadChanged(aDownload) {
     if (!gCombinedDownloadIntegration.shouldPersistDownload(aDownload)) {
       if (this._downloadsMap.has(aDownload)) {
         this._downloadsMap.delete(aDownload);
         this.saveSoon();
       }
       return;
     }
 
     let hash = aDownload.getSerializationHash();
     if (this._downloadsMap.get(aDownload) != hash) {
       this._downloadsMap.set(aDownload, hash);
       this.saveSoon();
     }
   },
 
   // DownloadList callback
-  onDownloadRemoved: function (aDownload)
-  {
+  onDownloadRemoved(aDownload) {
     if (this._downloadsMap.has(aDownload)) {
       this._downloadsMap.delete(aDownload);
       this.saveSoon();
     }
   },
 };