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 657699 - Add a GLib namespace extension providing comodities for conversion from/to GVariant
Add a GLib namespace extension providing comodities for conversion from/to GV...
Status: RESOLVED FIXED
Product: seed
Classification: Bindings
Component: libseed
git master
Other All
: Normal normal
: ---
Assigned To: seed-maint
seed-maint
Depends on:
Blocks:
 
 
Reported: 2011-08-30 12:50 UTC by Alexandre Mazari
Modified: 2013-02-07 07:30 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add a GLib namespace extension providing comodities for conversion from/to GVariant. (8.97 KB, patch)
2011-08-30 12:51 UTC, Alexandre Mazari
none Details | Review
Add a GLib namespace extension providing comodities for conversion from/to GVariant. (12.24 KB, patch)
2011-08-31 14:24 UTC, Alexandre Mazari
none Details | Review

Description Alexandre Mazari 2011-08-30 12:50:57 UTC
GVariant.
Comment 1 Alexandre Mazari 2011-08-30 12:51:09 UTC
Created attachment 195192 [details] [review]
Add a GLib namespace extension providing comodities for conversion from/to GVariant.

Add Variant.toJSON and Object.toVariant method.
Uses json-glib parsing facilities if present, fallbacks to javascript code
imported from Gjs otherwise.
Comment 2 Alan Knowles 2011-08-31 04:56:59 UTC
Should be to toJS() really - odd that gjs let that through.
Comment 3 Alexandre Mazari 2011-08-31 09:02:25 UTC
(In reply to comment #2)
> Should be to toJS() really - odd that gjs let that through.

Well, this code isn't imported from gjs so we are free to rename the method if you see fit or modify it to produce valid json.
What do you think is missing there ?  the quotes around the keys ?
Comment 4 Alexandre Mazari 2011-08-31 09:07:04 UTC
Oops, part of it is actually imported from gjs. I mixed up with another bug.

The Gjs override (their name for namespace extensions) calls those methods pack and unpack on the Variant structure.
I felt that those names weren't really descriptive, so renamed them. Still, I am not strongly opposed to used the original names.
Comment 5 Alan Knowles 2011-08-31 09:11:10 UTC
Just the naming, otherwise seems fine. (what did gjs call it?)

 function _toJSONNative(signature, variant)
to
function _toJSNative(signature, variant)

and

function _toJSON(signature, variant) {
to
function _toJS(signature, variant) {

GLib.Variant.prototype.toJSON = function(signature) {
to
GLib.Variant.prototype.toJS = function(signature) {


 GLib.Variant.prototype.toJSON = function(signature) {
to
GLib.Variant.prototype.toJS = function(signature) {
Comment 6 Alan Knowles 2011-08-31 09:16:24 UTC
yes, these names are alot clearer than pack/unpack ;)
Comment 7 Alexandre Mazari 2011-08-31 09:24:20 UTC
Allright, doing it ASAP.

I noticed you already committed the GDBus extension which depends on this patch.
Reverting it until it is updated to comply with this renaming might produce a clearer history.
Comment 8 Alan Knowles 2011-08-31 09:33:29 UTC
Done.

Regards
Alan
Comment 9 Alexandre Mazari 2011-08-31 09:55:16 UTC
Cool, thanks!

So i am reworking the patch for the renaming, adding some tests and documentation, I was wondering if using camelCase method names was such a good idea in extensions to be coherent with the extended API.
What is your take ?

Happy coding,
Alexandre

(In reply to comment #8)
> Done.
> 
> Regards
> Alan
Comment 10 Alexandre Mazari 2011-08-31 14:24:35 UTC
Created attachment 195304 [details] [review]
Add a GLib namespace extension providing comodities for conversion from/to GVariant.

Add Variant.toJSON and Variant.new methods for variant <-> js object conversion.
Uses json-glib parsing facilities if present, fallbacks to javascript code
imported from Gjs otherwise.

updated:
- toJSON -> to_js
- added documentation
- added unit tests
Comment 11 Alan Knowles 2013-02-07 07:30:39 UTC
better late than never...

sorry for the delay..