Skip to content

Commit 5f00667

Browse files
3v1n0mtwebster
authored andcommitted
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.
1 parent ac9e843 commit 5f00667

2 files changed

Lines changed: 19 additions & 34 deletions

File tree

installed-tests/js/testGio.js

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,6 @@ describe('Gio.FileEnumerator overrides', function () {
396396
});
397397

398398
describe('Gio.DesktopAppInfo fallback', function () {
399-
let writerFunc;
400399
const requiredVersion =
401400
GLib.MAJOR_VERSION > 2 ||
402401
(GLib.MAJOR_VERSION === 2 && GLib.MINOR_VERSION >= 86);
@@ -409,51 +408,39 @@ Exec=${GLib.find_program_in_path('sh')}
409408
`;
410409
beforeAll(function () {
411410
// Set up log writer for tests to override
412-
writerFunc = jasmine.createSpy('parsed writer func');
413-
const writerFuncWrapper = jasmine.createSpy('log writer func', (level, fields) => {
414-
const decoder = new TextDecoder('utf-8');
415-
const domain = decoder.decode(fields?.GLIB_DOMAIN);
416-
const message = `${decoder.decode(fields?.MESSAGE)}`;
417-
if (level < GLib.LogLevelFlags.LEVEL_WARNING) {
418-
level |= GLib.LogLevelFlags.FLAG_RECURSION;
419-
GLib.log_default_handler(domain, level, `${message}\n`, null);
420-
}
421-
writerFunc(domain, level, message);
422-
return GLib.LogWriterOutput.HANDLED;
423-
});
424-
writerFuncWrapper.and.callThrough();
425-
GLib.log_set_writer_func(writerFuncWrapper);
426-
427411
keyFile = new GLib.KeyFile();
428412
keyFile.load_from_data(desktopFileContent, desktopFileContent.length,
429413
GLib.KeyFileFlags.NONE);
430414
});
431415

432-
afterAll(function () {
433-
GLib.log_set_writer_default();
434-
});
435-
436416
beforeEach(function () {
437417
if (!GioUnix)
438418
pending('Not supported platform');
439419

440-
writerFunc.calls.reset();
420+
if (!requiredVersion)
421+
pending('Installed Gio is not new enough for this test');
441422
});
442423

424+
function expectDeprecationWarning(testFunction) {
425+
if (!requiredVersion)
426+
pending('Installed Gio is not new enough for this test');
427+
428+
GLib.test_expect_message('Cjs', GLib.LogLevelFlags.LEVEL_WARNING,
429+
'*Gio.DesktopAppInfo has been moved to a separate platform-specific library. ' +
430+
'Please update your code to use GioUnix.DesktopAppInfo instead*');
431+
testFunction();
432+
GLib.test_assert_expected_messages_internal('Cjs', 'testGio.js', 0,
433+
'Gio.DesktopAppInfo expectWarnsOnNewerGio');
434+
}
435+
443436
it('can be created using GioUnix', function () {
444437
expect(GioUnix.DesktopAppInfo.new_from_keyfile(keyFile)).not.toBeNull();
445-
expect(writerFunc).not.toHaveBeenCalled();
446438
});
447439

448440
it('can be created using Gio wrapper', function () {
441+
expectDeprecationWarning(() =>
442+
expect(Gio.DesktopAppInfo.new_from_keyfile(keyFile)).not.toBeNull());
449443
expect(Gio.DesktopAppInfo.new_from_keyfile(keyFile)).not.toBeNull();
450-
expect(writerFunc).toHaveBeenCalledWith('Cjs-Console',
451-
GLib.LogLevelFlags.LEVEL_WARNING,
452-
'Gio.DesktopAppInfo is deprecated, please use GioUnix.DesktopAppInfo instead');
453-
454-
writerFunc.calls.reset();
455-
expect(Gio.DesktopAppInfo.new_from_keyfile(keyFile)).not.toBeNull();
456-
expect(writerFunc).not.toHaveBeenCalled();
457444
});
458445

459446
describe('provides platform-independent functions', function () {

modules/core/overrides/Gio.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
var GLib = imports.gi.GLib;
55
var CjsPrivate = imports.gi.CjsPrivate;
66
var Signals = imports.signals;
7+
const { warnDeprecatedOncePerCallsite, PLATFORM_SPECIFIC_TYPELIB } = imports._print;
78
var Gio;
89

910
// Ensures that a Gio.UnixFDList being passed into or out of a DBus method with
@@ -506,11 +507,8 @@ function _init() {
506507
enumerable: true,
507508
configurable: false,
508509
get() {
509-
if (!newDesc._deprecationWarningDone) {
510-
console.warn(`Gio.${prop} is deprecated, please use ` +
511-
`${GioPlatform.__name__}.${prop} instead`);
512-
newDesc._deprecationWarningDone = true;
513-
}
510+
warnDeprecatedOncePerCallsite(PLATFORM_SPECIFIC_TYPELIB,
511+
`Gio.${prop}`, `${GioPlatform.__name__}.${prop}`);
514512
return desc.get?.() ?? desc.value;
515513
},
516514
};

0 commit comments

Comments
 (0)