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

Side by Side Diff: test/mjsunit/es6/block-scoping.js

Issue 1286923002: Add class to existing lexical scoping tests (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix test bug Created 5 years, 4 months 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
« no previous file with comments | « test/mjsunit/es6/block-let-semantics.js ('k') | test/mjsunit/harmony/block-conflicts-sloppy.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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 for (var j = 0; j < 5; ++j) f1(); 42 for (var j = 0; j < 5; ++j) f1();
43 %OptimizeFunctionOnNextCall(f1); 43 %OptimizeFunctionOnNextCall(f1);
44 f1(); 44 f1();
45 assertTrue(%GetOptimizationStatus(f1) != 2); 45 assertTrue(%GetOptimizationStatus(f1) != 2);
46 46
47 // Dynamic lookup in and through block contexts. 47 // Dynamic lookup in and through block contexts.
48 function f2(one) { 48 function f2(one) {
49 var x = one + 1; 49 var x = one + 1;
50 let y = one + 2; 50 let y = one + 2;
51 const u = one + 4; 51 const u = one + 4;
52 class a { static foo() { return one + 6; } }
52 { 53 {
53 let z = one + 3; 54 let z = one + 3;
54 const v = one + 5; 55 const v = one + 5;
56 class b { static foo() { return one + 7; } }
55 assertEquals(1, eval('one')); 57 assertEquals(1, eval('one'));
56 assertEquals(2, eval('x')); 58 assertEquals(2, eval('x'));
57 assertEquals(3, eval('y')); 59 assertEquals(3, eval('y'));
58 assertEquals(4, eval('z')); 60 assertEquals(4, eval('z'));
59 assertEquals(5, eval('u')); 61 assertEquals(5, eval('u'));
60 assertEquals(6, eval('v')); 62 assertEquals(6, eval('v'));
63 assertEquals(7, eval('a.foo()'));
64 assertEquals(8, eval('b.foo()'));
61 } 65 }
62 } 66 }
63 67
64 f2(1); 68 f2(1);
65 69
66 // Lookup in and through block contexts. 70 // Lookup in and through block contexts.
67 function f3(one) { 71 function f3(one) {
68 var x = one + 1; 72 var x = one + 1;
69 let y = one + 2; 73 let y = one + 2;
70 const u = one + 4; 74 const u = one + 4;
75 class a { static foo() { return one + 6; } }
71 { 76 {
72 let z = one + 3; 77 let z = one + 3;
73 const v = one + 5; 78 const v = one + 5;
79 class b { static foo() { return one + 7; } }
74 assertEquals(1, one); 80 assertEquals(1, one);
75 assertEquals(2, x); 81 assertEquals(2, x);
76 assertEquals(3, y); 82 assertEquals(3, y);
77 assertEquals(4, z); 83 assertEquals(4, z);
78 assertEquals(5, u); 84 assertEquals(5, u);
79 assertEquals(6, v); 85 assertEquals(6, v);
86 assertEquals(7, a.foo());
87 assertEquals(8, b.foo());
80 } 88 }
81 } 89 }
82 for (var j = 0; j < 5; ++j) f3(1); 90 for (var j = 0; j < 5; ++j) f3(1);
83 %OptimizeFunctionOnNextCall(f3); 91 %OptimizeFunctionOnNextCall(f3);
84 f3(1); 92 f3(1);
85 assertTrue(%GetOptimizationStatus(f3) != 2); 93 assertTrue(%GetOptimizationStatus(f3) != 2);
86 94
87 95
88 96
89 // Dynamic lookup from closure. 97 // Dynamic lookup from closure.
90 function f4(one) { 98 function f4(one) {
91 var x = one + 1; 99 var x = one + 1;
92 let y = one + 2; 100 let y = one + 2;
93 const u = one + 4; 101 const u = one + 4;
102 class a { static foo() { return one + 6; } }
94 { 103 {
95 let z = one + 3; 104 let z = one + 3;
96 const v = one + 5; 105 const v = one + 5;
106 class b { static foo() { return one + 7; } }
97 function f() { 107 function f() {
98 assertEquals(1, eval('one')); 108 assertEquals(1, eval('one'));
99 assertEquals(2, eval('x')); 109 assertEquals(2, eval('x'));
100 assertEquals(3, eval('y')); 110 assertEquals(3, eval('y'));
101 assertEquals(4, eval('z')); 111 assertEquals(4, eval('z'));
102 assertEquals(5, eval('u')); 112 assertEquals(5, eval('u'));
103 assertEquals(6, eval('v')); 113 assertEquals(6, eval('v'));
114 assertEquals(7, eval('a.foo()'));
115 assertEquals(8, eval('b.foo()'));
104 } 116 }
105 f(); 117 f();
106 } 118 }
107 } 119 }
108 f4(1); 120 f4(1);
109 121
110 122
111 // Lookup from closure. 123 // Lookup from closure.
112 function f5(one) { 124 function f5(one) {
113 var x = one + 1; 125 var x = one + 1;
114 let y = one + 2; 126 let y = one + 2;
115 const u = one + 4; 127 const u = one + 4;
128 class a { static foo() { return one + 6; } }
116 { 129 {
117 let z = one + 3; 130 let z = one + 3;
118 const v = one + 5; 131 const v = one + 5;
132 class b { static foo() { return one + 7; } }
119 function f() { 133 function f() {
120 assertEquals(1, one); 134 assertEquals(1, one);
121 assertEquals(2, x); 135 assertEquals(2, x);
122 assertEquals(3, y); 136 assertEquals(3, y);
123 assertEquals(4, z); 137 assertEquals(4, z);
124 assertEquals(5, u); 138 assertEquals(5, u);
125 assertEquals(6, v); 139 assertEquals(6, v);
140 assertEquals(7, a.foo());
141 assertEquals(8, b.foo());
126 } 142 }
127 f(); 143 f();
128 } 144 }
129 } 145 }
130 f5(1); 146 f5(1);
131 147
132 148
133 // Return from block. 149 // Return from block.
134 function f6() { 150 function f6() {
135 let x = 1; 151 let x = 1;
136 const u = 3; 152 const u = 3;
137 { 153 {
138 let y = 2; 154 let y = 2;
139 const v = 4; 155 const v = 4;
140 return x + y; 156 return x + y;
141 } 157 }
142 } 158 }
143 assertEquals(3, f6(6)); 159 assertEquals(3, f6(6));
144 160
145 161
146 // Variable shadowing and lookup. 162 // Variable shadowing and lookup.
147 function f7(a) { 163 function f7(a) {
148 let b = 1; 164 let b = 1;
149 var c = 1; 165 var c = 1;
150 var d = 1; 166 var d = 1;
151 const e = 1; 167 const e = 1;
152 { // let variables shadowing argument, let, const and var variables 168 class f { static foo() { return 1; } }
169 { // let variables shadowing argument, let, const, class and var variables
153 let a = 2; 170 let a = 2;
154 let b = 2; 171 let b = 2;
155 let c = 2; 172 let c = 2;
156 let e = 2; 173 let e = 2;
174 let f = 2;
157 assertEquals(2,a); 175 assertEquals(2,a);
158 assertEquals(2,b); 176 assertEquals(2,b);
159 assertEquals(2,c); 177 assertEquals(2,c);
160 assertEquals(2,e); 178 assertEquals(2,e);
179 assertEquals(2,f);
161 } 180 }
162 { // const variables shadowing argument, let, const and var variables 181 { // const variables shadowing argument, let, const and var variables
163 const a = 2; 182 const a = 2;
164 const b = 2; 183 const b = 2;
165 const c = 2; 184 const c = 2;
166 const e = 2; 185 const e = 2;
186 const f = 2;
167 assertEquals(2,a); 187 assertEquals(2,a);
168 assertEquals(2,b); 188 assertEquals(2,b);
169 assertEquals(2,c); 189 assertEquals(2,c);
170 assertEquals(2,e); 190 assertEquals(2,e);
191 assertEquals(2,f);
192 }
193 { // class variables shadowing argument, let, const and var variables
194 class a { static foo() { return 2; } }
195 class b { static foo() { return 2; } }
196 class c { static foo() { return 2; } }
197 class d { static foo() { return 2; } }
198 class e { static foo() { return 2; } }
199 class f { static foo() { return 2; } }
200 assertEquals(2,a.foo());
201 assertEquals(2,b.foo());
202 assertEquals(2,c.foo());
203 assertEquals(2,e.foo());
204 assertEquals(2,f.foo());
171 } 205 }
172 try { 206 try {
173 throw 'stuff1'; 207 throw 'stuff1';
174 } catch (a) { 208 } catch (a) {
175 assertEquals('stuff1',a); 209 assertEquals('stuff1',a);
176 // catch variable shadowing argument 210 // catch variable shadowing argument
177 a = 2; 211 a = 2;
178 assertEquals(2,a); 212 assertEquals(2,a);
179 { 213 {
180 // let variable shadowing catch variable 214 // let variable shadowing catch variable
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 })(); 252 })();
219 assertEquals('stuff3', c); 253 assertEquals('stuff3', c);
220 (function() { 254 (function() {
221 // var variable shadowing catch variable 255 // var variable shadowing catch variable
222 var c = 3; 256 var c = 3;
223 })(); 257 })();
224 assertEquals('stuff3', c); 258 assertEquals('stuff3', c);
225 c = 2; 259 c = 2;
226 } 260 }
227 assertEquals(1,c); 261 assertEquals(1,c);
228 (function(a,b,c,e) { 262 (function(a,b,c,e,f) {
229 // arguments shadowing argument, let, const and var variable 263 // arguments shadowing argument, let, const, class and var variable
230 a = 2; 264 a = 2;
231 b = 2; 265 b = 2;
232 c = 2; 266 c = 2;
233 e = 2; 267 e = 2;
268 f = 2;
234 assertEquals(2,a); 269 assertEquals(2,a);
235 assertEquals(2,b); 270 assertEquals(2,b);
236 assertEquals(2,c); 271 assertEquals(2,c);
237 assertEquals(2,e); 272 assertEquals(2,e);
273 assertEquals(2,f);
238 // var variable shadowing var variable 274 // var variable shadowing var variable
239 var d = 2; 275 var d = 2;
240 })(1,1); 276 })(1,1);
241 assertEquals(1,a); 277 assertEquals(1,a);
242 assertEquals(1,b); 278 assertEquals(1,b);
243 assertEquals(1,c); 279 assertEquals(1,c);
244 assertEquals(1,d); 280 assertEquals(1,d);
245 assertEquals(1,e); 281 assertEquals(1,e);
282 assertEquals(1,f.foo());
246 } 283 }
247 f7(1); 284 f7(1);
248 285
249 286
250 // Ensure let and const variables are block local 287 // Ensure let and const variables are block local
251 // and var variables function local. 288 // and var variables function local.
252 function f8() { 289 function f8() {
253 var let_accessors = []; 290 var let_accessors = [];
254 var var_accessors = []; 291 var var_accessors = [];
255 var const_accessors = []; 292 var const_accessors = [];
293 var class_accessors = [];
256 for (var i = 0; i < 10; i++) { 294 for (var i = 0; i < 10; i++) {
257 let x = i; 295 let x = i;
258 var y = i; 296 var y = i;
259 const z = i; 297 const z = i;
298 class a { static foo() { return x; } }
260 let_accessors[i] = function() { return x; } 299 let_accessors[i] = function() { return x; }
261 var_accessors[i] = function() { return y; } 300 var_accessors[i] = function() { return y; }
262 const_accessors[i] = function() { return z; } 301 const_accessors[i] = function() { return z; }
302 class_accessors[i] = function() { return a; }
263 } 303 }
264 for (var j = 0; j < 10; j++) { 304 for (var j = 0; j < 10; j++) {
265 y = j + 10; 305 y = j + 10;
266 assertEquals(j, let_accessors[j]()); 306 assertEquals(j, let_accessors[j]());
267 assertEquals(y, var_accessors[j]()); 307 assertEquals(y, var_accessors[j]());
268 assertEquals(j, const_accessors[j]()); 308 assertEquals(j, const_accessors[j]());
309 assertEquals(j, class_accessors[j]().foo());
269 } 310 }
270 } 311 }
271 f8(); 312 f8();
OLDNEW
« no previous file with comments | « test/mjsunit/es6/block-let-semantics.js ('k') | test/mjsunit/harmony/block-conflicts-sloppy.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698