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 // Flags: --harmony-arrow-functions |
6 | 7 |
7 (function TestObjectLiteralPattern() { | 8 (function TestObjectLiteralPattern() { |
8 var { x : x, y : y } = { x : 1, y : 2 }; | 9 var { x : x, y : y } = { x : 1, y : 2 }; |
9 assertEquals(1, x); | 10 assertEquals(1, x); |
10 assertEquals(2, y); | 11 assertEquals(2, y); |
11 | 12 |
12 var {z} = { z : 3 }; | 13 var {z} = { z : 3 }; |
13 assertEquals(3, z); | 14 assertEquals(3, z); |
14 | 15 |
15 | 16 |
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 var o = { __proto__:null, 'a1':1, 'b2':2 }; | 680 var o = { __proto__:null, 'a1':1, 'b2':2 }; |
680 var sx = ''; | 681 var sx = ''; |
681 var sy = ''; | 682 var sy = ''; |
682 for (var [x,y] in o) { | 683 for (var [x,y] in o) { |
683 sx += x; | 684 sx += x; |
684 sy += y; | 685 sy += y; |
685 } | 686 } |
686 assertEquals('ab', sx); | 687 assertEquals('ab', sx); |
687 assertEquals('12', sy); | 688 assertEquals('12', sy); |
688 }()); | 689 }()); |
| 690 |
| 691 |
| 692 (function TestParameters() { |
| 693 function f({a, b}) { return a - b; } |
| 694 assertEquals(1, f({a : 6, b : 5})); |
| 695 |
| 696 function f1(c, {a, b}) { return c + a - b; } |
| 697 assertEquals(8, f1(7, {a : 6, b : 5})); |
| 698 |
| 699 function f2({c, d}, {a, b}) { return c - d + a - b; } |
| 700 assertEquals(7, f2({c : 7, d : 1}, {a : 6, b : 5})); |
| 701 |
| 702 function f3([{a, b}]) { return a - b; } |
| 703 assertEquals(1, f3([{a : 6, b : 5}])); |
| 704 |
| 705 var g = ({a, b}) => { return a - b; }; |
| 706 assertEquals(1, g({a : 6, b : 5})); |
| 707 |
| 708 var g1 = (c, {a, b}) => { return c + a - b; }; |
| 709 assertEquals(8, g1(7, {a : 6, b : 5})); |
| 710 |
| 711 var g2 = ({c, d}, {a, b}) => { return c - d + a - b; }; |
| 712 assertEquals(7, g2({c : 7, d : 1}, {a : 6, b : 5})); |
| 713 |
| 714 var g3 = ([{a, b}]) => { return a - b; }; |
| 715 assertEquals(1, g3([{a : 6, b : 5}])); |
| 716 }()); |
| 717 |
| 718 |
| 719 (function TestDuplicatesInParameters() { |
| 720 assertThrows("'use strict';function f(x,x){}", SyntaxError); |
| 721 assertThrows("'use strict';function f({x,x}){}", SyntaxError); |
| 722 assertThrows("'use strict';function f(x, {x}){}", SyntaxError); |
| 723 assertThrows("'use strict';var f = (x,x) => {};", SyntaxError); |
| 724 assertThrows("'use strict';var f = ({x,x}) => {};", SyntaxError); |
| 725 assertThrows("'use strict';var f = (x, {x}) => {};", SyntaxError); |
| 726 |
| 727 function ok(x) { var x; }; ok(); |
| 728 assertThrows("function f({x}) { var x; }; f({});", SyntaxError); |
| 729 assertThrows("'use strict'; function f({x}) { let x = 0; }; f({});", SyntaxErr
or); |
| 730 }()); |
OLD | NEW |