Skip to content

Commit 4aebee4

Browse files
3v1n0mtwebster
authored andcommitted
overrides/Gio: Use Platform prefix for platform-only functions
In case a platform-only function is being mapped inside the Gio namespace and that has a platform-specific prefix, then we should use it inside the more generic Gio namespace. This is preserving the pre-girepository-2.0 behavior
1 parent bfedb44 commit 4aebee4

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

installed-tests/js/testIntrospection.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,22 @@ describe('Backwards compatibility for GLib/Gio platform specific GIRs', function
232232
'Expected deprecation message for Gio.Unix -> GioUnix');
233233
});
234234

235+
it('GioUnix functions are looked up in GioUnix, not Gio', function () {
236+
if (skip) {
237+
pending('GioUnix required for this test');
238+
return;
239+
}
240+
241+
GLib.test_expect_message('Cjs', GLib.LogLevelFlags.LEVEL_WARNING,
242+
'*Gio.unix_mounts_get*GioUnix.mounts_get*instead*');
243+
244+
expect(imports.gi.Gio.unix_mounts_get.name).toBe('g_unix_mounts_get');
245+
246+
GLib.test_assert_expected_messages_internal('Cjs',
247+
'testIntrospection.js', 0,
248+
'Expected deprecation message for Gio.Unix -> GioUnix');
249+
});
250+
235251
it("doesn't print the message if the type isn't resolved directly", function () {
236252
if (skip) {
237253
pending('GioUnix required for this test');

modules/core/overrides/Gio.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,13 +497,17 @@ function _init() {
497497
}
498498

499499
const platformName = `${GioPlatform?.__name__?.slice(3 /* 'Gio'.length */)}`;
500+
const platformNameLower = platformName.toLowerCase();
500501
Object.entries(Object.getOwnPropertyDescriptors(GioPlatform)).forEach(([prop, desc]) => {
501502
let genericProp = prop;
502503

503504
const originalValue = GioPlatform[prop];
504505
const gtypeName = originalValue.$gtype?.name;
505506
if (gtypeName?.startsWith(`G${platformName}`))
506507
genericProp = `${platformName}${prop}`;
508+
else if (originalValue instanceof Function &&
509+
originalValue.name.startsWith(`g_${platformNameLower}_`))
510+
genericProp = `${platformNameLower}_${prop}`;
507511

508512
if (Object.hasOwn(Gio, genericProp)) {
509513
console.debug(`Gio already contains property ${genericProp}`);

0 commit comments

Comments
 (0)