Are function arguments with the value `undefined` "present"?

Rick Waldron waldron.rick at gmail.com
Fri May 31 08:01:48 PDT 2013


On Fri, May 31, 2013 at 7:33 AM, Till Schneidereit
<tschneidereit at gmail.com>wrote:

> I couldn't find any precise definition for the spec term "present", so
> this is not entirely clear to me.
>
> Example:
> In step 7 of 15.4.3.21 Array.prototype.reduce, a TypeError must be thrown
> if the optional argument `initialValue` isn't present. If a value of
> `undefined` does *not* cause the argument to be present, that function can
> be implemented with the following signature:
>
> `function ArrayReduce(callbackfn, initialValue = undefined)`
>

`undefined` is a valid initial value for Array.prototype.reduce.
`undefined` will also trigger the default parameter, so this works until
nothing is provided, which breaks Step 10.


>
> If, however, the value `undefined` means that the argument is present, the
> signature should probably be:
>
> `function ArrayReduce(callbackfn, ...rest)`
>

With minor changes to steps 9 and 10, plus the addition of steps to check
rest.length and then Get(rest, "0"), this would work. I suspect that Allen
would prefer to craft some sort of spec mechanism, from this use case, for
"is foo present" assertions throughout the spec.


Rick


>
>
> The question isn't entirely academic, as I'm trying to get the self-hosted
> implementations of builtins in SpiderMonkey to be as close to the spec as
> possible.
>
>
> thanks,
> till
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130531/4e10bb23/attachment.html>


More information about the es-discuss mailing list