OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 // |
| 5 // Flags: --harmony-scoping |
| 6 |
| 7 'use strict'; |
| 8 |
| 9 // Top-level code |
| 10 let s = 0; |
| 11 let f = [undefined, undefined, undefined] |
| 12 for (const x of [1,2,3]) { |
| 13 s += x; |
| 14 f[x-1] = function() { return x; } |
| 15 } |
| 16 assertEquals(6, s); |
| 17 assertEquals(1, f[0]()); |
| 18 assertEquals(2, f[1]()); |
| 19 assertEquals(3, f[2]()); |
| 20 |
| 21 let x = 1; |
| 22 s = 0; |
| 23 for (const x of [x, x+1, x+2]) { |
| 24 s += x; |
| 25 } |
| 26 assertEquals(6, s); |
| 27 |
| 28 s = 0; |
| 29 var q = 1; |
| 30 for (const q of [q, q+1, q+2]) { |
| 31 s += q; |
| 32 } |
| 33 assertEquals(6, s); |
| 34 |
| 35 let z = 1; |
| 36 s = 0; |
| 37 for (const x = 1; z < 2; z++) { |
| 38 s += x + z; |
| 39 } |
| 40 assertEquals(2, s); |
| 41 |
| 42 |
| 43 s = ""; |
| 44 for (const x in [1,2,3]) { |
| 45 s += x; |
| 46 } |
| 47 assertEquals("012", s); |
| 48 |
| 49 assertThrows(function() { for(const x in [1,2,3]) { x++ } }, SyntaxError); |
| 50 |
| 51 // Function scope |
| 52 (function() { |
| 53 let s = 0; |
| 54 for (const x of [1,2,3]) { |
| 55 s += x; |
| 56 } |
| 57 assertEquals(6, s); |
| 58 |
| 59 let x = 1; |
| 60 s = 0; |
| 61 for (const x of [x, x+1, x+2]) { |
| 62 s += x; |
| 63 } |
| 64 assertEquals(6, s); |
| 65 |
| 66 s = 0; |
| 67 var q = 1; |
| 68 for (const q of [q, q+1, q+2]) { |
| 69 s += q; |
| 70 } |
| 71 assertEquals(6, s); |
| 72 |
| 73 s = ""; |
| 74 for (const x in [1,2,3]) { |
| 75 s += x; |
| 76 } |
| 77 assertEquals("012", s); |
| 78 }()); |
OLD | NEW |