[gjs: 1/7] overrides/Gio: Allow promisifying static methods



commit cb0b1311d77ceb094241d3a1141900fa3f624c88
Author: Florian Müllner <fmuellner gnome org>
Date:   Tue Mar 24 02:14:24 2020 +0100

    overrides/Gio: Allow promisifying static methods
    
    GIO's async pattern is not only used for object methods like
    Gio.DBusProxy.prototype.call(), but also for static methods
    like Gio.DBusProxy.new().
    
    In order to make _promisify() usable with the latter, check whether the
    finish function actually exists for the GAsyncReadyCallback's source
    parameter, and call it on the proto otherwise.

 modules/core/overrides/Gio.js | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
---
diff --git a/modules/core/overrides/Gio.js b/modules/core/overrides/Gio.js
index 0aa9f437..46a91865 100644
--- a/modules/core/overrides/Gio.js
+++ b/modules/core/overrides/Gio.js
@@ -429,7 +429,9 @@ function _promisify(proto, asyncFunc, finishFunc) {
             const callStack = new Error().stack.split('\n').filter(line => 
!line.match(/promisify/)).join('\n');
             this[`_original_${asyncFunc}`](...args, function (source, res) {
                 try {
-                    const result = source[finishFunc](res);
+                    const result = source !== null && source[finishFunc] !== undefined
+                        ? source[finishFunc](res)
+                        : proto[finishFunc](res);
                     if (Array.isArray(result) && result.length > 1 && result[0] === true)
                         result.shift();
                     resolve(result);


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