Skip to content

Add overrides for signal matching methods

g_signal_handler_find(), g_signal_handlers_block_matched(), g_signal_handlers_unblock_matched(), and g_signal_handlers_disconnect_matched() are all technically introspectable but don't work in GJS when matching by function, because when connecting signals we create a GClosure object for each signal callback. The JS code has no way to search for this object, since it is private, and additionally there would be no way to match more than one signal with the same handler connected because they would have different GClosure objects.

We solve this by storing a pointer to the callable JS object in the data field of the GClosure so we can search for it. This is normally a bad idea since bare pointers to GC things may be moved or finalized, but I believe it's OK here because signal connections are never rooted, always traced, and the pointer can only be moved or finalized after tracing, so we can just update or null it out at that point.

We add private C++ methods to ObjectBase/ObjectInstance, and overrides to GObject.js to call the C++ methods, with API that matches the C API as much as possible. We do change the mask/optional arguments mechanism to a more natural properties-object mechanism. We also add convenience API to match g_signal_handlers_block_by_func() etc., which are macros in C and so not introspectable at all, but easy to implement here.

Closes: #290 (closed)

Merge request reports