W3C home > Mailing lists > Public > public-script-coord@w3.org > July to September 2013

[Bug 23056] Function's length property is inconsistent with EcmaScript

From: <bugzilla@jessica.w3.org>
Date: Wed, 28 Aug 2013 04:31:47 +0000
To: public-script-coord@w3.org
Message-ID: <bug-23056-3890-hnXfYC2Jt2@http.www.w3.org/Bugs/Public/>

--- Comment #6 from Allen Wirfs-Brock <allen@wirfs-brock.com> ---
(In reply to comment #5)
> In WebIDL, a function can generally speaking have some number of
> non-optional arguments, then some number of optional arguments, with or
> without default values.  Optional arguments are ones that can be not passed
> in the arguments.length sense.  An example:
>   void foo(long arg1, long arg2, optional long arg3, optional long arg4 = 5,
>            optional long arg5);
> This produces behavior similar to this ES function, as far as I can tell:
>   void foo(arg1, arg2, arg3, arg4 = 5, arg5) {
>     if (arguments.length < 2) { throw TypeError(); }
>     // stuff
>   }
> If I read the ES spec correctly, the .length of such a function would be 3,
> correct?  The .length of the WebIDL function shown above is 2 at the
> moment...

A better mapping is:
   foo(arg1, arg2, arg3 = 0, arg4 = 5, arg5) {
     if (arguments.length < 2) { throw TypeError(); }
     // stuff

Which ES6 will assign a 'length' property of 2.

The appropriate translation of WebIDL to ES6 is that WebIDL "optional" always
turns into an ES6 parameter with a default value initialiser. If the WebIDL
source includes an explicit default value then that value should be used as the
ES6 default value.  If the WebIDL does not have an explicit default value then
the implicit WebIDL default should be used as the ES6 default value.

If you do this, then the WebIDL length based upon "optional" should match the
ES6 length based upon default value initialisers.

You are receiving this mail because:
You are on the CC list for the bug.
Received on Wednesday, 28 August 2013 04:31:49 UTC

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