Bug 1544834 - Replace non-test uses of deprecated Array generics r=evilpie,dao

- `Array.forEach` becomes for-of loop or `array.forEach`.
- `Array.slice(a)` or `Array.slice(a, 0)` becomes `Array.from(a)`.
- `Array.map` becomes `Array.from`
- `Array` copy + concatenation becomes Array literal + spread syntax.
- All other `Array.X(a, ...)` become `Array.prototype.X.call` or `Array.from(a).X(...)`

Differential Revision: https://phabricator.services.mozilla.com/D27802

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Rob Wu 2019-04-17 19:03:17 +00:00
parent 7426d1f4e9
commit 1af4c55c01
27 changed files with 51 additions and 47 deletions

View File

@ -289,7 +289,8 @@ var ctrlTab = {
},
advanceFocus: function ctrlTab_advanceFocus(aForward) {
let selectedIndex = Array.indexOf(this.previews, this.selected);
let selectedIndex = Array.prototype.indexOf.call(this.previews,
this.selected);
do {
selectedIndex += aForward ? 1 : -1;
if (selectedIndex < 0)
@ -565,7 +566,7 @@ var ctrlTab = {
_initRecentlyUsedTabs() {
this._recentlyUsedTabs =
Array.filter(gBrowser.tabs, tab => !tab.closing)
Array.prototype.filter.call(gBrowser.tabs, tab => !tab.closing)
.sort((tab1, tab2) => tab2.lastAccessed - tab1.lastAccessed);
},

View File

@ -101,10 +101,10 @@ pageInfoTreeView.prototype = {
this.sortdir
);
Array.forEach(tree.columns, function(col) {
for (let col of tree.columns) {
col.element.removeAttribute("sortActive");
col.element.removeAttribute("sortDirection");
});
}
treecol.element.setAttribute("sortActive", "true");
treecol.element.setAttribute("sortDirection", this.sortdir ?
"ascending" : "descending");
@ -195,10 +195,10 @@ gImageView.onPageMediaSort = function(columnname) {
this.sortdir
);
Array.forEach(tree.columns, function(col) {
for (let col of tree.columns) {
col.element.removeAttribute("sortActive");
col.element.removeAttribute("sortDirection");
});
}
treecol.element.setAttribute("sortActive", "true");
treecol.element.setAttribute("sortDirection", this.sortdir ?
"ascending" : "descending");

View File

@ -180,7 +180,7 @@
// Override scrollbox.xml method, since our scrollbox's children are
// inherited from the scrollbox binding parent (this).
arrowScrollbox._getScrollableElements = () => {
return Array.filter(this.children, arrowScrollbox._canScrollToElement);
return Array.prototype.filter.call(this.children, arrowScrollbox._canScrollToElement);
};
arrowScrollbox._canScrollToElement = tab => {
return !tab._pinnedUnscrollable && !tab.hidden;

View File

@ -1701,7 +1701,7 @@ CustomizeMode.prototype = {
dragValue = "after";
} else {
let targetParent = targetNode.parentNode;
let position = Array.indexOf(targetParent.children, targetNode);
let position = Array.prototype.indexOf.call(targetParent.children, targetNode);
if (position == -1) {
dragOverItem = (targetAreaType == "toolbar"
? this._findVisiblePreviousSiblingNode(targetNode.lastElementChild)

View File

@ -153,14 +153,14 @@ var DownloadsCommon = {
strings[stringName] = function() {
// Convert "arguments" to a real array before calling into XPCOM.
return sb.formatStringFromName(stringName,
Array.slice(arguments, 0),
Array.from(arguments),
arguments.length);
};
} else if (stringName in kDownloadsStringsRequiringPluralForm) {
strings[stringName] = function(aCount) {
// Convert "arguments" to a real array before calling into XPCOM.
let formattedString = sb.formatStringFromName(stringName,
Array.slice(arguments, 0),
Array.from(arguments),
arguments.length);
return PluralForm.get(aCount, formattedString);
};

View File

@ -295,8 +295,9 @@ DownloadsPlacesView.prototype = {
},
get selectedNodes() {
return Array.filter(this._richlistbox.selectedItems,
element => element._shell.download.placesNode);
return Array.prototype.filter.call(
this._richlistbox.selectedItems,
element => element._shell.download.placesNode);
},
get selectedNode() {
@ -501,14 +502,15 @@ DownloadsPlacesView.prototype = {
case "downloadsCmd_clearDownloads":
return this.canClearDownloads(this._richlistbox);
default:
return Array.every(this._richlistbox.selectedItems,
element => element._shell.isCommandEnabled(aCommand));
return Array.prototype.every.call(
this._richlistbox.selectedItems,
element => element._shell.isCommandEnabled(aCommand));
}
},
_copySelectedDownloadsToClipboard() {
let urls = Array.map(this._richlistbox.selectedItems,
element => element._shell.download.source.url);
let urls = Array.from(this._richlistbox.selectedItems,
element => element._shell.download.source.url);
Cc["@mozilla.org/widget/clipboardhelper;1"]
.getService(Ci.nsIClipboardHelper)

View File

@ -3667,7 +3667,7 @@ var SessionStoreInternal = {
// can be moved to the end of the restored tabs.
let initialTabs;
if (!overwriteTabs && firstWindow) {
initialTabs = Array.slice(tabbrowser.tabs);
initialTabs = Array.from(tabbrowser.tabs);
}
// Get rid of tabs that aren't needed anymore.
@ -4052,7 +4052,7 @@ var SessionStoreInternal = {
// In case we didn't collect/receive data for any tabs yet we'll have to
// fill the array with at least empty tabData objects until |_tPos| or
// we'll end up with |null| entries.
for (let otherTab of Array.slice(tabbrowser.tabs, 0, tab._tPos)) {
for (let otherTab of Array.prototype.slice.call(tabbrowser.tabs, 0, tab._tPos)) {
let emptyState = {entries: [], lastAccessed: otherTab.lastAccessed};
this._windows[window.__SSi].tabs.push(emptyState);
}

View File

@ -419,7 +419,7 @@ class AsyncTabSwitcher {
let tabpanels = this.tabbrowser.tabpanels;
let showPanel = this.tabbrowser.tabContainer.getRelatedElement(showTab);
let index = Array.indexOf(tabpanels.children, showPanel);
let index = Array.prototype.indexOf.call(tabpanels.children, showPanel);
if (index != -1) {
this.log(`Switch to tab ${index} - ${this.tinfo(showTab)}`);
tabpanels.setAttribute("selectedIndex", index);

View File

@ -143,7 +143,8 @@ const ToolbarView = {
_onHiddenMarkersChanged: function() {
const checkedMenuItems =
$$("#performance-filter-menupopup menuitem[marker-type]:not([checked])");
const hiddenMarkers = Array.map(checkedMenuItems, e => e.getAttribute("marker-type"));
const hiddenMarkers =
Array.from(checkedMenuItems, e => e.getAttribute("marker-type"));
PerformanceController.setPref("hidden-markers", hiddenMarkers);
},

View File

@ -470,7 +470,8 @@ AbstractTreeItem.prototype = {
*/
_getSiblingAtDelta: function(delta) {
const childNodes = this._containerNode.childNodes;
const indexOfSelf = Array.indexOf(childNodes, this._targetNode);
const indexOfSelf =
Array.prototype.indexOf.call(childNodes, this._targetNode);
if (indexOfSelf + delta >= 0) {
return childNodes[indexOfSelf + delta];
}

View File

@ -57,7 +57,7 @@ var WebConsoleUtils = {
if (Array.isArray(object)) {
temp = [];
Array.forEach(object, function(value, index) {
object.forEach(function(value, index) {
if (!filter || filter(index, value, object)) {
temp.push(recursive ? WebConsoleUtils.cloneObject(value) : value);
}

View File

@ -27,8 +27,7 @@ function defineNoReturnMethod(fn) {
return function method() {
if (!this._domRequestReady) {
// Remote browser haven't been created, we just queue the API call.
let args = Array.slice(arguments);
args.unshift(this);
let args = [this, ...arguments];
this._pendingAPICalls.push(method.bind.apply(fn, args));
return;
}

View File

@ -7,8 +7,8 @@ var ConsoleAPI = {
observe: function observe(aMessage, aTopic, aData) {
aMessage = aMessage.wrappedJSObject;
let mappedArguments = Array.map(aMessage.arguments, this.formatResult, this);
let joinedArguments = Array.join(mappedArguments, " ");
let mappedArguments = Array.from(aMessage.arguments, this.formatResult, this);
let joinedArguments = mappedArguments.join(" ");
if (aMessage.level == "error" || aMessage.level == "warn") {
let flag = (aMessage.level == "error" ? Ci.nsIScriptError.errorFlag : Ci.nsIScriptError.warningFlag);

View File

@ -51,8 +51,8 @@ var GeckoViewConsole = {
_handleConsoleMessage(aMessage) {
aMessage = aMessage.wrappedJSObject;
const mappedArguments = Array.map(aMessage.arguments, this.formatResult, this);
const joinedArguments = Array.join(mappedArguments, " ");
const mappedArguments = Array.from(aMessage.arguments, this.formatResult, this);
const joinedArguments = mappedArguments.join(" ");
if (aMessage.level == "error" || aMessage.level == "warn") {
const flag = (aMessage.level == "error" ? Ci.nsIScriptError.errorFlag : Ci.nsIScriptError.warningFlag);

View File

@ -389,7 +389,7 @@ nsresult nsIndexedToHTML::DoOnStartRequest(nsIRequest* request,
" headCells[i].addEventListener(\"click\", rowAction(i), true);\n"
" }\n"
" if (gUI_showHidden) {\n"
" gRows = Array.slice(gTBody.rows);\n"
" gRows = Array.from(gTBody.rows);\n"
" hiddenObjects = gRows.some(row => row.className == "
"\"hidden-object\");\n"
" }\n"
@ -421,7 +421,7 @@ nsresult nsIndexedToHTML::DoOnStartRequest(nsIRequest* request,
"}\n"
"function orderBy(column) {\n"
" if (!gRows)\n"
" gRows = Array.slice(gTBody.rows);\n"
" gRows = Array.from(gTBody.rows);\n"
" var order;\n"
" if (gOrderBy == column) {\n"
" order = gTable.getAttribute(\"order\") == \"asc\" ? \"desc\" : "

View File

@ -29,12 +29,11 @@ var Async = {
* });
* });
*/
chain: function chain() {
let funcs = Array.slice(arguments);
chain: function chain(...funcs) {
let thisObj = this;
return function callback() {
if (funcs.length) {
let args = Array.slice(arguments).concat(callback);
let args = [...arguments, callback];
let f = funcs.shift();
f.apply(thisObj, args);
}

View File

@ -39,7 +39,7 @@ this.DownloadList.prototype = {
* @rejects JavaScript exception.
*/
getAll: function DL_getAll() {
return Promise.resolve(Array.slice(this._downloads, 0));
return Promise.resolve(Array.from(this._downloads));
},
/**

View File

@ -69,7 +69,7 @@ XPCOMUtils.defineLazyGetter(DownloadUIHelper, "strings", function() {
strings[stringName] = function() {
// Convert "arguments" to a real array before calling into XPCOM.
return sb.formatStringFromName(stringName,
Array.slice(arguments, 0),
Array.from(arguments),
arguments.length);
};
} else {

View File

@ -610,8 +610,8 @@ var LoginManagerContent = {
let hasLoginForm = ChromeUtils.nondeterministicGetWeakSetKeys(rootElsWeakSet)
.filter(el => el.isConnected).length > 0;
return (hasLoginForm && !thisWindow.isSecureContext) ||
Array.some(thisWindow.frames,
frame => hasInsecureLoginForms(frame));
Array.prototype.some.call(thisWindow.frames,
frame => hasInsecureLoginForms(frame));
};
let messageManager = topWindow.docShell.messageManager;

View File

@ -54,7 +54,8 @@ MozElements.NotificationBox = class NotificationBox {
var closedNotification = this._closedNotification;
var notifications = this.stack.getElementsByTagName("notification");
return Array.filter(notifications, n => n != closedNotification);
return Array.prototype.filter.call(
notifications, n => n != closedNotification);
}
getNotificationWithValue(aValue) {

View File

@ -912,7 +912,7 @@ MozElements.MozRichlistitem = class MozRichlistitem extends MozElements.BaseText
get label() {
const XULNS =
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
return Array.map(this.getElementsByTagNameNS(XULNS, "label"),
return Array.from(this.getElementsByTagNameNS(XULNS, "label"),
label => label.value)
.join(" ");
}

View File

@ -44,7 +44,7 @@
<![CDATA[
const XULNS =
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
return Array.map(this.getElementsByTagNameNS(XULNS, "label"),
return Array.from(this.getElementsByTagNameNS(XULNS, "label"),
label => label.value)
.join(" ");
]]>

View File

@ -336,7 +336,7 @@
nodes = document.getBindingParent(this).children;
}
return Array.filter(nodes, this._canScrollToElement, this);
return Array.prototype.filter.call(nodes, this._canScrollToElement, this);
]]></body>
</method>

View File

@ -228,7 +228,7 @@ class MozTabpanels extends MozXULElement {
// Return tab element having 'linkedpanel' attribute equal to the id
// of the tab panel or the same index as the tab panel element.
let tabpanelIdx = Array.indexOf(this.children, aTabPanelElm);
let tabpanelIdx = Array.prototype.indexOf.call(this.children, aTabPanelElm);
if (tabpanelIdx == -1)
return null;

View File

@ -490,10 +490,10 @@
// Set resizeafter="farthest" on the splitters if nothing else has been
// specified.
Array.forEach(this.getElementsByTagName("splitter"), function(splitter) {
for (let splitter of this.getElementsByTagName("splitter")) {
if (!splitter.hasAttribute("resizeafter"))
splitter.setAttribute("resizeafter", "farthest");
});
}
}
}

View File

@ -1436,7 +1436,7 @@ PopupNotifications.prototype = {
let notifications = this._getNotificationsForBrowser(browser);
// Mark notifications as dismissed and call dismissal callbacks
Array.forEach(this.panel.children, function(nEl) {
for (let nEl of this.panel.children) {
let notificationObj = nEl.notification;
// Never call a dismissal handler on a notification that's been removed.
if (!notifications.includes(notificationObj))
@ -1460,7 +1460,7 @@ PopupNotifications.prototype = {
notificationObj.dismissed = true;
this._fireCallback(notificationObj, NOTIFICATION_EVENT_DISMISSED);
}
}, this);
}
},
_onCheckboxCommand(event) {

View File

@ -1816,7 +1816,7 @@ function sortElements(aElements, aSortBy, aAscending) {
}
function sortList(aList, aSortBy, aAscending) {
var elements = Array.slice(aList.childNodes, 0);
var elements = Array.from(aList.childNodes);
sortElements(elements, [aSortBy], aAscending);
while (aList.lastChild)