Can't use construct properties
System information
What is your operating system and version? alpine edge
What is your version of GJS? 1.81.1
If the bug is related to GNOME Shell, what is your version of GNOME Shell? N/A
Bug information
Steps to reproduce
Here's a reproducer file
#!/usr/bin/env -S gjs -m
import Adw from "gi://Adw";
import GObject from "gi://GObject";
import Gtk from "gi://Gtk?version=4.0";
class MyComponent extends Adw.Bin {
label = new Gtk.Label();
/**
* @param {Partial<Adw.Bin.ConstructorProperties> | undefined} props
*/
constructor(props) {
super(props);
this.set_child(this.label);
}
get text() {
return this.label.label;
}
set text(value) {
this.label.label = value;
}
static {
GObject.registerClass({
Properties: {
"text": GObject.param_spec_string(
"text",
"Text",
"text for the widget",
"",
GObject.ParamFlags.READWRITE,
),
},
}, this);
}
}
const app = new Adw.Application({
application_id: "com.vixalien.listtest",
});
app.connect("activate", () => {
const win = new Adw.ApplicationWindow({
application: app,
default_width: 400,
default_height: 600,
});
const toolbarView = Adw.ToolbarView.new();
const header = Adw.HeaderBar.new();
const content = new MyComponent({
valign: Gtk.Align.CENTER,
halign: Gtk.Align.CENTER,
text: "Hello, World!"
});
toolbarView.add_top_bar(header);
toolbarView.set_content(content);
win.set_content(toolbarView);
win.present();
});
app.run([]);
Current behaviour
The code fails with:
(gjs:12345): Gjs-CRITICAL **: 13:35:05.082: JS ERROR: TypeError: this.label is undefined
set text@file:///home/alien/sites/muzika/test3.mjs:21:5
_init/Gtk.Widget.prototype._init@resource:///org/gnome/gjs/modules/core/overrides/Gtk.js:39:56
MyComponent@file:///home/alien/sites/muzika/test3.mjs:13:5
@file:///home/alien/sites/muzika/test3.mjs:52:19
@file:///home/alien/sites/muzika/test3.mjs:65:5
It's not possible to set the property text
at construct time, because "at construct-time", the other properties hasn't been initialised yet.
This means that the property can't access the other properties of the class (label
).
Expected behaviour
I would expect the class object properties to be initialised by the time the setter/getter of other properties is called.