| 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 // Var-let conflict in a function throws, even if the var is in an eval | 5 // Var-let conflict in a function throws, even if the var is in an eval |
| 6 | 6 |
| 7 // Throws at the top level of a function | 7 // Throws at the top level of a function |
| 8 assertThrows(function() { | 8 assertThrows(function() { |
| 9 let x = 1; | 9 let x = 1; |
| 10 eval('var x'); | 10 eval('var x'); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 }, SyntaxError); | 54 }, SyntaxError); |
| 55 | 55 |
| 56 // Legal if the const is no longer visible | 56 // Legal if the const is no longer visible |
| 57 assertDoesNotThrow(function() { | 57 assertDoesNotThrow(function() { |
| 58 { | 58 { |
| 59 const x = 1; | 59 const x = 1; |
| 60 } | 60 } |
| 61 eval('var x'); | 61 eval('var x'); |
| 62 }); | 62 }); |
| 63 | 63 |
| 64 // The same should work for lexical function declarations: |
| 65 // If the const is in its own block scope, with the eval, throws |
| 66 assertThrows(function() { |
| 67 { |
| 68 function x() {} |
| 69 eval('var x'); |
| 70 } |
| 71 }, SyntaxError); |
| 72 |
| 73 // If the eval is in its own block scope, throws |
| 74 assertThrows(function() { |
| 75 { |
| 76 function y() {} |
| 77 { eval('var y'); } |
| 78 } |
| 79 }, SyntaxError); |
| 80 |
| 64 // In global scope | 81 // In global scope |
| 65 let caught = false; | 82 let caught = false; |
| 66 try { | 83 try { |
| 67 let z = 1; | 84 let z = 1; |
| 68 eval('var z'); | 85 eval('var z'); |
| 69 } catch (e) { | 86 } catch (e) { |
| 70 caught = true; | 87 caught = true; |
| 71 } | 88 } |
| 72 assertTrue(caught); | 89 assertTrue(caught); |
| 73 | 90 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 (function() { | 146 (function() { |
| 130 { | 147 { |
| 131 let x = 1; | 148 let x = 1; |
| 132 eval('{ function x() {} }'); | 149 eval('{ function x() {} }'); |
| 133 } | 150 } |
| 134 })(); | 151 })(); |
| 135 } catch (e) { | 152 } catch (e) { |
| 136 caught = true; | 153 caught = true; |
| 137 } | 154 } |
| 138 assertFalse(caught); | 155 assertFalse(caught); |
| OLD | NEW |