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 676833 - A few helpful hints for debugging JS function calling issues
A few helpful hints for debugging JS function calling issues
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-25 18:15 UTC by Jasper St. Pierre (not reading bugmail)
Modified: 2012-05-25 19:02 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
function: Add argument names to our function's toString (2.90 KB, patch)
2012-05-25 18:15 UTC, Jasper St. Pierre (not reading bugmail)
reviewed Details | Review
function: Support Function.prototype.length (1.58 KB, patch)
2012-05-25 18:15 UTC, Jasper St. Pierre (not reading bugmail)
reviewed Details | Review
function: Add argument names to our function's toString (3.05 KB, patch)
2012-05-25 18:46 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review
function: Support Function.prototype.length (1.88 KB, patch)
2012-05-25 18:46 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review

Description Jasper St. Pierre (not reading bugmail) 2012-05-25 18:15:30 UTC
Some people have been concerned about the mapping from C to JS, and
we haven't been able to give them a decent solution. The best is "look
at the GIR, and then omit user_data arguments and gerrors". Look, gjs
already *calculates* what arguments will be skipped, so why not show
them to the user?

As a fun side-hack, this brings us a bit of silly compatibility with
a few JS libraries that parse f.toString() to provide kwargs functionality
or other stupid things.
Comment 1 Jasper St. Pierre (not reading bugmail) 2012-05-25 18:15:32 UTC
Created attachment 214969 [details] [review]
function: Add argument names to our function's toString

It's sometimes hard to know what each argument is when translated to JS. This
should provide a helpful debugging hint for those new to the GNOME JS dev
process, and also help with debugging hard errors about wrong argument types.
Comment 2 Jasper St. Pierre (not reading bugmail) 2012-05-25 18:15:35 UTC
Created attachment 214970 [details] [review]
function: Support Function.prototype.length

Meaning the number of arguments the function takes.
Comment 3 Colin Walters 2012-05-25 18:28:50 UTC
Review of attachment 214969 [details] [review]:

The "decent solution" is clearly documentation...but there's no reason not to do this too.

::: gi/function.c
@@ +1342,3 @@
+
+        if (priv->param_types[i] == PARAM_SKIPPED)
+            continue;

You're not handling direction here, so don't output arguments show up as input?
Comment 4 Colin Walters 2012-05-25 18:30:30 UTC
Review of attachment 214970 [details] [review]:

Might link to https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/Length in the comment or something.

::: gi/function.c
@@ +1324,3 @@
+    n_jsargs = n_args;
+    for (i = 0; i < n_args; i++) {
+        if (priv->param_types[i] == PARAM_SKIPPED) n_jsargs--;

And also need to handle direction here?
Comment 5 Jasper St. Pierre (not reading bugmail) 2012-05-25 18:46:34 UTC
Created attachment 214980 [details] [review]
function: Add argument names to our function's toString

It's sometimes hard to know what each argument is when translated to JS. This
should provide a helpful debugging hint for those new to the GNOME JS dev
process, and also help with debugging hard errors about wrong argument types.



Good catch, didn't think about that.
Comment 6 Jasper St. Pierre (not reading bugmail) 2012-05-25 18:46:39 UTC
Created attachment 214981 [details] [review]
function: Support Function.prototype.length

Meaning the number of arguments the function takes.

See https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/Length for more information
Comment 7 Colin Walters 2012-05-25 18:51:43 UTC
Review of attachment 214980 [details] [review]:

Looks OK now.
Comment 8 Colin Walters 2012-05-25 18:52:13 UTC
Review of attachment 214981 [details] [review]:

Looks good.
Comment 9 Jasper St. Pierre (not reading bugmail) 2012-05-25 19:02:05 UTC
Attachment 214980 [details] pushed as 0023abb - function: Add argument names to our function's toString
Attachment 214981 [details] pushed as 631680b - function: Support Function.prototype.length