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 | 5 // Flags: --harmony-sloppy --harmony-sloppy-let --harmony-sloppy-function |
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 let caught = false; | 9 // Throws at the top level of a function |
| 10 assertThrows(function() { |
| 11 let x = 1; |
| 12 eval('const x = 2'); |
| 13 }, TypeError); |
10 | 14 |
11 // Throws at the top level of a function | 15 // If the eval is in its own block scope, throws |
12 try { | 16 assertThrows(function() { |
13 (function() { | 17 let y = 1; |
| 18 { eval('const y = 2'); } |
| 19 }, TypeError); |
| 20 |
| 21 // If the let is in its own block scope, with the eval, throws |
| 22 assertThrows(function() { |
| 23 { |
14 let x = 1; | 24 let x = 1; |
15 eval('const x = 2'); | 25 eval('const x = 2'); |
16 })() | 26 } |
17 } catch (e) { | 27 }, TypeError); |
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('const 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('const x = 2'); | |
41 } | |
42 })(); | |
43 } catch (e) { | |
44 caught = true; | |
45 } | |
46 assertTrue(caught); | |
47 | 28 |
48 // Legal if the let is no longer visible | 29 // Legal if the let is no longer visible |
49 caught = false | 30 assertDoesNotThrow(function() { |
50 try { | 31 { |
51 (function() { | 32 let x = 1; |
52 { | 33 } |
53 let x = 1; | 34 eval('const x = 2'); |
54 } | 35 }); |
55 eval('const x = 2'); | |
56 })(); | |
57 } catch (e) { | |
58 caught = true; | |
59 } | |
60 assertFalse(caught); | |
61 | 36 |
62 // In global scope | 37 // In global scope |
63 caught = false; | 38 let caught = false; |
64 try { | 39 try { |
65 let z = 1; | 40 let z = 1; |
66 eval('const z = 2'); | 41 eval('const z = 2'); |
67 } catch (e) { | 42 } catch (e) { |
68 caught = true; | 43 caught = true; |
69 } | 44 } |
70 assertTrue(caught); | 45 assertTrue(caught); |
71 | 46 |
72 // Let declarations beyond a function boundary don't conflict | 47 // Let declarations beyond a function boundary don't conflict |
73 caught = false; | 48 caught = false; |
(...skipping 26 matching lines...) Expand all Loading... |
100 (function() { | 75 (function() { |
101 let x; | 76 let x; |
102 with ({x: 1}) { | 77 with ({x: 1}) { |
103 eval("const x = 2;"); | 78 eval("const x = 2;"); |
104 } | 79 } |
105 })(); | 80 })(); |
106 } catch (e) { | 81 } catch (e) { |
107 caught = true; | 82 caught = true; |
108 } | 83 } |
109 assertTrue(caught); | 84 assertTrue(caught); |
OLD | NEW |