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

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

Issue 1240463002: [es6] Implement inner scope for functions with destructuring (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 5 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
« src/scopes.cc ('K') | « test/mjsunit/big-array-literal.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 --harmony-computed-property-names 5 // Flags: --harmony-destructuring --harmony-computed-property-names
6 // Flags: --harmony-arrow-functions 6 // Flags: --harmony-arrow-functions
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);
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 assertEquals(8, g1(7, {a : 6, b : 5})); 709 assertEquals(8, g1(7, {a : 6, b : 5}));
710 710
711 var g2 = ({c, d}, {a, b}) => { return c - d + a - b; }; 711 var g2 = ({c, d}, {a, b}) => { return c - d + a - b; };
712 assertEquals(7, g2({c : 7, d : 1}, {a : 6, b : 5})); 712 assertEquals(7, g2({c : 7, d : 1}, {a : 6, b : 5}));
713 713
714 var g3 = ([{a, b}]) => { return a - b; }; 714 var g3 = ([{a, b}]) => { return a - b; };
715 assertEquals(1, g3([{a : 6, b : 5}])); 715 assertEquals(1, g3([{a : 6, b : 5}]));
716 }()); 716 }());
717 717
718 718
719 (function TestParameterScoping() {
720 var x = 1;
721
722 function f1({a = x}) { var x = 2; return a; }
723 assertEquals(1, f1({}));
724 function f2({a = x}) { function x() {}; return a; }
725 assertEquals(1, f2({}));
726 function f3({a = x}) { 'use strict'; let x = 2; return a; }
727 assertEquals(1, f3({}));
728 function f4({a = x}) { 'use strict'; const x = 2; return a; }
729 assertEquals(1, f4({}));
730 function f5({a = x}) { 'use strict'; function x() {}; return a; }
731 assertEquals(1, f5({}));
732
733 var g1 = ({a = x}) => { var x = 2; return a; };
734 assertEquals(1, g1({}));
735 var g2 = ({a = x}) => { function x() {}; return a; };
736 assertEquals(1, g2({}));
737 var g3 = ({a = x}) => { 'use strict'; let x = 2; return a; };
738 assertEquals(1, g3({}));
739 var g4 = ({a = x}) => { 'use strict'; const x = 2; return a; };
740 assertEquals(1, g4({}));
741 var g5 = ({a = x}) => { 'use strict'; function x() {}; return a; };
742 assertEquals(1, g5({}));
743
744 var y = 'a';
745 function f6({[y]: x}) { var y = 'b'; return x; }
746 assertEquals(1, f6({a: 1, b: 2}));
747 var g6 = ({[y]: x}) => { var y = 'b'; return x; };
748 assertEquals(1, g6({a: 1, b: 2}));
749 })();
750
751
719 (function TestDuplicatesInParameters() { 752 (function TestDuplicatesInParameters() {
720 assertThrows("'use strict';function f(x,x){}", SyntaxError); 753 assertThrows("'use strict';function f(x,x){}", SyntaxError);
721 assertThrows("'use strict';function f({x,x}){}", SyntaxError); 754 assertThrows("'use strict';function f({x,x}){}", SyntaxError);
722 assertThrows("'use strict';function f(x, {x}){}", SyntaxError); 755 assertThrows("'use strict';function f(x, {x}){}", SyntaxError);
723 assertThrows("'use strict';var f = (x,x) => {};", SyntaxError); 756 assertThrows("'use strict';var f = (x,x) => {};", SyntaxError);
724 assertThrows("'use strict';var f = ({x,x}) => {};", SyntaxError); 757 assertThrows("'use strict';var f = ({x,x}) => {};", SyntaxError);
725 assertThrows("'use strict';var f = (x, {x}) => {};", SyntaxError); 758 assertThrows("'use strict';var f = (x, {x}) => {};", SyntaxError);
726 759
727 function ok(x) { var x; }; ok(); 760 function ok(x) { var x; }; ok();
728 assertThrows("function f({x}) { var x; }; f({});", SyntaxError); 761 // TODO(rossberg): Check for variable collision.
adamk 2015/07/13 19:27:31 Do you mean to take care of this in this patch or
rossberg 2015/07/14 06:24:51 I leave that for a future CL. Leaving out this che
729 assertThrows("'use strict'; function f({x}) { let x = 0; }; f({});", SyntaxErr or); 762 // assertThrows("function f({x}) { var x; }; f({});", SyntaxError);
763 // assertThrows("'use strict'; function f({x}) { let x = 0; }; f({});", Syntax Error);
730 }()); 764 }());
731 765
732 766
733 (function TestForInOfTDZ() { 767 (function TestForInOfTDZ() {
734 assertThrows("'use strict'; let x = {}; for (let [x, y] of {x});", ReferenceEr ror); 768 assertThrows("'use strict'; let x = {}; for (let [x, y] of {x});", ReferenceEr ror);
735 assertThrows("'use strict'; let x = {}; for (let [y, x] of {x});", ReferenceEr ror); 769 assertThrows("'use strict'; let x = {}; for (let [y, x] of {x});", ReferenceEr ror);
736 assertThrows("'use strict'; let x = {}; for (let [x, y] in {x});", ReferenceEr ror); 770 assertThrows("'use strict'; let x = {}; for (let [x, y] in {x});", ReferenceEr ror);
737 assertThrows("'use strict'; let x = {}; for (let [y, x] in {x});", ReferenceEr ror); 771 assertThrows("'use strict'; let x = {}; for (let [y, x] in {x});", ReferenceEr ror);
738 }()); 772 }());
OLDNEW
« src/scopes.cc ('K') | « test/mjsunit/big-array-literal.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698