Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: test/mjsunit/harmony/block-let-semantics.js

Issue 8404030: Version 3.7.1 (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/mjsunit/harmony/block-let-declaration.js ('k') | test/mjsunit/harmony/block-scoping.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 function TestAll(s) { 54 function TestAll(s) {
55 TestBlockLocal(s); 55 TestBlockLocal(s);
56 TestFunctionLocal(s); 56 TestFunctionLocal(s);
57 } 57 }
58 58
59 // Use before initialization in declaration statement. 59 // Use before initialization in declaration statement.
60 TestAll('let x = x + 1'); 60 TestAll('let x = x + 1');
61 TestAll('let x = x += 1'); 61 TestAll('let x = x += 1');
62 TestAll('let x = x++'); 62 TestAll('let x = x++');
63 TestAll('let x = ++x'); 63 TestAll('let x = ++x');
64 TestAll('const x = x + 1');
64 65
65 // Use before initialization in prior statement. 66 // Use before initialization in prior statement.
66 TestAll('x + 1; let x;'); 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; let x;'); 70 TestAll('++x; let x;');
70 TestAll('x++; let x;'); 71 TestAll('x++; let x;');
72 TestAll('let y = x; const x = 1;');
71 73
72 TestAll('f(); let x; function f() { return x + 1; }'); 74 TestAll('f(); let x; function f() { return x + 1; }');
73 TestAll('f(); let x; function f() { x = 1; }'); 75 TestAll('f(); let x; function f() { x = 1; }');
74 TestAll('f(); let x; function f() { x += 1; }'); 76 TestAll('f(); let x; function f() { x += 1; }');
75 TestAll('f(); let x; function f() { ++x; }'); 77 TestAll('f(); let x; function f() { ++x; }');
76 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; }');
77 80
78 TestAll('f()(); let x; function f() { return function() { return x + 1; } }'); 81 TestAll('f()(); let x; function f() { return function() { return x + 1; } }');
79 TestAll('f()(); let x; function f() { return function() { x = 1; } }'); 82 TestAll('f()(); let x; function f() { return function() { x = 1; } }');
80 TestAll('f()(); let x; function f() { return function() { x += 1; } }'); 83 TestAll('f()(); let x; function f() { return function() { x += 1; } }');
81 TestAll('f()(); let x; function f() { return function() { ++x; } }'); 84 TestAll('f()(); let x; function f() { return function() { ++x; } }');
82 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; } }');
83 87
84 // Use before initialization with a dynamic lookup. 88 // Use before initialization with a dynamic lookup.
85 TestAll('eval("x + 1;"); let x;'); 89 TestAll('eval("x + 1;"); let x;');
86 TestAll('eval("x = 1;"); let x;'); 90 TestAll('eval("x = 1;"); let x;');
87 TestAll('eval("x += 1;"); let x;'); 91 TestAll('eval("x += 1;"); let x;');
88 TestAll('eval("++x;"); let x;'); 92 TestAll('eval("++x;"); let x;');
89 TestAll('eval("x++;"); let x;'); 93 TestAll('eval("x++;"); let x;');
94 TestAll('eval("x"); const x = 1;');
90 95
91 // Use before initialization with check for eval-shadowed bindings. 96 // Use before initialization with check for eval-shadowed bindings.
92 TestAll('function f() { eval("var y = 2;"); x + 1; }; f(); let x;'); 97 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;'); 98 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;'); 99 TestAll('function f() { eval("var y = 2;"); x += 1; }; f(); let x;');
95 TestAll('function f() { eval("var y = 2;"); ++x; }; f(); let x;'); 100 TestAll('function f() { eval("var y = 2;"); ++x; }; f(); let x;');
96 TestAll('function f() { eval("var y = 2;"); x++; }; f(); let x;'); 101 TestAll('function f() { eval("var y = 2;"); x++; }; f(); let x;');
97 102
98 // Test that variables introduced by function declarations are created and 103 // Test that variables introduced by function declarations are created and
99 // initialized upon entering a function / block scope. 104 // initialized upon entering a function / block scope.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 } 137 }
133 assertEquals(1, m()); 138 assertEquals(1, m());
134 139
135 try { 140 try {
136 throw 2; 141 throw 2;
137 } catch(b) { 142 } catch(b) {
138 n = h; 143 n = h;
139 function h() { 144 function h() {
140 return b + c; 145 return b + c;
141 } 146 }
142 let b = 3; 147 let c = 3;
143 } 148 }
144 assertEquals(5, n()); 149 assertEquals(5, n());
150
151 {
152 o = i;
153 function i() {
154 return d;
155 }
156 let d = 4;
157 }
158 assertEquals(4, o());
159
160 try {
161 throw 5;
162 } catch(e) {
163 p = j;
164 function j() {
165 return e + f;
166 }
167 let f = 6;
168 }
169 assertEquals(11, p());
145 } 170 }
171 f2();
146 172
147 // Test that resolution of let bound variables works with scopes that call eval. 173 // Test that resolution of let bound variables works with scopes that call eval.
148 function outer() { 174 function outer() {
149 function middle() { 175 function middle() {
150 function inner() { 176 function inner() {
151 return x; 177 return x;
152 } 178 }
153 eval("1 + 1"); 179 eval("1 + 1");
154 return x + inner(); 180 return x + inner();
155 } 181 }
156 182
157 let x = 1; 183 let x = 1;
158 return middle(); 184 return middle();
159 } 185 }
160 186
161 assertEquals(2, outer()); 187 assertEquals(2, outer());
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/block-let-declaration.js ('k') | test/mjsunit/harmony/block-scoping.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698