Function proxy length (Was: length property value for functions with parameter enhancements)

David Bruant david.bruant at labri.fr
Tue Aug 30 09:41:04 PDT 2011


Le 29/08/2011 16:43, Tom Van Cutsem a écrit :
> (changed subject to fork off discussion on function proxies)
>
> 2011/8/29 Allen Wirfs-Brock <allen at wirfs-brock.com
> <mailto:allen at wirfs-brock.com>>
>
>     On Aug 27, 2011, at 6:12 AM, Andreas Rossberg wrote:
>      > True, and actually, there are more issues with length & function
>     > proxies. I don't have my notes with me right now, but for
>     example, it
>     > is not clear at all what length Function.prototype.bind should set
>     > when called on a function proxy. 0? 1? Should it try to get the
>     length
>     > property from the proxy and subtract N? What if length is not
>     defined
>     > on the proxy, or not a (natural) number?
>
>     The ES5.1 spec.  defines how how bind determines the length for
>     the function it creates based upon the length property of the
>     target function.  I would expect the same rules would apply when
>     the target is a function proxy.
>
>
> I see two options here:
> a) either query the function proxy for its "length" property via its
> "get" trap, and convert the result using ToInteger, introducing a new
> error case if the conversion fails.
> b) or determine "length" based on the function proxy's call trap
> (which is presumably a non-proxy function. If it is a function proxy
> itself, recurse)
>
> The spec currently uses the wording: "Let L be the length property of
> Target ..." (ES5.1 section 15.3.4.5)
> If that is not equivalent to "Let L be the result of calling the
> [[Get]] internal method of Target with argument "length"", then option
> b) seems better.
There is no mention of function proxy lengths in
harmony:proxies_semantics [1] nor in harmony:proxies and i'd like to
discuss this.
-----
var f = Proxy.createFunction(functionHandler, function(){}, function(){})
var l = f.length; // ?
-----
Currently, nothing is really said about how is handled f.length,
f.prototype and such. So, it seems to be left to the proxy author.
In order to facilitate the author work, it could be possible to have an
ES5.1-13.2-like function proxy constructor especially when it comes to
steps 15, 17, 18 (i'm in doubt with steps 5 and 19).
Step 15 would be a way for the engine to communicate with the handler to
pass the [[Call]].length value. In order to initially set the length
value, i think it would make sense to take [[Call]].length too (what if
[[Call]].length !== [[Construct]].length?). Also, it would facilitate
the way the handler has access to [[Call]].length when writing
functionHandler.get and functionHandler.get{Own}PropertyDescriptor
It could be left to the programmer the initiative to refuse the addition
of the length property (if it's necessary to emulate an host object) (by
returning false at the end of the defineProperty trap iirc)

This would facilitate the author work when it comes to creating
functions that look like functions without having to always include some
initialization code for .length, .prototype and such.
It will still be possible to opt-out of .length or .prototype if the
author doesn't

David

[1] http://wiki.ecmascript.org/doku.php?id=harmony:proxies_semantics
[2] http://wiki.ecmascript.org/doku.php?id=strawman:fixed_properties
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110830/4a363cac/attachment-0001.html>


More information about the es-discuss mailing list