forked from nodejs/node-v0.x-archive
-
Notifications
You must be signed in to change notification settings - Fork 0
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. Also add a regression test to make sure subsequent V8 upgrades include this floating patch if needed. 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@{nodejs#25363} Fixes nodejs#9113 and nodejs#14411.
- Loading branch information
Showing
3 changed files
with
251 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); |
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,38 @@ | ||
// Copyright Joyent, Inc. and other Node contributors. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a | ||
// copy of this software and associated documentation files (the | ||
// "Software"), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to permit | ||
// persons to whom the Software is furnished to do so, subject to the | ||
// following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included | ||
// in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
// USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
/* | ||
* This is a regression test for the issue described at: | ||
* https://github.com/joyent/node/issues/9113. | ||
* | ||
* This problem has been fixed by floating a patch on V8, this test makes | ||
* sure that the appropriate patch is floated even after future V8 upgrades. | ||
* | ||
* If the bug is reproduced, this test stalls and the tests suite makes it | ||
* time out eventually (currently after one minute). Otherwise it exits after | ||
* the for loop completes its execution. | ||
*/ | ||
var spawn = require('child_process').spawn; | ||
var args = ['--harmony', | ||
'--use-strict', | ||
'-e', | ||
'for (let i = 0; i < 3; ++i) { if (i == 1) { continue; } }']; | ||
var child = spawn(process.execPath, args); |