[gjs: 3/6] Gio: Avoid computing the callStack at call time




commit 2ebfea71455004e2cd671b1ea57aaf11e6e20bd1
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Fri Jul 8 04:18:55 2022 +0200

    Gio: Avoid computing the callStack at call time
    
    We don't need it unless we have an error to throw, so only compute it
    in such case, also avoid using Regexes

 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 b1377d7e5..fab7af024 100644
--- a/modules/core/overrides/Gio.js
+++ b/modules/core/overrides/Gio.js
@@ -433,7 +433,7 @@ function _promisify(proto, asyncFunc,
         if (!args.every(arg => typeof arg !== 'function'))
             return this[originalFuncName](...args);
         return new Promise((resolve, reject) => {
-            const callStack = new Error().stack.split('\n').filter(line => 
!line.match(/promisify/)).join('\n');
+            let {stack: callStack} = new Error();
             this[originalFuncName](...args, function (source, res) {
                 try {
                     const result = source !== null && source[finishFunc] !== undefined
@@ -443,6 +443,8 @@ function _promisify(proto, asyncFunc,
                         result.shift();
                     resolve(result);
                 } catch (error) {
+                    callStack = callStack.split('\n').filter(line =>
+                        line.indexOf('_promisify/') === -1).join('\n');
                     if (error.stack)
                         error.stack += `### Promise created here: ###\n${callStack}`;
                     else


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