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

Side by Side Diff: test/mjsunit/es6/catch-parameter-redeclaration.js

Issue 2109733003: Add errors for declarations which conflict with catch parameters. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: correct loop index 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
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 lexical_e = [
31 'let e',
32 'let f, g, e',
33 'let [f] = [], [] = [], e = e, h',
34 'let {e} = 0',
35 'let {f, e} = 0',
36 'let {f, g} = 0, {e} = 0',
37 'let {f = 0, e = 1} = 0',
38 'let [e] = 0',
39 'let [f, e] = 0',
40 'let {f:e} = 0',
41 'let [[[], e]] = 0',
42 'const e = 0',
43 'const f = 0, g = 0, e = 0',
44 'const {e} = 0',
45 'const [e] = 0',
46 'const {f:e} = 0',
47 'const [[[], e]] = 0',
48 'function e(){}',
49 'function* e(){}',
50 ];
51
52 let not_lexical_e = [
53 'var e',
54 'var f, e',
55 'var {e} = 0',
56 'let {} = 0',
57 'let {e:f} = 0',
58 '{ function e(){} }'
59 ];
60
61 // Check that lexical declarations cannot override a simple catch parameter
62 for (let declaration of lexical_e) {
63 checkIsRedeclarationError(`
64 try {
65 throw 0;
66 } catch(e) {
67 ${declaration}
68 }
69 `);
70 }
71
72 // Check that lexical declarations cannot override a complex catch parameter
73 for (let declaration of lexical_e) {
74 checkIsRedeclarationError(`
75 try {
76 throw 0;
77 } catch({e}) {
78 ${declaration}
79 }
80 `);
81 }
82
83 // Check that non-lexical declarations can override a simple catch parameter
84 for (let declaration of not_lexical_e) {
85 checkIsNotRedeclarationError(`
86 try {
87 throw 0;
88 } catch(e) {
89 ${declaration}
90 }
91 `);
92 }
93
94 // Check that the above error does not occur if a declaration scope is between
95 // the catch and the loop.
96 for (let declaration of lexical_e) {
97 checkIsNotRedeclarationError(`
98 try {
99 throw 0;
100 } catch(e) {
101 (()=>{${declaration}})();
102 }
103 `);
104
105 checkIsNotRedeclarationError(`
106 try {
107 throw 0;
108 } catch(e) {
109 (function(){${declaration}})();
110 }
111 `);
112 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698