cleanup: Don't shadow variables

Having variables that share the same name in overlapping scopes is
confusing and error-prone, and is best avoided.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/805
This commit is contained in:
Florian Müllner 2019-08-20 02:20:08 +02:00 committed by Georges Basile Stavracas Neto
parent 2e4e2500dd
commit 682bd7e97c
34 changed files with 85 additions and 86 deletions

View File

@ -984,7 +984,7 @@ var LoginDialog = GObject.registerClass({
let hold = new Batch.Hold();
let signalId = this._userList.connect('item-added',
() => {
let item = this._userList.getItemFromUserName(userName);
item = this._userList.getItemFromUserName(userName);
if (item)
hold.release();

View File

@ -157,10 +157,10 @@ var IBusManager = class {
} catch (e) {
}
// If an engine is already active we need to get its properties
this._ibus.get_global_engine_async(-1, this._cancellable, (_bus, result) => {
this._ibus.get_global_engine_async(-1, this._cancellable, (_bus, res) => {
let engine;
try {
engine = this._ibus.get_global_engine_async_finish(result);
engine = this._ibus.get_global_engine_async_finish(res);
if (!engine)
return;
} catch (e) {

View File

@ -110,14 +110,14 @@ var LoginManagerSystemd = class {
let sessionId = GLib.getenv('XDG_SESSION_ID');
if (!sessionId) {
log('Unset XDG_SESSION_ID, getCurrentSessionProxy() called outside a user session. Asking logind directly.');
let [session, objectPath_] = this._userProxy.Display;
let [session, objectPath] = this._userProxy.Display;
if (session) {
log(`Will monitor session ${session}`);
sessionId = session;
} else {
log('Failed to find "Display" session; are we the greeter?');
for (let [session, objectPath] of this._userProxy.Sessions) {
for ([session, objectPath] of this._userProxy.Sessions) {
let sessionProxy = new SystemdLoginSession(Gio.DBus.system,
'org.freedesktop.login1',
objectPath);

View File

@ -405,7 +405,7 @@ function ensureActorVisibleInScrollView(scrollView, actor) {
if (!parent)
throw new Error("actor not in scroll view");
let box = parent.get_allocation_box();
box = parent.get_allocation_box();
y1 += box.y1;
y2 += box.y1;
parent = parent.get_parent();

View File

@ -47,11 +47,11 @@ var WeatherClient = class {
return;
}
this._permStore.LookupRemote('gnome', 'geolocation', (res, error) => {
if (error)
log(`Error looking up permission: ${error.message}`);
this._permStore.LookupRemote('gnome', 'geolocation', (res, err) => {
if (err)
log(`Error looking up permission: ${err.message}`);
let [perms, data] = error ? [{}, null] : res;
let [perms, data] = err ? [{}, null] : res;
let params = ['gnome', 'geolocation', false, data, perms];
this._onPermStoreChanged(this._permStore, '', params);
});

View File

@ -673,7 +673,7 @@ var AllView = GObject.registerClass({
addFolderPopup(popup) {
this._stack.add_actor(popup);
popup.connect('open-state-changed', (popup, isOpen) => {
popup.connect('open-state-changed', (o, isOpen) => {
this._eventBlocker.reactive = isOpen;
if (this._currentPopup) {

View File

@ -145,7 +145,7 @@ var BackgroundCache = class BackgroundCache {
let monitor = file.monitor(Gio.FileMonitorFlags.NONE, null);
monitor.connect('changed',
(obj, file, otherFile, eventType) => {
(obj, theFile, otherFile, eventType) => {
// Ignore CHANGED and CREATED events, since in both cases
// we'll get a CHANGES_DONE_HINT event when done.
if (eventType != Gio.FileMonitorEvent.CHANGED &&

View File

@ -35,7 +35,7 @@ function addBackgroundMenu(actor, layoutManager) {
}
let clickAction = new Clutter.ClickAction();
clickAction.connect('long-press', (action, actor, state) => {
clickAction.connect('long-press', (action, theActor, state) => {
if (state == Clutter.LongPressState.QUERY)
return ((action.get_button() == 0 ||
action.get_button() == 1) &&

View File

@ -996,7 +996,7 @@ class NotificationSection extends MessageList.MessageListSection {
notificationAddedId: 0,
};
obj.destroyId = source.connect('destroy', source => {
obj.destroyId = source.connect('destroy', () => {
this._onSourceDestroy(source, obj);
});
obj.notificationAddedId = source.connect('notification-added',
@ -1170,7 +1170,7 @@ class CalendarMessageList extends St.Widget {
Util.ensureActorVisibleInScrollView(this._scrollView, messageActor);
}));
connectionsIds.push(section.connect('destroy', (section) => {
connectionsIds.push(section.connect('destroy', () => {
connectionsIds.forEach(id => section.disconnect(id));
this._sectionList.remove_actor(section);
}));

View File

@ -109,7 +109,7 @@ var AutomountManager = class {
// mount operation object
if (drive.can_stop()) {
drive.stop(Gio.MountUnmountFlags.FORCE, null, null,
(drive, res) => {
(o, res) => {
try {
drive.stop_finish(res);
} catch (e) {
@ -118,7 +118,7 @@ var AutomountManager = class {
});
} else if (drive.can_eject()) {
drive.eject_with_operation(Gio.MountUnmountFlags.FORCE, null, null,
(drive, res) => {
(o, res) => {
try {
drive.eject_with_operation_finish(res);
} catch (e) {

View File

@ -115,7 +115,8 @@ var ContentTypeDiscoverer = class {
let hotplugSniffer = new HotplugSniffer();
hotplugSniffer.SniffURIRemote(root.get_uri(),
([contentTypes]) => {
result => {
[contentTypes] = result;
this._emitCallback(mount, contentTypes);
});
}
@ -166,7 +167,7 @@ var AutorunManager = class {
if (!this._session.SessionIsActive)
return;
let discoverer = new ContentTypeDiscoverer((mount, apps, contentTypes) => {
let discoverer = new ContentTypeDiscoverer((m, apps, contentTypes) => {
this._dispatcher.addMount(mount, apps, contentTypes);
});
discoverer.guessContentTypes(mount);

View File

@ -248,7 +248,7 @@ class TelepathyClient extends Tp.BaseClient {
}
// Approve private text channels right away as we are going to handle it
dispatchOp.claim_with_async(this, (dispatchOp, result) => {
dispatchOp.claim_with_async(this, (o, result) => {
try {
dispatchOp.claim_with_finish(result);
this._handlingChannels(account, conn, [channel], false);

View File

@ -481,7 +481,7 @@ var Dash = GObject.registerClass({
let appIcon = new DashIcon(app);
appIcon.connect('menu-state-changed',
(appIcon, opened) => {
(o, opened) => {
this._itemMenuStateChanged(item, opened);
});

View File

@ -155,7 +155,7 @@ var _Draggable = class _Draggable {
this._grabbedDevice = pointer;
this._touchSequence = touchSequence;
this._capturedEventId = global.stage.connect('captured-event', (actor, event) => {
this._capturedEventId = global.stage.connect('captured-event', (o, event) => {
let device = event.get_device();
if (device != this._grabbedDevice &&
device.get_device_type() != Clutter.InputDeviceType.KEYBOARD_DEVICE)

View File

@ -24,7 +24,7 @@ function installExtension(uuid, invocation) {
let message = Soup.form_request_new_from_hash('GET', REPOSITORY_URL_INFO, params);
_httpSession.queue_message(message, (session, message) => {
_httpSession.queue_message(message, () => {
if (message.status_code != Soup.KnownStatusCode.OK) {
Main.extensionManager.logExtensionError(uuid, `downloading info: ${message.status_code}`);
invocation.return_dbus_error('org.gnome.Shell.DownloadInfoError', message.status_code.toString());
@ -90,7 +90,7 @@ function gotExtensionZipFile(session, message, uuid, dir, callback, errback) {
return;
}
GLib.child_watch_add(GLib.PRIORITY_DEFAULT, pid, (pid, status) => {
GLib.child_watch_add(GLib.PRIORITY_DEFAULT, pid, (o, status) => {
GLib.spawn_close_pid(pid);
if (status != 0)
@ -113,7 +113,7 @@ function updateExtension(uuid) {
let url = REPOSITORY_URL_DOWNLOAD.format(uuid);
let message = Soup.form_request_new_from_hash('GET', url, params);
_httpSession.queue_message(message, (session, message) => {
_httpSession.queue_message(message, session => {
gotExtensionZipFile(session, message, uuid, newExtensionTmpDir, () => {
let oldExtension = Main.extensionManager.lookup(uuid);
let extensionDir = oldExtension.dir;
@ -145,8 +145,8 @@ function updateExtension(uuid) {
}
FileUtils.recursivelyDeleteDir(oldExtensionTmpDir, true);
}, (code, message) => {
log('Error while updating extension %s: %s (%s)'.format(uuid, code, message ? message : ''));
}, (code, msg) => {
log(`Error while updating extension ${uuid}: ${code} (${msg})`);
});
});
}
@ -162,7 +162,7 @@ function checkForUpdates() {
let url = REPOSITORY_URL_UPDATE;
let message = Soup.form_request_new_from_hash('GET', url, params);
_httpSession.queue_message(message, (session, message) => {
_httpSession.queue_message(message, () => {
if (message.status_code != Soup.KnownStatusCode.OK)
return;
@ -220,10 +220,9 @@ class InstallExtensionDialog extends ModalDialog.ModalDialog {
let uuid = this._uuid;
let dir = Gio.File.new_for_path(GLib.build_filenamev([global.userdatadir, 'extensions', uuid]));
let invocation = this._invocation;
function errback(code, message) {
let msg = message ? message.toString() : '';
log('Error while installing %s: %s (%s)'.format(uuid, code, msg));
invocation.return_dbus_error(`org.gnome.Shell.${code}`, msg);
function errback(code, msg) {
log(`Error while installing ${uuid}: ${code} (${msg})`);
invocation.return_dbus_error(`org.gnome.Shell.${code}`, msg || '');
}
function callback() {
@ -241,7 +240,7 @@ class InstallExtensionDialog extends ModalDialog.ModalDialog {
invocation.return_value(GLib.Variant.new('(s)', ['successful']));
}
_httpSession.queue_message(message, (session, message) => {
_httpSession.queue_message(message, session => {
gotExtensionZipFile(session, message, uuid, dir, callback, errback);
});

View File

@ -60,11 +60,11 @@ var ExtensionManager = class {
let orderReversed = order.slice().reverse();
for (let i = 0; i < orderReversed.length; i++) {
let uuid = orderReversed[i];
let otherUuid = orderReversed[i];
try {
this.lookup(uuid).stateObj.disable();
this.lookup(otherUuid).stateObj.disable();
} catch (e) {
this.logExtensionError(uuid, e);
this.logExtensionError(otherUuid, e);
}
}
@ -81,11 +81,11 @@ var ExtensionManager = class {
}
for (let i = 0; i < order.length; i++) {
let uuid = order[i];
let otherUuid = order[i];
try {
this.lookup(uuid).stateObj.enable();
this.lookup(otherUuid).stateObj.enable();
} catch (e) {
this.logExtensionError(uuid, e);
this.logExtensionError(otherUuid, e);
}
}

View File

@ -134,10 +134,10 @@ var InhibitShortcutsDialog = GObject.registerClass({
this._permStore.LookupRemote(APP_PERMISSIONS_TABLE,
APP_PERMISSIONS_ID,
(res, error) => {
if (error) {
(res, err) => {
if (err) {
this._dialog.open();
log(error.message);
log(err.message);
return;
}

View File

@ -469,8 +469,7 @@ var LayoutManager = GObject.registerClass({
}
_updateBackgrounds() {
let i;
for (i = 0; i < this._bgManagers.length; i++)
for (let i = 0; i < this._bgManagers.length; i++)
this._bgManagers[i].destroy();
this._bgManagers = [];

View File

@ -423,10 +423,10 @@ class ObjInspector extends St.ScrollView {
} catch (e) {
link = new St.Label({ text: '<error>' });
}
let hbox = new St.BoxLayout();
hbox.add(new St.Label({ text: `${propName}: ` }));
hbox.add(link);
this._container.add_actor(hbox);
let box = new St.BoxLayout();
box.add(new St.Label({ text: `${propName}: ` }));
box.add(link);
this._container.add_actor(box);
}
}
}

View File

@ -296,7 +296,7 @@ function _getStylesheet(name) {
let dataDirs = GLib.get_system_data_dirs();
for (let i = 0; i < dataDirs.length; i++) {
let path = GLib.build_filenamev([dataDirs[i], 'gnome-shell', 'theme', name]);
let stylesheet = Gio.file_new_for_path(path);
stylesheet = Gio.file_new_for_path(path);
if (stylesheet.query_exists(null))
return stylesheet;
}

View File

@ -245,7 +245,7 @@ var FdoNotificationDaemon = class FdoNotificationDaemon {
return;
}
let [pid] = result;
[pid] = result;
source = this._getSource(appName, pid, ndata, sender, null);
this._senderToPid[sender] = pid;

View File

@ -110,7 +110,7 @@ var PointerA11yTimeout = class PointerA11yTimeout {
constructor() {
let manager = Clutter.DeviceManager.get_default();
manager.connect('ptr-a11y-timeout-started', (manager, device, type, timeout) => {
manager.connect('ptr-a11y-timeout-started', (o, device, type, timeout) => {
let [x, y] = global.get_pointer();
this._pieTimer = new PieTimer();
@ -123,7 +123,7 @@ var PointerA11yTimeout = class PointerA11yTimeout {
global.display.set_cursor(Meta.Cursor.CROSSHAIR);
});
manager.connect('ptr-a11y-timeout-stopped', (manager, device, type, clicked) => {
manager.connect('ptr-a11y-timeout-stopped', (o, device, type, clicked) => {
if (!clicked)
this._pieTimer.destroy();

View File

@ -507,7 +507,7 @@ var PopupMenuBase = class {
menuItem = new PopupMenuItem(title);
this.addMenuItem(menuItem);
menuItem.connect('activate', (menuItem, event) => {
menuItem.connect('activate', (o, event) => {
callback(event);
});
@ -565,7 +565,7 @@ var PopupMenuBase = class {
}
_connectItemSignals(menuItem) {
menuItem._activeChangeId = menuItem.connect('notify::active', menuItem => {
menuItem._activeChangeId = menuItem.connect('notify::active', () => {
let active = menuItem.active;
if (active && this._activeMenuItem != menuItem) {
if (this._activeMenuItem)
@ -589,7 +589,7 @@ var PopupMenuBase = class {
menuItem.actor.grab_key_focus();
}
});
menuItem._activateId = menuItem.connect_after('activate', (menuItem, _event) => {
menuItem._activateId = menuItem.connect_after('activate', () => {
this.emit('activate', menuItem);
this.itemActivated(BoxPointer.PopupAnimation.FULL);
});
@ -602,7 +602,7 @@ var PopupMenuBase = class {
// the menuItem may have, called destroyId
// (FIXME: in the future it may make sense to have container objects
// like PopupMenuManager does)
menuItem._popupMenuDestroyId = menuItem.connect('destroy', menuItem => {
menuItem._popupMenuDestroyId = menuItem.connect('destroy', () => {
menuItem.disconnect(menuItem._popupMenuDestroyId);
menuItem.disconnect(menuItem._activateId);
menuItem.disconnect(menuItem._activeChangeId);

View File

@ -217,12 +217,12 @@ class RunDialog extends ModalDialog.ModalDialog {
try {
Gio.app_info_launch_default_for_uri(file.get_uri(),
global.create_app_launch_context(0, -1));
} catch (e) {
} catch (err) {
// The exception from gjs contains an error string like:
// Error invoking Gio.app_info_launch_default_for_uri: No application
// is registered as handling this file
// We are only interested in the part after the first colon.
let message = e.message.replace(/[^:]*: *(.+)/, '$1');
let message = err.message.replace(/[^:]*: *(.+)/, '$1');
this._showError(message);
}
} else {

View File

@ -230,10 +230,10 @@ var NotificationsBox = GObject.registerClass({
this._showSource(source, obj, obj.sourceBox);
this._notificationBox.add_child(obj.sourceBox);
obj.sourceCountChangedId = source.connect('notify::count', source => {
obj.sourceCountChangedId = source.connect('notify::count', () => {
this._countChanged(source, obj);
});
obj.sourceTitleChangedId = source.connect('notify::title', source => {
obj.sourceTitleChangedId = source.connect('notify::title', () => {
this._titleChanged(source, obj);
});
obj.policyChangedId = source.policy.connect('notify', (policy, pspec) => {
@ -242,7 +242,7 @@ var NotificationsBox = GObject.registerClass({
else
this._detailedChanged(source, obj);
});
obj.sourceDestroyId = source.connect('destroy', source => {
obj.sourceDestroyId = source.connect('destroy', () => {
this._onSourceDestroy(source, obj);
});

View File

@ -230,7 +230,7 @@ var ScreenshotService = class {
SelectAreaAsync(params, invocation) {
let selectArea = new SelectArea();
selectArea.show();
selectArea.connect('finished', (selectArea, areaRectangle) => {
selectArea.connect('finished', (o, areaRectangle) => {
if (areaRectangle) {
let retRectangle = this._unscaleArea(areaRectangle.x, areaRectangle.y,
areaRectangle.width, areaRectangle.height);
@ -260,7 +260,7 @@ var ScreenshotService = class {
PickColorAsync(params, invocation) {
let pickPixel = new PickPixel();
pickPixel.show();
pickPixel.connect('finished', (pickPixel, coords) => {
pickPixel.connect('finished', (obj, coords) => {
if (coords) {
let screenshot = this._createScreenshot(invocation, false);
if (!screenshot)

View File

@ -186,7 +186,7 @@ class ATIndicator extends PanelMenu.Button {
});
settings.connect(`changed::${KEY_TEXT_SCALING_FACTOR}`, () => {
let factor = settings.get_double(KEY_TEXT_SCALING_FACTOR);
factor = settings.get_double(KEY_TEXT_SCALING_FACTOR);
let active = (factor > 1.0);
widget.setToggleState(active);

View File

@ -986,16 +986,16 @@ class InputSourceIndicator extends PanelMenu.Button {
return;
let group = item.radioGroup;
for (let i = 0; i < group.length; ++i) {
if (group[i] == item) {
for (let j = 0; j < group.length; ++j) {
if (group[j] == item) {
item.setOrnament(PopupMenu.Ornament.DOT);
item.prop.set_state(IBus.PropState.CHECKED);
ibusManager.activateProperty(item.prop.get_key(),
IBus.PropState.CHECKED);
} else {
group[i].setOrnament(PopupMenu.Ornament.NONE);
group[i].prop.set_state(IBus.PropState.UNCHECKED);
ibusManager.activateProperty(group[i].prop.get_key(),
group[j].setOrnament(PopupMenu.Ornament.NONE);
group[j].prop.set_state(IBus.PropState.UNCHECKED);
ibusManager.activateProperty(group[j].prop.get_key(),
IBus.PropState.UNCHECKED);
}
}

View File

@ -271,7 +271,7 @@ var NMConnectionSection = class NMConnectionSection {
return;
item.connect('icon-changed', () => this._iconChanged());
item.connect('activation-failed', (item, reason) => {
item.connect('activation-failed', (o, reason) => {
this.emit('activation-failed', reason);
});
item.connect('name-changed', this._sync.bind(this));
@ -1987,9 +1987,9 @@ class Indicator extends PanelMenu.SystemIndicator {
} else if (result == PortalHelperResult.COMPLETED) {
this._closeConnectivityCheck(path);
} else if (result == PortalHelperResult.RECHECK) {
this._client.check_connectivity_async(null, (client, result) => {
this._client.check_connectivity_async(null, (client, res) => {
try {
let state = client.check_connectivity_finish(result);
let state = client.check_connectivity_finish(res);
if (state >= NM.ConnectivityState.FULL)
this._closeConnectivityCheck(path);
} catch (e) { }

View File

@ -28,7 +28,7 @@ class RemoteAccessApplet extends PanelMenu.SystemIndicator {
this._indicator = null;
this._menuSection = null;
controller.connect('new-handle', (controller, handle) => {
controller.connect('new-handle', (o, handle) => {
this._onNewHandle(handle);
});
}

View File

@ -509,7 +509,7 @@ var SwitcherList = GObject.registerClass({
maxChildNat = Math.max(childNat, maxChildNat);
if (this._squareItems) {
let [childMin, childNat] = this._items[i].get_preferred_height(-1);
[childMin, childNat] = this._items[i].get_preferred_height(-1);
maxChildMin = Math.max(childMin, maxChildMin);
maxChildNat = Math.max(childNat, maxChildNat);
}

View File

@ -48,7 +48,7 @@ var WindowAttentionHandler = class {
source.showNotification(notification);
source.signalIDs.push(window.connect('notify::title', () => {
let [title, banner] = this._getTitleAndBanner(app, window);
[title, banner] = this._getTitleAndBanner(app, window);
notification.update(title, banner);
}));
}

View File

@ -30,7 +30,8 @@ var WINDOW_ANIMATION_TIME = 250;
var DIM_BRIGHTNESS = -0.3;
var DIM_TIME = 500;
var UNDIM_TIME = 250;
var MOTION_THRESHOLD = 100;
var WS_MOTION_THRESHOLD = 100;
var APP_MOTION_THRESHOLD = 30;
var ONE_SECOND = 1000; // in ms
@ -493,13 +494,13 @@ var TouchpadWorkspaceSwitchAction = class {
_checkActivated() {
let dir;
if (this._dy < -MOTION_THRESHOLD)
if (this._dy < -WS_MOTION_THRESHOLD)
dir = Meta.MotionDirection.DOWN;
else if (this._dy > MOTION_THRESHOLD)
else if (this._dy > WS_MOTION_THRESHOLD)
dir = Meta.MotionDirection.UP;
else if (this._dx < -MOTION_THRESHOLD)
else if (this._dx < -WS_MOTION_THRESHOLD)
dir = Meta.MotionDirection.RIGHT;
else if (this._dx > MOTION_THRESHOLD)
else if (this._dx > WS_MOTION_THRESHOLD)
dir = Meta.MotionDirection.LEFT;
else
return false;
@ -586,8 +587,8 @@ var WorkspaceSwitchAction = GObject.registerClass({
vfunc_swipe(actor, direction) {
let [x, y] = this.get_motion_coords(0);
let [xPress, yPress] = this.get_press_coords(0);
if (Math.abs(x - xPress) < MOTION_THRESHOLD &&
Math.abs(y - yPress) < MOTION_THRESHOLD) {
if (Math.abs(x - xPress) < WS_MOTION_THRESHOLD &&
Math.abs(y - yPress) < WS_MOTION_THRESHOLD) {
this.emit('cancel');
return;
}
@ -654,15 +655,14 @@ var AppSwitchAction = GObject.registerClass({
}
vfunc_gesture_progress(_actor) {
const MOTION_THRESHOLD = 30;
if (this.get_n_current_points() == 3) {
for (let i = 0; i < this.get_n_current_points(); i++) {
let [startX, startY] = this.get_press_coords(i);
let [x, y] = this.get_motion_coords(i);
if (Math.abs(x - startX) > MOTION_THRESHOLD ||
Math.abs(y - startY) > MOTION_THRESHOLD)
if (Math.abs(x - startX) > APP_MOTION_THRESHOLD ||
Math.abs(y - startY) > APP_MOTION_THRESHOLD)
return false;
}

View File

@ -508,7 +508,7 @@ var WorkspaceThumbnail = GObject.registerClass({
_addWindowClone(win) {
let clone = new WindowClone(win);
clone.connect('selected', (clone, time) => {
clone.connect('selected', (o, time) => {
this.activate(time);
});
clone.connect('drag-begin', () => {