Closed
Bug 1144672
Opened 10 years ago
Closed 10 years ago
Function arguments don't include default parameters
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: robincafolla, Unassigned)
Details
Attachments
(1 file)
385 bytes,
text/html
|
Details |
User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:36.0) Gecko/20100101 Firefox/36.0
Build ID: 20150224134236
Steps to reproduce:
Tried to access the arguments of a function with a default parameter.
var f = function( a, b = 1 ) {
return arguments;
}
f( 1 );
Actual results:
arguments doesn't include the default parameter, only parameters passed to the function are listed.
returns [ 1 ]
Expected results:
arguments should include default parameters.
should return [ 1, 1 ]
Updated•10 years ago
|
Status: UNCONFIRMED → NEW
Ever confirmed: true
Comment 1•10 years ago
|
||
OK - I *think* what the ES6 specification says here is:
1. Because the argument list contains a default parameter, an unmapped arguments object is
created instead of the normal mapped kind.
I am actually not entirely clear on this point, but note that CreateMappedArgumentsObject
would flunk an assertion if we got there:
http://people.mozilla.org/~jorendorff/es6-draft.html#sec-createmappedargumentsobject
> 1. Assert: formals does not contain a rest parameter, any binding patterns, or any
> initializers. It may contain duplicate identifiers.
"Initializers" means default parameters.
2. Unmapped arguments objects contain the original values of the arguments actually passed.
They're created before default arguments are populated and they don't get updated later
when the default values are filled in.
http://people.mozilla.org/~jorendorff/es6-draft.html#sec-createunmappedargumentsobject
I'm going to check with the spec editor and see what we can figure out.
Setting needinfo?me so I don't forget about this.
Updated•10 years ago
|
Flags: needinfo?(jorendorff)
Comment 2•10 years ago
|
||
OK, before checking with the spec editor I double-checked the spec one last time, and it says:
http://people.mozilla.org/~jorendorff/es6-draft.html#sec-destructuring-binding-patterns-static-semantics-issimpleparameterlist
> 13.2.3.4 Static Semantics: IsSimpleParameterList
>
> [...]
>
> SingleNameBinding : BindingIdentifier Initializer
>
> 1. Return false.
That is, a parameter with an Initializer, like `b = 1`, is *not* a simple parameter. So this function gets an unmapped arguments object containing only the arguments actually passed in. (phew!)
One reason for this is so you can use arguments.length to ask how many arguments were actually passed.
Rest parameters are a nicer alternative to the `arguments` object in most situations.
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → INVALID
Updated•10 years ago
|
Flags: needinfo?(jorendorff)
Reporter | ||
Comment 3•10 years ago
|
||
So that means that there's no way to iterate over the default arguments of a function? I'd consulted the spec but it didn't seem clear to me what should be happening.
You need to log in
before you can comment on or make changes to this bug.
Description
•