Closed
Bug 1022967
Opened 10 years ago
Closed 8 years ago
Separate environment for default parameter and function body if default parameter contains expression
Categories
(Core :: JavaScript Engine, defect)
Core
JavaScript Engine
Tracking
()
RESOLVED
FIXED
People
(Reporter: arai, Assigned: shu)
References
Details
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:30.0) Gecko/20100101 Firefox/30.0 (Beta/Release)
Build ID: 20140605174243
Steps to reproduce:
(Separated from 1018628)
Evaluate following code in Firefox 29:
> var z = 10;
> function f(b=(() => z) {
> var z = 20;
> return b();
> }
> f()
Actual results:
|f()| returns |20|.
Expected results:
|f()| should return |10|.
This is caused by that variable |z| inside function body is visible from closure in default parameter, and the closure captures it instead of |z| in outer binding.
Related to step 28 of 9.2.13 in the spec:
http://people.mozilla.org/~jorendorff/es6-draft.html#sec-functiondeclarationinstantiation
Reporter | ||
Updated•10 years ago
|
Comment 1•10 years ago
|
||
There is a missing parens in your code above (and the >). Repasting one which is easier to copy:
var z = 10;
function f(b=(() => z)) {
var z = 20;
return b();
}
console.log(f())
Status: UNCONFIRMED → NEW
Ever confirmed: true
Reporter | ||
Updated•10 years ago
|
Summary: Separate environment for default parameter and function body if default parameter contains closure → Separate environment for default parameter and function body if default parameter contains expression
Reporter | ||
Comment 2•10 years ago
|
||
This bug will also have effect for the case when default parameter refers the function declared in the function body.
So I changed the Summary to follow the spec:
6. Let needsParameterEnvironment be ContainsExpression of formals.
Assignee | ||
Updated•9 years ago
|
Assignee: nobody → shu
Updated•8 years ago
|
Blocks: es6bindings
Assignee | ||
Comment 6•8 years ago
|
||
Fixed by bug 1263355.
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•