Re: [WebIDL] Callback functions and callback interfaces should allow optional arguments sanely

Boris Zbarsky wrote:
> The grammar for callbacks allows optional arguments. But the processing
> model in
> http://dev.w3.org/2006/webapi/WebIDL/#es-invoking-callback-functions
> (which references the one in
> http://dev.w3.org/2006/webapi/WebIDL/#es-user-objects ) doesn't really
> describe what to do with such arguments. I would like to propose a
> processing model as follows:
>
> 1) Start with a list of n IDL argument values idlarg_{0 ... n-1}. This
> assumes that we have a way to represent a "not passed" optional value as
> an IDL type, which I believe we have agreed we need anyway.
> 2) Set argcount to n.
> 3) Set i to n-1.
> 4) While i >= 0 and the idlarg_i is not passed and the
> corresponding argument of the IDL callback type is optional:
> a) Set argcount to argcount - 1
> b) Set i to i - 1
> 5) Continue with the algorithm as currently defined, but using
> argcount, not n, as the number of arguments.
>
> We will also need to define that converting a "not passed" value to an
> ECMAScript value produces undefined, I think.
>
> Thoughts?
>
> -Boris
>
> P.S. I'm implementing the above in Gecko anyway, because it's needed to
> implement window.onerror. But I figured I'd at least sanity-check it.

That sounds reasonable to me.  I've allowed "missing" optional argument 
values in the middle of the argument list, as we've done for operations. 
  Also, I don't think we need to handle the case where a "missing" value 
is passed and the argument is not optional, since that shouldn't be allowed.

http://dev.w3.org/cvsweb/2006/webapi/WebIDL/Overview.xml.diff?r1=1.645;r2=1.646;f=h

http://dev.w3.org/2006/webapi/WebIDL/#es-invoking-callback-functions

Received on Tuesday, 23 July 2013 07:34:34 UTC