OLD | NEW |
---|---|
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-sloppy --harmony-sloppy-let --harmony-sloppy-function --no-l egacy-const | 5 // Flags: --harmony-sloppy --harmony-sloppy-let --harmony-sloppy-function --no-l egacy-const |
6 | 6 |
7 // Var-let conflict in a function throws, even if the var is in an eval | 7 // Var-let conflict in a function throws, even if the var is in an eval |
8 | 8 |
9 // Throws at the top level of a function | |
10 assertThrows(function() { | |
11 let x = 1; | |
12 eval('var x'); | |
Dan Ehrenberg
2015/11/12 23:41:57
How about leaving in the previous tests and adding
adamk
2015/11/12 23:45:17
What do you feel the initializer versions add to t
Dan Ehrenberg
2015/11/12 23:53:18
Well, my thinking is rather mechanical:
1. You fou
adamk
2015/11/13 07:06:01
All I was thinking was that we desugar "var x = 1"
adamk
2015/11/13 20:59:07
After more discussion offline, I convinced Dan tha
| |
13 }, TypeError); | |
14 | |
15 // If the eval is in its own block scope, throws | |
16 assertThrows(function() { | |
17 let y = 1; | |
18 { eval('var y'); } | |
19 }, TypeError); | |
20 | |
21 // If the let is in its own block scope, with the eval, throws | |
22 assertThrows(function() { | |
23 { | |
24 let x = 1; | |
25 eval('var x'); | |
26 } | |
27 }, TypeError); | |
28 | |
29 // Legal if the let is no longer visible | |
30 assertDoesNotThrow(function() { | |
31 { | |
32 let x = 1; | |
33 } | |
34 eval('var x'); | |
35 }); | |
36 | |
37 // All the same works for const: | |
38 // Throws at the top level of a function | |
39 assertThrows(function() { | |
40 const x = 1; | |
41 eval('var x'); | |
42 }, TypeError); | |
43 | |
44 // If the eval is in its own block scope, throws | |
45 assertThrows(function() { | |
46 const y = 1; | |
47 { eval('var y'); } | |
48 }, TypeError); | |
49 | |
50 // If the const is in its own block scope, with the eval, throws | |
51 assertThrows(function() { | |
52 { | |
53 const x = 1; | |
54 eval('var x'); | |
55 } | |
56 }, TypeError); | |
57 | |
58 // Legal if the const is no longer visible | |
59 assertDoesNotThrow(function() { | |
60 { | |
61 const x = 1; | |
62 } | |
63 eval('var x'); | |
64 }); | |
65 | |
66 // In global scope | |
9 let caught = false; | 67 let caught = false; |
10 | |
11 // Throws at the top level of a function | |
12 try { | 68 try { |
13 (function() { | 69 let z = 1; |
14 let x = 1; | 70 eval('var z'); |
15 eval('var x = 2'); | |
16 })() | |
17 } catch (e) { | 71 } catch (e) { |
18 caught = true; | 72 caught = true; |
19 } | 73 } |
20 assertTrue(caught); | |
21 | |
22 // If the eval is in its own block scope, throws | |
23 caught = false; | |
24 try { | |
25 (function() { | |
26 let y = 1; | |
27 { eval('var y = 2'); } | |
28 })() | |
29 } catch (e) { | |
30 caught = true; | |
31 } | |
32 assertTrue(caught); | |
33 | |
34 // If the let is in its own block scope, with the eval, throws | |
35 caught = false | |
36 try { | |
37 (function() { | |
38 { | |
39 let x = 1; | |
40 eval('var x = 2'); | |
41 } | |
42 })(); | |
43 } catch (e) { | |
44 caught = true; | |
45 } | |
46 assertTrue(caught); | |
47 | |
48 // Legal if the let is no longer visible | |
49 caught = false | |
50 try { | |
51 (function() { | |
52 { | |
53 let x = 1; | |
54 } | |
55 eval('var x = 2'); | |
56 })(); | |
57 } catch (e) { | |
58 caught = true; | |
59 } | |
60 assertFalse(caught); | |
61 | |
62 // All the same works for const: | |
63 // Throws at the top level of a function | |
64 try { | |
65 (function() { | |
66 const x = 1; | |
67 eval('var x = 2'); | |
68 })(); | |
69 } catch (e) { | |
70 caught = true; | |
71 } | |
72 assertTrue(caught); | |
73 | |
74 // If the eval is in its own block scope, throws | |
75 caught = false; | |
76 try { | |
77 (function() { | |
78 const y = 1; | |
79 { eval('var y = 2'); } | |
80 })(); | |
81 } catch (e) { | |
82 caught = true; | |
83 } | |
84 assertTrue(caught); | |
85 | |
86 // If the const is in its own block scope, with the eval, throws | |
87 caught = false | |
88 try { | |
89 (function() { | |
90 { | |
91 const x = 1; | |
92 eval('var x = 2'); | |
93 } | |
94 })(); | |
95 } catch (e) { | |
96 caught = true; | |
97 } | |
98 assertTrue(caught); | |
99 | |
100 // Legal if the const is no longer visible | |
101 caught = false | |
102 try { | |
103 (function() { | |
104 { | |
105 const x = 1; | |
106 } | |
107 eval('var x = 2'); | |
108 })(); | |
109 } catch (e) { | |
110 caught = true; | |
111 } | |
112 assertFalse(caught); | |
113 | |
114 // In global scope | |
115 caught = false; | |
116 try { | |
117 let z = 1; | |
118 eval('var z = 2'); | |
119 } catch (e) { | |
120 caught = true; | |
121 } | |
122 assertTrue(caught); | 74 assertTrue(caught); |
123 | 75 |
124 // Let declarations beyond a function boundary don't conflict | 76 // Let declarations beyond a function boundary don't conflict |
125 caught = false; | 77 caught = false; |
126 try { | 78 try { |
127 let a = 1; | 79 let a = 1; |
128 (function() { | 80 (function() { |
129 eval('var a'); | 81 eval('var a'); |
130 })(); | 82 })(); |
131 } catch (e) { | 83 } catch (e) { |
132 caught = true; | 84 caught = true; |
133 } | 85 } |
134 assertFalse(caught); | 86 assertFalse(caught); |
135 | 87 |
136 // var across with doesn't conflict | 88 // var across with doesn't conflict |
137 caught = false; | 89 caught = false; |
138 try { | 90 try { |
139 (function() { | 91 (function() { |
140 with ({x: 1}) { | 92 with ({x: 1}) { |
141 eval("var x = 2;"); | 93 eval("var x"); |
142 } | 94 } |
143 })(); | 95 })(); |
144 } catch (e) { | 96 } catch (e) { |
145 caught = true; | 97 caught = true; |
146 } | 98 } |
147 assertFalse(caught); | 99 assertFalse(caught); |
148 | 100 |
149 // var can still conflict with let across a with | 101 // var can still conflict with let across a with |
150 caught = false; | 102 caught = false; |
151 try { | 103 try { |
152 (function() { | 104 (function() { |
153 let x; | 105 let x; |
154 with ({x: 1}) { | 106 with ({x: 1}) { |
155 eval("var x = 2;"); | 107 eval("var x"); |
156 } | 108 } |
157 })(); | 109 })(); |
158 } catch (e) { | 110 } catch (e) { |
159 caught = true; | 111 caught = true; |
160 } | 112 } |
161 assertTrue(caught); | 113 assertTrue(caught); |
162 | 114 |
163 // Functions declared in eval also conflict | 115 // Functions declared in eval also conflict |
164 caught = false | 116 caught = false |
165 try { | 117 try { |
(...skipping 16 matching lines...) Expand all Loading... | |
182 { | 134 { |
183 let x = 1; | 135 let x = 1; |
184 eval('{ function x() {} }'); | 136 eval('{ function x() {} }'); |
185 } | 137 } |
186 })(); | 138 })(); |
187 } catch (e) { | 139 } catch (e) { |
188 caught = true; | 140 caught = true; |
189 } | 141 } |
190 // TODO(littledan): switch to assertTrue when bug is fixed | 142 // TODO(littledan): switch to assertTrue when bug is fixed |
191 assertTrue(caught); | 143 assertTrue(caught); |
OLD | NEW |