OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 // Flags: --harmony-sloppy --harmony-sloppy-let --harmony-sloppy-function --no-l egacy-const | |
adamk
2015/10/05 17:20:36
Nit: split this line into two "Flags: " lines to f
| |
6 | |
7 // Var-let conflict in a function throws, even if the var is in an eval | |
8 | |
9 let caught = false; | |
10 | |
11 // Throws at the top level of a function | |
12 try { | |
13 (function() { | |
14 let x = 1; | |
15 eval('var x = 2'); | |
adamk
2015/10/05 17:20:36
Can you add tests for function declarations (I'm n
Dan Ehrenberg
2015/10/05 18:27:14
The spec says that no hoisting out of lexical bloc
| |
16 })() | |
17 } catch (e) { | |
18 caught = true; | |
19 } | |
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); | |
123 | |
124 // Let declarations beyond a function boundary don't conflict | |
125 caught = false; | |
126 try { | |
127 let a = 1; | |
128 (function() { | |
129 eval('var a'); | |
130 })(); | |
131 } catch (e) { | |
132 caught = true; | |
133 } | |
134 assertFalse(caught); | |
135 | |
136 // var across with doesn't conflict | |
137 caught = false; | |
138 try { | |
139 (function() { | |
140 with ({x: 1}) { | |
141 eval("var x = 2;"); | |
142 } | |
143 })(); | |
144 } catch (e) { | |
145 caught = true; | |
146 } | |
147 assertFalse(caught); | |
148 | |
149 // var can still conflict with let across a with | |
150 caught = false; | |
151 try { | |
152 (function() { | |
153 let x; | |
154 with ({x: 1}) { | |
155 eval("var x = 2;"); | |
156 } | |
157 })(); | |
158 } catch (e) { | |
159 caught = true; | |
160 } | |
161 assertTrue(caught); | |
OLD | NEW |