OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // Flags: --harmony-destructuring | 5 // Flags: --harmony-destructuring |
6 | 6 |
7 (function TestObjectLiteralPattern() { | 7 (function TestObjectLiteralPattern() { |
8 var { x : x, y : y } = { x : 1, y : 2 }; | 8 var { x : x, y : y } = { x : 1, y : 2 }; |
9 assertEquals(1, x); | 9 assertEquals(1, x); |
10 assertEquals(2, y); | 10 assertEquals(2, y); |
11 | 11 |
12 var {z} = { z : 3 }; | 12 var {z} = { z : 3 }; |
13 assertEquals(3, z); | 13 assertEquals(3, z); |
| 14 |
| 15 |
| 16 var sum = 0; |
| 17 for(var {z} = { z : 3 }; z != 0; z--) { |
| 18 sum += z; |
| 19 } |
| 20 assertEquals(6, sum); |
14 }()); | 21 }()); |
| 22 |
| 23 |
| 24 (function TestObjectLiteralPatternLexical() { |
| 25 'use strict'; |
| 26 let { x : x, y : y } = { x : 1, y : 2 }; |
| 27 assertEquals(1, x); |
| 28 assertEquals(2, y); |
| 29 |
| 30 let {z} = { z : 3 }; |
| 31 assertEquals(3, z); |
| 32 |
| 33 |
| 34 let sum = 0; |
| 35 for(let {x, z} = { x : 0, z : 3 }; z != 0; z--) { |
| 36 assertEquals(0, x); |
| 37 sum += z; |
| 38 } |
| 39 assertEquals(6, sum); |
| 40 }()); |
| 41 |
| 42 |
| 43 (function TestObjectLiteralPatternLexicalConst() { |
| 44 'use strict'; |
| 45 const { x : x, y : y } = { x : 1, y : 2 }; |
| 46 assertEquals(1, x); |
| 47 assertEquals(2, y); |
| 48 |
| 49 const {z} = { z : 3 }; |
| 50 assertEquals(3, z); |
| 51 |
| 52 |
| 53 for(const {x, z} = { x : 0, z : 3 }; z != 3 || x != 0;) { |
| 54 assertTrue(false); |
| 55 } |
| 56 }()); |
OLD | NEW |