Fwd: undefined being treated as a missing optional argument

Allen Wirfs-Brock allen at wirfs-brock.com
Wed Apr 11 17:35:09 PDT 2012

See below:

I'm not sure who told Cameron that this is likely to change from the current spec. but regardless I don't think it is a good idea. 

Just to start, it means a method like:

Array.prototype.fill = function(value=null) { this.forEach((v,i)=>this[i]=value)}

wouldn't do the obvious thing when called as:



Begin forwarded message:

> Resent-From: public-script-coord at w3.org
> From: Cameron McCormack <cam at mcc.id.au>
> Date: April 11, 2012 5:15:35 PM PDT
> To: "public-script-coord at w3.org" <public-script-coord at w3.org>
> Cc: Jonas Sicking <jonas at sicking.cc>, Brendan Eich <brendan at mozilla.com>, David Herman <dherman at mozilla.com>, Sam Tobin-Hochstadt <samth at ccs.neu.edu>
> Subject: undefined being treated as a missing optional argument
> A few months ago we had some long discussions about what it means to pass undefined as the value of an optional argument, for example:
>  void f(optional long x);
> called with:
>  f(undefined);
> What we eventually settled on was that an explicit undefined is always treated as a specified argument, so for the above case undefined would be converted to the IDL long value 0.  Here's where the original decision was announced:
>  http://www.w3.org/mid/4EF3DB9C.4080401@mcc.id.au
> Maybe the strongest reason for deciding this way was to align with how ES6 was going to handle function argument default values.  It's been brought to my attention though that this behaviour is not yet fixed for ES6 and there's a good possibility that ES6 will specify that passing undefined will cause the argument's default value to be used.  If that happens, then it seems like we might again want Web IDL to change to be consistent with that.
> Unless there are any objections, I'm going to add a note to the spec to point out that undefined is currently not treated as a missing optional argument in alignment with ES6, but that ES6 may yet change and that we might revisit the decision at that point.
> (If we did revisit the decision, there are various knock-on changes we'd need to make (again) such as bringing dictionaries in line by having an undefined value specified for a dictionary member mean that it is not present, ensuring that the overload resolution algorithm can handle this, deciding what it means to pass undefined to an optional argument of IDL type any, and so on.)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120411/b6cc69e7/attachment.html>

More information about the es-discuss mailing list