Trouble with new overriden Gtk.Builder in gjs

,

Hello all, I’ve found that the new GtkJSBuilder that overrides Gtk.Builder in the development version of gjs seems to garbage collect the callbacks before it should do so.

A minimal test case that exemplifies the issue is the following user interface (compiled from blueprint):

<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <object class="AdwApplicationWindow" id="root">
    <property name="maximized">true</property>
    <property name="content">
      <object class="GtkButton">
        <signal name="activate" handler="activate"/>
      </object>
    </property>
  </object>
</interface>

and a simple implementation of the activate callback that logs a message Activated!.

If the button is activated shortly after construction (within 20 seconds approximately), it will log the desired message; however, it will no longer do so after that amount of time. I’m not really sure if it is related to my previous post regarding garbage collection (Gjs garbage collection) because in that case the critical time was about 10 seconds.

P.S.: Since the overriding GtkJSBuilder is noy yet in stable gjs, I’ve tested it by patching it in my test itself by copying and pasting the relevant code from the repository.

After doing some tests, it seems that, within the vfunc_create_closure implementation of NonTemplateBuilderScope, both connectObject and builder.get_current_object() are null, so the lifetime of the returned closure is tied to the lifetime of the scope itself. That would explain the 20 second threshold; since after 10 seconds, the scope gets garbage collected and 10 seconds after that the closure garbage collects the inner function.

Am I correct to assume that it is a bug that both connectObject and builder.get_current_object() are null?

P.S.: Also, the same issue affects closures used for property bindings in ui files.