author | David Rajchenbach-Teller <dteller@mozilla.com> |
Fri, 21 Sep 2012 23:36:15 -0400 | |
changeset 107793 | 3c29b24fd648208ada710a23cf807c3eed564f8c |
parent 107792 | c6aadfcb3ccf553d3d303a4c9e3d7683d798d3c2 |
child 107794 | 6ceb3039c0a8322194339a75abd85cc481e4c77f |
push id | 23509 |
push user | ryanvm@gmail.com |
push date | Sat, 22 Sep 2012 12:28:38 +0000 |
treeherder | mozilla-central@b461a7cd250e [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | froydnj |
bugs | 782231 |
milestone | 18.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
|
--- a/toolkit/components/osfile/osfile_shared_front.jsm +++ b/toolkit/components/osfile/osfile_shared_front.jsm @@ -196,16 +196,32 @@ AbstractFile.normalizeToPointer = functi AbstractFile.AbstractIterator = function AbstractIterator() { }; AbstractFile.AbstractIterator.prototype = { /** * Allow iterating with |for| */ __iterator__: function __iterator__() { return this; + }, + /** + * Apply a function to all elements of the directory sequentially. + * + * @param {Function} cb This function will be applied to all entries + * of the directory. It receives as arguments + * - the OS.File.Entry corresponding to the entry; + * - the index of the entry in the enumeration; + * - 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); + } } }; /** * Utility function shared by implementations of |OS.File.open|: * extract read/write/trunc/create/existing flags from a |mode| * object. *