Removing the concept of "optional any"

Right now WebIDL allows arguments of type "any" to be either optional or 
not.

However in the new world where we want to treat undefined and missing 
identically, this doesn't make much sense, since "any" allows any ES 
value, including undefined.  So the only difference between "any" and 
"optional any" is for trailing "any" arguments and the only difference 
is whether an argc check is done.  Well that and conceptually that when 
undefined is passed for an "any" value you get an "any" with the value 
"undefined", while when it's passed for an "optional any" value you get 
a "not passed".  This distinction doesn't seem very useful.

So I would like to propose that we get rid of the concept of optional 
"any" altogether, but just ignore "any" arguments when computing the 
.length of functions or doing the argc checks for required arguments.

So this function would have length 0:

   void f(any arg);

and not throw if called as f().  Doing "void f(optional any arg)" would 
not be valid IDL, though we could allow "void f(optional any arg = 
null)" to avoid changing the grammar, which we would need to do to 
support "void f(any arg = null)".

The other alternative, as discussed in 
https://www.w3.org/Bugs/Public/show_bug.cgi?id=23602, is to remove 
"undefined" from the value set of "any" and then require explicitly 
opting in to accepting "undefined" by saying "optional any".  But that 
seems a bit odd...

Thoughts?

Note that I've landed this change in current Gecko nightlies for the 
moment to test it out, but I'm pretty darned sure it's web-compatible.

-Boris

Received on Wednesday, 19 February 2014 15:00:27 UTC