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 --harmony-computed-property-names | 5 // Flags: --harmony-destructuring --harmony-computed-property-names |
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); |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 'use strict'; | 616 'use strict'; |
617 log = []; | 617 log = []; |
618 let [{x, y}, [a, b]] = f(); | 618 let [{x, y}, [a, b]] = f(); |
619 assertSame(1, x); | 619 assertSame(1, x); |
620 assertSame(2, y); | 620 assertSame(2, y); |
621 assertSame(42, a); | 621 assertSame(42, a); |
622 assertSame(27, b); | 622 assertSame(27, b); |
623 assertArrayEquals(["1", "2"], log); | 623 assertArrayEquals(["1", "2"], log); |
624 }()); | 624 }()); |
625 }()); | 625 }()); |
| 626 |
| 627 |
| 628 (function TestForEachLexical() { |
| 629 'use strict'; |
| 630 let a = [{x:1, y:-1}, {x:2,y:-2}, {x:3,y:-3}]; |
| 631 let sumX = 0; |
| 632 let sumY = 0; |
| 633 let fs = []; |
| 634 for (let {x,y} of a) { |
| 635 sumX += x; |
| 636 sumY += y; |
| 637 fs.push({fx : function() { return x; }, fy : function() { return y }}); |
| 638 } |
| 639 assertSame(6, sumX); |
| 640 assertSame(-6, sumY); |
| 641 assertSame(3, fs.length); |
| 642 for (let i = 0; i < fs.length; i++) { |
| 643 let {fx,fy} = fs[i]; |
| 644 assertSame(i+1, fx()); |
| 645 assertSame(-(i+1), fy()); |
| 646 } |
| 647 |
| 648 var o = { 'a1':1, 'b2':2 }; |
| 649 o.__proto__ = null; |
| 650 let sx = ''; |
| 651 let sy = ''; |
| 652 for (let [x,y] in o) { |
| 653 sx += x; |
| 654 sy += y; |
| 655 } |
| 656 assertEquals('ab', sx); |
| 657 assertEquals('12', sy); |
| 658 }()); |
OLD | NEW |