On Oct 3, 2011, at 1:00 PM, Sean Eagan wrote:
> On Mon, Oct 3, 2011 at 11:35 AM, Allen Wirfs-Brock
> <[email protected]> wrote:
>>
>> On Oct 3, 2011, at 8:45 AM, Sean Eagan wrote:
>>
>>> On Mon, Oct 3, 2011 at 10:30 AM, Erik Arvidsson
>>> <[email protected]> wrote:
>>>> But Function.prototype.apply doesn't preserve holes.
>>>
>>> Function.prototype.apply doesn't preserve holes for the the
>>> `arguments` object, but rest parameters aren't yet standardized, and
>>> are intended to replace the `arguments` object, so they could, and in
>>> my view, should preserve holes for both Function.prototype.apply and
>>> foo(...args) activations, at least if array structuring and
>>> destructuring preserve holes as currently specified in the ES.next
>>> draft spec.
>>
>>
>> In general, a call site doesn't have any knowledge of format of the formal
>> parameter list of the callee and the callee doesn't have any knowledge of
>> how the caller constructed the argument list. So the caller and callee
>> argument semantics can't be interdependent.
>
> I'm not suggesting the semantics of the caller and callee be
> interdependent, just that the semantics of a function are dependent on
> whether it has yet upgraded from `arguments` to rest parameters.
as it currently stands, a function is allowed to use both:
function f(a,b,c,...rest) {
g(...arguments);
h(...rest);
}
>
>> Also, we probably need to factor in the fact that most current
>> implementations probably don't have a mechanism for passing holes in an
>> argument and that adding such a mechanism might be a deep and expensive
>> change. Would the cost to implementors really be worth the benefit to JS
>> developers?
>
> I have no implementation experience, but I don't see what cost you are
> referring to. It seems likely to me that there would be a performance
> benefit since implementations don't need to add undefined values to
> the rest parameter, and since user code can skip holes if desired such
> as via ES5 Array extras.
In a high perf implementation, the arguments to a function call will typically
be passed as a dense sequence of values on the processor stack. Not as an
actual array object. Such a sequence normally does not include any way to
encode the existence of "holes" so a new mechanism would have to be added by
implementors. Probably a distinguished value. Such mechanisms typically carry
a cost. For example, such a distinguished internal marker value must never be
exposed to JS code as the value of formal parameter. So, the callee might have
to scrub each argument position and replace each hole with undefined. It
already has to do something like that for default value parameters (based on
the size of the argument list) but now it would have to do it for every
parameter.
Allen
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss