File: overrides-Gio-Use-print-s-warnDeprecatedOncePerCallsite-t.patch

package info (click to toggle)
cjs 128.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,264 kB
  • sloc: cpp: 34,377; javascript: 27,762; ansic: 13,033; sh: 1,611; python: 780; xml: 116; makefile: 38
file content (117 lines) | stat: -rw-r--r-- 4,954 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
From: =?utf-8?b?Ik1hcmNvIFRyZXZpc2FuIChUcmV2acOxbyki?= <mail@3v1n0.net>
Date: Fri, 12 Sep 2025 00:21:10 +0200
Subject: overrides/Gio: Use print's warnDeprecatedOncePerCallsite to warn

Re-use the C definition to warn when using a deprecated namespace
instead of doing the same in pure JS.
---
 installed-tests/js/testGio.js | 45 +++++++++++++++----------------------------
 modules/core/overrides/Gio.js |  8 +++-----
 2 files changed, 19 insertions(+), 34 deletions(-)

diff --git a/installed-tests/js/testGio.js b/installed-tests/js/testGio.js
index e74059a..f67aec4 100644
--- a/installed-tests/js/testGio.js
+++ b/installed-tests/js/testGio.js
@@ -396,7 +396,6 @@ describe('Gio.FileEnumerator overrides', function () {
 });
 
 describe('Gio.DesktopAppInfo fallback', function () {
-    let writerFunc;
     const requiredVersion =
         GLib.MAJOR_VERSION > 2 ||
             (GLib.MAJOR_VERSION === 2 && GLib.MINOR_VERSION >= 86);
@@ -409,51 +408,39 @@ Exec=${GLib.find_program_in_path('sh')}
 `;
     beforeAll(function () {
         // Set up log writer for tests to override
-        writerFunc = jasmine.createSpy('parsed writer func');
-        const writerFuncWrapper = jasmine.createSpy('log writer func', (level, fields) => {
-            const decoder = new TextDecoder('utf-8');
-            const domain = decoder.decode(fields?.GLIB_DOMAIN);
-            const message = `${decoder.decode(fields?.MESSAGE)}`;
-            if (level < GLib.LogLevelFlags.LEVEL_WARNING) {
-                level |= GLib.LogLevelFlags.FLAG_RECURSION;
-                GLib.log_default_handler(domain, level, `${message}\n`, null);
-            }
-            writerFunc(domain, level, message);
-            return GLib.LogWriterOutput.HANDLED;
-        });
-        writerFuncWrapper.and.callThrough();
-        GLib.log_set_writer_func(writerFuncWrapper);
-
         keyFile = new GLib.KeyFile();
         keyFile.load_from_data(desktopFileContent, desktopFileContent.length,
             GLib.KeyFileFlags.NONE);
     });
 
-    afterAll(function () {
-        GLib.log_set_writer_default();
-    });
-
     beforeEach(function () {
         if (!GioUnix)
             pending('Not supported platform');
 
-        writerFunc.calls.reset();
+        if (!requiredVersion)
+            pending('Installed Gio is not new enough for this test');
     });
 
+    function expectDeprecationWarning(testFunction) {
+        if (!requiredVersion)
+            pending('Installed Gio is not new enough for this test');
+
+        GLib.test_expect_message('Cjs', GLib.LogLevelFlags.LEVEL_WARNING,
+            '*Gio.DesktopAppInfo has been moved to a separate platform-specific library. ' +
+            'Please update your code to use GioUnix.DesktopAppInfo instead*');
+        testFunction();
+        GLib.test_assert_expected_messages_internal('Cjs', 'testGio.js', 0,
+            'Gio.DesktopAppInfo expectWarnsOnNewerGio');
+    }
+
     it('can be created using GioUnix', function () {
         expect(GioUnix.DesktopAppInfo.new_from_keyfile(keyFile)).not.toBeNull();
-        expect(writerFunc).not.toHaveBeenCalled();
     });
 
     it('can be created using Gio wrapper', function () {
+        expectDeprecationWarning(() =>
+            expect(Gio.DesktopAppInfo.new_from_keyfile(keyFile)).not.toBeNull());
         expect(Gio.DesktopAppInfo.new_from_keyfile(keyFile)).not.toBeNull();
-        expect(writerFunc).toHaveBeenCalledWith('Cjs-Console',
-            GLib.LogLevelFlags.LEVEL_WARNING,
-            'Gio.DesktopAppInfo is deprecated, please use GioUnix.DesktopAppInfo instead');
-
-        writerFunc.calls.reset();
-        expect(Gio.DesktopAppInfo.new_from_keyfile(keyFile)).not.toBeNull();
-        expect(writerFunc).not.toHaveBeenCalled();
     });
 
     describe('provides platform-independent functions', function () {
diff --git a/modules/core/overrides/Gio.js b/modules/core/overrides/Gio.js
index 6bcc20f..f5c24fc 100644
--- a/modules/core/overrides/Gio.js
+++ b/modules/core/overrides/Gio.js
@@ -4,6 +4,7 @@
 var GLib = imports.gi.GLib;
 var CjsPrivate = imports.gi.CjsPrivate;
 var Signals = imports.signals;
+const { warnDeprecatedOncePerCallsite, PLATFORM_SPECIFIC_TYPELIB } = imports._print;
 var Gio;
 
 // Ensures that a Gio.UnixFDList being passed into or out of a DBus method with
@@ -506,11 +507,8 @@ function _init() {
             enumerable: true,
             configurable: false,
             get() {
-                if (!newDesc._deprecationWarningDone) {
-                    console.warn(`Gio.${prop} is deprecated, please use ` +
-                        `${GioPlatform.__name__}.${prop} instead`);
-                    newDesc._deprecationWarningDone = true;
-                }
+                warnDeprecatedOncePerCallsite(PLATFORM_SPECIFIC_TYPELIB,
+                    `Gio.${prop}`, `${GioPlatform.__name__}.${prop}`);
                 return desc.get?.() ?? desc.value;
             },
         };