diff --git a/browser/base/content/test/static/head.js b/browser/base/content/test/static/head.js index 4ac035dabc9a..f2b8204adbd4 100644 --- a/browser/base/content/test/static/head.js +++ b/browser/base/content/test/static/head.js @@ -108,11 +108,9 @@ function getURLForFile(file) { */ function* generateEntriesFromJarFile(jarFile, extension) { let zr = new ZipReader(jarFile); - let entryEnumerator = zr.findEntries("*" + extension + "$"); - const kURIStart = getURLForFile(jarFile); - while (entryEnumerator.hasMore()) { - let entry = entryEnumerator.getNext(); + + for (let entry of zr.findEntries("*" + extension + "$")) { // Ignore the JS cache which is stored in omni.ja if (entry.startsWith("jsloader") || entry.startsWith("jssubloader")) { continue; diff --git a/browser/components/distribution.js b/browser/components/distribution.js index 00e03c3706f1..c5116170781e 100644 --- a/browser/components/distribution.js +++ b/browser/components/distribution.js @@ -94,7 +94,7 @@ DistributionCustomizer.prototype = { }, async _parseBookmarksSection(parentGuid, section) { - let keys = Array.from(enumerate(this._ini.getKeys(section))).sort(); + let keys = Array.from(this._ini.getKeys(section)).sort(); let re = /^item\.(\d+)\.(\w+)\.?(\w*)/; let items = {}; let defaultIndex = -1; @@ -317,7 +317,7 @@ DistributionCustomizer.prototype = { var usedPreferences = []; if (sections["Preferences-" + this._locale]) { - for (let key of enumerate(this._ini.getKeys("Preferences-" + this._locale))) { + for (let key of this._ini.getKeys("Preferences-" + this._locale)) { try { let value = this._ini.getString("Preferences-" + this._locale, key); if (value) { @@ -329,7 +329,7 @@ DistributionCustomizer.prototype = { } if (sections["Preferences-" + this._language]) { - for (let key of enumerate(this._ini.getKeys("Preferences-" + this._language))) { + for (let key of this._ini.getKeys("Preferences-" + this._language)) { if (usedPreferences.indexOf(key) > -1) { continue; } @@ -344,7 +344,7 @@ DistributionCustomizer.prototype = { } if (sections.Preferences) { - for (let key of enumerate(this._ini.getKeys("Preferences"))) { + for (let key of this._ini.getKeys("Preferences")) { if (usedPreferences.indexOf(key) > -1) { continue; } @@ -369,7 +369,7 @@ DistributionCustomizer.prototype = { var usedLocalizablePreferences = []; if (sections["LocalizablePreferences-" + this._locale]) { - for (let key of enumerate(this._ini.getKeys("LocalizablePreferences-" + this._locale))) { + for (let key of this._ini.getKeys("LocalizablePreferences-" + this._locale)) { try { let value = this._ini.getString("LocalizablePreferences-" + this._locale, key); if (value) { @@ -383,7 +383,7 @@ DistributionCustomizer.prototype = { } if (sections["LocalizablePreferences-" + this._language]) { - for (let key of enumerate(this._ini.getKeys("LocalizablePreferences-" + this._language))) { + for (let key of this._ini.getKeys("LocalizablePreferences-" + this._language)) { if (usedLocalizablePreferences.indexOf(key) > -1) { continue; } @@ -400,7 +400,7 @@ DistributionCustomizer.prototype = { } if (sections.LocalizablePreferences) { - for (let key of enumerate(this._ini.getKeys("LocalizablePreferences"))) { + for (let key of this._ini.getKeys("LocalizablePreferences")) { if (usedLocalizablePreferences.indexOf(key) > -1) { continue; } @@ -461,14 +461,9 @@ function parseValue(value) { return value; } -function* enumerate(UTF8Enumerator) { - while (UTF8Enumerator.hasMore()) - yield UTF8Enumerator.getNext(); -} - function enumToObject(UTF8Enumerator) { let ret = {}; - for (let i of enumerate(UTF8Enumerator)) + for (let i of UTF8Enumerator) ret[i] = 1; return ret; } diff --git a/browser/components/migration/360seProfileMigrator.js b/browser/components/migration/360seProfileMigrator.js index f8aceef3eea3..e3cecf549e27 100644 --- a/browser/components/migration/360seProfileMigrator.js +++ b/browser/components/migration/360seProfileMigrator.js @@ -63,14 +63,10 @@ function parseINIStrings(file) { getService(Ci.nsIINIParserFactory); let parser = factory.createINIParser(file); let obj = {}; - let sections = parser.getSections(); - while (sections.hasMore()) { - let section = sections.getNext(); + for (let section of parser.getSections()) { obj[section] = {}; - let keys = parser.getKeys(section); - while (keys.hasMore()) { - let key = keys.getNext(); + for (let key of parser.getKeys(section)) { obj[section][key] = parser.getString(section, key); } } diff --git a/chrome/test/unit/test_bug848297.js b/chrome/test/unit/test_bug848297.js index 6cab202c13a3..84c694e889a3 100644 --- a/chrome/test/unit/test_bug848297.js +++ b/chrome/test/unit/test_bug848297.js @@ -19,12 +19,7 @@ var chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"] chromeReg.checkForNewChrome(); function enum_to_array(strings) { - let rv = []; - while (strings.hasMore()) { - rv.push(strings.getNext()); - } - rv.sort(); - return rv; + return Array.from(strings).sort(); } function run_test() { diff --git a/dom/cache/test/xpcshell/head.js b/dom/cache/test/xpcshell/head.js index 86306adcf1c3..917a299af1ed 100644 --- a/dom/cache/test/xpcshell/head.js +++ b/dom/cache/test/xpcshell/head.js @@ -33,12 +33,7 @@ function create_test_profile(zipFileName) { .createInstance(Ci.nsIZipReader); zipReader.open(packageFile); - var entryNames = []; - var entries = zipReader.findEntries(null); - while (entries.hasMore()) { - var entry = entries.getNext(); - entryNames.push(entry); - } + var entryNames = Array.from(zipReader.findEntries(null)); entryNames.sort(); for (var entryName of entryNames) { diff --git a/dom/indexedDB/test/unit/xpcshell-head-parent-process.js b/dom/indexedDB/test/unit/xpcshell-head-parent-process.js index eeaf942731b7..d751d00e6950 100644 --- a/dom/indexedDB/test/unit/xpcshell-head-parent-process.js +++ b/dom/indexedDB/test/unit/xpcshell-head-parent-process.js @@ -286,9 +286,7 @@ function installPackagedProfile(packageName) zipReader.open(packageFile); let entryNames = []; - let entries = zipReader.findEntries(null); - while (entries.hasMore()) { - let entry = entries.getNext(); + for (let entry of zipReader.findEntries(null)) { if (entry != "create_db.html") { entryNames.push(entry); } diff --git a/dom/quota/test/unit/head.js b/dom/quota/test/unit/head.js index 6ffc233d8b85..2a0b54b66a51 100644 --- a/dom/quota/test/unit/head.js +++ b/dom/quota/test/unit/head.js @@ -171,12 +171,7 @@ function installPackage(packageName) .createInstance(Ci.nsIZipReader); zipReader.open(packageFile); - let entryNames = []; - let entries = zipReader.findEntries(null); - while (entries.hasMore()) { - let entry = entries.getNext(); - entryNames.push(entry); - } + let entryNames = Array.from(zipReader.findEntries(null)); entryNames.sort(); for (let entryName of entryNames) { diff --git a/js/xpconnect/loader/XPCOMUtils.jsm b/js/xpconnect/loader/XPCOMUtils.jsm index a09e1b26f03b..07a5051e76d1 100644 --- a/js/xpconnect/loader/XPCOMUtils.jsm +++ b/js/xpconnect/loader/XPCOMUtils.jsm @@ -413,10 +413,9 @@ var XPCOMUtils = { * @param e The string enumerator (nsIUTF8StringEnumerator or * nsIStringEnumerator) over which to iterate. */ - IterStringEnumerator: function* XPCU_IterStringEnumerator(e) + IterStringEnumerator: function XPCU_IterStringEnumerator(e) { - while (e.hasMore()) - yield e.getNext(); + return e; }, /** diff --git a/modules/libjar/test/unit/test_corrupt_1211262.js b/modules/libjar/test/unit/test_corrupt_1211262.js index f69619c17325..1b71f50f62b0 100644 --- a/modules/libjar/test/unit/test_corrupt_1211262.js +++ b/modules/libjar/test/unit/test_corrupt_1211262.js @@ -11,11 +11,8 @@ function run_test() { createInstance(Ci.nsIZipReader); zipreader.open(file); - var entries = zipreader.findEntries('*'); var failed = false; - - while (entries.hasMore()) { - let entryPath = entries.getNext(); + for (let entryPath of zipreader.findEntries('*')) { let entry = zipreader.getEntry(entryPath); if (!entry.isDirectory) { try { diff --git a/security/manager/ssl/tests/unit/test_signed_apps.js b/security/manager/ssl/tests/unit/test_signed_apps.js index 31940dccaaa6..39d12edde94a 100644 --- a/security/manager/ssl/tests/unit/test_signed_apps.js +++ b/security/manager/ssl/tests/unit/test_signed_apps.js @@ -25,9 +25,7 @@ function tamper(inFilePath, outFilePath, modifications, newEntries) { .createInstance(Ci.nsIZipReader); reader.open(inFilePath); try { - let entries = reader.findEntries(""); - while (entries.hasMore()) { - let entryName = entries.getNext(); + for (let entryName of reader.findEntries("")) { let inEntry = reader.getEntry(entryName); let entryInput = reader.getInputStream(entryName); try { diff --git a/testing/mochitest/chrome-harness.js b/testing/mochitest/chrome-harness.js index 061cf0f91961..5136413419a3 100644 --- a/testing/mochitest/chrome-harness.js +++ b/testing/mochitest/chrome-harness.js @@ -135,9 +135,8 @@ function extractJarToTmp(jar) { /* Create dir structure first, no guarantee about ordering of directories and * files returned from findEntries. */ - var dirs = zReader.findEntries(filepath + "*/"); - while (dirs.hasMore()) { - var targetDir = buildRelativePath(dirs.getNext(), tmpdir, filepath); + for (let dir of zReader.findEntries(filepath + "*/")) { + var targetDir = buildRelativePath(dir, tmpdir, filepath); // parseInt is used because octal escape sequences cause deprecation warnings // in strict mode (which is turned on in debug builds) if (!targetDir.exists()) { @@ -146,9 +145,7 @@ function extractJarToTmp(jar) { } // now do the files - var files = zReader.findEntries(filepath + "*"); - while (files.hasMore()) { - var fname = files.getNext(); + for (var fname of zReader.findEntries(filepath + "*")) { if (fname.substr(-1) != "/") { var targetFile = buildRelativePath(fname, tmpdir, filepath); zReader.extract(fname, targetFile); diff --git a/toolkit/components/xulstore/tests/xpcshell/test_XULStore.js b/toolkit/components/xulstore/tests/xpcshell/test_XULStore.js index 8da8dca9fcb7..53174b71d6f4 100644 --- a/toolkit/components/xulstore/tests/xpcshell/test_XULStore.js +++ b/toolkit/components/xulstore/tests/xpcshell/test_XULStore.js @@ -26,30 +26,11 @@ function checkValueExists(uri, id, attr, exists) { } function getIDs(uri) { - let it = XULStore.getIDsEnumerator(uri); - let result = []; - - while (it.hasMore()) { - let value = it.getNext(); - result.push(value); - } - - result.sort(); - return result; + return Array.from(XULStore.getIDsEnumerator(uri)).sort(); } function getAttributes(uri, id) { - let it = XULStore.getAttributeEnumerator(uri, id); - - let result = []; - - while (it.hasMore()) { - let value = it.getNext(); - result.push(value); - } - - result.sort(); - return result; + return Array.from(XULStore.getAttributeEnumerator(uri, id)).sort(); } function checkArrays(a, b) { diff --git a/toolkit/content/contentAreaUtils.js b/toolkit/content/contentAreaUtils.js index 4b28ec530957..e125216742cf 100644 --- a/toolkit/content/contentAreaUtils.js +++ b/toolkit/content/contentAreaUtils.js @@ -848,11 +848,8 @@ function appendFiltersForContentType(aFilePicker, aContentType, aFileExtension, var mimeInfo = getMIMEInfoForType(aContentType, aFileExtension); if (mimeInfo) { - var extEnumerator = mimeInfo.getFileExtensions(); - var extString = ""; - while (extEnumerator.hasMore()) { - var extension = extEnumerator.getNext(); + for (var extension of mimeInfo.getFileExtensions()) { if (extString) extString += "; "; // If adding more than one extension, // separate by semi-colon diff --git a/toolkit/crashreporter/CrashSubmit.jsm b/toolkit/crashreporter/CrashSubmit.jsm index b1e6f34481a7..5eef5377bb2a 100644 --- a/toolkit/crashreporter/CrashSubmit.jsm +++ b/toolkit/crashreporter/CrashSubmit.jsm @@ -28,9 +28,7 @@ function parseINIStrings(path) { getService(Ci.nsIINIParserFactory); let parser = factory.createINIParser(file); let obj = {}; - let en = parser.getKeys("Strings"); - while (en.hasMore()) { - let key = en.getNext(); + for (let key of parser.getKeys("Strings")) { obj[key] = parser.getString("Strings", key); } return obj; diff --git a/toolkit/modules/ZipUtils.jsm b/toolkit/modules/ZipUtils.jsm index 2d64916bea2b..6512d90060ed 100644 --- a/toolkit/modules/ZipUtils.jsm +++ b/toolkit/modules/ZipUtils.jsm @@ -105,10 +105,7 @@ var ZipUtils = { return (async function() { // Get all of the entries in the zip and sort them so we create directories // before files - let entries = zipReader.findEntries(null); - let names = []; - while (entries.hasMore()) - names.push(entries.getNext()); + let names = Array.from(zipReader.findEntries(null)); names.sort(); for (let name of names) { @@ -168,9 +165,7 @@ var ZipUtils = { try { // create directories first - let entries = zipReader.findEntries("*/"); - while (entries.hasMore()) { - let entryName = entries.getNext(); + for (let entryName of zipReader.findEntries("*/")) { let target = getTargetFile(aDir, entryName); if (!target.exists()) { try { @@ -182,9 +177,7 @@ var ZipUtils = { } } - entries = zipReader.findEntries(null); - while (entries.hasMore()) { - let entryName = entries.getNext(); + for (let entryName of zipReader.findEntries(null)) { let target = getTargetFile(aDir, entryName); if (target.exists()) continue; diff --git a/toolkit/mozapps/extensions/internal/AddonTestUtils.jsm b/toolkit/mozapps/extensions/internal/AddonTestUtils.jsm index fb06ab00423a..2b4fd4b3708a 100644 --- a/toolkit/mozapps/extensions/internal/AddonTestUtils.jsm +++ b/toolkit/mozapps/extensions/internal/AddonTestUtils.jsm @@ -1172,9 +1172,7 @@ var AddonTestUtils = { dir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY); let zip = ZipReader(xpiFile); - let entries = zip.findEntries(null); - while (entries.hasMore()) { - let entry = entries.getNext(); + for (let entry of zip.findEntries(null)) { let target = dir.clone(); for (let part of entry.split("/")) target.append(part); diff --git a/toolkit/mozapps/extensions/internal/XPIInstall.jsm b/toolkit/mozapps/extensions/internal/XPIInstall.jsm index 03d4465c045a..6421550f15c5 100644 --- a/toolkit/mozapps/extensions/internal/XPIInstall.jsm +++ b/toolkit/mozapps/extensions/internal/XPIInstall.jsm @@ -339,7 +339,7 @@ XPIPackage = class XPIPackage extends Package { } async iterFiles(callback) { - for (let path of XPCOMUtils.IterStringEnumerator(this.zipReader.findEntries("*"))) { + for (let path of this.zipReader.findEntries("*")) { let entry = this.zipReader.getEntry(path); callback({ path, diff --git a/toolkit/mozapps/installer/precompile_cache.js b/toolkit/mozapps/installer/precompile_cache.js index 6f4375284d22..4f11574c6ce3 100644 --- a/toolkit/mozapps/installer/precompile_cache.js +++ b/toolkit/mozapps/installer/precompile_cache.js @@ -15,12 +15,7 @@ function endsWith(str, end) { } function jar_entries(jarReader, pattern) { - var entries = []; - var enumerator = jarReader.findEntries(pattern); - while (enumerator.hasMore()) { - entries.push(enumerator.getNext()); - } - return entries; + return Array.from(jarReader.findEntries(pattern)); } function dir_entries(baseDir, subpath, ext) { diff --git a/uriloader/exthandler/HandlerService.js b/uriloader/exthandler/HandlerService.js index d786b9c96150..aea2abfed2aa 100644 --- a/uriloader/exthandler/HandlerService.js +++ b/uriloader/exthandler/HandlerService.js @@ -277,10 +277,9 @@ HandlerService.prototype = { } if (this._isMIMEInfo(handlerInfo)) { - let extEnumerator = handlerInfo.getFileExtensions(); let extensions = storedHandlerInfo.extensions || []; - while (extEnumerator.hasMore()) { - let extension = extEnumerator.getNext().toLowerCase(); + for (let extension of handlerInfo.getFileExtensions()) { + extension = extension.toLowerCase(); // If the caller stored duplicate extensions, we save them only once. if (!extensions.includes(extension)) { extensions.push(extension); diff --git a/xpcom/tests/unit/test_iniParser.js b/xpcom/tests/unit/test_iniParser.js index 14dde5666d49..21053ffae487 100644 --- a/xpcom/tests/unit/test_iniParser.js +++ b/xpcom/tests/unit/test_iniParser.js @@ -44,17 +44,11 @@ function checkParserOutput(parser, expected) { function getParserOutput(parser) { let output = {}; - let sections = parser.getSections(); - Assert.ok(!!sections); - while (sections.hasMore()) { - let section = sections.getNext(); + for (let section of parser.getSections()) { Assert.equal(false, section in output); // catch dupes output[section] = {}; - let keys = parser.getKeys(section); - Assert.ok(!!keys); - while (keys.hasMore()) { - let key = keys.getNext(); + for (let key of parser.getKeys(section)) { Assert.equal(false, key in output[section]); // catch dupes let value = parser.getString(section, key); output[section][key] = value;