On Aug 29, 2011, at 7:43 AM, Tom Van Cutsem wrote:

> (changed subject to fork off discussion on function proxies)
> 
> 2011/8/29 Allen Wirfs-Brock <[email protected]>
> 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.

It should be considered to be a [[Get]] (and should be restarted as such).

A deeper question is whether or not function proxy objects are ES5 
[[Class]]=='Function' objects (regardless of how this is actually expressed in 
the ES6 spec.)  For ES5, the distinction between objects that are callable and 
more specific objects where [[Class]]=='Function' was that 
[[Class]]=='Function' implies all of the invariants from sections 13.2 and 15.3 
and their subsections while isCallable only means that the object supports 
[[Call]]. For example, such object always have a immutable 'length' property 
whose value is a number but host objects that are callable might not have such 
a property.  Hence the test in 15.3.4.5 step 15.

Because of their nature, it would seem unreasonable to assume that function 
proxy objects conform to all of the 13.2 and 15.3 invariants. 

That means that according to 15.3.4.5 a bound function that targets a function 
proxy would have a length of 0.  That doesn't seem quite right either.  I think 
15.3.4.5 should be generalize so that the computation of the length property 
isn't predicted by [[Class]]=='Function' but instead should just use the the 
numeric value of the target's length property, if it exists.  If the target 
does not have a length property or if its value is not a number then the bound 
function would get a length value of 0.


Allen

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to