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 733414 - Don't use addSignalMethods when not needed
Don't use addSignalMethods when not needed
Status: RESOLVED FIXED
Product: gnome-maps
Classification: Applications
Component: general
git master
Other Linux
: Normal major
: ---
Assigned To: gnome-maps-maint
gnome-maps-maint
Depends on:
Blocks:
 
 
Reported: 2014-07-19 19:15 UTC by Damián Nohales
Modified: 2014-10-10 18:13 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Geoclue inherits from Gobject hence added Signals property instead of using Utils.addSignalMethod (678 bytes, patch)
2014-09-26 21:59 UTC, Shipra Banga
none Details | Review
Geoclue inherits from Gobject hence added Signals property instead of using Utils.addSignalMethod (678 bytes, patch)
2014-09-26 22:15 UTC, Shipra Banga
none Details | Review
Geoclue inherits from Gobject hence added Signals property instead of using Utils.addSignalMethod (972 bytes, patch)
2014-09-26 22:16 UTC, Shipra Banga
needs-work Details | Review
https://bugzilla.gnome.org/show_bug.cgi?id=733414 (1.49 KB, patch)
2014-09-28 22:21 UTC, Shipra Banga
none Details | Review
Used Signals Property instead of addSignalsMethods (630 bytes, patch)
2014-09-28 22:26 UTC, Shipra Banga
needs-work Details | Review
Added Signals property instead of using Utils.addSignalMethod (1.74 KB, patch)
2014-09-29 07:00 UTC, Shipra Banga
needs-work Details | Review
Added Signals property instead of using Utils.addSignalMethod (3.17 KB, patch)
2014-09-29 07:51 UTC, Shipra Banga
needs-work Details | Review
Use Signals Property instead of addSignalsMethods for Gobject classes (3.28 KB, patch)
2014-09-29 08:10 UTC, Shipra Banga
committed Details | Review

Description Damián Nohales 2014-07-19 19:15:22 UTC
When you call addSignalMethods to a GObject inherited class, it overrides the native connect, emit and disconnect functions coming from GObject. And this impede us to connect or emit native signals (those signals inherited from the native type) from JavaScript, because we are using the built-in signal management in Gjs instead of the GObject one. For example:

---
const Foo = new Lang.Class({
    Extends: Gtk.Button
    ...
});
Signals.addSignalMethods(Foo.prototype);

let a = new Foo();
a.connect('clicked', function() {
    //never emited (emitted by GObject system, connected using 
    //Gjs signal management)
});
---

We need to avoid addSignalMethods if we are inheriting from GObject.Object and use the Signals property of the Lang.Class constructor to add the custom signals.

What do you think?
Comment 1 Jonas Danielsson 2014-07-21 05:37:28 UTC
Sounds sane. Do we have many such cases atm? And are they trivial to convert?
Do we have any bugs or buglets stemming from this atm?

Is it urgent or could it be a gnome-love thing?
Comment 2 Damián Nohales 2014-07-21 15:12:47 UTC
It seems that it didn't cause much problem (I didn't search about related bugs, just deducting from regular usage), it should not be urgent if we are careful or if we have luck (as is happening now!), but we don't want to play with luck :P

They are trivial to convert, just rip off the addSignalMethods call to classes which have GObject in the inheritance tree and look for custom signal connection/emission to add it to the Lang.Class Signals property.
Comment 3 Shipra Banga 2014-09-25 07:04:54 UTC
I am interested in solving this bug and am going to be an OPW applicant this year. I read through this page and understood this much ! Basically wherever its a call to an inherited Gobject we have to avoid use addSignalMethods and instead use Lang.Class Signals property ? How would that go?
Comment 4 Damián Nohales 2014-09-25 19:13:03 UTC
(In reply to comment #3)
> I am interested in solving this bug and am going to be an OPW applicant this
> year. I read through this page and understood this much ! Basically wherever
> its a call to an inherited Gobject we have to avoid use addSignalMethods and
> instead use Lang.Class Signals property ? How would that go?

Yes, you got it right, summarizing:

1) Remove Signals.addSignalMethods or Utils.addSignalMethods for classes that inherits from GObject (directly or indirectly)
2) If a modified class adds a custom signal, add it by using the Signals property.
3) We usually use our Utils.addSignalMethods instead of gjs's Signals.addSignalMethods. Our function adds the "once" method to the classes besides connect, disconnect, etc; make sure that you don't use the "once" method for instances of modified classes and use Utils.once instead.
Comment 5 Shipra Banga 2014-09-26 21:59:59 UTC
Created attachment 287214 [details] [review]
Geoclue inherits from Gobject hence added Signals property instead of using Utils.addSignalMethod
Comment 6 Shipra Banga 2014-09-26 22:05:57 UTC
Ummm sorry I did not do a reset after my first commit hence it gives a diff with my prev wrong commit! It isnt giving a diff with the original file in use which had Utils.addSignalMethods() for a class inheriting from a Gobject!
Comment 7 Shipra Banga 2014-09-26 22:15:08 UTC
Created attachment 287215 [details] [review]
Geoclue inherits from Gobject hence added Signals property instead of using Utils.addSignalMethod
Comment 8 Shipra Banga 2014-09-26 22:16:40 UTC
Created attachment 287216 [details] [review]
Geoclue inherits from Gobject hence added Signals property instead of using Utils.addSignalMethod
Comment 9 Shipra Banga 2014-09-26 22:18:15 UTC
Okay I updated the patch. This is fine. Please review it ! :)
Comment 10 Jonas Danielsson 2014-09-27 05:57:59 UTC
Review of attachment 287216 [details] [review]:

Hi, thanks for the patch!
It looks nice.

For the commit message I would prefer something like: "geoclue: Use GObject Signals property"

Was this the only module were this change was needed?

Thx!
Comment 11 Jonas Danielsson 2014-09-27 06:02:12 UTC
Review of attachment 287216 [details] [review]:

Add maybe use your patch description in this bug for commit message body. Also the body should include a link to this bug. See other commits, using git log, to get the idea.
Comment 12 Shipra Banga 2014-09-27 06:28:15 UTC
Ok cool (y) ! Should I commit this patch again? And yes this is the only module where this was required. I grepped addSignals in the module and a few files came up. I all of them this was the only class I found inheriting from Gobject.
Comment 13 Jonas Danielsson 2014-09-27 06:46:32 UTC
And nothing inheriting a subclass of GObject? Like a Gtk widget?
Comment 14 Shipra Banga 2014-09-27 06:51:32 UTC
I think there were a few classes inheriting from Gtk Popbox . I will check... Do we have to fix that too?
Comment 15 Jonas Danielsson 2014-09-27 07:11:32 UTC
They have the same issue, yes.
Comment 16 Shipra Banga 2014-09-27 19:50:59 UTC
I was trying to fix the class searchPopup which inherits from Gtk widget PopOver . I removed the addSignalsMethod() and instead added a Signals for 'selected' which is getting emitted with 1 argument. So when I write Signals: 'selected': { } without any argument it gives me an error when I try to run search. How do I fix this?  Basically how do I add an argument here =>  Signals: {
        'selected': { }
    }
Also when no signal is getting emitted, do I need to include a Signals property.
Comment 17 Jonas Danielsson 2014-09-28 13:17:29 UTC
Hi, you can look here for syntax:
https://git.gnome.org/browse/gjs/tree/installed-tests/js/testGObjectClass.js#n115

When we do not emit a signal, we do not need to define one.
Comment 18 Jonas Danielsson 2014-09-28 13:20:53 UTC
And the parameter that geys emitted is a GeocodePlace which inherits from GObject, so type should beGObject.TYPE_OBJECT
Comment 20 Shipra Banga 2014-09-28 22:26:18 UTC
Created attachment 287315 [details] [review]
Used Signals Property instead of addSignalsMethods
Comment 21 Jonas Danielsson 2014-09-29 05:13:25 UTC
Review of attachment 287315 [details] [review]:

Thanks!

Did something happen while generating this patch? It does not look very complete. Have you looked into using git bz for attaching patches to bugzilla?
https://wiki.gnome.org/Projects/GnomeShell/Development/WorkingWithPatches
Comment 22 Shipra Banga 2014-09-29 06:40:54 UTC
I attached one patch and then realized that another line had to be removed so attached another patch. Hence, it is showing the most recent changes. If you go see the obsolete patches , https://bugzilla.gnome.org/attachment.cgi?id=287314&action=diff , this shows the changes I made in the first go.
Comment 23 Jonas Danielsson 2014-09-29 06:43:40 UTC
Ok. :)
Well don't do that :)

The patch attached represents the commit that I will push/merge. It should follow all the guidelines that are in the links I sent you with regards to commit message and scope.

So please re-attach a patch that has all the changes that you want to be commited and with a commit message and shortlog that follow the guidelines.

Thanks!
Comment 24 Jonas Danielsson 2014-09-29 06:50:51 UTC
If you have questions about using git to split a commit into multiple commit or to squash together multiple commits to one commit, feel free to ask on irc or another media.
Comment 25 Shipra Banga 2014-09-29 07:00:31 UTC
Created attachment 287320 [details] [review]
Added Signals property instead of using Utils.addSignalMethod
Comment 26 Shipra Banga 2014-09-29 07:01:37 UTC
This final patch fixes all the files where class was inheriting from Gtk.object. Please review this. This is working :)
Comment 27 Shipra Banga 2014-09-29 07:03:28 UTC
Ohh okay I will resubmit a patch which has all the commits together merged.
Comment 28 Jonas Danielsson 2014-09-29 07:14:21 UTC
Review of attachment 287320 [details] [review]:

Thanks!

What about the geoclue.js? It is a GObject as well? And emits a signal.
And what about contextMenu.js?

Also, I am wondering, are you really basing this of the master branch? I do not see a GeocodeGLib imports in searcPopup.js in my repo.

I think I want you to re-check to make sure you catch all, at least geoclue.js is missing in this patch.

Also the commit message is not formatted like we usually do them in Maps, check with git log to see.
The link to the bug should stand on its own, on the last line of the commit message.

Also, change 'Gtk inherited classes' 'GObject inherited classes'. Try to keep the shortlog message (the header) to be less than or equal to 50 chars.

So maybe: 'Remove addSignalsMethods for GObject classes'

And, "Used" => "Use"

Otherwise looks fine.

::: src/searchPopup.js
@@ +23,3 @@
 const GdkPixbuf = imports.gi.GdkPixbuf;
 const GObject = imports.gi.GObject;
+const GeocodeGlib = imports.gi.GeocodeGlib;

I do not have this line in my repo.
Comment 29 Shipra Banga 2014-09-29 07:51:12 UTC
Created attachment 287322 [details] [review]
Added Signals property instead of using Utils.addSignalMethod
Comment 30 Jonas Danielsson 2014-09-29 07:55:07 UTC
Review of attachment 287322 [details] [review]:

Thanks!

Almost there!

Please use the imperative form in the commit log:
"Removed" => "Remove"

For the log, maybe you could add a bit of Damiáns explanation of why this is needed?

::: src/searchPopup.js
@@ +23,3 @@
 const GdkPixbuf = imports.gi.GdkPixbuf;
 const GObject = imports.gi.GObject;
+const GeocodeGlib = imports.gi.GeocodeGlib;

Do not add this line. It should not be there and has no relevance to this change.
Comment 31 Shipra Banga 2014-09-29 08:10:33 UTC
Created attachment 287324 [details] [review]
Use Signals Property instead of addSignalsMethods for Gobject classes
Comment 32 Jonas Danielsson 2014-09-29 08:14:47 UTC
Review of attachment 287324 [details] [review]:

Thanks this looks great!

There are some nit comments on the formatting and spelling in the commit message.
And also you removed an non-relevant empty line in searchPopup.js.

Please consider these things in the future!

As for now I can fix up the last nits when I merge this.

However it will not be merged right now. We are still in a period where we collect bugs to be fixed in the stable releases.
So this will get commited after we branch of the stable branch gnome-3-14.

Thanks!

::: src/searchPopup.js
@@ +23,2 @@
 const GdkPixbuf = imports.gi.GdkPixbuf;
 const GObject = imports.gi.GObject;

You removed an empty line here. Please do not do that.
Comment 33 Shipra Banga 2014-09-29 12:36:52 UTC
Ok will make sure I don't do that in my further work.