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 // Flags: --legacy-const |
6 | 7 |
7 // Var-let conflict in a function throws, even if the var is in an eval | 8 // Legacy-const-let conflict in a function throws, even if the legacy const |
| 9 // is in an eval |
8 | 10 |
9 // Throws at the top level of a function | 11 // Throws at the top level of a function |
10 assertThrows(function() { | 12 assertThrows(function() { |
11 let x = 1; | 13 let x = 1; |
12 eval('const x = 2'); | 14 eval('const x = 2'); |
13 }, TypeError); | 15 }, TypeError); |
14 | 16 |
15 // If the eval is in its own block scope, throws | 17 // If the eval is in its own block scope, throws |
16 assertThrows(function() { | 18 assertThrows(function() { |
17 let y = 1; | 19 let y = 1; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 try { | 51 try { |
50 let a = 1; | 52 let a = 1; |
51 (function() { | 53 (function() { |
52 eval('const a'); | 54 eval('const a'); |
53 })(); | 55 })(); |
54 } catch (e) { | 56 } catch (e) { |
55 caught = true; | 57 caught = true; |
56 } | 58 } |
57 assertFalse(caught); | 59 assertFalse(caught); |
58 | 60 |
59 // var across with doesn't conflict | 61 // legacy const across with doesn't conflict |
60 caught = false; | 62 caught = false; |
61 try { | 63 try { |
62 (function() { | 64 (function() { |
63 with ({x: 1}) { | 65 with ({x: 1}) { |
64 eval("const x = 2;"); | 66 eval("const x = 2;"); |
65 } | 67 } |
66 })(); | 68 })(); |
67 } catch (e) { | 69 } catch (e) { |
68 caught = true; | 70 caught = true; |
69 } | 71 } |
70 assertFalse(caught); | 72 assertFalse(caught); |
71 | 73 |
72 // var can still conflict with let across a with | 74 // legacy const can still conflict with let across a with |
73 caught = false; | 75 caught = false; |
74 try { | 76 try { |
75 (function() { | 77 (function() { |
76 let x; | 78 let x; |
77 with ({x: 1}) { | 79 with ({x: 1}) { |
78 eval("const x = 2;"); | 80 eval("const x = 2;"); |
79 } | 81 } |
80 })(); | 82 })(); |
81 } catch (e) { | 83 } catch (e) { |
82 caught = true; | 84 caught = true; |
83 } | 85 } |
84 assertTrue(caught); | 86 assertTrue(caught); |
OLD | NEW |