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

Side by Side Diff: test/debugger/debug/debug-scopes-suspended-generators.js

Issue 2898163002: Make non-Module generators only context allocate parameters. (Closed)
Patch Set: Rebase Created 3 years, 6 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 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Flags: --ignition --turbo 5 // Flags: --ignition --turbo
6 // The functions used for testing backtraces. They are at the top to make the 6 // The functions used for testing backtraces. They are at the top to make the
7 // testing of source line/column easier. 7 // testing of source line/column easier.
8 8
9 var Debug = debug.Debug; 9 var Debug = debug.Debug;
10 10
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 100 }
101 101
102 // Simple empty closure scope. 102 // Simple empty closure scope.
103 103
104 function *gen1() { 104 function *gen1() {
105 yield 1; 105 yield 1;
106 return 2; 106 return 2;
107 } 107 }
108 108
109 var g = gen1(); 109 var g = gen1();
110 CheckScopeChain([debug.ScopeType.Closure, 110 CheckScopeChain([debug.ScopeType.Local,
111 debug.ScopeType.Script, 111 debug.ScopeType.Script,
112 debug.ScopeType.Global], g); 112 debug.ScopeType.Global], g);
113 CheckScopeContent({}, 0, g); 113 CheckScopeContent({}, 0, g);
114 114
115 // Closure scope with a parameter. 115 // Closure scope with a parameter.
116 116
117 function *gen2(a) { 117 function *gen2(a) {
118 yield a; 118 yield a;
119 return 2; 119 return 2;
120 } 120 }
121 121
122 g = gen2(42); 122 g = gen2(42);
123 CheckScopeChain([debug.ScopeType.Closure, 123 CheckScopeChain([debug.ScopeType.Local,
124 debug.ScopeType.Script, 124 debug.ScopeType.Script,
125 debug.ScopeType.Global], g); 125 debug.ScopeType.Global], g);
126 CheckScopeContent({a: 42}, 0, g); 126 CheckScopeContent({a: 42}, 0, g);
127 127
128 // Closure scope with a parameter. 128 // Closure scope with a parameter.
129 129
130 function *gen3(a) { 130 function *gen3(a) {
131 var b = 1 131 var b = 1
132 yield a; 132 yield a;
133 return b; 133 return b;
134 } 134 }
135 135
136 g = gen3(0); 136 g = gen3(0);
137 CheckScopeChain([debug.ScopeType.Closure, 137 CheckScopeChain([debug.ScopeType.Local,
138 debug.ScopeType.Script, 138 debug.ScopeType.Script,
139 debug.ScopeType.Global], g); 139 debug.ScopeType.Global], g);
140 CheckScopeContent({a: 0, b: undefined}, 0, g); 140 CheckScopeContent({a: 0, b: undefined}, 0, g);
141 141
142 g.next(); // Create b. 142 g.next(); // Create b.
143 CheckScopeContent({a: 0, b: 1}, 0, g); 143 CheckScopeContent({a: 0, b: 1}, 0, g);
144 144
145 // Closure scope with a parameter. 145 // Closure scope with a parameter.
146 146
147 function *gen4(a, b) { 147 function *gen4(a, b) {
148 var x = 2; 148 var x = 2;
149 yield a; 149 yield a;
150 var y = 3; 150 var y = 3;
151 yield a;
151 return b; 152 return b;
152 } 153 }
153 154
154 g = gen4(0, 1); 155 g = gen4(0, 1);
155 CheckScopeChain([debug.ScopeType.Closure, 156 CheckScopeChain([debug.ScopeType.Local,
156 debug.ScopeType.Script, 157 debug.ScopeType.Script,
157 debug.ScopeType.Global], g); 158 debug.ScopeType.Global], g);
158 CheckScopeContent({a: 0, b: 1, x: undefined, y: undefined}, 0, g); 159 CheckScopeContent({a: 0, b: 1, x: undefined, y: undefined}, 0, g);
159 160
160 g.next(); // Create x. 161 g.next(); // Create x.
161 CheckScopeContent({a: 0, b: 1, x: 2, y: undefined}, 0, g); 162 CheckScopeContent({a: 0, b: 1, x: 2, y: undefined}, 0, g);
162 163
163 g.next(); // Create y. 164 g.next(); // Create y.
164 CheckScopeContent({a: 0, b: 1, x: 2, y: 3}, 0, g); 165 CheckScopeContent({a: 0, b: 1, x: 2, y: 3}, 0, g);
165 166
166 // Closure introducing local variable using eval. 167 // Closure introducing local variable using eval.
167 168
168 function *gen5(a) { 169 function *gen5(a) {
169 eval('var b = 2'); 170 eval('var b = 2');
171 yield a;
170 return b; 172 return b;
171 } 173 }
172 174
173 g = gen5(1); 175 g = gen5(1);
174 g.next(); 176 g.next();
175 CheckScopeChain([debug.ScopeType.Closure, 177 CheckScopeChain([debug.ScopeType.Local,
176 debug.ScopeType.Script, 178 debug.ScopeType.Script,
177 debug.ScopeType.Global], g); 179 debug.ScopeType.Global], g);
178 CheckScopeContent({a: 1, b: 2}, 0, g); 180 CheckScopeContent({a: 1, b: 2}, 0, g);
179 181
180 // Single empty with block. 182 // Single empty with block.
181 183
182 function *gen6() { 184 function *gen6() {
183 with({}) { 185 with({}) {
184 yield 1; 186 yield 1;
185 } 187 }
186 yield 2; 188 yield 2;
187 return 3; 189 return 3;
188 } 190 }
189 191
190 g = gen6(); 192 g = gen6();
191 g.next(); 193 g.next();
192 CheckScopeChain([debug.ScopeType.With, 194 CheckScopeChain([debug.ScopeType.With,
193 debug.ScopeType.Closure, 195 debug.ScopeType.Local,
194 debug.ScopeType.Script, 196 debug.ScopeType.Script,
195 debug.ScopeType.Global], g); 197 debug.ScopeType.Global], g);
196 CheckScopeContent({}, 0, g); 198 CheckScopeContent({}, 0, g);
197 199
198 g.next(); 200 g.next();
199 CheckScopeChain([debug.ScopeType.Closure, 201 CheckScopeChain([debug.ScopeType.Local,
200 debug.ScopeType.Script, 202 debug.ScopeType.Script,
201 debug.ScopeType.Global], g); 203 debug.ScopeType.Global], g);
202 204
203 // Nested empty with blocks. 205 // Nested empty with blocks.
204 206
205 function *gen7() { 207 function *gen7() {
206 with({}) { 208 with({}) {
207 with({}) { 209 with({}) {
208 yield 1; 210 yield 1;
209 } 211 }
210 yield 2; 212 yield 2;
211 } 213 }
212 return 3; 214 return 3;
213 } 215 }
214 216
215 g = gen7(); 217 g = gen7();
216 g.next(); 218 g.next();
217 CheckScopeChain([debug.ScopeType.With, 219 CheckScopeChain([debug.ScopeType.With,
218 debug.ScopeType.With, 220 debug.ScopeType.With,
219 debug.ScopeType.Closure, 221 debug.ScopeType.Local,
220 debug.ScopeType.Script, 222 debug.ScopeType.Script,
221 debug.ScopeType.Global], g); 223 debug.ScopeType.Global], g);
222 CheckScopeContent({}, 0, g); 224 CheckScopeContent({}, 0, g);
223 225
224 // Nested with blocks using in-place object literals. 226 // Nested with blocks using in-place object literals.
225 227
226 function *gen8() { 228 function *gen8() {
227 with({a: 1,b: 2}) { 229 with({a: 1,b: 2}) {
228 with({a: 2,b: 1}) { 230 with({a: 2,b: 1}) {
229 yield a; 231 yield a;
230 } 232 }
231 yield a; 233 yield a;
232 } 234 }
233 return 3; 235 return 3;
234 } 236 }
235 237
236 g = gen8(); 238 g = gen8();
237 g.next(); 239 g.next();
238 CheckScopeChain([debug.ScopeType.With, 240 CheckScopeChain([debug.ScopeType.With,
239 debug.ScopeType.With, 241 debug.ScopeType.With,
240 debug.ScopeType.Closure, 242 debug.ScopeType.Local,
241 debug.ScopeType.Script, 243 debug.ScopeType.Script,
242 debug.ScopeType.Global], g); 244 debug.ScopeType.Global], g);
243 CheckScopeContent({a: 2, b: 1}, 0, g); 245 CheckScopeContent({a: 2, b: 1}, 0, g);
244 246
245 g.next(); 247 g.next();
246 CheckScopeContent({a: 1, b: 2}, 0, g); 248 CheckScopeContent({a: 1, b: 2}, 0, g);
247 249
248 // Catch block. 250 // Catch block.
249 251
250 function *gen9() { 252 function *gen9() {
251 try { 253 try {
252 throw 42; 254 throw 42;
253 } catch (e) { 255 } catch (e) {
254 yield e; 256 yield e;
255 } 257 }
256 return 3; 258 return 3;
257 } 259 }
258 260
259 g = gen9(); 261 g = gen9();
260 g.next(); 262 g.next();
261 CheckScopeChain([debug.ScopeType.Catch, 263 CheckScopeChain([debug.ScopeType.Catch,
262 debug.ScopeType.Closure, 264 debug.ScopeType.Local,
263 debug.ScopeType.Script, 265 debug.ScopeType.Script,
264 debug.ScopeType.Global], g); 266 debug.ScopeType.Global], g);
265 CheckScopeContent({e: 42}, 0, g); 267 CheckScopeContent({e: 42}, 0, g);
266 268
267 // For statement with block scope. 269 // For statement with block scope.
268 270
269 function *gen10() { 271 function *gen10() {
270 for (let i = 0; i < 42; i++) yield i; 272 for (let i = 0; i < 42; i++) yield i;
271 return 3; 273 return 3;
272 } 274 }
273 275
274 g = gen10(); 276 g = gen10();
275 g.next(); 277 g.next();
276 CheckScopeChain([debug.ScopeType.Block, 278 CheckScopeChain([debug.ScopeType.Block,
277 debug.ScopeType.Block, 279 debug.ScopeType.Local,
278 debug.ScopeType.Closure,
279 debug.ScopeType.Script, 280 debug.ScopeType.Script,
280 debug.ScopeType.Global], g); 281 debug.ScopeType.Global], g);
281 CheckScopeContent({i: 0}, 0, g); 282 CheckScopeContent({i: 0}, 0, g);
282 283
283 g.next(); 284 g.next();
284 CheckScopeContent({i: 1}, 0, g); 285 CheckScopeContent({i: 1}, 0, g);
285 CheckScopeContent({i: 0}, 1, g); // Additional block scope with i = 0;
286 286
287 // Nested generators. 287 // Nested generators.
288 288
289 var gen12; 289 var gen12;
290 function *gen11() { 290 function *gen11() {
291 var b = 2;
291 gen12 = function*() { 292 gen12 = function*() {
292 var a = 1; 293 var a = 1;
293 yield 1; 294 yield 1;
294 return 2; 295 return b;
295 }(); 296 }();
296 297
297 var a = 0; 298 var a = 0;
298 yield* gen12; 299 yield* gen12;
299 } 300 }
300 301
301 gen11().next(); 302 gen11().next();
302 g = gen12; 303 g = gen12;
303 304
304 CheckScopeChain([debug.ScopeType.Closure, 305 CheckScopeChain([debug.ScopeType.Local,
305 debug.ScopeType.Closure, 306 debug.ScopeType.Closure,
306 debug.ScopeType.Script, 307 debug.ScopeType.Script,
307 debug.ScopeType.Global], g); 308 debug.ScopeType.Global], g);
308 CheckScopeContent({a: 1}, 0, g); 309 CheckScopeContent({a: 1}, 0, g);
309 CheckScopeContent({a: 0}, 1, g); 310 CheckScopeContent({b: 2}, 1, g);
310 311
311 // Set a variable in an empty scope. 312 // Set a variable in an empty scope.
312 313
313 function *gen13() { 314 function *gen13() {
314 yield 1; 315 yield 1;
315 return 2; 316 return 2;
316 } 317 }
317 318
318 var g = gen13(); 319 var g = gen13();
319 assertThrows(() => Debug.generatorScope(g, 0).setVariableValue("a", 42)); 320 assertThrows(() => Debug.generatorScope(g, 0).setVariableValue("a", 42));
(...skipping 28 matching lines...) Expand all
348 var e = 5; 349 var e = 5;
349 } 350 }
350 yield e; 351 yield e;
351 return e; 352 return e;
352 } 353 }
353 354
354 var g = gen15(); 355 var g = gen15();
355 assertEquals(1, g.next().value); 356 assertEquals(1, g.next().value);
356 357
357 CheckScopeChain([debug.ScopeType.With, 358 CheckScopeChain([debug.ScopeType.With,
358 debug.ScopeType.Closure, 359 debug.ScopeType.Local,
359 debug.ScopeType.Script, 360 debug.ScopeType.Script,
360 debug.ScopeType.Global], g); 361 debug.ScopeType.Global], g);
361 CheckScopeContent({a: 1, b: 2}, 0, g); 362 CheckScopeContent({a: 1, b: 2}, 0, g);
362 CheckScopeContent({c: 3, d: 4, e: undefined}, 1, g); 363 CheckScopeContent({c: 3, d: 4, e: undefined}, 1, g);
363 364
364 // Variables don't exist in given scope. 365 // Variables don't exist in given scope.
365 assertThrows(() => Debug.generatorScope(g, 0).setVariableValue("c", 42)); 366 assertThrows(() => Debug.generatorScope(g, 0).setVariableValue("c", 42));
366 assertThrows(() => Debug.generatorScope(g, 1).setVariableValue("a", 42)); 367 assertThrows(() => Debug.generatorScope(g, 1).setVariableValue("a", 42));
367 368
368 // Variables in with scope are immutable. 369 // Variables in with scope are immutable.
369 assertThrows(() => Debug.generatorScope(g, 0).setVariableValue("a", 3)); 370 assertThrows(() => Debug.generatorScope(g, 0).setVariableValue("a", 3));
370 assertThrows(() => Debug.generatorScope(g, 0).setVariableValue("b", 3)); 371 assertThrows(() => Debug.generatorScope(g, 0).setVariableValue("b", 3));
371 372
372 Debug.generatorScope(g, 1).setVariableValue("c", 1); 373 Debug.generatorScope(g, 1).setVariableValue("c", 1);
373 Debug.generatorScope(g, 1).setVariableValue("e", 42); 374 Debug.generatorScope(g, 1).setVariableValue("e", 42);
374 375
375 CheckScopeContent({a: 1, b: 2}, 0, g); 376 CheckScopeContent({a: 1, b: 2}, 0, g);
376 CheckScopeContent({c: 1, d: 4, e: 42}, 1, g); 377 CheckScopeContent({c: 1, d: 4, e: 42}, 1, g);
377 assertEquals(5, g.next().value); // Initialized after set. 378 assertEquals(5, g.next().value); // Initialized after set.
378 379
379 CheckScopeChain([debug.ScopeType.Closure, 380 CheckScopeChain([debug.ScopeType.Local,
380 debug.ScopeType.Script, 381 debug.ScopeType.Script,
381 debug.ScopeType.Global], g); 382 debug.ScopeType.Global], g);
382 383
383 Debug.generatorScope(g, 0).setVariableValue("e", 42); 384 Debug.generatorScope(g, 0).setVariableValue("e", 42);
384 385
385 CheckScopeContent({c: 1, d: 4, e: 42}, 0, g); 386 CheckScopeContent({c: 1, d: 4, e: 42}, 0, g);
386 assertEquals(42, g.next().value); 387 assertEquals(42, g.next().value);
387 388
388 // Set a variable in nested with blocks using in-place object literals plus a 389 // Set a variable in nested with blocks using in-place object literals plus a
389 // nested block scope. 390 // nested block scope.
390 391
391 function *gen16() { 392 function *gen16() {
392 var c = 3; 393 var c = 3;
393 with({a: 1,b: 2}) { 394 with({a: 1,b: 2}) {
394 let d = 4; 395 let d = 4;
395 yield a; 396 yield a;
396 let e = 5; 397 let e = 5;
397 yield d; 398 yield d;
398 } 399 }
399 return 3; 400 return 3;
400 } 401 }
401 402
402 var g = gen16(); 403 var g = gen16();
403 g.next(); 404 g.next();
404 405
405 CheckScopeChain([debug.ScopeType.Block, 406 CheckScopeChain([debug.ScopeType.Block,
406 debug.ScopeType.With, 407 debug.ScopeType.With,
407 debug.ScopeType.Closure, 408 debug.ScopeType.Local,
408 debug.ScopeType.Script, 409 debug.ScopeType.Script,
409 debug.ScopeType.Global], g); 410 debug.ScopeType.Global], g);
410 CheckScopeContent({d: 4}, 0, g); 411 CheckScopeContent({d: 4, e: undefined}, 0, g);
411 CheckScopeContent({a: 1, b: 2}, 1, g); 412 CheckScopeContent({a: 1, b: 2}, 1, g);
412 CheckScopeContent({c: 3}, 2, g); 413 CheckScopeContent({c: 3}, 2, g);
413 414
414 Debug.generatorScope(g, 0).setVariableValue("d", 1); 415 Debug.generatorScope(g, 0).setVariableValue("d", 1);
415 CheckScopeContent({d: 1}, 0, g); 416 CheckScopeContent({d: 1, e: undefined}, 0, g);
416 417
417 assertEquals(1, g.next().value); 418 assertEquals(1, g.next().value);
418 419
419 // Set variable in catch block. 420 // Set variable in catch block.
420 421
421 var yyzyzzyz = 4829; 422 var yyzyzzyz = 4829;
422 let xxxyyxxyx = 42284; 423 let xxxyyxxyx = 42284;
423 function *gen17() { 424 function *gen17() {
424 try { 425 try {
425 throw 42; 426 throw 42;
426 } catch (e) { 427 } catch (e) {
427 yield e; 428 yield e;
428 yield e; 429 yield e;
429 } 430 }
430 return 3; 431 return 3;
431 } 432 }
432 433
433 g = gen17(); 434 g = gen17();
434 g.next(); 435 g.next();
435 436
436 CheckScopeChain([debug.ScopeType.Catch, 437 CheckScopeChain([debug.ScopeType.Catch,
437 debug.ScopeType.Closure, 438 debug.ScopeType.Local,
438 debug.ScopeType.Script, 439 debug.ScopeType.Script,
439 debug.ScopeType.Global], g); 440 debug.ScopeType.Global], g);
440 CheckScopeContent({e: 42}, 0, g); 441 CheckScopeContent({e: 42}, 0, g);
441 CheckScopeContent({xxxyyxxyx: 42284, 442 CheckScopeContent({xxxyyxxyx: 42284,
442 printProtocolMessages : printProtocolMessages, 443 printProtocolMessages : printProtocolMessages,
443 activeWrapper : activeWrapper, 444 activeWrapper : activeWrapper,
444 DebugWrapper : DebugWrapper 445 DebugWrapper : DebugWrapper
445 }, 2, g); 446 }, 2, g);
446 447
447 Debug.generatorScope(g, 0).setVariableValue("e", 1); 448 Debug.generatorScope(g, 0).setVariableValue("e", 1);
448 CheckScopeContent({e: 1}, 0, g); 449 CheckScopeContent({e: 1}, 0, g);
449 450
450 assertEquals(1, g.next().value); 451 assertEquals(1, g.next().value);
451 452
452 // Script scope. 453 // Script scope.
453 Debug.generatorScope(g, 2).setVariableValue("xxxyyxxyx", 42); 454 Debug.generatorScope(g, 2).setVariableValue("xxxyyxxyx", 42);
454 assertEquals(42, xxxyyxxyx); 455 assertEquals(42, xxxyyxxyx);
455 456
456 // Global scope. 457 // Global scope.
457 assertThrows(() => Debug.generatorScope(g, 3).setVariableValue("yyzyzzyz", 42)); 458 assertThrows(() => Debug.generatorScope(g, 3).setVariableValue("yyzyzzyz", 42));
458 assertEquals(4829, yyzyzzyz); 459 assertEquals(4829, yyzyzzyz);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698