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

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

Issue 1286923002: Add class to existing lexical scoping tests (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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
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 10 matching lines...) Expand all
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Flags: --allow-natives-syntax --harmony-sloppy --no-legacy-const --harmony-sl oppy-let 28 // Flags: --allow-natives-syntax --harmony-sloppy --no-legacy-const --harmony-sl oppy-let
29 // Test functionality of block scopes. 29 // Test functionality of block scopes.
30 30
31 "use strict";
adamk 2015/08/12 03:36:49 I don't think this should be strict...
Dan Ehrenberg 2015/08/12 17:53:01 Oops, deleted.
32
31 // Hoisting of var declarations. 33 // Hoisting of var declarations.
32 function f1() { 34 function f1() {
33 { 35 {
34 var x = 1; 36 var x = 1;
35 var y; 37 var y;
36 } 38 }
37 assertEquals(1, x) 39 assertEquals(1, x)
38 assertEquals(undefined, y) 40 assertEquals(undefined, y)
39 } 41 }
40 for (var j = 0; j < 5; ++j) f1(); 42 for (var j = 0; j < 5; ++j) f1();
41 %OptimizeFunctionOnNextCall(f1); 43 %OptimizeFunctionOnNextCall(f1);
42 f1(); 44 f1();
43 assertTrue(%GetOptimizationStatus(f1) != 2); 45 assertTrue(%GetOptimizationStatus(f1) != 2);
44 46
45 // Dynamic lookup in and through block contexts. 47 // Dynamic lookup in and through block contexts.
46 function f2(one) { 48 function f2(one) {
47 var x = one + 1; 49 var x = one + 1;
48 let y = one + 2; 50 let y = one + 2;
49 const u = one + 4; 51 const u = one + 4;
52 class a { static foo() { return one + 6; } }
50 { 53 {
51 let z = one + 3; 54 let z = one + 3;
52 const v = one + 5; 55 const v = one + 5;
56 class b { static foo() { return one + 7; } }
53 assertEquals(1, eval('one')); 57 assertEquals(1, eval('one'));
54 assertEquals(2, eval('x')); 58 assertEquals(2, eval('x'));
55 assertEquals(3, eval('y')); 59 assertEquals(3, eval('y'));
56 assertEquals(4, eval('z')); 60 assertEquals(4, eval('z'));
57 assertEquals(5, eval('u')); 61 assertEquals(5, eval('u'));
58 assertEquals(6, eval('v')); 62 assertEquals(6, eval('v'));
63 assertEquals(7, eval('a.foo()'));
64 assertEquals(8, eval('b.foo()'));
59 } 65 }
60 } 66 }
61 67
62 f2(1); 68 f2(1);
63 69
64 // Lookup in and through block contexts. 70 // Lookup in and through block contexts.
65 function f3(one) { 71 function f3(one) {
66 var x = one + 1; 72 var x = one + 1;
67 let y = one + 2; 73 let y = one + 2;
68 const u = one + 4; 74 const u = one + 4;
75 class a { static foo() { return one + 6; } }
69 { 76 {
70 let z = one + 3; 77 let z = one + 3;
71 const v = one + 5; 78 const v = one + 5;
79 class b { static foo() { return one + 7; } }
72 assertEquals(1, one); 80 assertEquals(1, one);
73 assertEquals(2, x); 81 assertEquals(2, x);
74 assertEquals(3, y); 82 assertEquals(3, y);
75 assertEquals(4, z); 83 assertEquals(4, z);
76 assertEquals(5, u); 84 assertEquals(5, u);
77 assertEquals(6, v); 85 assertEquals(6, v);
86 assertEquals(7, a.foo());
87 assertEquals(8, b.foo());
78 } 88 }
79 } 89 }
80 for (var j = 0; j < 5; ++j) f3(1); 90 for (var j = 0; j < 5; ++j) f3(1);
81 %OptimizeFunctionOnNextCall(f3); 91 %OptimizeFunctionOnNextCall(f3);
82 f3(1); 92 f3(1);
83 assertTrue(%GetOptimizationStatus(f3) != 2); 93 assertTrue(%GetOptimizationStatus(f3) != 2);
84 94
85 95
86 96
87 // Dynamic lookup from closure. 97 // Dynamic lookup from closure.
88 function f4(one) { 98 function f4(one) {
89 var x = one + 1; 99 var x = one + 1;
90 let y = one + 2; 100 let y = one + 2;
91 const u = one + 4; 101 const u = one + 4;
102 class a { static foo() { return one + 6; } }
92 { 103 {
93 let z = one + 3; 104 let z = one + 3;
94 const v = one + 5; 105 const v = one + 5;
106 class b { static foo() { return one + 7; } }
95 function f() { 107 function f() {
96 assertEquals(1, eval('one')); 108 assertEquals(1, eval('one'));
97 assertEquals(2, eval('x')); 109 assertEquals(2, eval('x'));
98 assertEquals(3, eval('y')); 110 assertEquals(3, eval('y'));
99 assertEquals(4, eval('z')); 111 assertEquals(4, eval('z'));
100 assertEquals(5, eval('u')); 112 assertEquals(5, eval('u'));
101 assertEquals(6, eval('v')); 113 assertEquals(6, eval('v'));
114 assertEquals(7, eval('a.foo()'));
115 assertEquals(8, eval('b.foo()'));
102 } 116 }
103 f(); 117 f();
104 } 118 }
105 } 119 }
106 f4(1); 120 f4(1);
107 121
108 122
109 // Lookup from closure. 123 // Lookup from closure.
110 function f5(one) { 124 function f5(one) {
111 var x = one + 1; 125 var x = one + 1;
112 let y = one + 2; 126 let y = one + 2;
113 const u = one + 4; 127 const u = one + 4;
128 class a { static foo() { return one + 6; } }
114 { 129 {
115 let z = one + 3; 130 let z = one + 3;
116 const v = one + 5; 131 const v = one + 5;
132 class b { static foo() { return one + 7; } }
117 function f() { 133 function f() {
118 assertEquals(1, one); 134 assertEquals(1, one);
119 assertEquals(2, x); 135 assertEquals(2, x);
120 assertEquals(3, y); 136 assertEquals(3, y);
121 assertEquals(4, z); 137 assertEquals(4, z);
122 assertEquals(5, u); 138 assertEquals(5, u);
123 assertEquals(6, v); 139 assertEquals(6, v);
140 assertEquals(7, a.foo());
141 assertEquals(8, b.foo());
124 } 142 }
125 f(); 143 f();
126 } 144 }
127 } 145 }
128 f5(1); 146 f5(1);
129 147
130 148
131 // Return from block. 149 // Return from block.
132 function f6() { 150 function f6() {
133 let x = 1; 151 let x = 1;
134 const u = 3; 152 const u = 3;
135 { 153 {
136 let y = 2; 154 let y = 2;
137 const v = 4; 155 const v = 4;
138 return x + y; 156 return x + y;
139 } 157 }
140 } 158 }
141 assertEquals(3, f6(6)); 159 assertEquals(3, f6(6));
142 160
143 161
144 // Variable shadowing and lookup. 162 // Variable shadowing and lookup.
145 function f7(a) { 163 function f7(a) {
146 let b = 1; 164 let b = 1;
147 var c = 1; 165 var c = 1;
148 var d = 1; 166 var d = 1;
149 const e = 1; 167 const e = 1;
150 { // 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
151 let a = 2; 170 let a = 2;
152 let b = 2; 171 let b = 2;
153 let c = 2; 172 let c = 2;
154 let e = 2; 173 let e = 2;
174 let f = 2;
155 assertEquals(2,a); 175 assertEquals(2,a);
156 assertEquals(2,b); 176 assertEquals(2,b);
157 assertEquals(2,c); 177 assertEquals(2,c);
158 assertEquals(2,e); 178 assertEquals(2,e);
179 assertEquals(2,f);
159 } 180 }
160 { // const variables shadowing argument, let, const and var variables 181 { // const variables shadowing argument, let, const and var variables
161 const a = 2; 182 const a = 2;
162 const b = 2; 183 const b = 2;
163 const c = 2; 184 const c = 2;
164 const e = 2; 185 const e = 2;
186 const f = 2;
165 assertEquals(2,a); 187 assertEquals(2,a);
166 assertEquals(2,b); 188 assertEquals(2,b);
167 assertEquals(2,c); 189 assertEquals(2,c);
168 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());
169 } 205 }
170 try { 206 try {
171 throw 'stuff1'; 207 throw 'stuff1';
172 } catch (a) { 208 } catch (a) {
173 assertEquals('stuff1',a); 209 assertEquals('stuff1',a);
174 // catch variable shadowing argument 210 // catch variable shadowing argument
175 a = 2; 211 a = 2;
176 assertEquals(2,a); 212 assertEquals(2,a);
177 { 213 {
178 // let variable shadowing catch variable 214 // let variable shadowing catch variable
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 assertEquals('stuff3', c); 253 assertEquals('stuff3', c);
218 (function() { 254 (function() {
219 // var variable shadowing catch variable 255 // var variable shadowing catch variable
220 var c = 3; 256 var c = 3;
221 })(); 257 })();
222 assertEquals('stuff3', c); 258 assertEquals('stuff3', c);
223 c = 2; 259 c = 2;
224 } 260 }
225 assertEquals(1,c); 261 assertEquals(1,c);
226 (function(a,b,c,e) { 262 (function(a,b,c,e) {
227 // arguments shadowing argument, let, const and var variable 263 // arguments shadowing argument, let, const, class and var variable
228 a = 2; 264 a = 2;
229 b = 2; 265 b = 2;
230 c = 2; 266 c = 2;
231 e = 2; 267 e = 2;
268 f = 2;
232 assertEquals(2,a); 269 assertEquals(2,a);
233 assertEquals(2,b); 270 assertEquals(2,b);
234 assertEquals(2,c); 271 assertEquals(2,c);
235 assertEquals(2,e); 272 assertEquals(2,e);
273 assertEquals(2,f);
236 // var variable shadowing var variable 274 // var variable shadowing var variable
237 var d = 2; 275 var d = 2;
238 })(1,1); 276 })(1,1);
239 assertEquals(1,a); 277 assertEquals(1,a);
240 assertEquals(1,b); 278 assertEquals(1,b);
241 assertEquals(1,c); 279 assertEquals(1,c);
242 assertEquals(1,d); 280 assertEquals(1,d);
243 assertEquals(1,e); 281 assertEquals(1,e);
282 //assertEquals(1,f.foo());
adamk 2015/08/12 03:36:49 Another odd comment; is something broken?
Dan Ehrenberg 2015/08/12 17:53:01 Fixed, thanks.
244 } 283 }
245 f7(1); 284 f7(1);
246 285
247 286
248 // Ensure let and const variables are block local 287 // Ensure let and const variables are block local
249 // and var variables function local. 288 // and var variables function local.
250 function f8() { 289 function f8() {
251 var let_accessors = []; 290 var let_accessors = [];
252 var var_accessors = []; 291 var var_accessors = [];
253 var const_accessors = []; 292 var const_accessors = [];
293 var class_accessors = [];
254 for (var i = 0; i < 10; i++) { 294 for (var i = 0; i < 10; i++) {
255 let x = i; 295 let x = i;
256 var y = i; 296 var y = i;
257 const z = i; 297 const z = i;
298 class a { static foo() { return x; } }
258 let_accessors[i] = function() { return x; } 299 let_accessors[i] = function() { return x; }
259 var_accessors[i] = function() { return y; } 300 var_accessors[i] = function() { return y; }
260 const_accessors[i] = function() { return z; } 301 const_accessors[i] = function() { return z; }
302 class_accessors[i] = function() { return a; }
261 } 303 }
262 for (var j = 0; j < 10; j++) { 304 for (var j = 0; j < 10; j++) {
263 y = j + 10; 305 y = j + 10;
264 assertEquals(j, let_accessors[j]()); 306 assertEquals(j, let_accessors[j]());
265 assertEquals(y, var_accessors[j]()); 307 assertEquals(y, var_accessors[j]());
266 assertEquals(j, const_accessors[j]()); 308 assertEquals(j, const_accessors[j]());
309 assertEquals(j, class_accessors[j]().foo());
267 } 310 }
268 } 311 }
269 f8(); 312 f8();
OLDNEW
« test/mjsunit/es6/block-scoping.js ('K') | « test/mjsunit/harmony/block-let-semantics-sloppy.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698