W3C home > Mailing lists > Public > public-script-coord@w3.org > January to March 2014

Removing the concept of "optional any"

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Wed, 19 Feb 2014 09:59:54 -0500
Message-ID: <5304C6EA.3090009@mit.edu>
To: "public-script-coord@w3.org" <public-script-coord@w3.org>
Right now WebIDL allows arguments of type "any" to be either optional or 

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...


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.

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

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:19 UTC