After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 626682 - attempting to wrap a new GObject mid-construction blows up
attempting to wrap a new GObject mid-construction blows up
Status: RESOLVED OBSOLETE
Product: gjs
Classification: Bindings
Component: general
unspecified
Other Linux
: Normal minor
: ---
Assigned To: gjs-maint
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2010-08-11 21:18 UTC by Havoc Pennington
Modified: 2018-01-27 11:44 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Havoc Pennington 2010-08-11 21:18:03 UTC
In gi/object.c:object_instance_constructor, if you did a "new Foo()" in JS where Foo is a GObject, we do:
 priv->gobj = g_object_newv(gtype, n_params, params);

Unfortunately, g_object_newv can/will emit signals on other objects, such as those passed in as "params". If one of these signals has the new Foo as an argument, we try to wrap the Foo instance which ends up recursively calling object_instance_constructor on the new Foo.

This assertion then fails:
   g_assert(peek_js_obj(context, priv->gobj) == NULL);

because g_object_newv already wrapped the object we were constructing with another JS object, instead of the JS object that we were constructing.

An example of when this would happen is if two objects refer to each other (say a widget points to its parent container and vice versa) and you set the parent at construct time which sets the child of the container, *and* someone has hooked up a JS callback that watches new children of the container, then the JS callback needs to wrap the child that we just constructed.
 new Child({ parent: myContainer }) 
blows up if JS connected to myContainer would see the new child, since that JS will need a wrapper for the new child GObject inside of g_object_new.

I have no idea how to fix this without making a huge mess of the code. (For example, we could keep a stack of object_instance_constructor in progress and try to handle the case that way, but ...)
Comment 1 GNOME Infrastructure Team 2018-01-27 11:44:32 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gjs/issues/50.