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

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: Fix comment Created 3 years, 7 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,
neis 2017/05/24 10:39:37 What's going on here?
Jarin 2017/05/24 12:32:21 Forgotten scope. Now removed.
277 debug.ScopeType.Block, 279 debug.ScopeType.Block,
278 debug.ScopeType.Closure, 280 debug.ScopeType.Local,
279 debug.ScopeType.Script, 281 debug.ScopeType.Script,
280 debug.ScopeType.Global], g); 282 debug.ScopeType.Global], g);
281 CheckScopeContent({i: 0}, 0, g); 283 CheckScopeContent({i: 0}, 0, g);
282 284
283 g.next(); 285 g.next();
284 CheckScopeContent({i: 1}, 0, g); 286 CheckScopeContent({i: 1}, 0, g);
285 CheckScopeContent({i: 0}, 1, g); // Additional block scope with i = 0;
286 287
287 // Nested generators. 288 // Nested generators.
288 289
289 var gen12; 290 var gen12;
290 function *gen11() { 291 function *gen11() {
292 var b = 2;
291 gen12 = function*() { 293 gen12 = function*() {
292 var a = 1; 294 var a = 1;
293 yield 1; 295 yield 1;
294 return 2; 296 return b;
295 }(); 297 }();
296 298
297 var a = 0; 299 var a = 0;
298 yield* gen12; 300 yield* gen12;
299 } 301 }
300 302
301 gen11().next(); 303 gen11().next();
302 g = gen12; 304 g = gen12;
303 305
304 CheckScopeChain([debug.ScopeType.Closure, 306 CheckScopeChain([debug.ScopeType.Local,
305 debug.ScopeType.Closure, 307 debug.ScopeType.Closure,
306 debug.ScopeType.Script, 308 debug.ScopeType.Script,
307 debug.ScopeType.Global], g); 309 debug.ScopeType.Global], g);
308 CheckScopeContent({a: 1}, 0, g); 310 CheckScopeContent({a: 1}, 0, g);
309 CheckScopeContent({a: 0}, 1, g); 311 CheckScopeContent({b: 2}, 1, g);
310 312
311 // Set a variable in an empty scope. 313 // Set a variable in an empty scope.
312 314
313 function *gen13() { 315 function *gen13() {
314 yield 1; 316 yield 1;
315 return 2; 317 return 2;
316 } 318 }
317 319
318 var g = gen13(); 320 var g = gen13();
319 assertThrows(() => Debug.generatorScope(g, 0).setVariableValue("a", 42)); 321 assertThrows(() => Debug.generatorScope(g, 0).setVariableValue("a", 42));
(...skipping 28 matching lines...) Expand all
348 var e = 5; 350 var e = 5;
349 } 351 }
350 yield e; 352 yield e;
351 return e; 353 return e;
352 } 354 }
353 355
354 var g = gen15(); 356 var g = gen15();
355 assertEquals(1, g.next().value); 357 assertEquals(1, g.next().value);
356 358
357 CheckScopeChain([debug.ScopeType.With, 359 CheckScopeChain([debug.ScopeType.With,
358 debug.ScopeType.Closure, 360 debug.ScopeType.Local,
359 debug.ScopeType.Script, 361 debug.ScopeType.Script,
360 debug.ScopeType.Global], g); 362 debug.ScopeType.Global], g);
361 CheckScopeContent({a: 1, b: 2}, 0, g); 363 CheckScopeContent({a: 1, b: 2}, 0, g);
362 CheckScopeContent({c: 3, d: 4, e: undefined}, 1, g); 364 CheckScopeContent({c: 3, d: 4, e: undefined}, 1, g);
363 365
364 // Variables don't exist in given scope. 366 // Variables don't exist in given scope.
365 assertThrows(() => Debug.generatorScope(g, 0).setVariableValue("c", 42)); 367 assertThrows(() => Debug.generatorScope(g, 0).setVariableValue("c", 42));
366 assertThrows(() => Debug.generatorScope(g, 1).setVariableValue("a", 42)); 368 assertThrows(() => Debug.generatorScope(g, 1).setVariableValue("a", 42));
367 369
368 // Variables in with scope are immutable. 370 // Variables in with scope are immutable.
369 assertThrows(() => Debug.generatorScope(g, 0).setVariableValue("a", 3)); 371 assertThrows(() => Debug.generatorScope(g, 0).setVariableValue("a", 3));
370 assertThrows(() => Debug.generatorScope(g, 0).setVariableValue("b", 3)); 372 assertThrows(() => Debug.generatorScope(g, 0).setVariableValue("b", 3));
371 373
372 Debug.generatorScope(g, 1).setVariableValue("c", 1); 374 Debug.generatorScope(g, 1).setVariableValue("c", 1);
373 Debug.generatorScope(g, 1).setVariableValue("e", 42); 375 Debug.generatorScope(g, 1).setVariableValue("e", 42);
374 376
375 CheckScopeContent({a: 1, b: 2}, 0, g); 377 CheckScopeContent({a: 1, b: 2}, 0, g);
376 CheckScopeContent({c: 1, d: 4, e: 42}, 1, g); 378 CheckScopeContent({c: 1, d: 4, e: 42}, 1, g);
377 assertEquals(5, g.next().value); // Initialized after set. 379 assertEquals(5, g.next().value); // Initialized after set.
378 380
379 CheckScopeChain([debug.ScopeType.Closure, 381 CheckScopeChain([debug.ScopeType.Local,
380 debug.ScopeType.Script, 382 debug.ScopeType.Script,
381 debug.ScopeType.Global], g); 383 debug.ScopeType.Global], g);
382 384
383 Debug.generatorScope(g, 0).setVariableValue("e", 42); 385 Debug.generatorScope(g, 0).setVariableValue("e", 42);
384 386
385 CheckScopeContent({c: 1, d: 4, e: 42}, 0, g); 387 CheckScopeContent({c: 1, d: 4, e: 42}, 0, g);
386 assertEquals(42, g.next().value); 388 assertEquals(42, g.next().value);
387 389
388 // Set a variable in nested with blocks using in-place object literals plus a 390 // Set a variable in nested with blocks using in-place object literals plus a
389 // nested block scope. 391 // nested block scope.
390 392
391 function *gen16() { 393 function *gen16() {
392 var c = 3; 394 var c = 3;
393 with({a: 1,b: 2}) { 395 with({a: 1,b: 2}) {
394 let d = 4; 396 let d = 4;
395 yield a; 397 yield a;
396 let e = 5; 398 let e = 5;
397 yield d; 399 yield d;
398 } 400 }
399 return 3; 401 return 3;
400 } 402 }
401 403
402 var g = gen16(); 404 var g = gen16();
403 g.next(); 405 g.next();
404 406
405 CheckScopeChain([debug.ScopeType.Block, 407 CheckScopeChain([debug.ScopeType.Block,
406 debug.ScopeType.With, 408 debug.ScopeType.With,
407 debug.ScopeType.Closure, 409 debug.ScopeType.Local,
408 debug.ScopeType.Script, 410 debug.ScopeType.Script,
409 debug.ScopeType.Global], g); 411 debug.ScopeType.Global], g);
410 CheckScopeContent({d: 4}, 0, g); 412 CheckScopeContent({d: 4, e: undefined}, 0, g);
411 CheckScopeContent({a: 1, b: 2}, 1, g); 413 CheckScopeContent({a: 1, b: 2}, 1, g);
412 CheckScopeContent({c: 3}, 2, g); 414 CheckScopeContent({c: 3}, 2, g);
413 415
414 Debug.generatorScope(g, 0).setVariableValue("d", 1); 416 Debug.generatorScope(g, 0).setVariableValue("d", 1);
415 CheckScopeContent({d: 1}, 0, g); 417 CheckScopeContent({d: 1, e: undefined}, 0, g);
416 418
417 assertEquals(1, g.next().value); 419 assertEquals(1, g.next().value);
418 420
419 // Set variable in catch block. 421 // Set variable in catch block.
420 422
421 var yyzyzzyz = 4829; 423 var yyzyzzyz = 4829;
422 let xxxyyxxyx = 42284; 424 let xxxyyxxyx = 42284;
423 function *gen17() { 425 function *gen17() {
424 try { 426 try {
425 throw 42; 427 throw 42;
426 } catch (e) { 428 } catch (e) {
427 yield e; 429 yield e;
428 yield e; 430 yield e;
429 } 431 }
430 return 3; 432 return 3;
431 } 433 }
432 434
433 g = gen17(); 435 g = gen17();
434 g.next(); 436 g.next();
435 437
436 CheckScopeChain([debug.ScopeType.Catch, 438 CheckScopeChain([debug.ScopeType.Catch,
437 debug.ScopeType.Closure, 439 debug.ScopeType.Local,
438 debug.ScopeType.Script, 440 debug.ScopeType.Script,
439 debug.ScopeType.Global], g); 441 debug.ScopeType.Global], g);
440 CheckScopeContent({e: 42}, 0, g); 442 CheckScopeContent({e: 42}, 0, g);
441 CheckScopeContent({xxxyyxxyx: 42284, 443 CheckScopeContent({xxxyyxxyx: 42284,
442 printProtocolMessages : printProtocolMessages, 444 printProtocolMessages : printProtocolMessages,
443 activeWrapper : activeWrapper, 445 activeWrapper : activeWrapper,
444 DebugWrapper : DebugWrapper 446 DebugWrapper : DebugWrapper
445 }, 2, g); 447 }, 2, g);
446 448
447 Debug.generatorScope(g, 0).setVariableValue("e", 1); 449 Debug.generatorScope(g, 0).setVariableValue("e", 1);
448 CheckScopeContent({e: 1}, 0, g); 450 CheckScopeContent({e: 1}, 0, g);
449 451
450 assertEquals(1, g.next().value); 452 assertEquals(1, g.next().value);
451 453
452 // Script scope. 454 // Script scope.
453 Debug.generatorScope(g, 2).setVariableValue("xxxyyxxyx", 42); 455 Debug.generatorScope(g, 2).setVariableValue("xxxyyxxyx", 42);
454 assertEquals(42, xxxyyxxyx); 456 assertEquals(42, xxxyyxxyx);
455 457
456 // Global scope. 458 // Global scope.
457 assertThrows(() => Debug.generatorScope(g, 3).setVariableValue("yyzyzzyz", 42)); 459 assertThrows(() => Debug.generatorScope(g, 3).setVariableValue("yyzyzzyz", 42));
458 assertEquals(4829, yyzyzzyz); 460 assertEquals(4829, yyzyzzyz);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698