[gnome-shell] dash: Fix some JS warnings
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] dash: Fix some JS warnings
- Date: Thu, 13 Jul 2017 15:25:58 +0000 (UTC)
commit 2a01606c59894b366ff9fbbeb7cadda2d5c70dc8
Author: Florian Müllner <fmuellner gnome org>
Date: Tue Jun 13 03:41:42 2017 +0200
dash: Fix some JS warnings
We currently use "array[index]" to test whether an array has an
element at index before using it. However nowadays gjs warns about
accessing non-existent array elements, so the test itself already
produces a warning. Avoid this by checking the array length before
using an index to access an element.
https://bugzilla.gnome.org/show_bug.cgi?id=781471
js/ui/dash.js | 26 ++++++++++++++------------
1 files changed, 14 insertions(+), 12 deletions(-)
---
diff --git a/js/ui/dash.js b/js/ui/dash.js
index 802ae53..2252a74 100644
--- a/js/ui/dash.js
+++ b/js/ui/dash.js
@@ -756,42 +756,44 @@ const Dash = new Lang.Class({
let newIndex = 0;
let oldIndex = 0;
while (newIndex < newApps.length || oldIndex < oldApps.length) {
+ let oldApp = oldApps.length > oldIndex ? oldApps[oldIndex] : null;
+ let newApp = newApps.length > newIndex ? newApps[newIndex] : null;
+
// No change at oldIndex/newIndex
- if (oldApps[oldIndex] == newApps[newIndex]) {
+ if (oldApp == newApp) {
oldIndex++;
newIndex++;
continue;
}
// App removed at oldIndex
- if (oldApps[oldIndex] &&
- newApps.indexOf(oldApps[oldIndex]) == -1) {
+ if (oldApp && newApps.indexOf(oldApp) == -1) {
removedActors.push(children[oldIndex]);
oldIndex++;
continue;
}
// App added at newIndex
- if (newApps[newIndex] &&
- oldApps.indexOf(newApps[newIndex]) == -1) {
- addedItems.push({ app: newApps[newIndex],
- item: this._createAppItem(newApps[newIndex]),
+ if (newApp && oldApps.indexOf(newApp) == -1) {
+ addedItems.push({ app: newApp,
+ item: this._createAppItem(newApp),
pos: newIndex });
newIndex++;
continue;
}
// App moved
- let insertHere = newApps[newIndex + 1] &&
- newApps[newIndex + 1] == oldApps[oldIndex];
+ let nextApp = newApps.length > newIndex + 1 ? newApps[newIndex + 1]
+ : null;
+ let insertHere = nextApp && nextApp == oldApp;
let alreadyRemoved = removedActors.reduce(function(result, actor) {
let removedApp = actor.child._delegate.app;
- return result || removedApp == newApps[newIndex];
+ return result || removedApp == newApp;
}, false);
if (insertHere || alreadyRemoved) {
- let newItem = this._createAppItem(newApps[newIndex]);
- addedItems.push({ app: newApps[newIndex],
+ let newItem = this._createAppItem(newApp);
+ addedItems.push({ app: newApp,
item: newItem,
pos: newIndex + removedActors.length });
newIndex++;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]