Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1565)

Unified Diff: test/mjsunit/harmony/block-for.js

Issue 292743009: Make let variables fresh in each iteration of a for-loop. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address comments Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parser.cc ('k') | test/mjsunit/harmony/debug-blockscopes.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/block-for.js
diff --git a/test/mjsunit/harmony/block-for.js b/test/mjsunit/harmony/block-for.js
index e84f0d2fee852ce05c0e797d59b98b8dbd0c3260..2c112467bb708a14f265feb68abd8a0c38f836dd 100644
--- a/test/mjsunit/harmony/block-for.js
+++ b/test/mjsunit/harmony/block-for.js
@@ -102,7 +102,7 @@ assertThrows("function foo() { 'use strict'; for (let x, y = 4 in {}) { } }", Sy
assertThrows("function foo() { 'use strict'; for (let x = 3, y = 4 in {}) { } }", SyntaxError);
-// In a normal for statement the iteration variable is not
+// In a normal for statement the iteration variable is
// freshly allocated for each iteration.
function closures1() {
let a = [];
@@ -110,7 +110,7 @@ function closures1() {
a.push(function () { return i; });
}
for (let j = 0; j < 5; ++j) {
- assertEquals(5, a[j]());
+ assertEquals(j, a[j]());
}
}
closures1();
@@ -123,13 +123,45 @@ function closures2() {
b.push(function () { return j; });
}
for (let k = 0; k < 5; ++k) {
- assertEquals(5, a[k]());
- assertEquals(15, b[k]());
+ assertEquals(k, a[k]());
+ assertEquals(k + 10, b[k]());
}
}
closures2();
+function closure_in_for_init() {
+ let a = [];
+ for (let i = 0, f = function() { return i }; i < 5; ++i) {
+ a.push(f);
+ }
+ for (let k = 0; k < 5; ++k) {
+ assertEquals(0, a[k]());
+ }
+}
+closure_in_for_init();
+
+
+function closure_in_for_cond() {
+ let a = [];
+ for (let i = 0; a.push(function () { return i; }), i < 5; ++i) { }
+ for (let k = 0; k < 5; ++k) {
+ assertEquals(k, a[k]());
+ }
+}
+closure_in_for_next();
+
+
+function closure_in_for_next() {
+ let a = [];
+ for (let i = 0; i < 5; a.push(function () { return i; }), ++i) { }
+ for (let k = 0; k < 5; ++k) {
+ assertEquals(k + 1, a[k]());
+ }
+}
+closure_in_for_next();
+
+
// In a for-in statement the iteration variable is fresh
// for earch iteration.
function closures3(x) {
« no previous file with comments | « src/parser.cc ('k') | test/mjsunit/harmony/debug-blockscopes.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698