Bug 1594000 - Convert remaining nsISimpleEnumerator users to use JS iteration in /calendar. r=pmorris
authorKhushil Mistry <khushil324@gmail.com>
Fri, 10 Jan 2020 12:51:01 +0200
changeset 37927 74fb2e349d4e09a6b5c956e4a5c83476ea23cc2c
parent 37926 be621c5c7cd39d8110eb6eb4d4ee6ee0552ffb99
child 37928 807fb40cb098724ffe7f938946646c2a01f8c74a
push id398
push userclokep@gmail.com
push dateMon, 09 Mar 2020 19:10:28 +0000
reviewerspmorris
bugs1594000
Bug 1594000 - Convert remaining nsISimpleEnumerator users to use JS iteration in /calendar. r=pmorris
calendar/base/content/calendar-chrome-startup.js
calendar/base/content/calendar-extract.js
calendar/base/content/dialogs/calendar-event-dialog-timezone.js
calendar/base/content/dialogs/calendar-migration-dialog.js
calendar/base/content/preferences/general.js
calendar/base/modules/utils/calDateTimeUtils.jsm
calendar/base/modules/utils/calItemUtils.jsm
calendar/base/src/calTimezoneService.js
calendar/lightning/content/lightning-item-iframe.js
calendar/providers/ics/calICSCalendar.js
calendar/test/unit/test_timezone_definition.js
--- a/calendar/base/content/calendar-chrome-startup.js
+++ b/calendar/base/content/calendar-chrome-startup.js
@@ -4,17 +4,16 @@
 
 /* import-globals-from ../../lightning/content/messenger-overlay-sidebar.js */
 /* import-globals-from calendar-command-controller.js */
 /* import-globals-from calendar-management.js */
 /* import-globals-from calendar-ui-utils.js */
 /* import-globals-from calendar-views-utils.js */
 /* globals PanelUI */
 
-var { fixIterator } = ChromeUtils.import("resource:///modules/iteratorUtils.jsm");
 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var { AppConstants } = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 
 /* exported commonInitCalendar, commonFinishCalendar */
 
 /**
  * Common initialization steps for calendar chrome windows.
  */
@@ -127,17 +126,17 @@ var calendarWindowPrefs = {
    * @see nsIObserver
    */
   observe: function(aSubject, aTopic, aData) {
     if (aTopic == "nsPref:changed") {
       switch (aData) {
         case "calendar.view.useSystemColors": {
           let attributeValue =
             Services.prefs.getBoolPref("calendar.view.useSystemColors", false) && "true";
-          for (let win of fixIterator(Services.ww.getWindowEnumerator())) {
+          for (let win of Services.ww.getWindowEnumerator()) {
             setElementValue(win.document.documentElement, attributeValue, "systemcolors");
           }
           break;
         }
       }
     } else if (aTopic == "domwindowopened") {
       let win = aSubject;
       win.addEventListener("load", () => {
--- a/calendar/base/content/calendar-extract.js
+++ b/calendar/base/content/calendar-extract.js
@@ -11,21 +11,20 @@ var { Services } = ChromeUtils.import("r
 
 var calendarExtract = {
   onShowLocaleMenu: function(target) {
     let localeList = document.getElementById(target.id);
     let langs = [];
     let chrome = Cc["@mozilla.org/chrome/chrome-registry;1"]
       .getService(Ci.nsIXULChromeRegistry)
       .QueryInterface(Ci.nsIToolkitChromeRegistry);
-    let locales = chrome.getLocalesForPackage("calendar");
     let langRegex = /^(([^-]+)-*(.*))$/;
 
-    while (locales.hasMore()) {
-      let localeParts = langRegex.exec(locales.getNext());
+    for (let locale of chrome.getLocalesForPackage("calendar")) {
+      let localeParts = langRegex.exec(locale);
       let langName = localeParts[2];
 
       try {
         langName = cal.l10n.getAnyString("global", "languageNames", langName);
       } catch (ex) {
         // If no language name is found that is ok, keep the technical term
       }
 
--- a/calendar/base/content/dialogs/calendar-event-dialog-timezone.js
+++ b/calendar/base/content/dialogs/calendar-event-dialog-timezone.js
@@ -26,21 +26,20 @@ function onLoad() {
   // floating and UTC (if supported) at the top:
   if (args.calendar.getProperty("capabilities.timezones.floating.supported") !== false) {
     addMenuItem(tzMenuPopup, cal.dtz.floating.displayName, cal.dtz.floating.tzid);
   }
   if (args.calendar.getProperty("capabilities.timezones.UTC.supported") !== false) {
     addMenuItem(tzMenuPopup, cal.dtz.UTC.displayName, cal.dtz.UTC.tzid);
   }
 
-  let enumerator = tzProvider.timezoneIds;
   let tzids = {};
   let displayNames = [];
-  while (enumerator.hasMore()) {
-    let timezone = tzProvider.getTimezone(enumerator.getNext());
+  for (let timezoneId of tzProvider.timezoneIds) {
+    let timezone = tzProvider.getTimezone(timezoneId);
     if (timezone && !timezone.isFloating && !timezone.isUTC) {
       let displayName = timezone.displayName;
       displayNames.push(displayName);
       tzids[displayName] = timezone.tzid;
     }
   }
   // the display names need to be sorted
   displayNames.sort((a, b) => a.localeCompare(b));
--- a/calendar/base/content/dialogs/calendar-migration-dialog.js
+++ b/calendar/base/content/dialogs/calendar-migration-dialog.js
@@ -302,19 +302,17 @@ var gDataMigrator = {
 
     // We're lightning, check Sunbird
     if ((sbProf = this.getSunbirdProfile())) {
       profiles.push(sbProf);
     }
 
     // Now check all of the profiles in each of these folders for data
     for (let prof of profiles) {
-      let dirEnum = prof.directoryEntries;
-      while (dirEnum.hasMoreElements()) {
-        let profile = dirEnum.nextFile;
+      for (let profile of prof.directoryEntries) {
         if (profile.isFile()) {
           continue;
         } else {
           profile.append("Calendar");
           if (profile.exists()) {
             migLOG("Found old extension directory at" + profile.path);
             let title = "Mozilla Calendar";
             migrators.push(new dataMigrator(title, extMigrator, [profile]));
@@ -328,22 +326,20 @@ var gDataMigrator = {
 
   /**
    * Checks to see if Apple's iCal is installed and offers to migrate any data
    * the user has created in it.
    */
   checkIcal: function() {
     function icalMigrate(aDataDir, aCallback) {
       aDataDir.append("Sources");
-      let dirs = aDataDir.directoryEntries;
       let calManager = cal.getCalendarManager();
 
       let i = 1;
-      while (dirs.hasMoreElements()) {
-        let dataDir = dirs.nextFile;
+      for (let dataDir of aDataDir.directoryEntries) {
         let dataStore = dataDir.clone();
         dataStore.append("corestorage.ics");
         if (!dataStore.exists()) {
           continue;
         }
 
         let fileStream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(
           Ci.nsIFileInputStream
@@ -431,19 +427,17 @@ var gDataMigrator = {
           calendar.name = "Evolution " + i++;
           calManager.registerCalendar(calendar);
           cal.view.getCompositeCalendar(window).addCalendar(calendar);
         }
         return dataStore.exists();
       };
 
       let calManager = cal.getCalendarManager();
-      let dirs = aDataDir.directoryEntries;
-      while (dirs.hasMoreElements()) {
-        let dataDir = dirs.nextFile;
+      for (let dataDir of aDataDir.directoryEntries) {
         let dataStore = dataDir.clone();
         dataStore.append("calendar.ics");
         evoDataMigrate(dataStore);
       }
 
       aCallback();
     }
 
--- a/calendar/base/content/preferences/general.js
+++ b/calendar/base/content/preferences/general.js
@@ -51,22 +51,21 @@ var gCalendarGeneralPane = {
     // deselect and reselect to update visible item title
     updateUnitLabelPlural("defaultlength", "defaultlengthunit", "minutes");
     this.updateDefaultTodoDates();
 
     let tzMenuList = document.getElementById("calendar-timezone-menulist");
     let tzMenuPopup = document.getElementById("calendar-timezone-menupopup");
 
     let tzService = cal.getTimezoneService();
-    let enumerator = tzService.timezoneIds;
     let tzids = {};
     let displayNames = [];
     // don't rely on what order the timezone-service gives you
-    while (enumerator.hasMore()) {
-      let timezone = tzService.getTimezone(enumerator.getNext());
+    for (let timezoneId of tzService.timezoneIds) {
+      let timezone = tzService.getTimezone(timezoneId);
       if (timezone && !timezone.isFloating && !timezone.isUTC) {
         let displayName = timezone.displayName;
         displayNames.push(displayName);
         tzids[displayName] = timezone.tzid;
       }
     }
     // the display names need to be sorted
     displayNames.sort((a, b) => a.localeCompare(b));
--- a/calendar/base/modules/utils/calDateTimeUtils.jsm
+++ b/calendar/base/modules/utils/calDateTimeUtils.jsm
@@ -270,19 +270,17 @@ var caldtz = {
       // If offset does not match, go through timezones. This will
       // give you the first tz in the alphabet and kill daylight
       // savings time, but we have no other choice
       if (dateTime.timezoneOffset != offset_in_s) {
         // TODO A patch to Bug 363191 should make this more efficient.
 
         let tzService = cal.getTimezoneService();
         // Enumerate timezones, set them, check their offset
-        let enumerator = tzService.timezoneIds;
-        while (enumerator.hasMore()) {
-          let id = enumerator.getNext();
+        for (let id of tzService.timezoneIds) {
           dateTime.timezone = tzService.getTimezone(id);
           if (dateTime.timezoneOffset == offset_in_s) {
             // This is our last step, so go ahead and return
             return dateTime;
           }
         }
         // We are still here: no timezone was found
         dateTime.timezone = cal.dtz.UTC;
--- a/calendar/base/modules/utils/calItemUtils.jsm
+++ b/calendar/base/modules/utils/calItemUtils.jsm
@@ -622,32 +622,28 @@ var calitem = {
 
   /**
    * Search for already open item dialog.
    *
    * @param aItem     The item of the dialog to search for.
    */
   findWindow: function(aItem) {
     // check for existing dialog windows
-    let list = Services.wm.getEnumerator("Calendar:EventDialog");
-    while (list.hasMoreElements()) {
-      let dlg = list.getNext();
+    for (let dlg of Services.wm.getEnumerator("Calendar:EventDialog")) {
       if (
         dlg.arguments[0] &&
         dlg.arguments[0].mode == "modify" &&
         dlg.arguments[0].calendarEvent &&
         dlg.arguments[0].calendarEvent.hashId == aItem.hashId
       ) {
         return dlg;
       }
     }
     // check for existing summary windows
-    list = Services.wm.getEnumerator("Calendar:EventSummaryDialog");
-    while (list.hasMoreElements()) {
-      let dlg = list.getNext();
+    for (let dlg of Services.wm.getEnumerator("Calendar:EventSummaryDialog")) {
       if (dlg.calendarItem && dlg.calendarItem.hashId == aItem.hashId) {
         return dlg;
       }
     }
     return null;
   },
 
   /**
--- a/calendar/base/src/calTimezoneService.js
+++ b/calendar/base/src/calTimezoneService.js
@@ -766,18 +766,17 @@ function guessSystemTimezone() {
     }
   } catch (ex) {
     // Oh well, this didn't work, next option...
     Cu.reportError(ex);
   }
 
   // Third, try all known timezones.
   const tzIDs = tzSvc.timezoneIds;
-  while (tzIDs.hasMore()) {
-    let tzId = tzIDs.getNext();
+  for (let tzId of tzIDs) {
     try {
       let score = checkTZ(tzId);
       switch (score) {
         case 0:
           break;
         case 1:
         case 2:
           if (score > probableTZScore) {
--- a/calendar/lightning/content/lightning-item-iframe.js
+++ b/calendar/lightning/content/lightning-item-iframe.js
@@ -2230,22 +2230,19 @@ function attachFile(cloudProvider) {
   if (lastDir) {
     filePicker.displayDirectory = lastDir;
   }
 
   filePicker.open(rv => {
     if (rv != Ci.nsIFilePicker.returnOK || !filePicker.files) {
       return;
     }
-    let files = filePicker.files;
 
     // Create the attachment
-    while (files.hasMoreElements()) {
-      let file = files.getNext().QueryInterface(Ci.nsIFile);
-
+    for (let file of filePicker.files) {
       let fileHandler = Services.io
         .getProtocolHandler("file")
         .QueryInterface(Ci.nsIFileProtocolHandler);
       let uriSpec = fileHandler.getURLSpecFromFile(file);
 
       if (!(uriSpec in gAttachMap)) {
         // If the attachment hasn't been added, then set the last display
         // directory.
--- a/calendar/providers/ics/calICSCalendar.js
+++ b/calendar/providers/ics/calICSCalendar.js
@@ -699,20 +699,18 @@ calICSCalendar.prototype = {
           // nsIFile.  That's not the end of the world.  We can
           // try to remove the file the next time around.
         }
       }
     }
 
     function purgeOldBackups() {
       // Enumerate files in the backupdir for expiry of old backups
-      let dirEnum = backupDir.directoryEntries;
       let files = [];
-      while (dirEnum.hasMoreElements()) {
-        let file = dirEnum.nextFile;
+      for (let file of backupDir.directoryEntries) {
         if (file.isFile()) {
           files.push({ name: file.leafName, lastmodified: file.lastModifiedTime });
         }
       }
 
       if (doDailyBackup) {
         purgeBackupsByType(files, "day");
       } else {
--- a/calendar/test/unit/test_timezone_definition.js
+++ b/calendar/test/unit/test_timezone_definition.js
@@ -33,40 +33,38 @@ add_task(async function zone_test() {
     ok(timezone.latitude && !!timezone.latitude.match(/^[+-]\d{7}$/), "Latitude test " + aZoneId);
     ok(
       timezone.longitude && !!timezone.longitude.match(/^[+-]\d{7}$/),
       "Longitude test " + aZoneId
     );
   }
 
   let tzs = cal.getTimezoneService();
-  let zones = tzs.timezoneIds;
   let foundZone = false;
-  while (zones.hasMore()) {
+  for (let zone of tzs.timezoneIds) {
     foundZone = true;
-    resolveZone(zones.getNext());
+    resolveZone(zone);
   }
 
   ok(foundZone, "There is at least one timezone");
 });
 
 // check whether all tz aliases resolve to a tz definition
 add_task(async function alias_test() {
   function resolveAlias(aAliasId) {
     let timezone = tzs.getTimezone(aAliasId);
     let tzid = timezone && timezone.tzid ? timezone.tzid : "";
     notEqual(tzid, "", "Alias resolution " + aAliasId + " -> " + tzid);
   }
 
   let tzs = cal.getTimezoneService();
-  let aliases = tzs.aliasIds;
   let foundAlias = false;
-  while (aliases.hasMore()) {
+  for (let aliasId of tzs.aliasIds) {
     foundAlias = true;
-    resolveAlias(aliases.getNext());
+    resolveAlias(aliasId);
   }
 
   ok(foundAlias, "There is at least one alias");
 });
 
 // Check completeness to avoid unintended removing of zones/aliases when updating zones.json
 // removed zones should at least remain as alias to not break UI like in bug 1210723.
 // previous.json is generated automatically by executing update-zones.py script