| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 TestAll('f(); let x; function f() { x += 1; }'); | 74 TestAll('f(); let x; function f() { x += 1; }'); |
| 75 TestAll('f(); let x; function f() { ++x; }'); | 75 TestAll('f(); let x; function f() { ++x; }'); |
| 76 TestAll('f(); let x; function f() { x++; }'); | 76 TestAll('f(); let x; function f() { x++; }'); |
| 77 | 77 |
| 78 TestAll('f()(); let x; function f() { return function() { return x + 1; } }'); | 78 TestAll('f()(); let x; function f() { return function() { return x + 1; } }'); |
| 79 TestAll('f()(); let x; function f() { return function() { x = 1; } }'); | 79 TestAll('f()(); let x; function f() { return function() { x = 1; } }'); |
| 80 TestAll('f()(); let x; function f() { return function() { x += 1; } }'); | 80 TestAll('f()(); let x; function f() { return function() { x += 1; } }'); |
| 81 TestAll('f()(); let x; function f() { return function() { ++x; } }'); | 81 TestAll('f()(); let x; function f() { return function() { ++x; } }'); |
| 82 TestAll('f()(); let x; function f() { return function() { x++; } }'); | 82 TestAll('f()(); let x; function f() { return function() { x++; } }'); |
| 83 | 83 |
| 84 // Use in before initialization with a dynamic lookup. | 84 // Use before initialization with a dynamic lookup. |
| 85 TestAll('eval("x + 1;"); let x;'); | 85 TestAll('eval("x + 1;"); let x;'); |
| 86 TestAll('eval("x = 1;"); let x;'); | 86 TestAll('eval("x = 1;"); let x;'); |
| 87 TestAll('eval("x += 1;"); let x;'); | 87 TestAll('eval("x += 1;"); let x;'); |
| 88 TestAll('eval("++x;"); let x;'); | 88 TestAll('eval("++x;"); let x;'); |
| 89 TestAll('eval("x++;"); let x;'); | 89 TestAll('eval("x++;"); let x;'); |
| 90 | 90 |
| 91 // Use before initialization with check for eval-shadowed bindings. |
| 92 TestAll('function f() { eval("var y = 2;"); x + 1; }; f(); let x;'); |
| 93 TestAll('function f() { eval("var y = 2;"); x = 1; }; f(); let x;'); |
| 94 TestAll('function f() { eval("var y = 2;"); x += 1; }; f(); let x;'); |
| 95 TestAll('function f() { eval("var y = 2;"); ++x; }; f(); let x;'); |
| 96 TestAll('function f() { eval("var y = 2;"); x++; }; f(); let x;'); |
| 97 |
| 91 // Test that variables introduced by function declarations are created and | 98 // Test that variables introduced by function declarations are created and |
| 92 // initialized upon entering a function / block scope. | 99 // initialized upon entering a function / block scope. |
| 93 function f() { | 100 function f() { |
| 94 { | 101 { |
| 95 assertEquals(2, g1()); | 102 assertEquals(2, g1()); |
| 96 assertEquals(2, eval("g1()")); | 103 assertEquals(2, eval("g1()")); |
| 97 | 104 |
| 98 // block scoped function declaration | 105 // block scoped function declaration |
| 99 function g1() { | 106 function g1() { |
| 100 return 2; | 107 return 2; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 129 throw 2; | 136 throw 2; |
| 130 } catch(b) { | 137 } catch(b) { |
| 131 n = h; | 138 n = h; |
| 132 function h() { | 139 function h() { |
| 133 return b + c; | 140 return b + c; |
| 134 } | 141 } |
| 135 let b = 3; | 142 let b = 3; |
| 136 } | 143 } |
| 137 assertEquals(5, n()); | 144 assertEquals(5, n()); |
| 138 } | 145 } |
| 146 |
| 147 // Test that resolution of let bound variables works with scopes that call eval. |
| 148 function outer() { |
| 149 function middle() { |
| 150 function inner() { |
| 151 return x; |
| 152 } |
| 153 eval("1 + 1"); |
| 154 return x + inner(); |
| 155 } |
| 156 |
| 157 let x = 1; |
| 158 return middle(); |
| 159 } |
| 160 |
| 161 assertEquals(2, outer()); |
| OLD | NEW |