GNOME Bugzilla – Bug 657699
Add a GLib namespace extension providing comodities for conversion from/to GVariant
Last modified: 2013-02-07 07:30:39 UTC
GVariant.
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.
Should be to toJS() really - odd that gjs let that through.
(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 ?
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.
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) {
yes, these names are alot clearer than pack/unpack ;)
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.
Done. Regards Alan
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
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
better late than never... sorry for the delay..