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 675479 - modules: Import a new "format" module
modules: Import a new "format" module
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gjs-maint
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2012-05-04 22:29 UTC by Jasper St. Pierre (not reading bugmail)
Modified: 2012-05-24 19:39 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
modules: Import a new "format" module (8.43 KB, patch)
2012-05-04 22:29 UTC, Jasper St. Pierre (not reading bugmail)
reviewed Details | Review
Switch string formatting to the one inside gjs (5.86 KB, patch)
2012-05-04 22:30 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review
modules: Import a new "format" module (8.50 KB, patch)
2012-05-07 18:38 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review

Description Jasper St. Pierre (not reading bugmail) 2012-05-04 22:29:30 UTC
This is imported from the Shell, where it has been copied to gnome-documents
and other libraries. Let's give it a new home in gjs.
Comment 1 Jasper St. Pierre (not reading bugmail) 2012-05-04 22:29:31 UTC
Created attachment 213473 [details] [review]
modules: Import a new "format" module

Imported from gnome-shell, this provides printf-like formatting to
JavaScript.
Comment 2 Jasper St. Pierre (not reading bugmail) 2012-05-04 22:30:18 UTC
Created attachment 213474 [details] [review]
Switch string formatting to the one inside gjs
Comment 3 Cosimo Cecchi 2012-05-07 18:30:48 UTC
Review of attachment 213473 [details] [review]:

Apart from this comment below, looks good to me.
Should we try to attach this to the String class directly from GJS? It would avoid the need to set up the override in every application (and applications could still override it again if they want it to do something different).

::: modules/format.c
@@ +41,3 @@
+        return JS_FALSE;
+    if (!gjs_string_from_utf8(context, g_strdup_printf("%Id", intval), -1, &rval))
+        return JS_FALSE;

Aren't you leaking the stirng returned by g_strdup_printf() here? It should be g_free()-d.
Comment 4 Jasper St. Pierre (not reading bugmail) 2012-05-07 18:33:34 UTC
I don't think that modifying a prototype is something that an interpreter should do.
Comment 5 Jasper St. Pierre (not reading bugmail) 2012-05-07 18:38:17 UTC
Created attachment 213616 [details] [review]
modules: Import a new "format" module

Imported from gnome-shell, this provides printf-like formatting to
JavaScript.



Gah, for some reason I always think string_from_utf8 steals its parameter.
Comment 6 Cosimo Cecchi 2012-05-07 20:12:45 UTC
(In reply to comment #4)
> I don't think that modifying a prototype is something that an interpreter
> should do.

But the format() function will stop working in case the application doesn't set it up, since doing "return vprintf(this, arguments);" assumes that format() is part of String.Prototype.
So my idea was to either we set it up automatically, or only provide vprintf() in Format and let applications define its interaction with String.Prototype.
Comment 7 Jasper St. Pierre (not reading bugmail) 2012-05-07 20:19:31 UTC
(In reply to comment #6)
> (In reply to comment #4)
> > I don't think that modifying a prototype is something that an interpreter
> > should do.
> 
> But the format() function will stop working in case the application doesn't set
> it up, since doing "return vprintf(this, arguments);" assumes that format() is
> part of String.Prototype.
> So my idea was to either we set it up automatically, or only provide vprintf()
> in Format and let applications define its interaction with String.Prototype.

The goal was "here's a readymade method for the prototype, install it if you want to", so everybody wouldn't have to create their own format method, even if it's only one line of code.
Comment 8 drago01 2012-05-08 15:02:55 UTC
I tend to agree with Cosimo here ... we should just set it up. It isn't part of the EMCAScript standard but we provide other non standard stuff anyway so not seeing any harm it would cause.
Comment 9 Jasper St. Pierre (not reading bugmail) 2012-05-08 19:24:15 UTC
(In reply to comment #8)
> I tend to agree with Cosimo here ... we should just set it up. It isn't part of
> the EMCAScript standard but we provide other non standard stuff anyway so not
> seeing any harm it would cause.

We don't modify any other prototypes. We made Lang.bind instead of Function.prototype.bind. I don't think it's right to stop that process now.
Comment 10 drago01 2012-05-08 19:43:09 UTC
(In reply to comment #9)
> (In reply to comment #8)
> > I tend to agree with Cosimo here ... we should just set it up. It isn't part of
> > the EMCAScript standard but we provide other non standard stuff anyway so not
> > seeing any harm it would cause.
> 
> We don't modify any other prototypes. We made Lang.bind instead of
> Function.prototype.bind. I don't think it's right to stop that process now.

OK, makes sense.
Comment 11 Jasper St. Pierre (not reading bugmail) 2012-05-23 18:45:19 UTC
Ping?
Comment 12 Cosimo Cecchi 2012-05-23 19:20:44 UTC
Patch looks fine to me, but I'm not a GJS maintainer...
Comment 13 drago01 2012-05-23 21:02:51 UTC
Review of attachment 213616 [details] [review]:

Looks good.
Comment 14 drago01 2012-05-23 21:03:08 UTC
Review of attachment 213474 [details] [review]:

Looks good.
Comment 15 Jasper St. Pierre (not reading bugmail) 2012-05-24 19:39:29 UTC
Attachment 213616 [details] pushed as 2ef9fe8 - modules: Import a new "format" module
Comment 16 Jasper St. Pierre (not reading bugmail) 2012-05-24 19:39:56 UTC
Comment on attachment 213474 [details] [review]
Switch string formatting to the one inside gjs

Attachment 213474 [details] pushed as 8a9e3e0 - Switch string formatting to the one inside gjs