OLD | NEW |
| (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 {e} = 0', | |
33 'let [e] = 0', | |
34 'let {f:e} = 0', | |
35 'let [[[], e]] = 0', | |
36 'const e = 0', | |
37 'const {e} = 0', | |
38 'const [e] = 0', | |
39 'const {f:e} = 0', | |
40 'const [[[], e]] = 0', | |
41 'function e(){}', | |
42 'function* e(){}', | |
43 ]; | |
44 | |
45 let not_lexical_e = [ | |
46 'var e', | |
47 'var {e} = 0', | |
48 'let {} = 0', | |
49 'let {e:f} = 0', | |
50 '{ function e(){} }' | |
51 ]; | |
52 | |
53 // Check that lexical declarations cannot override a simple catch parameter | |
54 for (let declaration of lexical_e) { | |
55 checkIsRedeclarationError(` | |
56 try { | |
57 throw 0; | |
58 } catch(e) { | |
59 ${declaration} | |
60 } | |
61 `); | |
62 } | |
63 | |
64 // Check that lexical declarations cannot override a complex catch parameter | |
65 for (let declaration of lexical_e) { | |
66 checkIsRedeclarationError(` | |
67 try { | |
68 throw 0; | |
69 } catch({e}) { | |
70 ${declaration} | |
71 } | |
72 `); | |
73 } | |
74 | |
75 // Check that non-lexical declarations can override a simple catch parameter | |
76 for (let declaration of not_lexical_e) { | |
77 checkIsNotRedeclarationError(` | |
78 try { | |
79 throw 0; | |
80 } catch(e) { | |
81 ${declaration} | |
82 } | |
83 `); | |
84 } | |
85 | |
86 // Check that the above error does not occur if a declaration scope is between | |
87 // the catch and the loop. | |
88 for (let declaration of lexical_e) { | |
89 checkIsNotRedeclarationError(` | |
90 try { | |
91 throw 0; | |
92 } catch(e) { | |
93 (()=>{${declaration}})(); | |
94 } | |
95 `); | |
96 | |
97 checkIsNotRedeclarationError(` | |
98 try { | |
99 throw 0; | |
100 } catch(e) { | |
101 (function(){${declaration}})(); | |
102 } | |
103 `); | |
104 } | |
OLD | NEW |