Bug 1234048 - Remove use of non-standard for-each from calendar/providers/gdata. r=philipp
authorTooru Fujisawa <arai_a@mac.com>
Wed, 09 Nov 2016 21:52:49 +0900
changeset 27036 9b5140bc343efa866f38ce840457e6d0e618263f
parent 27035 22a16959283a55d6918b2f09516efb26c6a113af
child 27037 20b628588a677efd802bc3830ad3f2ab336f4fb4
push idunknown
push userunknown
push dateunknown
reviewersphilipp
bugs1234048
Bug 1234048 - Remove use of non-standard for-each from calendar/providers/gdata. r=philipp
calendar/providers/gdata/components/calGoogleCalendar.js
calendar/providers/gdata/content/gdata-calendar-creation.js
calendar/providers/gdata/content/gdata-calendar-event-dialog.js
calendar/providers/gdata/content/gdata-event-dialog-reminder.js
calendar/providers/gdata/content/gdata-migration.js
calendar/providers/gdata/modules/gdataLogging.jsm
calendar/providers/gdata/modules/gdataUtils.jsm
calendar/providers/gdata/modules/shim/Loader.jsm
calendar/providers/gdata/modules/shim/Promise.jsm
--- a/calendar/providers/gdata/components/calGoogleCalendar.js
+++ b/calendar/providers/gdata/components/calGoogleCalendar.js
@@ -712,19 +712,19 @@ calGoogleCalendar.prototype = {
             calendarRequest.uri = this.createUsersURI("calendarList", this.mCalendarName)
             calendarPromise = this.session.asyncItemRequest(calendarRequest).then(function(aData) {
                 if (aData.defaultReminders) {
                     this.defaultReminders = aData.defaultReminders.map(function(x) { return JSONToAlarm(x, true); });
                 } else {
                     this.defaultReminders = [];
                 }
 
-                for each (let k in ["accessRole", "backgroundColor", "description",
-                                    "foregroundColor", "location", "primary",
-                                    "summary", "summaryOverride", "timeZone"]) {
+                for (let k of ["accessRole", "backgroundColor", "description",
+                               "foregroundColor", "location", "primary",
+                               "summary", "summaryOverride", "timeZone"]) {
                     this.setProperty("settings." + k, aData[k]);
                 }
                 this.setProperty("settings.defaultReminders", JSON.stringify(aData.defaultReminders));
             }.bind(this));
         }
 
         // Set up a request for the events
         let eventsRequest = new calGoogleRequest();
--- a/calendar/providers/gdata/content/gdata-calendar-creation.js
+++ b/calendar/providers/gdata/content/gdata-calendar-creation.js
@@ -10,17 +10,17 @@ Components.utils.import("resource://gdat
 
 CuImport("resource://gre/modules/Promise.jsm", this);
 
 (function() {
     function pageorder(anchor /*, ...pages */) {
         let pages = Array.slice(arguments, 1);
         let wizard = document.documentElement;
         let page = wizard.getPageById(anchor);
-        for each (let id in pages) {
+        for (let id of pages) {
             page.next = id;
             page = wizard.getPageById(id);
         }
     }
 
     function trycatch(func) {
         return function() {
             try {
@@ -162,17 +162,17 @@ CuImport("resource://gre/modules/Promise
             let newSessionItem = document.getElementById("gdata-session-name");
             session = sessionMgr.getSessionById(newSessionItem.value, true);
         }
 
         PromiseAll([session.getTasksList(), session.getCalendarList()])
                .then(function([tasksLists, calendarList]) {
             let existing = new Set();
             let sessionPrefix = "googleapi://" + session.id;
-            for each (let calendar in calMgr.getCalendars({})) {
+            for (let calendar of calMgr.getCalendars({})) {
                 let spec = calendar.uri.spec;
                 if (calendar.type == "gdata" && spec.substr(0, sessionPrefix.length) == sessionPrefix) {
                     let match;
                     if ((match = spec.match(/calendar=([^&]*)/))) {
                         existing.add(decodeURIComponent(match[0]));
                     }
                     if ((match = spec.match(/tasks=([^&]*)/))) {
                         existing.add(decodeURIComponent(match[0]));
--- a/calendar/providers/gdata/content/gdata-calendar-event-dialog.js
+++ b/calendar/providers/gdata/content/gdata-calendar-event-dialog.js
@@ -53,24 +53,24 @@ Components.utils.import("resource://gdat
             "options-privacy-menu",
             "options-priority-menu",
             "options-freebusy-menu",
             "button-attendees",
             "button-privacy",
             "button-url"
         ];
 
-        for each (let id in hideForTaskIds) {
+        for (let id of hideForTaskIds) {
             let node = document.getElementById(id);
             if (node) {
                 node.hidden = isGoogleTask;
             }
         }
 
-        for each (let id in disableForTaskIds) {
+        for (let id of disableForTaskIds) {
             let node = document.getElementById(id);
             if (node) {
                 node.disabled = isGoogleTask;
             }
         }
 
         let duedate = document.getElementById("todo-duedate");
         let duetime = document.getAnonymousElementByAttribute(duedate, "anonid", "time-picker");
@@ -91,17 +91,17 @@ Components.utils.import("resource://gdat
                 }
                 gEndTime.isDate = false;
                 gEndTime = gEndTime.getInTimezone(gEndTimezone);
             }
             updateDateTime();
         }
 
         let elements = document.getElementsByAttribute("provider", "gdata");
-        for each (let elem in Array.slice(elements)) {
+        for (let elem of Array.slice(elements)) {
             elem.style.display = isGoogleCalendar ? "" : "none";
         }
 
         let reminderList = document.getElementById("item-alarm");
         let hasDefaultReminders = isGoogleEvent && calendar.getProperty("settings.defaultReminders");
         if (isGoogleCalendar && !hasDefaultReminders && reminderList.value == "default") {
             reminderList.value = "none";
         }
@@ -203,16 +203,16 @@ Components.utils.import("resource://gdat
 
     monkeyPatch(window, "editReminder", function(protofunc /*, ...args */) {
         let rv = protofunc.apply(this, Array.slice(arguments, 1));
 
         // Now that the custom reminders were changed, we need to remove the
         // default alarm status, otherwise the wrong alarm will be set.
         let customItem = document.getElementById("reminder-custom-menuitem");
         if (customItem.reminders) {
-            for each (let reminder in customItem.reminders) {
+            for (let reminder of customItem.reminders) {
                 reminder.deleteProperty("X-DEFAULT-ALARM");
             }
         }
 
         return rv;
     });
 })();
--- a/calendar/providers/gdata/content/gdata-event-dialog-reminder.js
+++ b/calendar/providers/gdata/content/gdata-event-dialog-reminder.js
@@ -36,17 +36,17 @@
         return (seconds < 1 && seconds >= FOUR_WEEKS_BEFORE);
     }
 
     function checkAllReminders() {
         let listbox = document.getElementById("reminder-listbox");
         let notificationbox = document.getElementById("reminder-notifications");
 
         let validated = true;
-        for each (let node in Array.slice(listbox.childNodes)) {
+        for (let node of Array.slice(listbox.childNodes)) {
             validated = validated && checkReminderRange(node.reminder);
             if (!validated) {
                 break;
             }
         }
 
         let acceptButton = document.documentElement.getButton("accept");
         acceptButton.disabled = !validated;
--- a/calendar/providers/gdata/content/gdata-migration.js
+++ b/calendar/providers/gdata/content/gdata-migration.js
@@ -74,17 +74,17 @@ function getMigratableCalendars() {
 function gdata_migration_loader() {
     // Only load once
     window.removeEventListener("load", gdata_migration_loader, false);
 
     if (document.documentElement.id == "gdata-migration-wizard") {
         // This is the migration wizard, load the calendars neeeded.
         let listbox = document.getElementById("calendars-listbox");
 
-        for each (let calendar in sortCalendarArray(getMigratableCalendars())) {
+        for (let calendar of sortCalendarArray(getMigratableCalendars())) {
             let item = listbox.appendItem(calendar.name, calendar.id);
             item.setAttribute("type", "checkbox");
             item.calendar = calendar;
         }
 
         // Set up the "always check" field
         document.getElementById("showagain-checkbox").checked =
             Preferences.get("calendar.google.migrate", true);
--- a/calendar/providers/gdata/modules/gdataLogging.jsm
+++ b/calendar/providers/gdata/modules/gdataLogging.jsm
@@ -29,37 +29,37 @@ function stringException(e) {
  */
 function LOGitem(item) {
     if (!item) {
         return;
     }
 
     let attendees = item.getAttendees({});
     let attendeeString = "";
-    for each (let a in attendees) {
+    for (let a of attendees) {
         attendeeString += "\n" + LOGattendee(a);
     }
 
     let rstr = "\n";
     if (item.recurrenceInfo) {
         let ritems = item.recurrenceInfo.getRecurrenceItems({});
-        for each (let ritem in ritems) {
+        for (let ritem of ritems) {
             rstr += "\t\t" + ritem.icalProperty.icalString;
         }
 
         rstr += "\tExceptions:\n";
         let exids = item.recurrenceInfo.getExceptionIds({});
-        for each (let exc in exids) {
+        for (let exc of exids) {
             rstr += "\t\t" + exc + "\n";
         }
     }
 
     let astr = "\n";
     let alarms = item.getAlarms({});
-    for each (let alarm in alarms) {
+    for (let alarm of alarms) {
         astr += "\t\t" + LOGalarm(alarm) + "\n";
     }
 
     LOGverbose("[calGoogleCalendar] Logging calIEvent:" +
         "\n\tid:" + item.id +
         "\n\tcreated:" + item.getProperty("CREATED") +
         "\n\tupdated:" + item.getProperty("LAST-MODIFIED") +
         "\n\ttitle:" + item.title +
--- a/calendar/providers/gdata/modules/gdataUtils.jsm
+++ b/calendar/providers/gdata/modules/gdataUtils.jsm
@@ -79,17 +79,17 @@ function migrateItemMetadata(aOfflineSto
         deleteItemMetadata(aOfflineStorage, aNewItem);
     } else {
         saveItemMetadata(aOfflineStorage, aNewItem.hashId, aMetadata);
     }
 
     // If an exception was turned into an EXDATE, we need to clear its metadata
     if (aOldItem.recurrenceInfo && aNewItem.recurrenceInfo) {
         let newExIds = new Set(aNewItem.recurrenceInfo.getExceptionIds({}).map(function(x) { return x.icalString; }));
-        for each (let exId in aOldItem.recurrenceInfo.getExceptionIds({})) {
+        for (let exId of aOldItem.recurrenceInfo.getExceptionIds({})) {
             if (!newExIds.has(exId.icalString)) {
                 let ex = aOldItem.recurrenceInfo.getExceptionFor(exId);
                 deleteItemMetadata(aOfflineStorage, ex);
             }
         }
     }
 }
 
@@ -98,17 +98,17 @@ function migrateItemMetadata(aOfflineSto
  *
  * @param aOfflineStorage   The offline storage that holds the metadata for this item.
  * @param aItem             The item to delete metadata for.
  */
 function deleteItemMetadata(aOfflineStorage, aItem) {
     aOfflineStorage.deleteMetaData(aItem.hashId);
     if (aItem.recurrenceInfo) {
         let recInfo = aItem.recurrenceInfo;
-        for each (let exId in recInfo.getExceptionIds({})) {
+        for (let exId of recInfo.getExceptionIds({})) {
             let occ = recInfo.getExceptionFor(exId);
             aOfflineStorage.deleteMetaData(occ.hashId);
         }
     }
 }
 
 /**
  * Retrieve the item metadata for the given item
@@ -470,17 +470,17 @@ function EventToJSON(aItem, aOfflineStor
     // Now save the snooze object in source format as an extended property. Do
     // so always, since its currently impossible to unset extended properties.
     addExtendedProperty("X-GOOGLE-SNOOZE-RECUR", snoozeValue, true);
 
     // recurrence information
     if (aItem.recurrenceInfo) {
         itemData.recurrence = [];
         let recurrenceItems = aItem.recurrenceInfo.getRecurrenceItems({});
-        for each (let ritem in recurrenceItems) {
+        for (let ritem of recurrenceItems) {
             let prop = ritem.icalProperty;
             if (ritem instanceof Components.interfaces.calIRecurrenceDate) {
                 // EXDATES require special casing, since they might contain
                 // a TZID. To avoid the need for conversion of TZID strings,
                 // convert to UTC before serialization.
                 prop.valueAsDatetime = ritem.date.getInTimezone(cal.UTC());
             }
             itemData.recurrence.push(prop.icalString.trim());
@@ -515,27 +515,27 @@ function TaskToJSON(aItem, aOfflineStora
 
     if (aItem.dueDate) {
         let dueDate = aItem.dueDate.getInTimezone(cal.UTC());
         dueDate.isDate = false;
         itemData.due = cal.toRFC3339(dueDate);
     }
     setIf(itemData, "completed", cal.toRFC3339(aItem.completedDate));
 
-    for each (let relation in aItem.getRelations({})) {
+    for (let relation of aItem.getRelations({})) {
         if (relation.relId &&
             (!relation.relType || relation.relType == "PARENT")) {
             itemData.parent = relation.relId;
             break;
         }
     }
 
     let attachments = aItem.getAttachments({});
     if (attachments.length) itemData.links = [];
-    for each (let attach in aItem.getAttachments({})) {
+    for (let attach of aItem.getAttachments({})) {
         let attachData = {};
         attachData.link = attach.uri.spec;
         attachData.description = attach.getParameter("FILENAME");
         attachData.type = attach.getParameter("X-TYPE");
         itemData.links.push(attachData);
     }
 
     return itemData;
@@ -739,17 +739,17 @@ function JSONToEvent(aEntry, aCalendar, 
         item.removeAllAttendees();
         if (aEntry.attendees) {
             const statusMap = {
                 needsAction: "NEEDS-ACTION",
                 declined: "DECLINED",
                 tentative: "TENTATIVE",
                 accepted: "ACCEPTED"
             };
-            for each (let attendeeEntry in aEntry.attendees) {
+            for (let attendeeEntry of aEntry.attendees) {
                 let attendee = cal.createAttendee();
                 if (attendeeEntry.email) {
                     attendee.id = "mailto:" + attendeeEntry.email;
                 } else {
                     attendee.id = "urn:id:" + attendeeEntry.id;
                 }
                 attendee.commonName = attendeeEntry.displayName;
 
@@ -783,17 +783,17 @@ function JSONToEvent(aEntry, aCalendar, 
                 } else {
                     // Nothing to make clear we are using default reminders.
                     // Set an X-PROP until VALARM extensions are supported
                     item.setProperty("X-DEFAULT-ALARM", "TRUE");
                 }
             }
 
             if (aEntry.reminders.overrides) {
-                for each (let reminderEntry in aEntry.reminders.overrides) {
+                for (let reminderEntry of aEntry.reminders.overrides) {
                     item.addAlarm(JSONToAlarm(reminderEntry));
                 }
             }
         }
 
         // extendedProperty (alarmLastAck)
         item.alarmLastAck = cal.fromRFC3339(privateProps["X-MOZ-LASTACK"], calendarZone);
 
@@ -891,17 +891,17 @@ function JSONToTask(aEntry, aCalendar, a
         if (aEntry.parent) {
             let relation = cal.createRelation();
             relation.relType = "PARENT";
             relation.relId = aEntry.parent;
             item.addRelation(relation);
         }
 
         if (aEntry.links) {
-            for each (let link in aEntry.links) {
+            for (let link of aEntry.links) {
                 let attach = cal.createAttachment();
                 attach.uri = Services.io.newURI(link.link, null, null);
                 attach.setParameter("FILENAME", link.description);
                 attach.setParameter("X-GOOGLE-TYPE", link.type);
                 item.addAttachment(attach);
             }
         }
 
@@ -1063,17 +1063,17 @@ ItemSaver.prototype = {
                     committedUnits = cur;
                 }
             }
 
             // Go through all exceptions and attempt to find the master item in the
             // item stream. If it can't be found there, the offline storage is asked
             // for the parent item. If it still can't be found, then we have to do
             // this at the end.
-            for each (let exc in exceptionItems) {
+            for (let exc of exceptionItems) {
                 // If we have the master item in our cache then use it. Otherwise
                 // attempt to get it from the offline storage.
                 let item;
                 if (exc.id in this.masterItems) {
                     item = this.masterItems[exc.id];
                 } else {
                     item = (yield this.promiseOfflineStorage.getItem(exc.id))[0];
                 }
@@ -1173,17 +1173,17 @@ ItemSaver.prototype = {
     /**
      * Handle all remaining exceptions in the item saver. Ensures that any
      * missing master items are searched for or created.
      *
      * @return          A promise resolved on completion
      */
     processRemainingExceptions: function() {
         return Task.spawn(function() {
-            for each (let exc in this.missingParents) {
+            for (let exc of this.missingParents) {
                 let item = (yield this.promiseOfflineStorage.getItem(exc.id))[0];
                 if (item) {
                     yield this.processException(exc, item);
                 } else if (exc.status != "CANCELLED") {
                     // If the item could not be found, it could be that the
                     // user is invited to an instance of a recurring event.
                     // Unless this is a cancelled exception, create a mock
                     // parent item with one positive RDATE.
--- a/calendar/providers/gdata/modules/shim/Loader.jsm
+++ b/calendar/providers/gdata/modules/shim/Loader.jsm
@@ -158,17 +158,17 @@ function MapSetForEach(cb) {
 
 /**
  * This implementation of Map doesn't work quite like the ES6 Map, but it works
  * well enough for our purposes.
  */
 function Map(values) {
     this.data = Object.create(null);
     if (values) {
-        for each (let [k,v] in values) {
+        for (let [k,v] of values) {
             this.data[k] = v;
         }
     }
 }
 Map.prototype = {
     has: function(k) { return k in this.data; },
     set: function(k, v) { return this.data[k] = v; },
     get: function(k) { return this.data[k]; },
@@ -191,17 +191,17 @@ Map.prototype = {
 function Set(values) {
     this.data = [];
     if (values) {
         values.forEach(this.add, this);
     }
 }
 Set.prototype = {
     has: function(v) {
-        for each (let dv in this.data) {
+        for (let dv of this.data) {
             if (v == dv) return true;
         }
         return false;
     },
 
     get size() { return this.data.length; },
     add: function(v) { return this.has(v) ? null : this.data.push(v); },
     clear: function() { return this.data = []; },
@@ -210,24 +210,24 @@ Set.prototype = {
             if (this.data[i] == v) {
                 this.data.splice(i, 1);
                 return;
             }
         }
     },
 
     forEach: function(cb) {
-        for each (let v in this.data) {
+        for (let v of this.data) {
             cb(v, v, this);
         }
     },
 
     toSource: function() { return this.data.toSource(); },
     __iterator__: function() {
-        for each (let v in this.data) {
+        for (let v of this.data) {
             yield v;
         }
     }
 };
 
 if (!cal.hashColor) {
     cal.hashColor = function hashColor(str) {
         // This is the palette of colors in the current colorpicker implementation.
--- a/calendar/providers/gdata/modules/shim/Promise.jsm
+++ b/calendar/providers/gdata/modules/shim/Promise.jsm
@@ -42,17 +42,17 @@ var PromiseWalker = {
         thread.dispatch({
             run: function() {
                 PromiseWalker.walkerLoop();
             }
         }, Components.interfaces.nsIEventTarget.DISPATCH_NORMAL);
     },
 
     schedulePromise: function (aPromise) {
-        for each (let handler in aPromise._handlers) {
+        for (let handler of aPromise._handlers) {
             this.handlers.push(handler);
         }
         aPromise._handlers.length = 0;
 
         if (!this.walkerLoopScheduled) {
             this.scheduleWalkerLoop();
         }
     },