Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • gjs gjs
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 106
    • Issues 106
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 18
    • Merge requests 18
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GNOME
  • gjsgjs
  • Issues
  • #476
Closed
Open
Created Mar 29, 2022 by Philip Chimento@ptomato🚮Maintainer

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.

Assignee
Assign to
Time tracking