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