| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 TestAll('f(); let x; function f() { x++; }'); | 78 TestAll('f(); let x; function f() { x++; }'); |
| 79 TestAll('f(); const x = 1; function f() { return x; }'); | 79 TestAll('f(); const x = 1; function f() { return x; }'); |
| 80 | 80 |
| 81 TestAll('f()(); let x; function f() { return function() { return x + 1; } }'); | 81 TestAll('f()(); let x; function f() { return function() { return x + 1; } }'); |
| 82 TestAll('f()(); let x; function f() { return function() { x = 1; } }'); | 82 TestAll('f()(); let x; function f() { return function() { x = 1; } }'); |
| 83 TestAll('f()(); let x; function f() { return function() { x += 1; } }'); | 83 TestAll('f()(); let x; function f() { return function() { x += 1; } }'); |
| 84 TestAll('f()(); let x; function f() { return function() { ++x; } }'); | 84 TestAll('f()(); let x; function f() { return function() { ++x; } }'); |
| 85 TestAll('f()(); let x; function f() { return function() { x++; } }'); | 85 TestAll('f()(); let x; function f() { return function() { x++; } }'); |
| 86 TestAll('f()(); const x = 1; function f() { return function() { return x; } }'); | 86 TestAll('f()(); const x = 1; function f() { return function() { return x; } }'); |
| 87 | 87 |
| 88 // Use before initialization with a dynamic lookup. | 88 for (var kw of ['let', 'const']) { |
| 89 TestAll('eval("x + 1;"); let x;'); | 89 // Use before initialization with a dynamic lookup. |
| 90 TestAll('eval("x = 1;"); let x;'); | 90 TestAll(`eval("x"); ${kw} x = 2;`); |
| 91 TestAll('eval("x += 1;"); let x;'); | 91 TestAll(`eval("x + 1;"); ${kw} x = 2;`); |
| 92 TestAll('eval("++x;"); let x;'); | 92 TestAll(`eval("x = 1;"); ${kw} x = 2;`); |
| 93 TestAll('eval("x++;"); let x;'); | 93 TestAll(`eval("x += 1;"); ${kw} x = 2;`); |
| 94 TestAll('eval("x"); const x = 1;'); | 94 TestAll(`eval("++x;"); ${kw} x = 2;`); |
| 95 TestAll(`eval("x++;"); ${kw} x = 2;`); |
| 95 | 96 |
| 96 // Use before initialization with check for eval-shadowed bindings. | 97 // Use before initialization with check for eval-shadowed bindings. |
| 97 TestAll('function f() { eval("var y = 2;"); x + 1; }; f(); let x;'); | 98 TestAll(`function f() { eval("var y = 2;"); x + 1; }; f(); ${kw} x = 2;`); |
| 98 TestAll('function f() { eval("var y = 2;"); x = 1; }; f(); let x;'); | 99 TestAll(`function f() { eval("var y = 2;"); x = 1; }; f(); ${kw} x = 2;`); |
| 99 TestAll('function f() { eval("var y = 2;"); x += 1; }; f(); let x;'); | 100 TestAll(`function f() { eval("var y = 2;"); x += 1; }; f(); ${kw} x = 2;`); |
| 100 TestAll('function f() { eval("var y = 2;"); ++x; }; f(); let x;'); | 101 TestAll(`function f() { eval("var y = 2;"); ++x; }; f(); ${kw} x = 2;`); |
| 101 TestAll('function f() { eval("var y = 2;"); x++; }; f(); let x;'); | 102 TestAll(`function f() { eval("var y = 2;"); x++; }; f(); ${kw} x = 2;`); |
| 103 } |
| 102 | 104 |
| 103 // Test that variables introduced by function declarations are created and | 105 // Test that variables introduced by function declarations are created and |
| 104 // initialized upon entering a function / block scope. | 106 // initialized upon entering a function / block scope. |
| 105 function f() { | 107 function f() { |
| 106 { | 108 { |
| 107 assertEquals(2, g1()); | 109 assertEquals(2, g1()); |
| 108 assertEquals(2, eval("g1()")); | 110 assertEquals(2, eval("g1()")); |
| 109 | 111 |
| 110 // block scoped function declaration | 112 // block scoped function declaration |
| 111 function g1() { | 113 function g1() { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 } | 180 } |
| 179 eval("1 + 1"); | 181 eval("1 + 1"); |
| 180 return x + inner(); | 182 return x + inner(); |
| 181 } | 183 } |
| 182 | 184 |
| 183 let x = 1; | 185 let x = 1; |
| 184 return middle(); | 186 return middle(); |
| 185 } | 187 } |
| 186 | 188 |
| 187 assertEquals(2, outer()); | 189 assertEquals(2, outer()); |
| OLD | NEW |