Bug 737792 - Use for..of loops in browser.js. r=dao

--HG--
extra : rebase_source : df980b6310daecb9e80793ca900ba983aadb12c6
This commit is contained in:
Ian Moody 2012-08-21 18:56:07 +02:00
parent c2a0f28e4e
commit efcc5f0a50
4 changed files with 99 additions and 113 deletions

View File

@ -21,8 +21,7 @@ const gXPInstallObserver = {
_getBrowser: function (aDocShell)
{
for (var i = 0; i < gBrowser.browsers.length; ++i) {
var browser = gBrowser.getBrowserAtIndex(i);
for (let browser of gBrowser.browsers) {
if (this._findChildShell(browser.docShell, aDocShell))
return browser;
}
@ -116,23 +115,23 @@ const gXPInstallObserver = {
break;
case "addon-install-failed":
// TODO This isn't terribly ideal for the multiple failure case
installInfo.installs.forEach(function(aInstall) {
var host = (installInfo.originatingURI instanceof Ci.nsIStandardURL) &&
for (let install of installInfo.installs) {
let host = (installInfo.originatingURI instanceof Ci.nsIStandardURL) &&
installInfo.originatingURI.host;
if (!host)
host = (aInstall.sourceURI instanceof Ci.nsIStandardURL) &&
aInstall.sourceURI.host;
host = (install.sourceURI instanceof Ci.nsIStandardURL) &&
install.sourceURI.host;
var error = (host || aInstall.error == 0) ? "addonError" : "addonLocalError";
if (aInstall.error != 0)
error += aInstall.error;
else if (aInstall.addon.blocklistState == Ci.nsIBlocklistService.STATE_BLOCKED)
let error = (host || install.error == 0) ? "addonError" : "addonLocalError";
if (install.error != 0)
error += install.error;
else if (install.addon.blocklistState == Ci.nsIBlocklistService.STATE_BLOCKED)
error += "Blocklisted";
else
error += "Incompatible";
messageString = gNavigatorBundle.getString(error);
messageString = messageString.replace("#1", aInstall.name);
messageString = messageString.replace("#1", install.name);
if (host)
messageString = messageString.replace("#2", host);
messageString = messageString.replace("#3", brandShortName);
@ -140,7 +139,7 @@ const gXPInstallObserver = {
PopupNotifications.show(browser, notificationID, messageString, anchorID,
action, null, options);
});
}
break;
case "addon-install-complete":
var needsRestart = installInfo.installs.some(function(i) {
@ -167,14 +166,14 @@ const gXPInstallObserver = {
// installs
var types = {};
var bestType = null;
installInfo.installs.forEach(function(aInstall) {
if (aInstall.type in types)
types[aInstall.type]++;
for (let install of installInfo.installs) {
if (install.type in types)
types[install.type]++;
else
types[aInstall.type] = 1;
if (!bestType || types[aInstall.type] > types[bestType])
bestType = aInstall.type;
});
types[install.type] = 1;
if (!bestType || types[install.type] > types[bestType])
bestType = install.type;
}
BrowserOpenAddonsMgr("addons://list/" + bestType);
}
@ -214,10 +213,10 @@ let AddonsMgrListener = {
var defaultOrNoninteractive = this.addonBar.getAttribute("defaultset")
.split(",")
.concat(["separator", "spacer", "spring"]);
this.addonBar.currentSet.split(",").forEach(function (item) {
for (let item of this.addonBar.currentSet.split(",")) {
if (defaultOrNoninteractive.indexOf(item) == -1)
itemCount++;
});
}
return itemCount;
},

View File

@ -58,8 +58,7 @@ var FeedHandler = {
return false;
// Build the menu showing the available feed choices for viewing.
for (var i = 0; i < feeds.length; ++i) {
var feedInfo = feeds[i];
for (let feedInfo of feeds) {
var menuItem = document.createElement("menuitem");
var baseTitle = feedInfo.title || feedInfo.href;
var labelStr = gNavigatorBundle.getFormattedString("feedShowFeedNew", [baseTitle]);

View File

@ -519,39 +519,37 @@ var FullScreen = {
{
var els = document.getElementsByTagNameNS(this._XULNS, aTag);
for (var i = 0; i < els.length; ++i) {
for (let el of els) {
// XXX don't interfere with previously collapsed toolbars
if (els[i].getAttribute("fullscreentoolbar") == "true") {
if (el.getAttribute("fullscreentoolbar") == "true") {
if (!aShow) {
var toolbarMode = els[i].getAttribute("mode");
var toolbarMode = el.getAttribute("mode");
if (toolbarMode != "text") {
els[i].setAttribute("saved-mode", toolbarMode);
els[i].setAttribute("saved-iconsize",
els[i].getAttribute("iconsize"));
els[i].setAttribute("mode", "icons");
els[i].setAttribute("iconsize", "small");
el.setAttribute("saved-mode", toolbarMode);
el.setAttribute("saved-iconsize", el.getAttribute("iconsize"));
el.setAttribute("mode", "icons");
el.setAttribute("iconsize", "small");
}
// Give the main nav bar and the tab bar the fullscreen context menu,
// otherwise remove context menu to prevent breakage
els[i].setAttribute("saved-context",
els[i].getAttribute("context"));
if (els[i].id == "nav-bar" || els[i].id == "TabsToolbar")
els[i].setAttribute("context", "autohide-context");
el.setAttribute("saved-context", el.getAttribute("context"));
if (el.id == "nav-bar" || el.id == "TabsToolbar")
el.setAttribute("context", "autohide-context");
else
els[i].removeAttribute("context");
el.removeAttribute("context");
// Set the inFullscreen attribute to allow specific styling
// in fullscreen mode
els[i].setAttribute("inFullscreen", true);
el.setAttribute("inFullscreen", true);
}
else {
function restoreAttr(attrName) {
var savedAttr = "saved-" + attrName;
if (els[i].hasAttribute(savedAttr)) {
els[i].setAttribute(attrName, els[i].getAttribute(savedAttr));
els[i].removeAttribute(savedAttr);
if (el.hasAttribute(savedAttr)) {
el.setAttribute(attrName, el.getAttribute(savedAttr));
el.removeAttribute(savedAttr);
}
}
@ -559,15 +557,15 @@ var FullScreen = {
restoreAttr("iconsize");
restoreAttr("context");
els[i].removeAttribute("inFullscreen");
el.removeAttribute("inFullscreen");
}
} else {
// use moz-collapsed so it doesn't persist hidden/collapsed,
// so that new windows don't have missing toolbars
if (aShow)
els[i].removeAttribute("moz-collapsed");
el.removeAttribute("moz-collapsed");
else
els[i].setAttribute("moz-collapsed", "true");
el.setAttribute("moz-collapsed", "true");
}
}

View File

@ -527,14 +527,14 @@ var gPopupBlockerObserver = {
blockedPopupAllowSite.removeAttribute("disabled");
var foundUsablePopupURI = false;
var pageReport = gBrowser.pageReport;
if (pageReport) {
for (var i = 0; i < pageReport.length; ++i) {
var pageReports = gBrowser.pageReport;
if (pageReports) {
for (let pageReport of pageReports) {
// popupWindowURI will be null if the file picker popup is blocked.
// xxxdz this should make the option say "Show file picker" and do it (Bug 590306)
if (!pageReport[i].popupWindowURI)
if (!pageReport.popupWindowURI)
continue;
var popupURIspec = pageReport[i].popupWindowURI.spec;
var popupURIspec = pageReport.popupWindowURI.spec;
// Sometimes the popup URI that we get back from the pageReport
// isn't useful (for instance, netscape.com's popup URI ends up
@ -557,11 +557,11 @@ var gPopupBlockerObserver = {
[popupURIspec]);
menuitem.setAttribute("label", label);
menuitem.setAttribute("popupWindowURI", popupURIspec);
menuitem.setAttribute("popupWindowFeatures", pageReport[i].popupWindowFeatures);
menuitem.setAttribute("popupWindowName", pageReport[i].popupWindowName);
menuitem.setAttribute("popupWindowFeatures", pageReport.popupWindowFeatures);
menuitem.setAttribute("popupWindowName", pageReport.popupWindowName);
menuitem.setAttribute("oncommand", "gPopupBlockerObserver.showBlockedPopup(event);");
menuitem.requestingWindow = pageReport[i].requestingWindow;
menuitem.requestingDocument = pageReport[i].requestingDocument;
menuitem.requestingWindow = pageReport.requestingWindow;
menuitem.requestingDocument = pageReport.requestingDocument;
aEvent.target.appendChild(menuitem);
}
}
@ -915,7 +915,7 @@ let gGestureSupport = {
});
// Try each combination of key presses in decreasing order for commands
for each (let subCombo in this._power(keyCombos)) {
for (let subCombo of this._power(keyCombos)) {
// Convert a gesture and pressed keys into the corresponding command
// action where the preference has the gesture before "shift" before
// "alt" before "ctrl" before "meta" all separated by periods
@ -1658,8 +1658,8 @@ var gBrowserInit = {
'View:PageInfo', 'Tasks:InspectPage', 'Browser:ToggleTabView', 'Browser:ToggleAddonBar'];
var element;
for (var id in disabledItems) {
element = document.getElementById(disabledItems[id]);
for (let disabledItem of disabledItems) {
element = document.getElementById(disabledItem);
if (element)
element.setAttribute("disabled", "true");
}
@ -1668,8 +1668,8 @@ var gBrowserInit = {
// and zoom menu commands as well
if (window.location.href == "chrome://browser/content/hiddenWindow.xul") {
var hiddenWindowDisabledItems = ['cmd_close', 'minimizeWindow', 'zoomWindow'];
for (var id in hiddenWindowDisabledItems) {
element = document.getElementById(hiddenWindowDisabledItems[id]);
for (let hiddenWindowDisabledItem of hiddenWindowDisabledItems) {
element = document.getElementById(hiddenWindowDisabledItem);
if (element)
element.setAttribute("disabled", "true");
}
@ -1761,7 +1761,7 @@ var gBrowserInit = {
if (doMigrate) {
let cpdBranch = gPrefService.getBranch("privacy.cpd.");
let clearOnShutdownBranch = gPrefService.getBranch("privacy.clearOnShutdown.");
itemArray.forEach(function (name) {
for (let name of itemArray) {
try {
// don't migrate password or offlineApps clearing in the CRH dialog since
// there's no UI for those anymore. They default to false. bug 497656
@ -1772,7 +1772,7 @@ var gBrowserInit = {
catch(e) {
Cu.reportError("Exception thrown during privacy pref migration: " + e);
}
});
}
}
gPrefService.setBoolPref("privacy.sanitize.migrateFx3Prefs", true);
@ -2971,9 +2971,7 @@ function FillInHTMLTooltip(tipElement)
lookingForSVGTitle = false;
}
if (lookingForSVGTitle) {
let length = tipElement.childNodes.length;
for (let i = 0; i < length; i++) {
let childNode = tipElement.childNodes[i];
for (let childNode of tipElement.childNodes) {
if (childNode instanceof SVGTitleElement) {
SVGTitleText = childNode.textContent;
break;
@ -3217,10 +3215,9 @@ const DOMLinkHandler = {
var feedAdded = false;
var iconAdded = false;
var searchAdded = false;
var relStrings = rel.split(/\s+/);
var rels = {};
for (let i = 0; i < relStrings.length; i++)
rels[relStrings[i]] = true;
for (let relString of rel.split(/\s+/))
rels[relString] = true;
for (let relVal in rels) {
switch (relVal) {
@ -3576,8 +3573,8 @@ var gCustomizeSheet = false;
function BrowserCustomizeToolbar() {
// Disable the toolbar context menu items
var menubar = document.getElementById("main-menubar");
for (var i = 0; i < menubar.childNodes.length; ++i)
menubar.childNodes[i].setAttribute("disabled", true);
for (let childNode of menubar.childNodes)
childNode.setAttribute("disabled", true);
var cmd = document.getElementById("cmd_CustomizeToolbars");
cmd.setAttribute("disabled", "true");
@ -3674,8 +3671,8 @@ function BrowserToolboxCustomizeDone(aToolboxChanged) {
// Re-enable parts of the UI we disabled during the dialog
var menubar = document.getElementById("main-menubar");
for (var i = 0; i < menubar.childNodes.length; ++i)
menubar.childNodes[i].setAttribute("disabled", false);
for (let childNode of menubar.childNodes)
childNode.setAttribute("disabled", false);
var cmd = document.getElementById("cmd_CustomizeToolbars");
cmd.removeAttribute("disabled");
@ -3909,9 +3906,10 @@ var XULBrowserWindow = {
if (this._busyUI)
types.push("status");
types.push("jsStatus", "jsDefaultStatus", "defaultStatus");
for (let i = 0; !text && i < types.length; i++) {
type = types[i];
for (type of types) {
text = this[type];
if (text)
break;
}
// check the current value so we don't trigger an attribute change
@ -4170,12 +4168,12 @@ var XULBrowserWindow = {
let findCommands = [document.getElementById("cmd_find"),
document.getElementById("cmd_findAgain"),
document.getElementById("cmd_findPrevious")];
findCommands.forEach(function (elt) {
for (let elt of findCommands) {
if (disableFind)
elt.setAttribute("disabled", "true");
else
elt.removeAttribute("disabled");
});
}
if (gFindBarInitialized) {
if (gFindBar.findMode != gFindBar.FIND_NORMAL) {
@ -4697,8 +4695,8 @@ function onViewToolbarsPopupShowing(aEvent, aInsertPoint) {
let toolbarNodes = Array.slice(gNavToolbox.childNodes);
toolbarNodes.push(document.getElementById("addon-bar"));
toolbarNodes.forEach(function(toolbar) {
var toolbarName = toolbar.getAttribute("toolbarname");
for (let toolbar of toolbarNodes) {
let toolbarName = toolbar.getAttribute("toolbarname");
if (toolbarName) {
let menuItem = document.createElement("menuitem");
let hidingAttribute = toolbar.getAttribute("type") == "menubar" ?
@ -4717,7 +4715,7 @@ function onViewToolbarsPopupShowing(aEvent, aInsertPoint) {
menuItem.addEventListener("command", onViewToolbarCommand, false);
}
}, this);
}
}
function onViewToolbarCommand(aEvent) {
@ -4999,14 +4997,14 @@ function toggleSidebar(commandID, forceOpen) {
// ..but first update the 'checked' state of all sidebar broadcasters
var broadcasters = document.getElementsByAttribute("group", "sidebar");
for (var i = 0; i < broadcasters.length; ++i) {
for (let broadcaster of broadcasters) {
// skip elements that observe sidebar broadcasters and random
// other elements
if (broadcasters[i].localName != "broadcaster")
if (broadcaster.localName != "broadcaster")
continue;
if (broadcasters[i] != sidebarBroadcaster)
broadcasters[i].removeAttribute("checked");
if (broadcaster != sidebarBroadcaster)
broadcaster.removeAttribute("checked");
else
sidebarBroadcaster.setAttribute("checked", "true");
}
@ -5535,9 +5533,7 @@ var gPageStyleMenu = {
var haveAltSheets = false;
var altStyleSelected = false;
for (let i = 0; i < styleSheets.length; ++i) {
let currentStyleSheet = styleSheets[i];
for (let currentStyleSheet of styleSheets) {
if (!currentStyleSheet.title)
continue;
@ -5746,9 +5742,9 @@ var OfflineApps = {
// This depends on pseudo APIs of browser.js and tabbrowser.xml
aContentWindow = aContentWindow.top;
var browsers = aBrowserWindow.gBrowser.browsers;
for (var i = 0; i < browsers.length; ++i) {
if (browsers[i].contentWindow == aContentWindow)
return browsers[i];
for (let browser of browsers) {
if (browser.contentWindow == aContentWindow)
return browser;
}
return null;
},
@ -5779,10 +5775,10 @@ var OfflineApps = {
}
var browsers = gBrowser.browsers;
for (var i = 0; i < browsers.length; ++i) {
uri = this._getManifestURI(browsers[i].contentWindow);
for (let browser of browsers) {
uri = this._getManifestURI(browser.contentWindow);
if (uri && uri.equals(aCacheUpdate.manifestURI)) {
return browsers[i];
return browser;
}
}
@ -5828,10 +5824,10 @@ var OfflineApps = {
groups = cacheService.getGroups();
var usage = 0;
for (var i = 0; i < groups.length; i++) {
var uri = Services.io.newURI(groups[i], null, null);
for (let group of groups) {
var uri = Services.io.newURI(group, null, null);
if (uri.asciiHost == host) {
var cache = cacheService.getActiveCache(groups[i]);
var cache = cacheService.getActiveCache(group);
usage += cache.usage;
}
}
@ -5893,16 +5889,16 @@ var OfflineApps = {
label: gNavigatorBundle.getString("offlineApps.allow"),
accessKey: gNavigatorBundle.getString("offlineApps.allowAccessKey"),
callback: function() {
for (var i = 0; i < notification.documents.length; i++) {
OfflineApps.allowSite(notification.documents[i]);
for (let document of notification.documents) {
OfflineApps.allowSite(document);
}
}
},{
label: gNavigatorBundle.getString("offlineApps.never"),
accessKey: gNavigatorBundle.getString("offlineApps.neverAccessKey"),
callback: function() {
for (var i = 0; i < notification.documents.length; i++) {
OfflineApps.disallowSite(notification.documents[i]);
for (let document of notification.documents) {
OfflineApps.disallowSite(document);
}
}
},{
@ -6146,19 +6142,16 @@ function WindowIsClosing()
return false;
}
var reallyClose = closeWindow(false, warnAboutClosingWindow);
if (!reallyClose)
if (!closeWindow(false, warnAboutClosingWindow))
return false;
var numBrowsers = gBrowser.browsers.length;
for (let i = 0; reallyClose && i < numBrowsers; ++i) {
let ds = gBrowser.browsers[i].docShell;
for (let browser of gBrowser.browsers) {
let ds = browser.docShell;
if (ds.contentViewer && !ds.contentViewer.permitUnload())
reallyClose = false;
return false;
}
return reallyClose;
return true;
}
/**
@ -6326,7 +6319,6 @@ function AddKeywordForSearchField() {
[node.ownerDocument.title]);
var description = PlacesUIUtils.getDescriptionFromDocument(node.ownerDocument);
var el, type;
var formData = [];
function escapeNameValuePair(aName, aValue, aIsFormUrlEncoded) {
@ -6336,9 +6328,7 @@ function AddKeywordForSearchField() {
return escape(aName) + "=" + escape(aValue);
}
for (var i=0; i < node.form.elements.length; i++) {
el = node.form.elements[i];
for (let el of node.form.elements) {
if (!el.type) // happens with fieldsets
continue;
@ -6349,7 +6339,7 @@ function AddKeywordForSearchField() {
continue;
}
type = el.type.toLowerCase();
let type = el.type.toLowerCase();
if (((el instanceof HTMLInputElement && el.mozIsTextField(true)) ||
type == "hidden" || type == "textarea") ||
@ -7396,13 +7386,13 @@ var TabContextMenu = {
disabled && gBrowser.tabContainer._closeWindowWithLastTab;
var menuItems = aPopupMenu.getElementsByAttribute("tbattr", "tabbrowser-multiple");
for (var i = 0; i < menuItems.length; i++)
menuItems[i].disabled = disabled;
for (let menuItem of menuItems)
menuItem.disabled = disabled;
disabled = gBrowser.visibleTabs.length == 1;
menuItems = aPopupMenu.getElementsByAttribute("tbattr", "tabbrowser-multiple-visible");
for (var i = 0; i < menuItems.length; i++)
menuItems[i].disabled = disabled;
for (let menuItem of menuItems)
menuItem.disabled = disabled;
// Session store
document.getElementById("context_undoCloseTab").disabled =