[gjs: 2/7] modified _promisify function




commit 9772cf87bd2aa54a97171f486f71eb68417d1b0a
Author: veena <veenanitks gmail com>
Date:   Mon May 31 22:54:33 2021 +0530

    modified _promisify function

 installed-tests/js/testGio.js | 11 +++++++++++
 modules/core/overrides/Gio.js |  9 +++++++++
 2 files changed, 20 insertions(+)
---
diff --git a/installed-tests/js/testGio.js b/installed-tests/js/testGio.js
index 4260b202..ce0867e0 100644
--- a/installed-tests/js/testGio.js
+++ b/installed-tests/js/testGio.js
@@ -63,6 +63,17 @@ describe('Sorting in ListStore', function () {
     });
 });
 
+describe('Promisify function', function () {
+    it("doesn't crash when async function is not defined", function () {
+        expect(() => Gio._promisify(Gio.Subprocess.prototype, 'commuicate_utf8_async', 
'communicate_utf8_finish')).toThrowError(`commuicate_utf8_async is not defined`);
+    });
+
+    it("doesn't crash when finish function is not defined", function () {
+        expect(() => Gio._promisify(Gio.Subprocess.prototype, 'communicate_utf8_async', 
'commuicate_utf8_finish')).toThrowError(`commuicate_utf8_finish is not defined`);
+    });
+
+});
+
 describe('Gio.Settings overrides', function () {
     it("doesn't crash when forgetting to specify a schema ID", function () {
         expect(() => new Gio.Settings()).toThrowError(/schema/);
diff --git a/modules/core/overrides/Gio.js b/modules/core/overrides/Gio.js
index c1fc54c0..6cf0d836 100644
--- a/modules/core/overrides/Gio.js
+++ b/modules/core/overrides/Gio.js
@@ -404,6 +404,15 @@ function* _listModelIterator() {
 }
 
 function _promisify(proto, asyncFunc, finishFunc) {
+    if (proto[asyncFunc] === undefined){
+        throw new Error(`${asyncFunc} is not defined`);
+        return;
+    }
+    if (proto[finishFunc] === undefined){
+        throw new Error(`${finishFunc} is not defined`);
+        return;
+    }
+
     if (proto[`_original_${asyncFunc}`] !== undefined)
         return;
     proto[`_original_${asyncFunc}`] = proto[asyncFunc];


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