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

Side by Side Diff: test/mjsunit/es6/for-each-in-catch.js

Issue 2119933002: Reland of Add errors for declarations which conflict with catch parameters. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fixes per Adam Created 4 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
« no previous file with comments | « test/mjsunit/es6/catch-parameter-redeclaration.js ('k') | test/test262/test262.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 function checkIsRedeclarationError(code) {
6 try {
7 eval(`
8 checkIsRedeclarationError : {
9 break checkIsRedeclarationError;
10 ${code}
11 }
12 `);
13 assertUnreachable();
14 } catch(e) {
15 assertInstanceof(e, SyntaxError );
16 assertTrue( e.toString().indexOf("has already been declared") >= 0 );
17 }
18 }
19
20 function checkIsNotRedeclarationError(code) {
21 assertDoesNotThrow(()=>eval(`
22 checkIsNotRedeclarationError_label : {
23 break checkIsNotRedeclarationError_label;
24 ${code}
25 }
26 `));
27 }
28
29
30 let var_e = [
31 'var e',
32 'var {e}',
33 'var {f, e}',
34 'var [e]',
35 'var {f:e}',
36 'var [[[], e]]'
37 ];
38
39 let not_var_e = [
40 'var f',
41 'var {}',
42 'var {e:f}',
43 'e',
44 '{e}',
45 'let e',
46 'const e',
47 'let {e}',
48 'const {e}',
49 'let [e]',
50 'const [e]',
51 'let {f:e}',
52 'const {f:e}'
53 ];
54
55 // Check that `for (var ... of ...)` cannot redeclare a simple catch variable
56 // but `for (var ... in ...)` can.
57 for (let binding of var_e) {
58 checkIsRedeclarationError(`
59 try {
60 throw 0;
61 } catch(e) {
62 for (${binding} of []);
63 }
64 `);
65
66 checkIsNotRedeclarationError(`
67 try {
68 throw 0;
69 } catch(e) {
70 for (${binding} in []);
71 }
72 `);
73 }
74
75 // Check that the above error occurs even for nested catches.
76 for (let binding of var_e) {
77 checkIsRedeclarationError(`
78 try {
79 throw 0;
80 } catch(e) {
81 try {
82 throw 1;
83 } catch(f) {
84 try {
85 throw 2;
86 } catch({}) {
87 for (${binding} of []);
88 }
89 }
90 }
91 `);
92
93 checkIsNotRedeclarationError(`
94 try {
95 throw 0;
96 } catch(e) {
97 try {
98 throw 1;
99 } catch(f) {
100 try {
101 throw 2;
102 } catch({}) {
103 for (${binding} in []);
104 }
105 }
106 }
107 `);
108 }
109
110 // Check that the above error does not occur if a declaration scope is between
111 // the catch and the loop.
112 for (let binding of var_e) {
113 checkIsNotRedeclarationError(`
114 try {
115 throw 0;
116 } catch(e) {
117 (()=>{for (${binding} of []);})();
118 }
119 `);
120
121 checkIsNotRedeclarationError(`
122 try {
123 throw 0;
124 } catch(e) {
125 (function(){for (${binding} of []);})();
126 }
127 `);
128 }
129
130 // Check that there is no error when not declaring a var named e.
131 for (let binding of not_var_e) {
132 checkIsNotRedeclarationError(`
133 try {
134 throw 0;
135 } catch(e) {
136 for (${binding} of []);
137 }
138 `);
139 }
140
141 // Check that there is an error for both for-in and for-of when redeclaring
142 // a non-simple catch parameter
143 for (let binding of var_e) {
144 checkIsRedeclarationError(`
145 try {
146 throw 0;
147 } catch({e}) {
148 for (${binding} of []);
149 }
150 `);
151
152 checkIsRedeclarationError(`
153 try {
154 throw 0;
155 } catch({e}) {
156 for (${binding} in []);
157 }
158 `);
159 }
160
161 // Check that the above error occurs even for nested catches.
162 for (let binding of var_e) {
163 checkIsRedeclarationError(`
164 try {
165 throw 0;
166 } catch({e}) {
167 try {
168 throw 1;
169 } catch(f) {
170 try {
171 throw 2;
172 } catch({}) {
173 for (${binding} of []);
174 }
175 }
176 }
177 `);
178
179 checkIsRedeclarationError(`
180 try {
181 throw 0;
182 } catch({e}) {
183 try {
184 throw 1;
185 } catch(f) {
186 try {
187 throw 2;
188 } catch({}) {
189 for (${binding} in []);
190 }
191 }
192 }
193 `);
194 }
OLDNEW
« no previous file with comments | « test/mjsunit/es6/catch-parameter-redeclaration.js ('k') | test/test262/test262.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698