Skip to content

Support Native JSObject GType for Signals and Properties

Marco Trevisan requested to merge 3v1n0/gjs:native-jsobject-gtype into master

Define a new boxed 'JSObject' GType and use it to wrap native JSObject's.

To do this, create a GJSObject class that automatically roots and unroots a JSObject persistently. This class uses a private constructor and a pimpl idiom to force the allocation of the wrapper in the stack, that is doable using a 'boxed' static method that returns an unique_ptr. Internally the boxed wrapper uses a ref-counting system that allows us to avoid copies and re-rooting.

Define GObject.TYPE_JSOBJECT as 'JSObject' GType and use aliases for various JS native Objects using the $gtype property.

Add a ParamSpec jsobject alias.

Includes tests.


Few comments:

  • probably the rooting of the JSObject isn't that needed for my tests, since the very same pointer is always kept around when passed, from what I see, but I prefer not to any assumption of such type, unless we don't have any security over it.
  • I preferred not to reuse GjsMaybeOwned (even after a cleanup and subclassing for adding what I needed), since it would anyway add tools that we don't need.
  • I commented some tests whose failures seems to be uncatchable, so any help is welcome.

Merge request reports