I generally agree that it would be a good idea to specify apply (and call)
pretty much as proposed below by David-Sarah. The major reason that it makes it
explicit what happens for most currently unspecified edge cases such as a
sparse argArray or argArray properties that are accessors.
It would also eliminate the need to explicitly require that argArray be an
array or arguments object [but as a possible downside, I can imagine an
implementation reasonably using the current " must be an array" restriction to
implement apply in a manner that only works with objects that have some special
internal array representation].
It is clearly a (pretty obvious and hence not very significant) bug that the
Es3 specification doesn't say that apply and call return the result of
[[Call]]. At the very least that should be fixed in the ES3.1 spec.
I think putting in the argument number limit check is starting down a slippery
slope. There are many things in the spec. (number of locals, size of numbers,
size of methods, etc.) that might plausibly have an implementation limit. I
don't think we can reasonably identify all of them and I don't think this one
is special enough to make it an exception.
What does ToArrayLength do? Ensure a numeric value? It isn't in the current
spec. draft.
[this leads me to think that there is a problem that as currently specified,
Object.defineProperty(anArray,"length",{value: "xyz"}) will violate the array
length invariant...another ES3.1 bug]
Strictly speaking step 7 needs to compose the array elements into a List as
that is what [[Call]] takes as an argument
>-----Original Message-----
>From: [email protected] [mailto:es3.x-discuss-
>[email protected]] On Behalf Of David-Sarah Hopwood
>Sent: Wednesday, January 14, 2009 8:01 PM
[snip]
>----
>The following changes
> - make apply handle its argArray generically;
> - rewrite apply and call using the algorithm notation;
> - clarify that apply and call return the return value of the called
> function;
> - acknowledge that there may be an implementation-defined limit on
> the number of arguments to a function. (This also needs to be fixed
> in section 11.2.4.)
>
>====
>15.3.4.3 Function.prototype.apply (thisArg, argArray)
>
>The apply method takes two arguments, thisArg and argArray, and performs
>a function call using the [[Call]] property of the this object, by the
>following steps:
>
>1. If IsCallable(this) is false, then throw a TypeError exception.
>2. If argArray is null or undefined, then
> a. Call the [[Call]] method of this object, providing thisArg
> as the this value and no arguments.
> b. Return Result(2a).
>3. If Type(argArray) is not Object, then throw a TypeError exception.
>4. Call the [[Get]] method of argArray with property name "length".
>5. Let n be ToArrayLength(Result(4)).
>6. If n is greater than an implementation-defined limit on the number}
> of arguments to a function, then throw a RangeError exception.
>7. For every nonnegative integer k less than n:
> a. Let P_k be ToString(k).
> b. Let arg_k be the result of calling the [[Get]] method of
> argArray with property name P_k.
>8. Call the [[Call]] method of this object, providing thisArg as the
> this value and arg_0, arg_1, ... arg_{n-1} as the arguments.
>9. Return Result(8).
>
>The length property of the apply method is 2.
>
>
>15.3.4.4 Function.prototype.call (thisArg [ , arg_0 [ , arg_1, ... ] ] )
>
>The call method takes one or more arguments, thisArg and (optionally)
>arg_0, arg_1 etc., and performs a function call using the [[Call]]
>property of the object, by the following steps:
>
>1. If IsCallable(this) is false, then throw a TypeError exception.
>2. Call the [[Call]] method of this object, providing thisArg as the
> this value, and any remaining arguments to the call method starting
> with arg_0 (if provided) as the arguments.
>3. Return Result(2).
>
>The length property of the call method is 1.
>====
>
>--
>David-Sarah Hopwood ⚥
>
>_______________________________________________
>Es3.x-discuss mailing list
>[email protected]
>https://mail.mozilla.org/listinfo/es3.x-discuss
_______________________________________________
Es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss