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 | |
6 | |
7 // Var-let conflict in a function throws, even if the var is in an eval | |
8 | |
9 // Throws at the top level of a function | |
10 assertThrows(function() { | |
11 let x = 1; | |
12 eval('const x = 2'); | |
13 }, TypeError); | |
14 | |
15 // If the eval is in its own block scope, throws | |
16 assertThrows(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 { | |
24 let x = 1; | |
25 eval('const x = 2'); | |
26 } | |
27 }, TypeError); | |
28 | |
29 // Legal if the let is no longer visible | |
30 assertDoesNotThrow(function() { | |
31 { | |
32 let x = 1; | |
33 } | |
34 eval('const x = 2'); | |
35 }); | |
36 | |
37 // In global scope | |
38 let caught = false; | |
39 try { | |
40 let z = 1; | |
41 eval('const z = 2'); | |
42 } catch (e) { | |
43 caught = true; | |
44 } | |
45 assertTrue(caught); | |
46 | |
47 // Let declarations beyond a function boundary don't conflict | |
48 caught = false; | |
49 try { | |
50 let a = 1; | |
51 (function() { | |
52 eval('const a'); | |
53 })(); | |
54 } catch (e) { | |
55 caught = true; | |
56 } | |
57 assertFalse(caught); | |
58 | |
59 // var across with doesn't conflict | |
60 caught = false; | |
61 try { | |
62 (function() { | |
63 with ({x: 1}) { | |
64 eval("const x = 2;"); | |
65 } | |
66 })(); | |
67 } catch (e) { | |
68 caught = true; | |
69 } | |
70 assertFalse(caught); | |
71 | |
72 // var can still conflict with let across a with | |
73 caught = false; | |
74 try { | |
75 (function() { | |
76 let x; | |
77 with ({x: 1}) { | |
78 eval("const x = 2;"); | |
79 } | |
80 })(); | |
81 } catch (e) { | |
82 caught = true; | |
83 } | |
84 assertTrue(caught); | |
OLD | NEW |