diff --git a/toolkit/components/osfile/osfile_shared_front.jsm b/toolkit/components/osfile/osfile_shared_front.jsm index ff2662552b8..a065de44775 100644 --- a/toolkit/components/osfile/osfile_shared_front.jsm +++ b/toolkit/components/osfile/osfile_shared_front.jsm @@ -201,6 +201,22 @@ AbstractFile.AbstractIterator.prototype = { */ __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); + } } };