Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(707)

Side by Side Diff: test/mjsunit/harmony/destructuring.js

Issue 1287063004: [es6] Implement default parameters (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix TODO Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 --harmony-arrow-functions
6 // Flags: --harmony-arrow-functions --harmony-rest-parameters 6 // Flags: --harmony-default-parameters --harmony-rest-parameters
7 7
8 (function TestObjectLiteralPattern() { 8 (function TestObjectLiteralPattern() {
9 var { x : x, y : y } = { x : 1, y : 2 }; 9 var { x : x, y : y } = { x : 1, y : 2 };
10 assertEquals(1, x); 10 assertEquals(1, x);
11 assertEquals(2, y); 11 assertEquals(2, y);
12 12
13 var {z} = { z : 3 }; 13 var {z} = { z : 3 };
14 assertEquals(3, z); 14 assertEquals(3, z);
15 15
16 16
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 716
717 var g2 = ({c, d}, {a, b}) => { return c - d + a - b; }; 717 var g2 = ({c, d}, {a, b}) => { return c - d + a - b; };
718 assertEquals(7, g2({c : 7, d : 1}, {a : 6, b : 5})); 718 assertEquals(7, g2({c : 7, d : 1}, {a : 6, b : 5}));
719 719
720 var g3 = ([{a, b}]) => { return a - b; }; 720 var g3 = ([{a, b}]) => { return a - b; };
721 assertEquals(1, g3([{a : 6, b : 5}])); 721 assertEquals(1, g3([{a : 6, b : 5}]));
722 }()); 722 }());
723 723
724 724
725 (function TestExpressionsInParameters() { 725 (function TestExpressionsInParameters() {
726 function f0(x = eval(0)) { return x }
727 assertEquals(0, f0());
726 function f1({a = eval(1)}) { return a } 728 function f1({a = eval(1)}) { return a }
727 assertEquals(1, f1({})); 729 assertEquals(1, f1({}));
728 function f2([x = eval(2)]) { return x } 730 function f2([x = eval(2)]) { return x }
729 assertEquals(2, f2([])); 731 assertEquals(2, f2([]));
730 function f3({[eval(7)]: x}) { return x } 732 function f3({[eval(7)]: x}) { return x }
731 assertEquals(3, f3({7: 3})); 733 assertEquals(3, f3({7: 3}));
732 // TODO(rossberg, caitp): Add tests for default parameters.
733 })(); 734 })();
734 735
735 736
736 (function TestParameterScoping() { 737 (function TestParameterScoping() {
737 var x = 1; 738 var x = 1;
738 739
739 function f1({a = x}) { var x = 2; return a; } 740 function f1({a = x}) { var x = 2; return a; }
740 assertEquals(1, f1({})); 741 assertEquals(1, f1({}));
741 function f2({a = x}) { function x() {}; return a; } 742 function f2({a = x}) { function x() {}; return a; }
742 assertEquals(1, f2({})); 743 assertEquals(1, f2({}));
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 assertEquals(1, f20({a: 1, b: 2})); 813 assertEquals(1, f20({a: 1, b: 2}));
813 function f21({[eval('y')]: x}) { var y = 'b'; return x; } 814 function f21({[eval('y')]: x}) { var y = 'b'; return x; }
814 assertEquals(1, f21({a: 1, b: 2})); 815 assertEquals(1, f21({a: 1, b: 2}));
815 var g20 = ({[y]: x}) => { var y = 'b'; return x; }; 816 var g20 = ({[y]: x}) => { var y = 'b'; return x; };
816 assertEquals(1, g20({a: 1, b: 2})); 817 assertEquals(1, g20({a: 1, b: 2}));
817 var g21 = ({[eval('y')]: x}) => { var y = 'b'; return x; }; 818 var g21 = ({[eval('y')]: x}) => { var y = 'b'; return x; };
818 assertEquals(1, g21({a: 1, b: 2})); 819 assertEquals(1, g21({a: 1, b: 2}));
819 })(); 820 })();
820 821
821 822
822 (function TestParameterTDZ() { 823 (function TestParameterDestructuringTDZ() {
823 function f1({a = x}, x) { return a } 824 function f1({a = x}, x) { return a }
824 assertThrows(() => f1({}, 4), ReferenceError); 825 assertThrows(() => f1({}, 4), ReferenceError);
825 assertEquals(4, f1({a: 4}, 5)); 826 assertEquals(4, f1({a: 4}, 5));
826 function f2({a = eval("x")}, x) { return a } 827 function f2({a = eval("x")}, x) { return a }
827 assertThrows(() => f2({}, 4), ReferenceError); 828 assertThrows(() => f2({}, 4), ReferenceError);
828 assertEquals(4, f2({a: 4}, 5)); 829 assertEquals(4, f2({a: 4}, 5));
829 function f3({a = eval("x")}, x) { 'use strict'; return a } 830 function f3({a = eval("x")}, x) { 'use strict'; return a }
830 assertThrows(() => f3({}, 4), ReferenceError); 831 assertThrows(() => f3({}, 4), ReferenceError);
831 assertEquals(4, f3({a: 4}, 5)); 832 assertEquals(4, f3({a: 4}, 5));
832 function f4({a = eval("'use strict'; x")}, x) { return a } 833 function f4({a = eval("'use strict'; x")}, x) { return a }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 function f4(x, {}) { x = 2; return arguments[0] } 937 function f4(x, {}) { x = 2; return arguments[0] }
937 assertEquals(7, f4(7, {})); 938 assertEquals(7, f4(7, {}));
938 function f5(x, ...a) { arguments[0] = 0; return x } 939 function f5(x, ...a) { arguments[0] = 0; return x }
939 assertEquals(6, f5(6, {})); 940 assertEquals(6, f5(6, {}));
940 function f6(x, ...a) { x = 2; return arguments[0] } 941 function f6(x, ...a) { x = 2; return arguments[0] }
941 assertEquals(6, f6(6, {})); 942 assertEquals(6, f6(6, {}));
942 function f7({a: x}) { x = 2; return arguments[0].a } 943 function f7({a: x}) { x = 2; return arguments[0].a }
943 assertEquals(5, f7({a: 5})); 944 assertEquals(5, f7({a: 5}));
944 function f8(x, ...a) { a = []; return arguments[1] } 945 function f8(x, ...a) { a = []; return arguments[1] }
945 assertEquals(6, f8(5, 6)); 946 assertEquals(6, f8(5, 6));
946 // TODO(rossberg, caitp): Add cases for default parameters.
947 }()); 947 }());
948 948
949 949
950 (function TestForInOfTDZ() { 950 (function TestForInOfTDZ() {
951 assertThrows("'use strict'; let x = {}; for (let [x, y] of {x});", ReferenceEr ror); 951 assertThrows("'use strict'; let x = {}; for (let [x, y] of {x});", ReferenceEr ror);
952 assertThrows("'use strict'; let x = {}; for (let [y, x] of {x});", ReferenceEr ror); 952 assertThrows("'use strict'; let x = {}; for (let [y, x] of {x});", ReferenceEr ror);
953 assertThrows("'use strict'; let x = {}; for (let [x, y] in {x});", ReferenceEr ror); 953 assertThrows("'use strict'; let x = {}; for (let [x, y] in {x});", ReferenceEr ror);
954 assertThrows("'use strict'; let x = {}; for (let [y, x] in {x});", ReferenceEr ror); 954 assertThrows("'use strict'; let x = {}; for (let [y, x] in {x});", ReferenceEr ror);
955 }()); 955 }());
OLDNEW
« src/parser.cc ('K') | « test/mjsunit/harmony/default-parameters-debug.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698