Bug 782231 - Implement DirectoryIterator.prototype.nextBatch. r=froydnj
authorDavid Rajchenbach-Teller <dteller@mozilla.com>
Fri, 21 Sep 2012 23:36:15 -0400
changeset 107794 6ceb3039c0a8322194339a75abd85cc481e4c77f
parent 107793 3c29b24fd648208ada710a23cf807c3eed564f8c
child 107795 a1a658f7c1d62e63dd394699dd484c26884053d5
push id23509
push userryanvm@gmail.com
push dateSat, 22 Sep 2012 12:28:38 +0000
treeherdermozilla-central@b461a7cd250e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs782231
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 782231 - Implement DirectoryIterator.prototype.nextBatch. r=froydnj
toolkit/components/osfile/osfile_shared_front.jsm
--- a/toolkit/components/osfile/osfile_shared_front.jsm
+++ b/toolkit/components/osfile/osfile_shared_front.jsm
@@ -212,16 +212,38 @@ AbstractFile.AbstractIterator.prototype 
    *  - the iterator itself - calling |close| on the iterator stops
    *   the loop.
    */
   forEach: function forEach(cb) {
     let index = 0;
     for (let entry in this) {
       cb(entry, index++, this);
     }
+  },
+  /**
+   * Return several entries at once.
+   *
+   * Entries are returned in the same order as a walk with |forEach| or
+   * |for(...)|.
+   *
+   * @param {number=} length If specified, the number of entries
+   * to return. If unspecified, return all remaining entries.
+   * @return {Array} An array containing the next |length| entries, or
+   * less if the iteration contains less than |length| entries left.
+   */
+  nextBatch: function nextBatch(length) {
+    let array = [];
+    let i = 0;
+    for (let entry in this) {
+      array.push(entry);
+      if (++i >= length) {
+        return array;
+      }
+    }
+    return array;
   }
 };
 
 /**
  * Utility function shared by implementations of |OS.File.open|:
  * extract read/write/trunc/create/existing flags from a |mode|
  * object.
  *