GNOME Bugzilla – Bug 676833
A few helpful hints for debugging JS function calling issues
Last modified: 2012-05-25 19:02:10 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.
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.
Created attachment 214970 [details] [review] function: Support Function.prototype.length Meaning the number of arguments the function takes.
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?
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?
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.
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
Review of attachment 214980 [details] [review]: Looks OK now.
Review of attachment 214981 [details] [review]: Looks good.
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