Bug 1492735 - Port Bug 1486147: Provide Symbol.iterator for JS objects implementing nsIStringEnumerator; rs=bustage-fix DONTBUILD
authorGeoff Lankow <geoff@darktrojan.net>
Thu, 20 Sep 2018 21:39:01 +1200
changeset 33193 2bfc93d3de04b819cd58cb5b9c5166e27584f15c
parent 33192 9ebd1525937965ad68372dd6d971ffd178af6a0e
child 33194 8c63ea2dd66704719df0fbae5b895cb5669f9543
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersbustage-fix
bugs1492735, 1486147
Bug 1492735 - Port Bug 1486147: Provide Symbol.iterator for JS objects implementing nsIStringEnumerator; rs=bustage-fix DONTBUILD
calendar/base/public/calIICSService.idl
calendar/base/src/calTimezoneService.js
calendar/providers/wcap/calWcapSession.js
mailnews/mime/src/mimeJSComponents.js
--- a/calendar/base/public/calIICSService.idl
+++ b/calendar/base/public/calIICSService.idl
@@ -10,17 +10,16 @@
 
 interface calIItemBase;
 interface calIDateTime;
 interface calIDuration;
 interface calITimezone;
 interface calITimezoneProvider;
 
 interface calIIcalProperty;
-interface nsIUTF8StringEnumerator;
 interface nsIInputStream;
 
 /**
  * General notes:
  *
  * As with libical, use of getNextFoo(footype) is only valid if there have been
  * no intervening getNextFoo(otherfootype)s, or removeFoo()s, or addFoo()s. In
  * general, you want to do as little manipulation of your FooContainers as
--- a/calendar/base/src/calTimezoneService.js
+++ b/calendar/base/src/calTimezoneService.js
@@ -11,16 +11,19 @@ var { cal } = ChromeUtils.import("resour
 var { ICAL, unwrapSingle } = ChromeUtils.import("resource://calendar/modules/ical.js", null);
 
 function calStringEnumerator(stringArray) {
     this.mIndex = 0;
     this.mStringArray = stringArray;
 }
 calStringEnumerator.prototype = {
     // nsIUTF8StringEnumerator:
+    [Symbol.iterator]: function() {
+        return this.mStringArray.values();
+    },
     hasMore: function() {
         return (this.mIndex < this.mStringArray.length);
     },
     getNext: function() {
         if (!this.hasMore()) {
             throw Components.results.NS_ERROR_UNEXPECTED;
         }
         return this.mStringArray[this.mIndex++];
--- a/calendar/providers/wcap/calWcapSession.js
+++ b/calendar/providers/wcap/calWcapSession.js
@@ -144,16 +144,19 @@ calWcapSession.prototype = {
     m_serverTimezones: null,
     get timezoneIds() {
         let tzids = [];
         for (let tzid in this.m_serverTimezones) {
             tzids.push(tzid);
         }
         return { // nsIUTF8StringEnumerator:
             m_index: 0,
+            [Symbol.iterator]: function() {
+                return tzids.values();
+            },
             getNext: function() {
                 if (this.m_index >= tzids) {
                     cal.ASSERT(false, "calWcapSession::timezoneIds enumerator!");
                     throw Components.results.NS_ERROR_UNEXPECTED;
                 }
                 return tzids[this.m_index++];
             },
             hasMore: function() {
--- a/mailnews/mime/src/mimeJSComponents.js
+++ b/mailnews/mime/src/mimeJSComponents.js
@@ -12,18 +12,20 @@ function HeaderHandler() {
   this.deliverEOF = function () {};
 }
 
 function StringEnumerator(iterator) {
   this._iterator = iterator;
   this._next = undefined;
 }
 StringEnumerator.prototype = {
-  QueryInterface: ChromeUtils.generateQI([
-    Ci.nsIUTF8StringEnumerator]),
+  QueryInterface: ChromeUtils.generateQI([Ci.nsIUTF8StringEnumerator]),
+  [Symbol.iterator]: function () {
+    return this;
+  },
   _setNext: function () {
     if (this._next !== undefined)
       return;
     this._next = this._iterator.next();
   },
   hasMore: function () {
     this._setNext();
     return !this._next.done;