Skip to content

GInterface methods (e.g. GFile.getPath) missing on instances, only present on prototype #441

Description

@romgrk

Summary

Methods that come from a GInterface are not present on object instances — they only exist on the interface's prototype. For example a Gio.File returned by Gio.File.newForPath() (a GLocalFile, which implements the GFile interface) exposes only the base GObject methods; file.getPath, file.enumerateChildren, file.getBasename, etc. are all undefined.

The methods do exist on Gio.File.prototype, so they can be invoked with .call(), but they are not mixed into the instance's prototype chain.

Reproduction

const gi = require('node-gtk');
const Gio = gi.require('Gio', '2.0');

const f = Gio.File.newForPath('/tmp/example.txt');
console.log('typeof f.getPath           :', typeof f.getPath);
console.log('typeof f.getBasename       :', typeof f.getBasename);
console.log('typeof Gio.File.prototype.getPath:', typeof Gio.File.prototype.getPath);
console.log('via prototype.call         :', Gio.File.prototype.getPath.call(f));

Actual

typeof f.getPath           : undefined
typeof f.getBasename       : undefined
typeof Gio.File.prototype.getPath: function
via prototype.call         : /tmp/example.txt

Expected

f.getPath() should work directly, i.e. interface methods should be available on instances of types implementing that interface.

Notes

  • This also affects objects handed back from other APIs, e.g. the GFile retrieved via fileInfo.getAttributeObject('standard::file') from a GtkDirectoryList.
  • Concrete-class methods are unaffected — GFileInfo, GFileEnumerator, GtkDirectoryList etc. expose their own methods on instances normally.
  • The concrete type here (GLocalFile) is a private/non-introspectable type, so node-gtk wraps the instance using the declared return type GFile (the interface). The interface's methods don't get applied to the instance.
  • Workaround: Gio.File.prototype.<method>.call(instance, ...).

Environment

  • node-gtk 2.0.0
  • node v22.22.3
  • GTK 4.22.4, GLib 2.88.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions