[gnome-shell] Stop using conditional catch statements



commit e36ba874a85d90a7565769d2214bdff478a854b2
Author: Florian Müllner <fmuellner gnome org>
Date:   Sun Jul 15 03:17:42 2018 +0200

    Stop using conditional catch statements
    
    It is a mozilla extension that is going away in SpiderMonkey 60.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/151

 js/gdm/util.js              | 33 ++++++++++++++++++---------------
 js/ui/notificationDaemon.js | 15 ++++++++++-----
 js/ui/runDialog.js          |  7 ++++---
 js/ui/scripting.js          | 12 +++++++-----
 4 files changed, 39 insertions(+), 28 deletions(-)
---
diff --git a/js/gdm/util.js b/js/gdm/util.js
index 261e1e433..75feb77d0 100644
--- a/js/gdm/util.js
+++ b/js/gdm/util.js
@@ -350,16 +350,19 @@ var ShellUserVerifier = new Lang.Class({
         try {
             this._clearUserVerifier();
             this._userVerifier = client.open_reauthentication_channel_finish(result);
-        } catch(e if e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED)) {
-            return;
-        } catch(e if e.matches(Gio.DBusError, Gio.DBusError.ACCESS_DENIED) &&
-                !this._reauthOnly) {
-            // Gdm emits org.freedesktop.DBus.Error.AccessDenied when there is
-            // no session to reauthenticate. Fall back to performing verification
-            // from this login session
-            client.get_user_verifier(this._cancellable, this._userVerifierGot.bind(this));
-            return;
         } catch(e) {
+            if (e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED))
+                return;
+            if (e.matches(Gio.DBusError, Gio.DBusError.ACCESS_DENIED) &&
+                !this._reauthOnly) {
+                // Gdm emits org.freedesktop.DBus.Error.AccessDenied when there
+                // is no session to reauthenticate. Fall back to performing
+                // verification from this login session
+                client.get_user_verifier(this._cancellable,
+                                         this._userVerifierGot.bind(this));
+                return;
+            }
+
             this._reportInitError('Failed to open reauthentication channel', e);
             return;
         }
@@ -374,9 +377,9 @@ var ShellUserVerifier = new Lang.Class({
         try {
             this._clearUserVerifier();
             this._userVerifier = client.get_user_verifier_finish(result);
-        } catch(e if e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED)) {
-            return;
         } catch(e) {
+            if (e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED))
+                return;
             this._reportInitError('Failed to obtain user verifier', e);
             return;
         }
@@ -434,9 +437,9 @@ var ShellUserVerifier = new Lang.Class({
                                                                (obj, result) => {
                try {
                    obj.call_begin_verification_for_user_finish(result);
-               } catch(e if e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED)) {
-                   return;
                } catch(e) {
+                   if (e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED))
+                       return;
                    this._reportInitError('Failed to start verification for user', e);
                    return;
                }
@@ -449,9 +452,9 @@ var ShellUserVerifier = new Lang.Class({
                                                       (obj, result) => {
                try {
                    obj.call_begin_verification_finish(result);
-               } catch(e if e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED)) {
-                   return;
                } catch(e) {
+                   if (e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED))
+                       return;
                    this._reportInitError('Failed to start verification', e);
                    return;
                }
diff --git a/js/ui/notificationDaemon.js b/js/ui/notificationDaemon.js
index 9f085629f..2b5a453c7 100644
--- a/js/ui/notificationDaemon.js
+++ b/js/ui/notificationDaemon.js
@@ -831,8 +831,10 @@ var GtkNotificationDaemon = new Lang.Class({
                 let source;
                 try {
                     source = this._ensureAppSource(appId);
-                } catch(e if e instanceof InvalidAppError) {
-                    return;
+                } catch(e) {
+                    if (e instanceof InvalidAppError)
+                        return;
+                    throw e;
                 }
 
                 notifications.forEach(([notificationId, notification]) => {
@@ -863,9 +865,12 @@ var GtkNotificationDaemon = new Lang.Class({
         let source;
         try {
             source = this._ensureAppSource(appId);
-        } catch(e if e instanceof InvalidAppError) {
-            invocation.return_dbus_error('org.gtk.Notifications.InvalidApp', 'The app by ID "%s" could not 
be found'.format(appId));
-            return;
+        } catch(e) {
+            if (e instanceof InvalidAppError) {
+                invocation.return_dbus_error('org.gtk.Notifications.InvalidApp', 'The app by ID "%s" could 
not be found'.format(appId));
+                return;
+            }
+            throw e;
         }
 
         let timestamp = GLib.DateTime.new_now_local().to_unix();
diff --git a/js/ui/runDialog.js b/js/ui/runDialog.js
index 82deab5a3..606a68396 100644
--- a/js/ui/runDialog.js
+++ b/js/ui/runDialog.js
@@ -172,9 +172,10 @@ var RunDialog = new Lang.Class({
                     if (name.slice(0, text.length) == text)
                         results.push(name);
                 }
-            } catch (e if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.NOT_FOUND) &&
-                           !e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.NOT_DIRECTORY))) {
-                log(e);
+            } catch (e) {
+                if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.NOT_FOUND) &&
+                    !e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.NOT_DIRECTORY))
+                    log(e);
             } finally {
                 return results;
             }
diff --git a/js/ui/scripting.js b/js/ui/scripting.js
index c53083210..c96ebd1f9 100644
--- a/js/ui/scripting.js
+++ b/js/ui/scripting.js
@@ -216,12 +216,14 @@ function _step(g, finish, onError) {
                          if (onError)
                              onError(err);
                      });
-    } catch (err if err instanceof StopIteration) {
-        if (finish)
-            finish();
     } catch (err) {
-        if (onError)
-            onError(err);
+        if (err instanceof StopIteration) {
+            if (finish)
+                finish();
+        } else {
+            if (onError)
+                onError(err);
+        }
     }
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]