Bug 1594000 - Convert remaining nsISimpleEnumerator users to use JS iteration in /chat. r=mkmelin,clokep
authorKhushil Mistry <khushil324@gmail.com>
Wed, 08 Jan 2020 09:56:04 +1300
changeset 37916 089f6048f53fb2e990f62dd17bc7a366e7616165
parent 37915 ca3bda2ded047dc58d7f98e7242043ae4a35cbe9
child 37917 b4e1c22a54e49886946f3390c7369b1e5a1ce27c
push id398
push userclokep@gmail.com
push dateMon, 09 Mar 2020 19:10:28 +0000
reviewersmkmelin, clokep
bugs1594000
Bug 1594000 - Convert remaining nsISimpleEnumerator users to use JS iteration in /chat. r=mkmelin,clokep
chat/components/src/imCore.jsm
chat/components/src/test/test_logger.js
chat/content/chat-tooltip.js
chat/content/imAccountOptionsHelper.js
chat/modules/OTRHelpers.jsm
chat/modules/OTRUI.jsm
chat/modules/imThemes.jsm
chat/protocols/irc/irc.jsm
chat/protocols/twitter/twitter.jsm
--- a/chat/components/src/imCore.jsm
+++ b/chat/components/src/imCore.jsm
@@ -342,19 +342,20 @@ CoreService.prototype = {
   },
 
   getProtocols() {
     if (!this._initialized) {
       throw Cr.NS_ERROR_NOT_INITIALIZED;
     }
 
     let protocols = [];
-    let entries = categoryManager.enumerateCategory(kProtocolPluginCategory);
-    while (entries.hasMoreElements()) {
-      let id = entries.getNext().QueryInterface(Ci.nsISupportsCString).data;
+    for (let entry of categoryManager.enumerateCategory(
+      kProtocolPluginCategory
+    )) {
+      let id = entry.data;
 
       // If the preference is set to disable this prpl, don't show it in the
       // full list of protocols.
       let pref = "chat.prpls." + id + ".disable";
       if (
         Services.prefs.getPrefType(pref) == Services.prefs.PREF_BOOL &&
         Services.prefs.getBoolPref(pref)
       ) {
--- a/chat/components/src/test/test_logger.js
+++ b/chat/components/src/test/test_logger.js
@@ -409,18 +409,18 @@ var test_logging = async function() {
         ok(prop in message);
         equal(expectedMessage[prop], message[prop]);
       }
     }
   };
 
   let logs = await logger.getLogsForConversation(dummyConv);
   let allLogMsgs = [];
-  while (logs.hasMoreElements()) {
-    let conv = await logs.getNext().getConversation();
+  for (let log of logs) {
+    let conv = await log.getConversation();
     if (!conv) {
       continue;
     }
     allLogMsgs = allLogMsgs.concat(conv.getMessages());
   }
   // Two session messages, one for each valid log file.
   testMsgs(allLogMsgs, firstDayMsgs.concat(secondDayMsgs), 2);
 
@@ -434,18 +434,17 @@ var test_logging = async function() {
   };
 
   // Group expected messages by day.
   let messagesByDay = new Map();
   messagesByDay.set(reduceTimeToDate(firstDayMsgs[0].time), firstDayMsgs);
   messagesByDay.set(reduceTimeToDate(secondDayMsgs[0].time), secondDayMsgs);
 
   logs = await logger.getLogsForConversation(dummyConv, true);
-  while (logs.hasMoreElements()) {
-    let log = logs.getNext();
+  for (let log of logs) {
     let conv = await log.getConversation();
     let date = reduceTimeToDate(log.time);
     // 3 session messages - for daily logs, bad files are included.
     testMsgs(conv.getMessages(), messagesByDay.get(date), 3);
   }
 
   // Remove the created log files, testing forEach in the process.
   await logger.forEach({
--- a/chat/content/chat-tooltip.js
+++ b/chat/content/chat-tooltip.js
@@ -341,18 +341,17 @@
       let tooltipInfo = aBuddy.getTooltipInfo();
       if (tooltipInfo) {
         this.updateTooltipInfo(tooltipInfo);
       }
       return true;
     }
 
     updateTooltipInfo(aTooltipInfo) {
-      while (aTooltipInfo.hasMoreElements()) {
-        let elt = aTooltipInfo.getNext().QueryInterface(Ci.prplITooltipInfo);
+      for (let elt of aTooltipInfo) {
         switch (elt.type) {
           case Ci.prplITooltipInfo.pair:
           case Ci.prplITooltipInfo.sectionHeader:
             this.addRow(elt.label, elt.value);
             break;
           case Ci.prplITooltipInfo.sectionBreak:
             this.addSeparator();
             break;
--- a/chat/content/imAccountOptionsHelper.js
+++ b/chat/content/imAccountOptionsHelper.js
@@ -39,23 +39,21 @@ var accountOptionsHelper = {
     let hbox = document.createXULElement("hbox");
 
     let label = document.createXULElement("label");
     label.setAttribute("value", aLabel);
     label.setAttribute("control", aName);
     hbox.appendChild(label);
     vbox.appendChild(hbox);
 
-    aList.QueryInterface(Ci.nsISimpleEnumerator);
     let menulist = document.createXULElement("menulist");
     menulist.setAttribute("id", aName);
     menulist.setAttribute("flex", "1");
     let popup = menulist.appendChild(document.createXULElement("menupopup"));
-    while (aList.hasMoreElements()) {
-      let elt = aList.getNext();
+    for (let elt of aList) {
       let item = document.createXULElement("menuitem");
       item.setAttribute("label", elt.name);
       item.setAttribute("value", elt.value);
       popup.appendChild(item);
     }
     vbox.appendChild(menulist);
     return vbox;
   },
--- a/chat/modules/OTRHelpers.jsm
+++ b/chat/modules/OTRHelpers.jsm
@@ -6,19 +6,18 @@ const { OS } = ChromeUtils.import("resou
 const { Services } = ChromeUtils.import("resource:///modules/imServices.jsm");
 
 var OTRHelpers = {
   profilePath(filename) {
     return OS.Path.join(OS.Constants.Path.profileDir, filename);
   },
 
   *getAccounts() {
-    let accounts = Services.accounts.getAccounts();
-    while (accounts.hasMoreElements()) {
-      yield accounts.getNext();
+    for (let account of Services.accounts.getAccounts()) {
+      yield account;
     }
   },
 
   readTextFile(filename) {
     let decoder = new TextDecoder();
     return OS.File.read(filename).then(function(array) {
       return decoder.decode(array);
     });
--- a/chat/modules/OTRUI.jsm
+++ b/chat/modules/OTRUI.jsm
@@ -111,27 +111,25 @@ var OTRUI = {
   logMsg(msg) {
     if (!OTRUI.debug) {
       return;
     }
     Services.console.logStringMessage(msg);
   },
 
   addMenuObserver() {
-    let iter = Services.ww.getWindowEnumerator();
-    while (iter.hasMoreElements()) {
-      OTRUI.addMenus(iter.getNext());
+    for (let win of Services.ww.getWindowEnumerator()) {
+      OTRUI.addMenus(win);
     }
     Services.obs.addObserver(OTRUI, "domwindowopened");
   },
 
   removeMenuObserver() {
-    let iter = Services.ww.getWindowEnumerator();
-    while (iter.hasMoreElements()) {
-      OTRUI.removeMenus(iter.getNext());
+    for (let win of Services.ww.getWindowEnumerator()) {
+      OTRUI.removeMenus(win);
     }
     Services.obs.removeObserver(OTRUI, "domwindowopened");
   },
 
   addMenus(win) {
     let doc = win.document;
     // Account for unready windows
     if (doc.readyState !== "complete") {
@@ -267,39 +265,35 @@ var OTRUI = {
         // Disabled until #76 is resolved.
         // Services.obs.addObserver(OTRUI, "contact-added", false);
         Services.obs.addObserver(OTRUI, "account-added");
         // Services.obs.addObserver(OTRUI, "contact-signed-off", false);
         Services.obs.addObserver(OTRUI, "conversation-loaded");
         Services.obs.addObserver(OTRUI, "conversation-closed");
         Services.obs.addObserver(OTRUI, "prpl-quit");
 
-        let conversations = Services.conversations.getConversations();
-        while (conversations.hasMoreElements()) {
-          let aConv = conversations.getNext();
-          OTRUI.initConv(aConv);
+        for (let conv of Services.conversations.getConversations()) {
+          OTRUI.initConv(conv);
         }
         OTRUI.addMenuObserver();
 
         ChromeUtils.idleDispatch(OTRUI.genMissingKeys);
       })
       .catch(function(err) {
         // console.log("===> " + err + "\n");
         throw err;
       });
   },
 
   disconnect(aConv) {
     if (aConv) {
       return OTR.disconnect(aConv, true);
     }
     let allGood = true;
-    let conversations = Services.conversations.getConversations();
-    while (conversations.hasMoreElements()) {
-      let conv = conversations.getNext();
+    for (let conv of Services.conversations.getConversations()) {
       if (conv.isChat) {
         continue;
       }
       if (!OTR.disconnect(conv, true)) {
         allGood = false;
       }
     }
     return allGood;
@@ -860,17 +854,16 @@ var OTRUI = {
     Services.obs.removeObserver(OTR, "new-ui-conversation");
     // Services.obs.removeObserver(OTRUI, "contact-added");
     // Services.obs.removeObserver(OTRUI, "contact-signed-off");
     Services.obs.removeObserver(OTRUI, "account-added");
     Services.obs.removeObserver(OTRUI, "conversation-loaded");
     Services.obs.removeObserver(OTRUI, "conversation-closed");
     Services.obs.removeObserver(OTRUI, "prpl-quit");
 
-    let conversations = Services.conversations.getConversations();
-    while (conversations.hasMoreElements()) {
-      OTRUI.resetConv(conversations.getNext());
+    for (let conv of Services.conversations.getConversations()) {
+      OTRUI.resetConv(conv);
     }
     OTR.removeObserver(OTRUI);
     OTR.close();
     OTRUI.removeMenuObserver();
   },
 };
--- a/chat/modules/imThemes.jsm
+++ b/chat/modules/imThemes.jsm
@@ -331,31 +331,29 @@ function getDirectoryEntries(aDir) {
       return [];
     }
 
     let escapedEntry = strEntry.replace(/([*?$[\]^~()\\])/g, "\\$1");
     let filter = escapedEntry + "?*~" + escapedEntry + "?*/?*";
     let entries = zr.findEntries(filter);
 
     let parentLength = strEntry.length;
-    while (entries.hasMore()) {
-      results.push(entries.getNext().substring(parentLength));
+    for (let entry of entries) {
+      results.push(entry.substring(parentLength));
     }
     zr.close();
   } else if (uri.scheme == "file") {
     uri.QueryInterface(Ci.nsIFileURL);
     let dir = uri.file;
 
     if (!dir.exists() || !dir.isDirectory()) {
       return [];
     }
 
-    let children = dir.directoryEntries;
-    while (children.hasMoreElements()) {
-      let file = children.nextFile;
+    for (let file of dir.directoryEntries) {
       results.push(file.leafName);
     }
   }
 
   return results;
 }
 
 function getThemeVariants(aTheme) {
--- a/chat/protocols/irc/irc.jsm
+++ b/chat/protocols/irc/irc.jsm
@@ -385,19 +385,17 @@ var GenericIRCConversation = {
     // If the nick is offline, tell the user. In that case, it's WHOWAS info.
     let msgType = "message.whois";
     if ("offline" in account.whoisInformation.get(nick)) {
       msgType = "message.whowas";
     }
     let msg = _(msgType, account.whoisInformation.get(nick).nick);
 
     // Iterate over each field.
-    let tooltipInfo = aSubject.QueryInterface(Ci.nsISimpleEnumerator);
-    while (tooltipInfo.hasMoreElements()) {
-      let elt = tooltipInfo.getNext().QueryInterface(Ci.prplITooltipInfo);
+    for (let elt of aSubject.QueryInterface(Ci.nsISimpleEnumerator)) {
       switch (elt.type) {
         case Ci.prplITooltipInfo.pair:
         case Ci.prplITooltipInfo.sectionHeader:
           msg += "\n" + _("message.whoisEntry", elt.label, elt.value);
           break;
         case Ci.prplITooltipInfo.sectionBreak:
           break;
         case Ci.prplITooltipInfo.status:
--- a/chat/protocols/twitter/twitter.jsm
+++ b/chat/protocols/twitter/twitter.jsm
@@ -1207,19 +1207,17 @@ Account.prototype = {
       },
       QueryInterface: ChromeUtils.generateQI([Ci.prplIRequestBrowser]),
     };
     Services.obs.notifyObservers(this._browserRequest, "browser-request");
   },
   finishAuthorizationRequest() {
     // Clean up the cookies, so that several twitter OAuth dialogs can work
     // during the same session (bug 954308).
-    let cookies = Services.cookies.getCookiesFromHost("twitter.com", {});
-    while (cookies.hasMoreElements()) {
-      let cookie = cookies.getNext().QueryInterface(Ci.nsICookie);
+    for (let cookie of Services.cookies.getCookiesFromHost("twitter.com", {})) {
       Services.cookies.remove(
         cookie.host,
         cookie.name,
         cookie.path,
         false,
         cookie.originAttributes
       );
     }