Bug 1492735 - Port Bug 1486147: Provide Symbol.iterator for JS objects implementing nsIStringEnumerator, part 2. r=mkmelin,jorgk
authorGeoff Lankow <geoff@darktrojan.net>
Thu, 27 Sep 2018 22:44:17 +1200
changeset 33246 20b96eb01d6e51f0ae7b0f8f6dea5538b325f0f7
parent 33245 e6adb6f718934c05bc287a8247760f81ef640a83
child 33247 5664e476f06cdab4ccf1cea2c6e663298909e7b3
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersmkmelin, jorgk
bugs1492735, 1486147
Bug 1492735 - Port Bug 1486147: Provide Symbol.iterator for JS objects implementing nsIStringEnumerator, part 2. r=mkmelin,jorgk
mailnews/compose/test/unit/test_nsIMsgCompFields.js
mailnews/mime/src/mimeJSComponents.js
mailnews/mime/test/unit/test_structured_headers.js
--- a/mailnews/compose/test/unit/test_nsIMsgCompFields.js
+++ b/mailnews/compose/test/unit/test_nsIMsgCompFields.js
@@ -5,18 +5,18 @@
 /// Test that nsIMsgCompFields works properly
 
 var nsMsgCompFields = Components.Constructor(
   "@mozilla.org/messengercompose/composefields;1",
   Ci.nsIMsgCompFields);
 
 function check_headers(enumerator, container) {
   let checkValues = new Set(container.map(header => header.toLowerCase()));
-  while (enumerator.hasMore()) {
-    let value = enumerator.getNext().toLowerCase();
+  for (let value of enumerator) {
+    value = value.toLowerCase();
     Assert.ok(checkValues.has(value));
     checkValues.delete(value);
   }
   Assert.equal(checkValues.size, 0);
 }
 
 function run_test() {
   let fields = new nsMsgCompFields;
--- a/mailnews/mime/src/mimeJSComponents.js
+++ b/mailnews/mime/src/mimeJSComponents.js
@@ -14,17 +14,17 @@ function HeaderHandler() {
 
 function StringEnumerator(iterator) {
   this._iterator = iterator;
   this._next = undefined;
 }
 StringEnumerator.prototype = {
   QueryInterface: ChromeUtils.generateQI([Ci.nsIUTF8StringEnumerator]),
   [Symbol.iterator]: function () {
-    return this;
+    return this._iterator;
   },
   _setNext: function () {
     if (this._next !== undefined)
       return;
     this._next = this._iterator.next();
   },
   hasMore: function () {
     this._setNext();
@@ -174,19 +174,17 @@ MimeWritableStructuredHeaders.prototype 
     this._headers.set(aHeaderName.toLowerCase(), aValue);
   },
 
   deleteHeader: function (aHeaderName) {
     this._headers.delete(aHeaderName.toLowerCase());
   },
 
   addAllHeaders: function (aHeaders) {
-    let headerList = aHeaders.headerNames;
-    while (headerList.hasMore()) {
-      let header = headerList.getNext();
+    for (let header of aHeaders.headerNames) {
       this.setHeader(header, aHeaders.getHeader(header));
     }
   },
 
   setUnstructuredHeader: function (aHeaderName, aValue) {
     this.setHeader(aHeaderName, aValue);
   },
 
--- a/mailnews/mime/test/unit/test_structured_headers.js
+++ b/mailnews/mime/test/unit/test_structured_headers.js
@@ -116,28 +116,24 @@ add_task(async function check_raw() {
   Assert.equal(headers.getHeader("Not-Found-Anywhere"), 515);
   headers.deleteHeader("not-found-anywhere");
   Assert.equal(headers.getHeader("Not-Found-Anywhere"), undefined);
 
   // Check the enumeration of header values.
   headers.setHeader("unabashed-random-header", false);
   let headerList = ["Date", "Content-Description", "Subject",
     "Unabashed-Random-Header"];
-  let enumerator = headers.headerNames;
-  while (enumerator.hasMore()) {
-    let value = enumerator.getNext();
+  for (let value of headers.headerNames) {
     Assert.equal(value.toLowerCase(), headerList.shift().toLowerCase());
   }
 
   // Check that copying works
   let moreHeaders = new StructuredHeaders();
   moreHeaders.addAllHeaders(headers);
-  enumerator = headers.headerNames;
-  while (enumerator.hasMore()) {
-    let value = enumerator.getNext();
+  for (let value of headers.headerNames) {
     Assert.equal(moreHeaders.getHeader(value), headers.getHeader(value));
   }
   headers.deleteHeader("Date");
   Assert.ok(moreHeaders.hasHeader("Date"));
 })
 
 add_task(async function check_nsIMimeHeaders() {
   let headers = Cc["@mozilla.org/messenger/mimeheaders;1"]
@@ -150,19 +146,17 @@ add_task(async function check_nsIMimeHea
   Assert.equal(headers.getHeader("To")[0].email, "bugmail@example.org");
   Assert.equal(headers.getAddressingHeader("To").length, 1);
   Assert.equal(headers.getHeader("Content-Type").type, "text/html");
 
   let headerList = ["X-Mozilla-Status", "X-Mozilla-Status2", "X-Mozilla-Keys",
     "FCC", "BCC", "X-Identity-Key", "Message-ID", "Date", "From",
     "X-Mozilla-Draft-Info", "User-Agent", "MIME-Version", "To", "Subject",
     "Content-Type", "Content-Transfer-Encoding"];
-  let enumerator = headers.headerNames;
-  while (enumerator.hasMore()) {
-    let value = enumerator.getNext();
+  for (let value of headers.headerNames) {
     Assert.equal(value.toLowerCase(), headerList.shift().toLowerCase());
   }
 });
 
 add_task(async function checkBuildMimeText() {
   let headers = new StructuredHeaders();
   headers.setHeader("To", [{name: "François Smith", email: "user@☃.invalid"}]);
   headers.setHeader("From", [{name: "John Doe", email: "jdoe@test.invalid"}]);