object: Implement newEnumerate hook for GObject
Atm. it's not possible to get a list of a GObject's methods. This is because methods are resolved on demand and no enumerate hook is defined. A consequence is that
Object.getOwnPropertyNames(Object.getPrototypeOf(aGObject)) only include method names that have been accessed at some point.
We're making a gnome-shell mode for emacs and auto-completion of all methods are one of the last major pieces missing.
The above also holds for properties, but these are possible to list with
This is a proof of concept of a enumerate hook. It does nothing fancy (eg. no caching of method names). I decided to use the "newEnumerate" since it's "new" and looked simpler to implement. As a consequence gjs_object is now defined using the "js::"/"friend" API just like the importer.
It has been indicated on IRC that a patch would be welcome, but I think getting some feedback early is a good idea. We probably should also expose the properties for instance?
Object.entries does not seem to work in terms of the enumeration hook, so there's a mismatch between
PS: Autocompletion in looking glass is also crippled by this. Meta.prefs_get_keybinding_action and global.display.get_focus_window are examples for a freshly restarted shell here.
PS: I've attempted to use the JS bindings of g-object-introspection (
imports.gi.GIRepository.*) to get the method names, but I'm not sure if enough is exposed to make a robust solution. The real
GType is not exposed, and I can't figure out how to "cast" the
GIBaseInfo to concrete instances.