-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v8: fix issue with let bindings in for loops
Backport b17eaaa5755e625493c5fe537f42b58838923c52 from upstream v8. Original commit message: Fix desugaring of let bindings in for loops to handle continue properly This requires putting the original loop's body inside an inner for loop (with the same labels as the original loop) and re-binding the temp variables in its "next" expression. A second flag is added to the desugared code to ensure the loop body executes at most once per loop. BUG=v8:3683 LOG=y Review URL: https://codereview.chromium.org/720863002 Cr-Commit-Position: refs/heads/master@{#25363} Fixes #9113 and #14411. Reviewed-By: Colin Ihrig <[email protected]> PR-URL: nodejs/node-v0.x-archive#23948
- Loading branch information
Showing
2 changed files
with
213 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright 2014 the V8 project authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
// | ||
// Flags: --harmony-scoping | ||
|
||
"use strict"; | ||
|
||
// Simplest case | ||
var count = 0; | ||
for (let x = 0; x < 10;) { | ||
x++; | ||
count++; | ||
continue; | ||
} | ||
assertEquals(10, count); | ||
|
||
// Labeled | ||
count = 0; | ||
label: for (let x = 0; x < 10;) { | ||
while (true) { | ||
x++; | ||
count++; | ||
continue label; | ||
} | ||
} | ||
assertEquals(10, count); | ||
|
||
// Simple and labeled | ||
count = 0; | ||
label: for (let x = 0; x < 10;) { | ||
x++; | ||
count++; | ||
continue label; | ||
} | ||
assertEquals(10, count); | ||
|
||
// Shadowing loop variable in same scope as continue | ||
count = 0; | ||
for (let x = 0; x < 10;) { | ||
x++; | ||
count++; | ||
{ | ||
let x = "hello"; | ||
continue; | ||
} | ||
} | ||
assertEquals(10, count); | ||
|
||
// Nested let-bound for loops, inner continue | ||
count = 0; | ||
for (let x = 0; x < 10;) { | ||
x++; | ||
for (let y = 0; y < 2;) { | ||
y++; | ||
count++; | ||
continue; | ||
} | ||
} | ||
assertEquals(20, count); | ||
|
||
// Nested let-bound for loops, outer continue | ||
count = 0; | ||
for (let x = 0; x < 10;) { | ||
x++; | ||
for (let y = 0; y < 2;) { | ||
y++; | ||
count++; | ||
} | ||
continue; | ||
} | ||
assertEquals(20, count); | ||
|
||
// Nested let-bound for loops, labeled continue | ||
count = 0; | ||
outer: for (let x = 0; x < 10;) { | ||
x++; | ||
for (let y = 0; y < 2;) { | ||
y++; | ||
count++; | ||
if (y == 2) continue outer; | ||
} | ||
} | ||
assertEquals(20, count); |