Closed
Bug 348685
Opened 18 years ago
Closed 18 years ago
Let-scoped variables in for loop can be referenced outside the loop
Categories
(Core :: JavaScript Engine, defect, P1)
Core
JavaScript Engine
Tracking
()
VERIFIED
FIXED
mozilla1.8.1beta2
People
(Reporter: nanto, Assigned: brendan)
Details
(Keywords: verified1.8.1)
Attachments
(1 file, 1 obsolete file)
2.04 KB,
patch
|
mrbkap
:
review+
beltzner
:
approval1.8.1+
|
Details | Diff | Splinter Review |
Using let-scoped for loop variables outside the loop doesn't throw a ReferenceError exception under some conditions: - In a function - Repeat the loop more than one time - Use let declarations/statements/expressions in the loop body - Define functions or use function expressions in the loop body And the variable is evalueated to: - Last assigned value in the for loop - A function that uses the variable as a argument - Undefined if the variable is used as a argument and returned js> function f() { for (let i = 0; i < 2; i++) { let j = 42; function g() {} } var a = i; print(a); print(i); return i; } js> print(f()); 2 function print() { [native code] } undefined
Assignee | ||
Comment 1•18 years ago
|
||
Argh -- once we clone block objects and clear fp->blockChain, we must never again set it. Otherwise, we end up with duplicate clones on fp->scopeChain after the second iteration! /be
Assignee: general → brendan
Assignee | ||
Updated•18 years ago
|
Status: NEW → ASSIGNED
OS: Windows XP → All
Priority: -- → P1
Hardware: PC → All
Target Milestone: --- → mozilla1.8.1beta2
Assignee | ||
Comment 2•18 years ago
|
||
Comment says it all. /be
Attachment #233716 -
Flags: review?(mrbkap)
Assignee | ||
Comment 3•18 years ago
|
||
If we kept count of cloned blocks on the scope chain, or counted remaining ones on every LEAVEBLOCK, we could clear JSFRAME_POP_BLOCKS and do better for cases that open new, unrelated blocks later, after a block contains a closure or other scope capturing construct. Not sure this is worth optimizing. We could optimize nested functions harder to avoid capturing run-time scope, too. /be
Assignee | ||
Comment 4•18 years ago
|
||
Attachment #233716 -
Attachment is obsolete: true
Attachment #233719 -
Flags: review?(mrbkap)
Attachment #233716 -
Flags: review?(mrbkap)
Comment 5•18 years ago
|
||
Comment on attachment 233719 [details] [diff] [review] with correct assertion Seems reasonable.
Attachment #233719 -
Flags: review?(mrbkap) → review+
Assignee | ||
Comment 6•18 years ago
|
||
Fixed on trunk, already. /be
Status: ASSIGNED → RESOLVED
Closed: 18 years ago
Flags: blocking1.8.1?
Resolution: --- → FIXED
Comment 7•18 years ago
|
||
Checking in regress-348685.js; /cvsroot/mozilla/js/tests/js1_7/block/regress-348685.js,v <-- regress-348685.js initial revision: 1.1
Flags: in-testsuite+
Updated•18 years ago
|
Flags: blocking1.8.1? → blocking1.8.1+
Assignee | ||
Comment 8•18 years ago
|
||
Comment on attachment 233719 [details] [diff] [review] with correct assertion This is ready. /be
Attachment #233719 -
Flags: approval1.8.1?
Comment 9•18 years ago
|
||
Comment on attachment 233719 [details] [diff] [review] with correct assertion a=beltzner, on behalf of drivers for the 18branch
Attachment #233719 -
Flags: approval1.8.1? → approval1.8.1+
Comment 11•18 years ago
|
||
verified fixed 1.8 20060818 windows/mac*/linux not verified trunk crashed opt/dbg all platforms. I'll deal when I have fresh builds.
Keywords: fixed1.8.1 → verified1.8.1
You need to log in
before you can comment on or make changes to this bug.
Description
•