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 699817 - object: fix test suite after g_object_newv changes
object: fix test suite after g_object_newv changes
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gjs-maint
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2013-05-07 10:07 UTC by Giovanni Campagna
Modified: 2013-07-26 00:44 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
object: fix test suite after g_object_newv changes (1.70 KB, patch)
2013-05-07 10:07 UTC, Giovanni Campagna
rejected Details | Review
GjsContext: add the concept of "current context" (1.85 KB, patch)
2013-05-14 22:21 UTC, Giovanni Campagna
reviewed Details | Review
object: stop using GObject properties to set up context and instance for derived classes (8.62 KB, patch)
2013-05-14 22:21 UTC, Giovanni Campagna
reviewed Details | Review
object: add a custom hook to run at instance_init (3.09 KB, patch)
2013-05-14 22:21 UTC, Giovanni Campagna
none Details | Review
Enable all test cases (5.52 KB, patch)
2013-05-14 22:21 UTC, Giovanni Campagna
committed Details | Review
GjsContext: add the concept of "current context" (2.52 KB, patch)
2013-05-19 17:13 UTC, Giovanni Campagna
committed Details | Review
object: stop using GObject properties to set up context and instance for derived classes (7.70 KB, patch)
2013-05-19 17:14 UTC, Giovanni Campagna
committed Details | Review

Description Giovanni Campagna 2013-05-07 10:07:04 UTC
I don't remember what caused this, and apparently it works now,
but it looks right anyway.
Comment 1 Giovanni Campagna 2013-05-07 10:07:07 UTC
Created attachment 243461 [details] [review]
object: fix test suite after g_object_newv changes

Properties are now set in GObject class registration order, so
if we derive twice and install the js-context and js-object properties
twice, custom properties in the parent class get set before
js-context and js-object, which causes a crash.
Fix that by not installing the implementation properties in double
derived classes.
Comment 2 Colin Walters 2013-05-13 18:11:21 UTC
Review of attachment 243461 [details] [review]:

Blah.  I don't like these properties at all.  I'm inclined to just burn support for multiple GjsContext per process.  It sounds nice, but because of how toggle refs work, there can only be one GjsContext connecting to per-process shared infrastructure like the session GDBusConnection.  So we could just have gjs_context_get_default() -> gjs_context_get_native_context().

Instead of the js-object prop, could we have an internal API like GjsPrivate.set_constructing_object(this); that just sets a static variable, and then just grab the value inside a constructor for gjs object?

Anyways, gjs tests seem to pass at the moment.  Was this fixed by something else?
Comment 3 Giovanni Campagna 2013-05-14 21:10:56 UTC
(In reply to comment #2)
> Review of attachment 243461 [details] [review]:
> 
> Blah.  I don't like these properties at all.  I'm inclined to just burn support
> for multiple GjsContext per process.  It sounds nice, but because of how toggle
> refs work, there can only be one GjsContext connecting to per-process shared
> infrastructure like the session GDBusConnection.  So we could just have
> gjs_context_get_default() -> gjs_context_get_native_context().
> 
> Instead of the js-object prop, could we have an internal API like
> GjsPrivate.set_constructing_object(this); that just sets a static variable, and
> then just grab the value inside a constructor for gjs object?

I tried implementing this. There is no problem with the context, but stuff breaks when you associate the JS object with the GObject in instance_init, because init is called once for each level of JS class derivation, but you only have one object.
I don't want to break the assumption that associate_js_gobject is only called on disassociated JS objects.
Also, I was trying to make the thing fully reentrant, so that we could call out to custom JS code from instance_init(), to support Gtk widget templates.

For now, I'm going with the ugly hack of only doing work in the most derived instance_init(), which we can find because we know from the JS object the final GType and we can just cross-reference it with what we get from instance_init().
Comment 4 Giovanni Campagna 2013-05-14 22:21:06 UTC
Created attachment 244253 [details] [review]
GjsContext: add the concept of "current context"

Just a static global variable holding the GjsContext. There should
be at most once context at any time, so any new GjsContext is
immediately made current.
This will be used to avoid passing a JSContext where we can't easily.
Comment 5 Giovanni Campagna 2013-05-14 22:21:11 UTC
Created attachment 244254 [details] [review]
object: stop using GObject properties to set up context and instance for derived classes

It was an ugly hack, that would easily break with derived classes.
Instead, use a global stack of constructing objects, that is
pushed when building the JS object and retrieved in instance_init()
Comment 6 Giovanni Campagna 2013-05-14 22:21:16 UTC
Created attachment 244255 [details] [review]
object: add a custom hook to run at instance_init

This allows to run code that requires to be inside GTypeInstance
init(), such as gtk_widget_init_template()
Comment 7 Giovanni Campagna 2013-05-14 22:21:20 UTC
Created attachment 244256 [details] [review]
Enable all test cases

There is no point in having tests that we don't run
Comment 8 Colin Walters 2013-05-16 01:46:52 UTC
Review of attachment 244253 [details] [review]:

"should" vs "must be" seems kind of important here.  Why not just gjs_context_get() ?  

Oh, right, test/gjs-tests.c would break.  But if we made the finalize function clear the cache (as we should), then I assume it'd work.
Comment 9 Colin Walters 2013-05-16 01:51:05 UTC
Review of attachment 244254 [details] [review]:

This looks in general a *lot* cleaner!

::: gi/object.c
@@ +88,3 @@
 } ToggleRefNotifyOperation;
 
+GSList *object_init_list;

static

@@ +2407,3 @@
+    }
+
+    object_init_list = prev_head->next;

I think this would be cleaner as:

object_list_init = g_slist_delete_link (object_list_init, object_list_init);

@@ +2418,3 @@
+    ensure_uses_toggle_ref(context, object);
+
+    g_slist_free_1(prev_head);

Then you could delete this line, as well as the prev_head bookkeeping.

@@ -2588,2 @@
     gjs_define_object_class(cx, module, NULL, instance_type, &constructor);
-=======

Some bad rebase going on here...

@@ +2587,3 @@
     g_param_spec_set_qdata(pspec, gjs_is_custom_property_quark(), GINT_TO_POINTER(1));
 
+    g_object_class_install_property(G_OBJECT_CLASS (priv->klass), 1, pspec);

Why not keep PROP_JS_HANDLED instead of 1?
Comment 10 Colin Walters 2013-05-16 01:52:48 UTC
Review of attachment 244256 [details] [review]:

Oops, my bad.  Yes, looks good!
Comment 11 Colin Walters 2013-05-16 01:53:18 UTC
Review of attachment 244255 [details] [review]:

This seems like it should go with bug 700347
Comment 12 Giovanni Campagna 2013-05-19 17:13:41 UTC
Created attachment 244722 [details] [review]
GjsContext: add the concept of "current context"

Just a static global variable holding the GjsContext. There should
be at most one context at any time, and this is enforced by
make_current() checking the current context.
For backward compatibility, any new GjsContext is immediately made current,
which means that code that uses multiple context without handling
the current one manually will assert now. You can still use multiple
contexts if you take care to clear the current one.

This will be used to avoid passing a JSContext where we can't easily.
Comment 13 Giovanni Campagna 2013-05-19 17:14:07 UTC
Created attachment 244723 [details] [review]
object: stop using GObject properties to set up context and instance for derived classes

It was an ugly hack, that would easily break with derived classes.
Instead, use a global stack of constructing objects, that is
pushed when building the JS object and retrieved in instance_init()
Comment 14 Colin Walters 2013-05-19 20:09:44 UTC
Review of attachment 244722 [details] [review]:

Looks simple and correct!
Comment 15 Colin Walters 2013-05-19 20:11:15 UTC
Review of attachment 244723 [details] [review]:

This looks a lot nicer I think.  Thanks for doing the cleanup!
Comment 16 Giovanni Campagna 2013-05-19 21:15:42 UTC
Attachment 244256 [details] pushed as 83f8d97 - Enable all test cases
Attachment 244722 [details] pushed as 639e145 - GjsContext: add the concept of "current context"
Attachment 244723 [details] pushed as 62ac6bb - object: stop using GObject properties to set up context and instance for derived classes

Leaving open for the custom hook patch, unless you want me to move it to the other bug.
Comment 17 Colin Walters 2013-07-26 00:42:44 UTC
Yeah, let's move the hook to the widget bug, ok?
Comment 18 Colin Walters 2013-07-26 00:44:00 UTC
Moved.