WpProperties iterators don't work with gjs
When I save this script as propstest.js and run it with gjs propstest.js
:
const { GLib, Wp } = imports.gi;
Wp.init(Wp.InitFlags.PIPEWIRE);
const ctx = GLib.MainContext.new();
const loop = GLib.MainLoop.new(ctx, false);
ctx.push_thread_default();
const core = Wp.Core.new(ctx, null);
const om = Wp.ObjectManager.new();
om.add_interest_full(Wp.ObjectInterest.new_type(Wp.GlobalProxy.$gtype));
om.request_object_features(Wp.GlobalProxy.$gtype, Wp.OBJECT_FEATURES_ALL);
om.connect('object-added', (m_, obj) => {
const iter = obj.properties.new_iterator();
const item = iter.next();
print(item);
});
om.connect('installed', () => loop.quit());
core.install_object_manager(om);
core.connect();
loop.run();
ctx.pop_thread_default();
Then I get a bunch of these errors:
(gjs:216319): Gjs-CRITICAL **: 11:17:24.034: JS ERROR: Error: Can't convert non-null pointer to JS value
@propstest.js:14:21
@propstest.js:21:6
The issue here is that values of G_TYPE_POINTER
are not supported in gjs. I don't know if it's a good idea to add it there either because untyped pointer dereferences aren't really a safe operation. I think this could be fixed by making these iterators hold a small boxed type that holds the pointer and a weak reference to the properties object. That could probably be done without breaking the ABI, and would be safer, but it would be an extra allocation. It may also be possible to put this in a new fundamental type without causing any extra allocations, since a GValue has enough space for two pointers.