[gjs: 5/6] Gio._promisify: Avoid using a regex to guess the finish function
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 5/6] Gio._promisify: Avoid using a regex to guess the finish function
- Date: Thu, 21 Jul 2022 17:54:41 +0000 (UTC)
commit 9bc5a6606dabb23e35b7be1de57707c51142bc50
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date: Fri Jul 8 05:00:10 2022 +0200
Gio._promisify: Avoid using a regex to guess the finish function
modules/core/overrides/Gio.js | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/modules/core/overrides/Gio.js b/modules/core/overrides/Gio.js
index 041002a53..1dfa54e55 100644
--- a/modules/core/overrides/Gio.js
+++ b/modules/core/overrides/Gio.js
@@ -417,11 +417,17 @@ function* _listModelIterator() {
yield this.get_item(_index++);
}
-function _promisify(proto, asyncFunc,
- finishFunc = `${asyncFunc.replace(/_(begin|async)$/, '')}_finish`) {
+function _promisify(proto, asyncFunc, finishFunc = undefined) {
if (proto[asyncFunc] === undefined)
throw new Error(`${proto} has no method named ${asyncFunc}`);
+ if (finishFunc === undefined) {
+ if (asyncFunc.endsWith('_begin') || asyncFunc.endsWith('_async'))
+ finishFunc = `${asyncFunc.slice(0, -5)}finish`;
+ else
+ finishFunc = `${asyncFunc}_finish`;
+ }
+
if (proto[finishFunc] === undefined)
throw new Error(`${proto} has no method named ${finishFunc}`);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]