paperwm / gnome-shell-mode

Package for developing gnome-shell extensions
GNU General Public License v2.0
27 stars 7 forks source link

Improve pretty-printing of values #11

Open olejorgenb opened 7 years ago

olejorgenb commented 7 years ago

Atm. we just do JSON.stringify. This works nicely for simple objects like {foo: 1, bar: 2} and simple arrays, but not GObjects and complex "native" js objects, with constructors, etc.

GObjects are handled specially at top level, but not when they're members of a object.

Sometimes weird stuff happens:

a = { win: global.display.focus_window }
//: {"win":{"unmaximized_rect":{},"score":0.07142857142857142}}

unmaximzied_rect and score are not members of MetaWindow.

  1. Display the constructor name (except Arrays and Objects), and maybe only selectively members
  2. Handle the most interesting classes specially (like MetaWindow (show title), etc.)
olejorgenb commented 5 years ago

Provide fall back for crashing to string functions. Example:

    let monitor_index_for_rect;
    if (global.display.get_monitor_index_for_rect) {
        // 3.3
        monitor_index_for_rect = global.display.get_monitor_index_for_rect.bind(global.display);
    } else  {
        // COMPATIBILITY: 3.28
        monitor_index_for_rect = global.screen.get_monitor_index_for_rect.bind(global.screen);
    }
    monitor_index_for_rect.toString()
   // Object 0x7f9640cd2650 is not a subclass of GIRepositoryFunction, it's a Function