forgot file for implement iterator-helper module for dealing with xpcom arrays in js, 418490, r/sr=bienvenu
authorjminta@gmail.com
Tue, 28 Oct 2008 19:16:54 -0700
changeset 750 cb1cabceabff0128ed350a6ef007c7d59d5e98b6
parent 749 2f9bf540fd3efd7ac9605cf8109d67e6aaa7d7e3
child 751 e81e3f13af0e0a630bb675a5d38877c0a7098103
push idunknown
push userunknown
push dateunknown
bugs418490
forgot file for implement iterator-helper module for dealing with xpcom arrays in js, 418490, r/sr=bienvenu
mail/components/search/content/searchCommon.js
--- a/mail/components/search/content/searchCommon.js
+++ b/mail/components/search/content/searchCommon.js
@@ -47,16 +47,18 @@
  * - gPrefBase: the base for preferences that are stored
  * - gStreamListener: an nsIStreamListener to read message text
  */
 #endif
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 
+Components.utils.import("resource://gre/modules/iteratorUtils.jsm");
+
 var gCurrentFolderToIndex;
 var gLastFolderIndexedUri = ""; // this is stored in a pref
 var gHeaderEnumerator;
 var gMsgHdrsToIndex;
 var gMessenger;
 var gAlarm;
 var gBackgroundIndexingDone;
 var gPrefBranch = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService).getBranch(null);
@@ -97,32 +99,31 @@ function InitSupportIntegration(enabled)
  */
 function FindNextFolderToIndex()
 {
   accountManager = Cc["@mozilla.org/messenger/account-manager;1"].getService(Ci.nsIMsgAccountManager);
   var servers = accountManager.allServers;
   var foundFolder = false;
   var useNextFolder = false;
 
-  for (var i = 0; i < servers.Count() && !foundFolder; i++)
+  for each (var server in fixIterator(servers, Ci.nsIMsgIncomingServer))
   {
-    var server = servers.QueryElementAt(i, Ci.nsIMsgIncomingServer);
     var rootFolder = server.rootFolder;
     var allFolders = Cc["@mozilla.org/supports-array;1"].createInstance(Ci.nsISupportsArray);
     rootFolder.ListDescendents(allFolders);
     var numFolders = allFolders.Count();
     SIDump("in find next folder, gLastFolderIndexedUri = " + gLastFolderIndexedUri + "\n");
-    for (var folderIndex = 0; folderIndex < numFolders && !foundFolder; folderIndex++)
+    for each (var folder in fixIterator(allFolders, Ci.nsIMsgFolder))
     {
-      var folder = allFolders.GetElementAt(folderIndex).QueryInterface(Ci.nsIMsgFolder);
       // if no folder was indexed (or the pref's not set), just use the first folder
       if (!gLastFolderIndexedUri.length || useNextFolder)
       {
         gCurrentFolderToIndex = folder;
         foundFolder = true;
+        break;
       }
       else
       {
         if (gLastFolderIndexedUri == folder.URI)
           useNextFolder = true;
       }
     }
   }