зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1486147: Part 2 - Update JS string enumerator callers to use JS iteration. r=mccr8
Differential Revision: https://phabricator.services.mozilla.com/D4270 --HG-- extra : rebase_source : 2adadcc8e51a7bce1da02f4bee1333b77bfa9944 extra : histedit_source : 9df920fd186f8c96a5d8b9cbff53ea9529f26ee0
This commit is contained in:
Родитель
31cf107646
Коммит
1c20e8cbbb
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче