[gjs/wip/ptomato/develop: 2/4] overrides/Gio: Provide an empty array on error, rather than null



commit 1768dfa57ea5f8a25b355f30068b86616fa2583e
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Tue Jun 5 17:08:34 2012 -0400

    overrides/Gio: Provide an empty array on error, rather than null
    
    Gio is often used with destructuring assignment:
    
        proxy.ThingRemote(1, 2, 3, function([a, b, c], e) {
            log([a, b, c]);
        });
    
    If, on error, we provide null instead of an array, we'll crash as
    the runtime tries to iterate over null. As DBus return values are
    guaranteed to be tuples, this is always a safe choice.
    
    This is a backwards-incompatible change, since client code may have been
    checking for a null result on error. Original patch by Jasper St. Pierre,
    rebased and test added by Philip Chimento.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=677513

 installed-tests/js/testGDBus.js |   21 +++++++++++++++++++--
 modules/overrides/Gio.js        |    2 +-
 2 files changed, 20 insertions(+), 3 deletions(-)
---
diff --git a/installed-tests/js/testGDBus.js b/installed-tests/js/testGDBus.js
index 28e1f15..1be9eae 100644
--- a/installed-tests/js/testGDBus.js
+++ b/installed-tests/js/testGDBus.js
@@ -266,20 +266,37 @@ describe('Exported DBus object', function () {
             'JS ERROR: Exception in method call: alwaysThrowException: *');
 
         proxy.alwaysThrowExceptionRemote({}, function(result, excp) {
-            expect(result).toBeNull();
             expect(excp).not.toBeNull();
             loop.quit();
         });
         loop.run();
     });
 
+    it('can still destructure the return value when an exception is thrown', function () {
+        GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_WARNING,
+            'JS ERROR: Exception in method call: alwaysThrowException: *');
+
+        // This test will not fail, but instead if the functionality is not
+        // implemented correctly it will hang. The exception in the function
+        // argument destructuring will not propagate across the FFI boundary
+        // and the main loop will never quit.
+        // https://bugzilla.gnome.org/show_bug.cgi?id=729015
+        proxy.alwaysThrowExceptionRemote({}, function([a, b, c], excp) {
+            expect(a).not.toBeDefined();
+            expect(b).not.toBeDefined();
+            expect(c).not.toBeDefined();
+            void excp;
+            loop.quit();
+        });
+        loop.run();
+    });
+
     it('throws an exception when trying to call a method that does not exist', function () {
         /* First remove the method from the object! */
         delete Test.prototype.thisDoesNotExist;
 
         proxy.thisDoesNotExistRemote(function (result, excp) {
             expect(excp).not.toBeNull();
-            expect(result).toBeNull();
             loop.quit();
         });
         loop.run();
diff --git a/modules/overrides/Gio.js b/modules/overrides/Gio.js
index 950641b..328de0b 100644
--- a/modules/overrides/Gio.js
+++ b/modules/overrides/Gio.js
@@ -83,7 +83,7 @@ function _proxyInvoker(methodName, sync, inSignature, arg_array) {
             outVariant = proxy.call_finish(result);
             succeeded = true;
         } catch (e) {
-            replyFunc(null, e);
+            replyFunc([], e);
         }
 
         if (succeeded)


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