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 671833 - Don't pass object as first argument of vfunc.
Don't pass object as first argument of vfunc.
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gjs-maint
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2012-03-11 15:44 UTC by Giovanni Campagna
Modified: 2012-03-12 01:11 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Don't pass the object as the first argument to a vfunc (1.71 KB, patch)
2012-03-11 15:44 UTC, Giovanni Campagna
committed Details | Review

Description Giovanni Campagna 2012-03-11 15:44:26 UTC
See patch.
Comment 1 Giovanni Campagna 2012-03-11 15:44:54 UTC
Created attachment 209436 [details] [review]
Don't pass the object as the first argument to a vfunc

The object is already passed as this, there is no need to pass it
as the first argument, and it actually breaks expectations from
API users.
Comment 2 Jasper St. Pierre (not reading bugmail) 2012-03-12 00:09:43 UTC
Review of attachment 209436 [details] [review]:

If you're absolutely curious, the reason that I did this was to support a case like:

    const CustomContainer = new Lang.Class({
         Extends: St.Widget,

         vfunc_paint: St.Widget.paint_background,
    }):

Or something like that, because vfunc chaining is a mess... this is a very special edge case, so if we want the API change for the better, let's land this before we start using it.
Comment 3 Jasper St. Pierre (not reading bugmail) 2012-03-12 00:10:28 UTC
Review of attachment 209436 [details] [review]:

(Accidentally hit Publish before changing the status)
Comment 4 Giovanni Campagna 2012-03-12 00:36:01 UTC
(In reply to comment #2)
> Review of attachment 209436 [details] [review]:
> 
> If you're absolutely curious, the reason that I did this was to support a case
> like:
> 
>     const CustomContainer = new Lang.Class({
>          Extends: St.Widget,
> 
>          vfunc_paint: St.Widget.paint_background,
>     }):
> 
> Or something like that, because vfunc chaining is a mess... this is a very
> special edge case, so if we want the API change for the better, let's land this
> before we start using it.

Uhm... That's St.Widget.prototype.paint_background, and it wants the widget as this + nothing for argv.
I don't think there is a useful case of a function taking the object it operates on as the first argument without being a method, so I'm pushing the patch.
Comment 5 Giovanni Campagna 2012-03-12 00:38:01 UTC
Attachment 209436 [details] pushed as c0d38f4 - Don't pass the object as the first argument to a vfunc
Comment 6 Jasper St. Pierre (not reading bugmail) 2012-03-12 01:11:56 UTC
(In reply to comment #4)
> Uhm... That's St.Widget.prototype.paint_background, and it wants the widget as
> this + nothing for argv.

That's because I remembered wrong. I was testing with a variant of the "st-container: Implement standard pick and paint methods" patch from bug #649631 where the _st_container_paint/_st_container_pick methods were public to introspection. As I was implementing a container (replacing DashItemContainer, to be exact) with that patch applied, I needed to have the paint/pick methods as otherwise my container wouldn't paint anything.

Since st_container_paint/st_container_pick have a ClutterActor * as their first argument, it would be introspected as a function on St.Container, so instead of:

    const DashItemContainer = new Lang.Class({
        // ...
        vfunc_paint: function() {
            St.Container.paint(this);
        },

        vfunc_pick: function() {
            St.Container.pick(this);
        }
    });

I chose to just add the argument (or not omit it, rather). Now that I look back on it, I made a horrible decision (optimizing for one very minor use case in exchange for the loss of sanity), and this patch is a the right one.