cleanup: Use default parameters where appropriate

Since ES6 it is possible to set an explicit default value for optional
parameters (overriding the implicit value of 'undefined'). Use them
for a nice small cleanup.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/626
This commit is contained in:
Florian Müllner 2019-07-12 01:31:38 +02:00 committed by Georges Basile Stavracas Neto
parent 16ca7a21a7
commit 404bc34089
9 changed files with 9 additions and 32 deletions

View File

@ -151,11 +151,7 @@ function getAllProps(obj) {
// e.g., expr="({ foo: null, bar: null, 4: null })" will // e.g., expr="({ foo: null, bar: null, 4: null })" will
// return ["foo", "bar", ...] but the list will not include "4", // return ["foo", "bar", ...] but the list will not include "4",
// since methods accessed with '.' notation must star with a letter or _. // since methods accessed with '.' notation must star with a letter or _.
function getPropertyNamesFromExpression(expr, commandHeader) { function getPropertyNamesFromExpression(expr, commandHeader = '') {
if (commandHeader == null) {
commandHeader = '';
}
let obj = {}; let obj = {};
if (!isUnsafeExpression(expr)) { if (!isUnsafeExpression(expr)) {
try { try {

View File

@ -1416,7 +1416,7 @@ var AppFolderPopup = class AppFolderPopup {
Signals.addSignalMethods(AppFolderPopup.prototype); Signals.addSignalMethods(AppFolderPopup.prototype);
var AppIcon = class AppIcon { var AppIcon = class AppIcon {
constructor(app, iconParams) { constructor(app, iconParams = {}) {
this.app = app; this.app = app;
this.id = app.get_id(); this.id = app.get_id();
this.name = app.get_name(); this.name = app.get_name();
@ -1442,9 +1442,6 @@ var AppIcon = class AppIcon {
this.actor._delegate = this; this.actor._delegate = this;
if (!iconParams)
iconParams = {};
// Get the isDraggable property without passing it on to the BaseIcon: // Get the isDraggable property without passing it on to the BaseIcon:
let appIconParams = Params.parse(iconParams, { isDraggable: true }, true); let appIconParams = Params.parse(iconParams, { isDraggable: true }, true);
let isDraggable = appIconParams['isDraggable']; let isDraggable = appIconParams['isDraggable'];

View File

@ -4,7 +4,7 @@ const { Atk, Clutter, St } = imports.gi;
const Signals = imports.signals; const Signals = imports.signals;
var BarLevel = class { var BarLevel = class {
constructor(value, params) { constructor(value, params = {}) {
if (isNaN(value)) if (isNaN(value))
// Avoid spreading NaNs around // Avoid spreading NaNs around
throw TypeError('The bar level value must be a number'); throw TypeError('The bar level value must be a number');
@ -13,9 +13,6 @@ var BarLevel = class {
this._overdriveStart = 1; this._overdriveStart = 1;
this._barLevelWidth = 0; this._barLevelWidth = 0;
if (params == undefined)
params = {};
this.actor = new St.DrawingArea({ styleClass: params['styleClass'] || 'barlevel', this.actor = new St.DrawingArea({ styleClass: params['styleClass'] || 'barlevel',
can_focus: params['canFocus'] || false, can_focus: params['canFocus'] || false,
reactive: params['reactive'] || false, reactive: params['reactive'] || false,

View File

@ -122,10 +122,7 @@ var ContentTypeDiscoverer = class {
} }
} }
_emitCallback(mount, contentTypes) { _emitCallback(mount, contentTypes = []) {
if (!contentTypes)
contentTypes = [];
// we're not interested in win32 software content types here // we're not interested in win32 software content types here
contentTypes = contentTypes.filter( contentTypes = contentTypes.filter(
type => (type != 'x-content/win32-software') type => (type != 'x-content/win32-software')

View File

@ -841,7 +841,7 @@ var LayoutManager = GObject.registerClass({
// @params can have any of the same values as in addChrome(), // @params can have any of the same values as in addChrome(),
// though some possibilities don't make sense. By default, @actor has // though some possibilities don't make sense. By default, @actor has
// the same params as its chrome ancestor. // the same params as its chrome ancestor.
trackChrome(actor, params) { trackChrome(actor, params = {}) {
let ancestor = actor.get_parent(); let ancestor = actor.get_parent();
let index = this._findActor(ancestor); let index = this._findActor(ancestor);
while (ancestor && index == -1) { while (ancestor && index == -1) {
@ -851,8 +851,6 @@ var LayoutManager = GObject.registerClass({
let ancestorData = ancestor ? this._trackedActors[index] let ancestorData = ancestor ? this._trackedActors[index]
: defaultParams; : defaultParams;
if (!params)
params = {};
// We can't use Params.parse here because we want to drop // We can't use Params.parse here because we want to drop
// the extra values like ancestorData.actor // the extra values like ancestorData.actor
for (let prop in defaultParams) { for (let prop in defaultParams) {

View File

@ -33,9 +33,7 @@ function _fixMarkup(text, allowMarkup) {
} }
var URLHighlighter = class URLHighlighter { var URLHighlighter = class URLHighlighter {
constructor(text, lineWrap, allowMarkup) { constructor(text = '', lineWrap, allowMarkup) {
if (!text)
text = '';
this.actor = new St.Label({ reactive: true, style_class: 'url-highlighter', this.actor = new St.Label({ reactive: true, style_class: 'url-highlighter',
x_expand: true, x_align: Clutter.ActorAlign.START }); x_expand: true, x_align: Clutter.ActorAlign.START });
this._linkColor = '#ccccff'; this._linkColor = '#ccccff';

View File

@ -473,9 +473,7 @@ var Notification = class Notification {
this.destroy(); this.destroy();
} }
destroy(reason) { destroy(reason = NotificationDestroyedReason.DISMISSED) {
if (!reason)
reason = NotificationDestroyedReason.DISMISSED;
this.emit('destroy', reason); this.emit('destroy', reason);
} }
}; };

View File

@ -151,9 +151,7 @@ var OsdWindow = class {
} }
} }
setMaxLevel(maxLevel) { setMaxLevel(maxLevel = 100) {
if (maxLevel === undefined)
maxLevel = 100;
this._level.maxLevel = maxLevel; this._level.maxLevel = maxLevel;
} }

View File

@ -706,9 +706,7 @@ var PanelCorner = class {
var AggregateLayout = GObject.registerClass( var AggregateLayout = GObject.registerClass(
class AggregateLayout extends Clutter.BoxLayout { class AggregateLayout extends Clutter.BoxLayout {
_init(params) { _init(params = {}) {
if (!params)
params = {};
params['orientation'] = Clutter.Orientation.VERTICAL; params['orientation'] = Clutter.Orientation.VERTICAL;
super._init(params); super._init(params);