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 | |
7 | 6 |
8 (function TestObjectLiteralPattern() { | 7 (function TestObjectLiteralPattern() { |
9 var { x : x, y : y } = { x : 1, y : 2 }; | 8 var { x : x, y : y } = { x : 1, y : 2 }; |
10 assertEquals(1, x); | 9 assertEquals(1, x); |
11 assertEquals(2, y); | 10 assertEquals(2, y); |
12 | 11 |
13 var {z} = { z : 3 }; | 12 var {z} = { z : 3 }; |
14 assertEquals(3, z); | 13 assertEquals(3, z); |
15 | 14 |
16 | 15 |
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 var o = { __proto__:null, 'a1':1, 'b2':2 }; | 679 var o = { __proto__:null, 'a1':1, 'b2':2 }; |
681 var sx = ''; | 680 var sx = ''; |
682 var sy = ''; | 681 var sy = ''; |
683 for (var [x,y] in o) { | 682 for (var [x,y] in o) { |
684 sx += x; | 683 sx += x; |
685 sy += y; | 684 sy += y; |
686 } | 685 } |
687 assertEquals('ab', sx); | 686 assertEquals('ab', sx); |
688 assertEquals('12', sy); | 687 assertEquals('12', sy); |
689 }()); | 688 }()); |
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 |