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 663441 - gjs: Remove some cruft
gjs: Remove some cruft
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gjs-maint
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2011-11-05 03:01 UTC by Jasper St. Pierre (not reading bugmail)
Modified: 2011-11-28 19:45 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Remove usage of JSCLASS_CONSTRUCT_PROTOTYPE (13.49 KB, patch)
2011-11-05 03:01 UTC, Jasper St. Pierre (not reading bugmail)
none Details | Review
Remove the unthreadsafe_template_for_constructor (8.40 KB, patch)
2011-11-05 03:01 UTC, Jasper St. Pierre (not reading bugmail)
none Details | Review
Remove usage of JSCLASS_CONSTRUCT_PROTOTYPE (41.12 KB, patch)
2011-11-17 02:24 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review
Remove the unthreadsafe_template_for_constructor (28.23 KB, patch)
2011-11-17 19:49 UTC, Jasper St. Pierre (not reading bugmail)
reviewed Details | Review
Remove usage of JS_IsConstructing_PossiblyWithGivenThisObject (1.12 KB, patch)
2011-11-18 00:18 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review
Remove the unthreadsafe_template_for_constructor (27.60 KB, patch)
2011-11-18 00:18 UTC, Jasper St. Pierre (not reading bugmail)
reviewed Details | Review
Remove the unthreadsafe_template_for_constructor (27.60 KB, patch)
2011-11-19 02:03 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review

Description Jasper St. Pierre (not reading bugmail) 2011-11-05 03:01:28 UTC
This should hopefully fix bugs like the crashers in bug #661323
Comment 1 Jasper St. Pierre (not reading bugmail) 2011-11-05 03:01:30 UTC
Created attachment 200726 [details] [review]
Remove usage of JSCLASS_CONSTRUCT_PROTOTYPE

JSCLASS_CONSTRUCT_PROTOTYPE is an old hack that upstream wants to remove. We're
only using it to set the private instance, something we can do ourselves after
initting the class.
Comment 2 Jasper St. Pierre (not reading bugmail) 2011-11-05 03:01:34 UTC
Created attachment 200727 [details] [review]
Remove the unthreadsafe_template_for_constructor

Rather than setting a magic global which can get un-stuck at times, use the
JSAPI equivalent of ES5's Object.create to create an object without running
the constructor, so we can set a gobject ourselves
Comment 3 Jasper St. Pierre (not reading bugmail) 2011-11-15 03:10:27 UTC
Removal of JSCLASS_CONSRTUCT_PROPERTY upstream: https://bugzilla.mozilla.org/show_bug.cgi?id=702507
Comment 4 Jasper St. Pierre (not reading bugmail) 2011-11-17 02:24:33 UTC
Created attachment 201568 [details] [review]
Remove usage of JSCLASS_CONSTRUCT_PROTOTYPE

JSCLASS_CONSTRUCT_PROTOTYPE is an old hack that upstream wants to remove. We're
only using it to set the private instance, something we can do ourselves after
initting the class.



New patch attached that removes *all* uses of JSCLASS_CONSTRUCT_PROTOTYPE.
I doubt anybody is going to review this, so if/when upstream removes this,
I will push this.
Comment 5 Jasper St. Pierre (not reading bugmail) 2011-11-17 19:49:42 UTC
Created attachment 201619 [details] [review]
Remove the unthreadsafe_template_for_constructor

Rather than setting a magic global which can get un-stuck at times, use the
JSAPI equivalent of ES5's Object.create to create an object without running
the constructor, so we can set a gobject ourselves



$ git grep unthreadsafe
$
Comment 6 Colin Walters 2011-11-17 21:54:01 UTC
Review of attachment 201568 [details] [review]:

This makes sense to me.  There appears to be a lot of noise in the diff due the un-indentation of the if (!is_proto) case, but if you didn't change any of that, then I'd say it's fine.
Comment 7 Colin Walters 2011-11-17 22:38:23 UTC
Review of attachment 201619 [details] [review]:

This is a huge cleanup.  The changes to object.c make me a little nervous because it's such tricky code, but I'm not seeing anything obviously wrong.

::: gi/boxed.c
@@ +1236,3 @@
+        } else if (priv->can_allocate_directly) {
+            if (!boxed_new_direct(context, obj, priv))
+                return JS_FALSE;

Hm, so in the error paths like this, we're relying on the GC to eventually notice that our "obj" isn't in use, and it will collect it and the priv data?

::: gi/object.c
@@ +1502,3 @@
 
+        if (!obj)
+            goto out;

So won't the above code crash is obj is NULL?  Seems like we should be bailing earlier.

::: gi/union.c
@@ +237,3 @@
+     * gjs_invoke_c_function(), which returns a jsval.
+     * The returned "gboxed" here is owned by that jsval,
+     * not by us.2

Stray 2

@@ +246,3 @@
 
+    /* Because "gboxed" is owned by a jsval and will
+     * be garbage colleced, we make a copy here to be

collected
Comment 8 Jasper St. Pierre (not reading bugmail) 2011-11-18 00:12:59 UTC
Review of attachment 201619 [details] [review]:

If it would make you more comfortable, I could add a new_priv() function to GJS_DEFINE_DYNAMIC_PRIV_FROM_JS that would allocate and return a new private instance.

::: gi/boxed.c
@@ +1236,3 @@
+        } else if (priv->can_allocate_directly) {
+            if (!boxed_new_direct(context, obj, priv))
+                return JS_FALSE;

I don't think there's anything else we can do. I looked for an explicit "JS_DestroyObject" function, but it doesn't exist.

::: gi/union.c
@@ +237,3 @@
+     * gjs_invoke_c_function(), which returns a jsval.
+     * The returned "gboxed" here is owned by that jsval,
+     * not by us.2

Fixed locally.

@@ +246,3 @@
 
+    /* Because "gboxed" is owned by a jsval and will
+     * be garbage colleced, we make a copy here to be

An existing error, but fixed.
Comment 9 Jasper St. Pierre (not reading bugmail) 2011-11-18 00:18:50 UTC
Created attachment 201631 [details] [review]
Remove usage of JS_IsConstructing_PossiblyWithGivenThisObject
Comment 10 Jasper St. Pierre (not reading bugmail) 2011-11-18 00:18:57 UTC
Created attachment 201632 [details] [review]
Remove the unthreadsafe_template_for_constructor

Rather than setting a magic global which can get un-stuck at times, use the
JSAPI equivalent of ES5's Object.create to create an object without running
the constructor, so we can set a gobject ourselves
Comment 11 Jasper St. Pierre (not reading bugmail) 2011-11-18 00:19:52 UTC
Comment on attachment 201568 [details] [review]
Remove usage of JSCLASS_CONSTRUCT_PROTOTYPE

Attachment 201568 [details] pushed as f9276d7 - Remove usage of JSCLASS_CONSTRUCT_PROTOTYPE
Comment 12 Colin Walters 2011-11-18 20:44:32 UTC
Review of attachment 201631 [details] [review]:

This one needs a justification.  I'm guessing we'll be breaking compatibility with older spidermonkey versions?  

Hmm.  We'll no longer be assigning to object now, and just call JS_NewObjectForConstructor() always.  Is that really intended?
Comment 13 Colin Walters 2011-11-18 20:46:54 UTC
Review of attachment 201632 [details] [review]:

::: gi/object.c
@@ +1491,3 @@
+
+        if (obj == NULL)
+            goto out;

This will lose the JS_EndRequest()
Comment 14 Jasper St. Pierre (not reading bugmail) 2011-11-19 02:01:29 UTC
Review of attachment 201631 [details] [review]:

The justification is https://hg.mozilla.org/mozilla-central/rev/a7b658e309b9. The only place where constructors were called with a non-standard this object was when using JSCLASS_CONSTRUCT_PROTOTYPE. Constructors also must create their own new object. See the description for the constructor parameter in: https://developer.mozilla.org/en/SpiderMonkey/JSAPI_Reference/JS_InitClass
Comment 15 Jasper St. Pierre (not reading bugmail) 2011-11-19 02:03:08 UTC
Created attachment 201695 [details] [review]
Remove the unthreadsafe_template_for_constructor

Rather than setting a magic global which can get un-stuck at times, use the
JSAPI equivalent of ES5's Object.create to create an object without running
the constructor, so we can set a gobject ourselves



Whoops, sorry about being a moron there.
Comment 16 Colin Walters 2011-11-28 19:07:22 UTC
Review of attachment 201695 [details] [review]:

This one looks right to me.
Comment 17 Jasper St. Pierre (not reading bugmail) 2011-11-28 19:45:41 UTC
Attachment 201631 [details] pushed as 2e37d24 - Remove usage of JS_IsConstructing_PossiblyWithGivenThisObject
Attachment 201695 [details] pushed as 740cf9d - Remove the unthreadsafe_template_for_constructor