Improve pretty-print output for GObject-introspected objects
The old logging of objects with a toString() method did give some more information that the new pretty-printer didn't:
Old:
gjs> imports.gi.versions.Gdk = '3.0'
"3.0"
gjs> Gdk = imports.gi.Gdk
[object GIRepositoryNamespace]
gjs> new Gdk.Rectangle()
[boxed instance wrapper GIName:Gdk.Rectangle jsobj@0xeadfc7890c0 native@0x55610677abf0]
gjs> GObject = imports.gi.GObject
[object GIRepositoryNamespace]
gjs> new GObject.Object()
[object instance wrapper GIName:GObject.Object jsobj@0xeadfc789100 native@0x55610690eea0]
New:
gjs> imports.gi.versions.Gdk = '3.0'
3.0
gjs> Gdk = imports.gi.Gdk
{ }
gjs> new Gdk.Rectangle()
{ }
gjs> GObject = imports.gi.GObject
(gjs-console:164032): Gjs-WARNING **: 21:13:39.102: JS ERROR: TypeError: can't convert symbol to string
formatObject@resource:///org/gnome/gjs/modules/script/_bootstrap/default.js:56:49
prettyPrint@resource:///org/gnome/gjs/modules/script/_bootstrap/default.js:29:20
@<stdin>:1:42
[error printing value]
gjs> new GObject.Object()
{ }
We should consider special pretty printers for introspected objects (boxed objects such as Gdk.Rectangle, objects that inherit from GObject.Object, GI namespace objects...)
One simple way to do this might be to check if the object's toString
property equals Object.prototype.toString
or Array.prototype.toString
, and only do the pretty-printing if the toString
is one of these standard functions; otherwise call the custom one and print that. Or we could do something more specific for each of these types of objects. Or a combination of the custom toString
and the pretty-printer.
We should also figure out why printing imports.gi.GObject
throws an exception and fix that.