Argument matching

Mark S. Miller erights at
Sun May 11 09:46:30 PDT 2008


On Fri, May 9, 2008 at 10:43 AM, Lars Hansen <lhansen at> wrote:
> In strict code ("use strict") the number of passed arguments must match
> the number of expected arguments.  This has been agreed upon.

Hi Lars, much as it pains me to raise this again, it has *not* been
agreed upon. In order for ES3.1 strict mode to be a fail-stop subset
of ES4 strict mode, I don't see how we could possibly agree on this.
Please include es3.x-discuss on further discussion of this topic.

ES3.1 must define a language that depends only on features that will
parse successfully on 3/4 of the current major browsers. Therefore, it
cannot adopt ES4's notations for either optional or rest arguments.
Instead, I have proposed that in ES3.1 strict mode, and *therefore* in
ES4 strict mode as well:

* If a function is invoked with fewer arguments than its declared
parameters, the remaining parameters are bound to undefined. If an ES4
strict function wishes to reject calls with too few arguments, then it
should declare undefined-rejecting types on these remaining

* If a function is invoked with more arguments than its declared
parameters, and if the function either mentions the magic name
'arguments' freely in its body or (ES4 only) declares rest parameters,
then it is considered an unbounded arity function. Otherwise it is
considered a bounded arity function.

* If a strict bounded arity function is called with too many
arguments, the call is rejected with a throw.

> I would expect that if too few arguments are passed to a function with
> a typed interface then you get a type error unless the missing parameter
> has a type that includes "undefined" (ie no conversion takes place).

This should be the case for a strict function as well.

> Signalling an error "because the function has a typed interface" is
> a variant, I guess, but it seems like an orthogonal concern.

Since ES3.1 has no typed interface, I will stay out of debates about
the semantics of typed interfaces.

> I would expect excess arguments to typed functions to be ignored
> silently,
> as they can be picked up by 'arguments' inside the function.

In loose mode, yes. It strict mode, only of 'arguments' is mentioned
freely in the body of the function, or (ES4 only) if the function
declares rest parameters.


More information about the Es4-discuss mailing list