cleanup: Use Array.includes() to check for element existence

We can use that newer method where we don't care about the actual position
of an element inside the array.

(Array.includes() and Array.indexOf() do behave differently in edge cases,
for example in the handling of NaN, but those don't matter to us)

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/152
This commit is contained in:
Florian Müllner 2018-07-14 22:56:22 +02:00 committed by Florian Müllner
parent b87455c089
commit f6b4b96737
29 changed files with 49 additions and 50 deletions

View File

@ -582,12 +582,12 @@ class ExtensionRow extends Gtk.ListBoxRow {
_isEnabled() { _isEnabled() {
let extensions = this._settings.get_strv('enabled-extensions'); let extensions = this._settings.get_strv('enabled-extensions');
return extensions.indexOf(this.uuid) != -1; return extensions.includes(this.uuid);
} }
_enable() { _enable() {
let extensions = this._settings.get_strv('enabled-extensions'); let extensions = this._settings.get_strv('enabled-extensions');
if (extensions.indexOf(this.uuid) != -1) if (extensions.includes(this.uuid))
return; return;
extensions.push(this.uuid); extensions.push(this.uuid);

View File

@ -31,7 +31,7 @@ function getCurrentExtension() {
// Search for an occurrence of an extension stack frame // Search for an occurrence of an extension stack frame
// Start at 1 because 0 is the stack frame of this function // Start at 1 because 0 is the stack frame of this function
for (let i = 1; i < stack.length; i++) { for (let i = 1; i < stack.length; i++) {
if (stack[i].indexOf('/gnome-shell/extensions/') > -1) { if (stack[i].includes('/gnome-shell/extensions/')) {
extensionStackLine = stack[i]; extensionStackLine = stack[i];
break; break;
} }

View File

@ -125,7 +125,7 @@ var KeyboardManager = class {
_getLocaleLayout() { _getLocaleLayout() {
let locale = GLib.get_language_names()[0]; let locale = GLib.get_language_names()[0];
if (locale.indexOf('_') == -1) if (!locale.includes('_'))
locale = DEFAULT_LOCALE; locale = DEFAULT_LOCALE;
let [found, , id] = GnomeDesktop.get_input_source_from_locale(locale); let [found, , id] = GnomeDesktop.get_input_source_from_locale(locale);

View File

@ -69,7 +69,7 @@ function _getCategories(info) {
function _listsIntersect(a, b) { function _listsIntersect(a, b) {
for (let itemA of a) for (let itemA of a)
if (b.indexOf(itemA) >= 0) if (b.includes(itemA))
return true; return true;
return false; return false;
} }
@ -1165,7 +1165,7 @@ var FolderIcon = class FolderIcon {
let excludedApps = this._folder.get_strv('excluded-apps'); let excludedApps = this._folder.get_strv('excluded-apps');
let appSys = Shell.AppSystem.get_default(); let appSys = Shell.AppSystem.get_default();
let addAppId = appId => { let addAppId = appId => {
if (excludedApps.indexOf(appId) >= 0) if (excludedApps.includes(appId))
return; return;
let app = appSys.lookup_app(appId); let app = appSys.lookup_app(appId);
@ -1728,7 +1728,7 @@ var AppIconMenu = class AppIconMenu extends PopupMenu.PopupMenu {
let appInfo = this._source.app.get_app_info(); let appInfo = this._source.app.get_app_info();
let actions = appInfo.list_actions(); let actions = appInfo.list_actions();
if (this._source.app.can_open_new_window() && if (this._source.app.can_open_new_window() &&
actions.indexOf('new-window') == -1) { actions.includes('new-window')) {
this._newWindowMenuItem = this._appendMenuItem(_("New Window")); this._newWindowMenuItem = this._appendMenuItem(_("New Window"));
this._newWindowMenuItem.connect('activate', () => { this._newWindowMenuItem.connect('activate', () => {
if (this._source.app.state == Shell.AppState.STOPPED) if (this._source.app.state == Shell.AppState.STOPPED)
@ -1742,7 +1742,7 @@ var AppIconMenu = class AppIconMenu extends PopupMenu.PopupMenu {
if (discreteGpuAvailable && if (discreteGpuAvailable &&
this._source.app.state == Shell.AppState.STOPPED && this._source.app.state == Shell.AppState.STOPPED &&
actions.indexOf('activate-discrete-gpu') == -1) { actions.includes('activate-discrete-gpu')) {
this._onDiscreteGpuMenuItem = this._appendMenuItem(_("Launch using Dedicated Graphics Card")); this._onDiscreteGpuMenuItem = this._appendMenuItem(_("Launch using Dedicated Graphics Card"));
this._onDiscreteGpuMenuItem.connect('activate', () => { this._onDiscreteGpuMenuItem.connect('activate', () => {
if (this._source.app.state == Shell.AppState.STOPPED) if (this._source.app.state == Shell.AppState.STOPPED)

View File

@ -38,7 +38,7 @@ function isToday(date) {
function _isWorkDay(date) { function _isWorkDay(date) {
/* Translators: Enter 0-6 (Sunday-Saturday) for non-work days. Examples: "0" (Sunday) "6" (Saturday) "06" (Sunday and Saturday). */ /* Translators: Enter 0-6 (Sunday-Saturday) for non-work days. Examples: "0" (Sunday) "6" (Saturday) "06" (Sunday and Saturday). */
let days = C_('calendar-no-work', "06"); let days = C_('calendar-no-work', "06");
return days.indexOf(date.getDay().toString()) == -1; return !days.includes(date.getDay().toString());
} }
function _getBeginningOfDay(date) { function _getBeginningOfDay(date) {

View File

@ -13,13 +13,13 @@ var ComponentManager = class {
let newEnabledComponents = Main.sessionMode.components; let newEnabledComponents = Main.sessionMode.components;
newEnabledComponents.filter( newEnabledComponents.filter(
name => this._enabledComponents.indexOf(name) == -1 name => !this._enabledComponents.includes(name)
).forEach(name => { ).forEach(name => {
this._enableComponent(name); this._enableComponent(name);
}); });
this._enabledComponents.filter( this._enabledComponents.filter(
name => newEnabledComponents.indexOf(name) == -1 name => !newEnabledComponents.includes(name)
).forEach(name => { ).forEach(name => {
this._disableComponent(name); this._disableComponent(name);
}); });

View File

@ -40,7 +40,7 @@ function isMountRootHidden(root) {
let path = root.get_path(); let path = root.get_path();
// skip any mounts in hidden directory hierarchies // skip any mounts in hidden directory hierarchies
return (path.indexOf('/.') != -1); return (path.includes('/.'));
} }
function isMountNonLocal(mount) { function isMountNonLocal(mount) {
@ -192,15 +192,15 @@ var AutorunDispatcher = class {
_getAutorunSettingForType(contentType) { _getAutorunSettingForType(contentType) {
let runApp = this._settings.get_strv(SETTING_START_APP); let runApp = this._settings.get_strv(SETTING_START_APP);
if (runApp.indexOf(contentType) != -1) if (runApp.includes(contentType))
return AutorunSetting.RUN; return AutorunSetting.RUN;
let ignore = this._settings.get_strv(SETTING_IGNORE); let ignore = this._settings.get_strv(SETTING_IGNORE);
if (ignore.indexOf(contentType) != -1) if (ignore.includes(contentType))
return AutorunSetting.IGNORE; return AutorunSetting.IGNORE;
let openFiles = this._settings.get_strv(SETTING_OPEN_FOLDER); let openFiles = this._settings.get_strv(SETTING_OPEN_FOLDER);
if (openFiles.indexOf(contentType) != -1) if (openFiles.includes(contentType))
return AutorunSetting.FILES; return AutorunSetting.FILES;
return AutorunSetting.ASK; return AutorunSetting.ASK;

View File

@ -327,7 +327,7 @@ class NetworkSecretDialog extends ModalDialog.ModalDialog {
this._getPPPoESecrets(content.secrets); this._getPPPoESecrets(content.secrets);
break; break;
case 'gsm': case 'gsm':
if (this._hints.indexOf('pin') != -1) { if (this._hints.includes('pin')) {
let gsmSetting = this._connection.get_setting_gsm(); let gsmSetting = this._connection.get_setting_gsm();
content.title = _("PIN code required"); content.title = _("PIN code required");
content.message = _("PIN code is needed for the mobile broadband device"); content.message = _("PIN code is needed for the mobile broadband device");
@ -695,7 +695,7 @@ var NetworkAgent = class {
body = _("A password is required to connect to “%s”.".format(connection.get_id())); body = _("A password is required to connect to “%s”.".format(connection.get_id()));
break; break;
case 'gsm': case 'gsm':
if (hints.indexOf('pin') != -1) { if (hints.includes('pin')) {
let gsmSetting = connection.get_setting_gsm(); let gsmSetting = connection.get_setting_gsm();
title = _("PIN code required"); title = _("PIN code required");
body = _("PIN code is needed for the mobile broadband device"); body = _("PIN code is needed for the mobile broadband device");

View File

@ -45,9 +45,9 @@ var AuthenticationDialog = GObject.registerClass({
} }
let userName = GLib.get_user_name(); let userName = GLib.get_user_name();
if (userNames.indexOf(userName) < 0) if (!userNames.includes(userName))
userName = 'root'; userName = 'root';
if (userNames.indexOf(userName) < 0) if (!userNames.includes(userName))
userName = userNames[0]; userName = userNames[0];
this._user = AccountsService.UserManager.get_default().get_user(userName); this._user = AccountsService.UserManager.get_default().get_user(userName);

View File

@ -700,14 +700,14 @@ var Dash = class Dash {
} }
// App removed at oldIndex // App removed at oldIndex
if (oldApp && newApps.indexOf(oldApp) == -1) { if (oldApp && !newApps.includes(oldApp)) {
removedActors.push(children[oldIndex]); removedActors.push(children[oldIndex]);
oldIndex++; oldIndex++;
continue; continue;
} }
// App added at newIndex // App added at newIndex
if (newApp && oldApps.indexOf(newApp) == -1) { if (newApp && !oldApps.includes(newApp)) {
addedItems.push({ app: newApp, addedItems.push({ app: newApp,
item: this._createAppItem(newApp), item: this._createAppItem(newApp),
pos: newIndex }); pos: newIndex });

View File

@ -585,7 +585,7 @@ class EndSessionDialog extends ModalDialog.ModalDialog {
} }
_onInhibitorLoaded(inhibitor) { _onInhibitorLoaded(inhibitor) {
if (this._applications.indexOf(inhibitor) < 0) { if (!this._applications.includes(inhibitor)) {
// Stale inhibitor // Stale inhibitor
return; return;
} }

View File

@ -228,7 +228,7 @@ class InstallExtensionDialog extends ModalDialog.ModalDialog {
function callback() { function callback() {
// Add extension to 'enabled-extensions' for the user, always... // Add extension to 'enabled-extensions' for the user, always...
let enabledExtensions = global.settings.get_strv(ExtensionSystem.ENABLED_EXTENSIONS_KEY); let enabledExtensions = global.settings.get_strv(ExtensionSystem.ENABLED_EXTENSIONS_KEY);
if (enabledExtensions.indexOf(uuid) == -1) { if (!enabledExtensions.includes(uuid)) {
enabledExtensions.push(uuid); enabledExtensions.push(uuid);
global.settings.set_strv(ExtensionSystem.ENABLED_EXTENSIONS_KEY, enabledExtensions); global.settings.set_strv(ExtensionSystem.ENABLED_EXTENSIONS_KEY, enabledExtensions);
} }

View File

@ -169,7 +169,7 @@ function loadExtension(extension) {
if (checkVersion && ExtensionUtils.isOutOfDate(extension)) { if (checkVersion && ExtensionUtils.isOutOfDate(extension)) {
extension.state = ExtensionState.OUT_OF_DATE; extension.state = ExtensionState.OUT_OF_DATE;
} else { } else {
let enabled = enabledExtensions.indexOf(extension.uuid) != -1; let enabled = enabledExtensions.includes(extension.uuid);
if (enabled) { if (enabled) {
if (!initExtension(extension.uuid)) if (!initExtension(extension.uuid))
return; return;

View File

@ -87,7 +87,7 @@ var GrabHelper = class GrabHelper {
_isWithinGrabbedActor(actor) { _isWithinGrabbedActor(actor) {
let currentActor = this.currentGrab.actor; let currentActor = this.currentGrab.actor;
while (actor) { while (actor) {
if (this._actors.indexOf(actor) != -1) if (this._actors.includes(actor))
return true; return true;
if (actor == currentActor) if (actor == currentActor)
return true; return true;

View File

@ -111,7 +111,7 @@ var InhibitShortcutsDialog = GObject.registerClass({
} }
vfunc_show() { vfunc_show() {
if (this._app && APP_WHITELIST.indexOf(this._app.get_id()) != -1) { if (this._app && APP_WHITELIST.includes(this._app.get_id())) {
this._emitResponse(DialogResponse.ALLOW); this._emitResponse(DialogResponse.ALLOW);
return; return;
} }

View File

@ -1074,7 +1074,7 @@ var Keyboard = class Keyboard {
let manager = Clutter.DeviceManager.get_default(); let manager = Clutter.DeviceManager.get_default();
let device = manager.get_device(deviceId); let device = manager.get_device(deviceId);
if (device.get_device_name().indexOf('XTEST') < 0) { if (!device.get_device_name().includes('XTEST')) {
this._lastDeviceId = deviceId; this._lastDeviceId = deviceId;
this._syncEnabled(); this._syncEnabled();
} }

View File

@ -663,7 +663,7 @@ function initializeDeferredWork(actor, callback, props) {
_deferredWorkData[workId] = { 'actor': actor, _deferredWorkData[workId] = { 'actor': actor,
'callback': callback }; 'callback': callback };
actor.connect('notify::mapped', () => { actor.connect('notify::mapped', () => {
if (!(actor.mapped && _deferredWorkQueue.indexOf(workId) >= 0)) if (!(actor.mapped && _deferredWorkQueue.includes(workId)))
return; return;
_queueBeforeRedraw(workId); _queueBeforeRedraw(workId);
}); });
@ -693,7 +693,7 @@ function queueDeferredWork(workId) {
logError(new Error(message), message); logError(new Error(message), message);
return; return;
} }
if (_deferredWorkQueue.indexOf(workId) < 0) if (!_deferredWorkQueue.includes(workId))
_deferredWorkQueue.push(workId); _deferredWorkQueue.push(workId);
if (data.actor.mapped) { if (data.actor.mapped) {
_queueBeforeRedraw(workId); _queueBeforeRedraw(workId);

View File

@ -72,7 +72,7 @@ var URLHighlighter = class URLHighlighter {
let urlId = this._findUrlAtPos(event); let urlId = this._findUrlAtPos(event);
if (urlId != -1) { if (urlId != -1) {
let url = this._urls[urlId].url; let url = this._urls[urlId].url;
if (url.indexOf(':') == -1) if (!url.includes(':'))
url = 'http://' + url; url = 'http://' + url;
Gio.app_info_launch_default_for_uri(url, global.create_app_launch_context(0, -1)); Gio.app_info_launch_default_for_uri(url, global.create_app_launch_context(0, -1));

View File

@ -228,7 +228,7 @@ class NotificationApplicationPolicy extends NotificationPolicy {
this._settings.set_string('application-id', this.id + '.desktop'); this._settings.set_string('application-id', this.id + '.desktop');
let apps = this._masterSettings.get_strv('application-children'); let apps = this._masterSettings.get_strv('application-children');
if (apps.indexOf(this._canonicalId) < 0) { if (!apps.includes(this._canonicalId)) {
apps.push(this._canonicalId); apps.push(this._canonicalId);
this._masterSettings.set_strv('application-children', apps); this._masterSettings.set_strv('application-children', apps);
} }
@ -772,7 +772,7 @@ var Source = class Source {
} }
pushNotification(notification) { pushNotification(notification) {
if (this.notifications.indexOf(notification) >= 0) if (this.notifications.includes(notification))
return; return;
while (this.notifications.length >= MAX_NOTIFICATIONS_PER_SOURCE) while (this.notifications.length >= MAX_NOTIFICATIONS_PER_SOURCE)
@ -1069,7 +1069,7 @@ var MessageTray = class MessageTray {
// If a new notification is updated while it is being hidden, // If a new notification is updated while it is being hidden,
// we stop hiding it and show it again. // we stop hiding it and show it again.
this._updateShowingNotification(); this._updateShowingNotification();
} else if (this._notificationQueue.indexOf(notification) < 0) { } else if (!this._notificationQueue.includes(notification)) {
// If the queue is "full", we skip banner mode and just show a small // If the queue is "full", we skip banner mode and just show a small
// indicator in the panel; however do make an exception for CRITICAL // indicator in the panel; however do make an exception for CRITICAL
// notifications, as only banner mode allows expansion. // notifications, as only banner mode allows expansion.

View File

@ -630,7 +630,7 @@ var PadOsd = class {
// If the device is being removed, destroy the padOsd. // If the device is being removed, destroy the padOsd.
if (device == this.padDevice) { if (device == this.padDevice) {
this.destroy(); this.destroy();
} else if (this._groupPads.indexOf(device) != -1) { } else if (this._groupPads.includes(device)) {
// Or update the pad chooser if the device belongs to // Or update the pad chooser if the device belongs to
// the same group. // the same group.
this._groupPads.splice(this._groupPads.indexOf(device), 1); this._groupPads.splice(this._groupPads.indexOf(device), 1);
@ -749,8 +749,7 @@ var PadOsd = class {
} }
_requestForOtherPad(pad) { _requestForOtherPad(pad) {
if (pad == this.padDevice || if (pad == this.padDevice || !this._groupPads.includes(pad))
this._groupPads.indexOf(pad) == -1)
return; return;
let editionMode = this._editionMode; let editionMode = this._editionMode;
@ -801,7 +800,7 @@ var PadOsd = class {
// If the event comes from another pad in the same group, // If the event comes from another pad in the same group,
// show the OSD for it. // show the OSD for it.
if (this._groupPads.indexOf(event.get_source_device()) != -1) { if (this._groupPads.includes(event.get_source_device())) {
this._requestForOtherPad(event.get_source_device()); this._requestForOtherPad(event.get_source_device());
return Clutter.EVENT_STOP; return Clutter.EVENT_STOP;
} }

View File

@ -1056,9 +1056,9 @@ class Panel extends St.Widget {
this._updateBox(panel.center, this._centerBox); this._updateBox(panel.center, this._centerBox);
this._updateBox(panel.right, this._rightBox); this._updateBox(panel.right, this._rightBox);
if (panel.left.indexOf('dateMenu') != -1) if (panel.left.includes('dateMenu'))
Main.messageTray.bannerAlignment = Clutter.ActorAlign.START; Main.messageTray.bannerAlignment = Clutter.ActorAlign.START;
else if (panel.right.indexOf('dateMenu') != -1) else if (panel.right.includes('dateMenu'))
Main.messageTray.bannerAlignment = Clutter.ActorAlign.END; Main.messageTray.bannerAlignment = Clutter.ActorAlign.END;
// Default to center if there is no dateMenu // Default to center if there is no dateMenu
else else

View File

@ -146,10 +146,10 @@ function loadRemoteSearchProviders(searchSettings, callback) {
if (provider.defaultEnabled) { if (provider.defaultEnabled) {
let disabled = searchSettings.get_strv('disabled'); let disabled = searchSettings.get_strv('disabled');
return disabled.indexOf(appId) == -1; return !disabled.includes(appId);
} else { } else {
let enabled = searchSettings.get_strv('enabled'); let enabled = searchSettings.get_strv('enabled');
return enabled.indexOf(appId) != -1; return enabled.includes(appId);
} }
}); });

View File

@ -182,7 +182,7 @@ class RunDialog extends ModalDialog.ModalDialog {
} }
_getCompletion(text) { _getCompletion(text) {
if (text.indexOf('/') != -1) { if (text.includes('/')) {
return this._pathCompleter.get_completion_suffix(text); return this._pathCompleter.get_completion_suffix(text);
} else { } else {
return this._getCommandCompletion(text); return this._getCommandCompletion(text);

View File

@ -128,7 +128,7 @@ function _loadMode(file, info) {
let propBlacklist = ['unlockDialog']; let propBlacklist = ['unlockDialog'];
for (let prop in _modes[DEFAULT_MODE]) { for (let prop in _modes[DEFAULT_MODE]) {
if (newMode[prop] !== undefined && if (newMode[prop] !== undefined &&
propBlacklist.indexOf(prop) == -1) !propBlacklist.includes(prop))
_modes[modeName][prop] = newMode[prop]; _modes[modeName][prop] = newMode[prop];
} }
_modes[modeName]['isPrimary'] = true; _modes[modeName]['isPrimary'] = true;

View File

@ -1040,7 +1040,7 @@ class NMWirelessDialog extends ModalDialog.ModalDialog {
_checkConnections(network, accessPoint) { _checkConnections(network, accessPoint) {
this._connections.forEach(connection => { this._connections.forEach(connection => {
if (accessPoint.connection_valid(connection) && if (accessPoint.connection_valid(connection) &&
network.connections.indexOf(connection) == -1) { !network.connections.includes(connection)) {
network.connections.push(connection); network.connections.push(connection);
} }
}); });
@ -1059,7 +1059,7 @@ class NMWirelessDialog extends ModalDialog.ModalDialog {
if (pos != -1) { if (pos != -1) {
network = this._networks[pos]; network = this._networks[pos];
if (network.accessPoints.indexOf(accessPoint) != -1) { if (network.accessPoints.includes(accessPoint)) {
log('Access point was already seen, not adding again'); log('Access point was already seen, not adding again');
return; return;
} }

View File

@ -215,7 +215,7 @@ var OutputStreamSlider = class extends StreamSlider {
// of different identifiers for headphones, and I could // of different identifiers for headphones, and I could
// not find the complete list // not find the complete list
if (sink.get_ports().length > 0) if (sink.get_ports().length > 0)
return sink.get_port().port.indexOf('headphone') >= 0; return sink.get_port().port.includes('headphone');
return false; return false;
} }

View File

@ -1288,7 +1288,7 @@ var WindowManager = class {
return false; return false;
let type = actor.meta_window.get_window_type(); let type = actor.meta_window.get_window_type();
return types.indexOf(type) >= 0; return types.includes(type);
} }
_removeEffect(list, actor) { _removeEffect(list, actor) {
@ -1501,7 +1501,7 @@ var WindowManager = class {
_sizeChangedWindow(shellwm, actor) { _sizeChangedWindow(shellwm, actor) {
if (!actor.__animationInfo) if (!actor.__animationInfo)
return; return;
if (this._resizing.indexOf(actor) != -1) if (this._resizing.includes(actor))
return; return;
let actorClone = actor.__animationInfo.clone; let actorClone = actor.__animationInfo.clone;

View File

@ -536,7 +536,7 @@ var WindowOverlay = class {
let [cloneX, cloneY, cloneWidth, cloneHeight] = this._windowClone.slot; let [cloneX, cloneY, cloneWidth, cloneHeight] = this._windowClone.slot;
let layout = Meta.prefs_get_button_layout(); let layout = Meta.prefs_get_button_layout();
let side = layout.left_buttons.indexOf(Meta.ButtonFunction.CLOSE) > -1 ? St.Side.LEFT : St.Side.RIGHT; let side = layout.left_buttons.includes(Meta.ButtonFunction.CLOSE) ? St.Side.LEFT : St.Side.RIGHT;
let buttonX; let buttonX;
let buttonY = cloneY - (button.height - button._overlap); let buttonY = cloneY - (button.height - button._overlap);

View File

@ -378,7 +378,7 @@ var WorkspaceThumbnail = class {
return; return;
} }
if (this._allWindows.indexOf(metaWin) == -1) { if (!this._allWindows.includes(metaWin)) {
let minimizedChangedId = metaWin.connect('notify::minimized', let minimizedChangedId = metaWin.connect('notify::minimized',
this._updateMinimized.bind(this)); this._updateMinimized.bind(this));
this._allWindows.push(metaWin); this._allWindows.push(metaWin);