OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 #include "vm/ast_printer.h" | 6 #include "vm/ast_printer.h" |
7 #include "vm/class_finalizer.h" | 7 #include "vm/class_finalizer.h" |
8 #include "vm/debugger.h" | 8 #include "vm/debugger.h" |
9 #include "vm/longjump.h" | 9 #include "vm/longjump.h" |
10 #include "vm/object.h" | 10 #include "vm/object.h" |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 " return param + value;\n" // line 4 | 265 " return param + value;\n" // line 4 |
266 " }\n" | 266 " }\n" |
267 " return f(22);\n" | 267 " return f(22);\n" |
268 "}\n"; | 268 "}\n"; |
269 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 269 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
270 EXPECT_VALID(lib); | 270 EXPECT_VALID(lib); |
271 char* vars = CaptureVarsAtLine(lib, "main", 4); | 271 char* vars = CaptureVarsAtLine(lib, "main", 4); |
272 EXPECT_STREQ( | 272 EXPECT_STREQ( |
273 // function f uses one ctx var at (0); doesn't save ctx. | 273 // function f uses one ctx var at (0); doesn't save ctx. |
274 "main.f\n" | 274 "main.f\n" |
275 " 0 ContextVar level=0 begin=14 end=28 name=value\n" | 275 " 0 ContextLevel level=0 begin=0 end=12\n" |
276 " 1 StackVar scope=1 begin=16 end=28 name=param\n" | 276 " 1 ContextVar level=0 begin=14 end=28 name=value\n" |
277 " 2 CurrentCtx scope=0 begin=0 end=0" | 277 " 2 StackVar scope=1 begin=16 end=28 name=param\n" |
278 " name=:current_context_var\n" | 278 " 3 CurrentCtx scope=0 begin=0 end=0 name=:current_context_var\n" |
279 | 279 |
280 // Closure call saves current context. | 280 // Closure call saves current context. |
281 "_Closure.call\n" | 281 "_Closure.call\n" |
282 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 282 " 0 ContextLevel level=0 begin=0 end=8\n" |
283 " 1 CurrentCtx scope=0 begin=0 end=0" | 283 " 1 StackVar scope=1 begin=-1 end=0 name=this\n" |
284 " name=:current_context_var\n" | 284 " 2 CurrentCtx scope=0 begin=0 end=0 name=:current_context_var\n" |
285 | 285 |
286 // function main uses one ctx var at (1); saves caller ctx. | 286 // function main uses one ctx var at (1); saves caller ctx. |
287 "main\n" | 287 "main\n" |
288 " 0 CurrentCtx scope=0 begin=0 end=0" | 288 " 0 ContextLevel level=0 begin=0 end=6\n" |
289 " name=:current_context_var\n" | 289 " 1 ContextLevel level=1 begin=8 end=16\n" |
290 " 1 ContextLevel level=1 scope=2 begin=4 end=37\n" | 290 " 2 CurrentCtx scope=0 begin=0 end=0 name=:current_context_var\n" |
291 " 2 ContextVar level=1 begin=10 end=37 name=value\n" | 291 " 3 ContextVar level=1 begin=10 end=37 name=value\n" |
292 " 3 StackVar scope=2 begin=12 end=37 name=f\n", | 292 " 4 StackVar scope=2 begin=12 end=37 name=f\n", |
293 vars); | 293 vars); |
294 free(vars); | 294 free(vars); |
295 } | 295 } |
296 | 296 |
297 | 297 |
298 TEST_CASE(Parser_AllocateVariables_NestedCapturedVar) { | 298 TEST_CASE(Parser_AllocateVariables_NestedCapturedVar) { |
299 const char* kScriptChars = | 299 const char* kScriptChars = |
300 "int a() {\n" | 300 "int a() {\n" |
301 " int b() {\n" | 301 " int b() {\n" |
302 " var value = 11;\n" | 302 " var value = 11;\n" |
303 " int c() {\n" | 303 " int c() {\n" |
304 " return value;\n" // line 5 | 304 " return value;\n" // line 5 |
305 " }\n" | 305 " }\n" |
306 " return c();\n" | 306 " return c();\n" |
307 " }\n" | 307 " }\n" |
308 " return b();\n" | 308 " return b();\n" |
309 "}\n"; | 309 "}\n"; |
310 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 310 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
311 EXPECT_VALID(lib); | 311 EXPECT_VALID(lib); |
312 char* vars = CaptureVarsAtLine(lib, "a", 5); | 312 char* vars = CaptureVarsAtLine(lib, "a", 5); |
313 EXPECT_STREQ( | 313 EXPECT_STREQ( |
314 // Innermost function uses captured variable 'value' from middle | 314 // Innermost function uses captured variable 'value' from middle |
315 // function. | 315 // function. |
316 "a.b.c\n" | 316 "a.b.c\n" |
317 " 0 ContextVar level=0 begin=20 end=30 name=value\n" | 317 " 0 ContextLevel level=0 begin=0 end=10\n" |
318 " 1 CurrentCtx scope=0 begin=0 end=0" | 318 " 1 ContextVar level=0 begin=20 end=30 name=value\n" |
319 " name=:current_context_var\n" | 319 " 2 CurrentCtx scope=0 begin=0 end=0 name=:current_context_var\n" |
320 | 320 |
321 // Closure call saves current context. | 321 // Closure call saves current context. |
322 "_Closure.call\n" | 322 "_Closure.call\n" |
323 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 323 " 0 ContextLevel level=0 begin=0 end=8\n" |
324 " 1 CurrentCtx scope=0 begin=0 end=0" | 324 " 1 StackVar scope=1 begin=-1 end=0 name=this\n" |
325 " name=:current_context_var\n" | 325 " 2 CurrentCtx scope=0 begin=0 end=0 name=:current_context_var\n" |
326 | |
327 // Middle function saves the entry context. Notice that this | 326 // Middle function saves the entry context. Notice that this |
328 // happens here and not in the outermost function. We always | 327 // happens here and not in the outermost function. We always |
329 // save the entry context at the last possible moment. | 328 // save the entry context at the last possible moment. |
330 "a.b\n" | 329 "a.b\n" |
331 " 0 CurrentCtx scope=0 begin=0 end=0" | 330 " 0 ContextLevel level=0 begin=0 end=6\n" |
332 " name=:current_context_var\n" | 331 " 1 ContextLevel level=1 begin=8 end=16\n" |
333 " 1 ContextLevel level=1 scope=2 begin=10 end=38\n" | 332 " 2 CurrentCtx scope=0 begin=0 end=0 name=:current_context_var\n" |
334 " 2 ContextVar level=1 begin=16 end=38 name=value\n" | 333 " 3 ContextVar level=1 begin=16 end=38 name=value\n" |
335 " 3 StackVar scope=2 begin=18 end=38 name=c\n" | 334 " 4 StackVar scope=2 begin=18 end=38 name=c\n" |
336 | 335 |
337 // Closure call saves current context. | 336 // Closure call saves current context. |
338 "_Closure.call\n" | 337 "_Closure.call\n" |
339 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 338 " 0 ContextLevel level=0 begin=0 end=8\n" |
340 " 1 CurrentCtx scope=0 begin=0 end=0" | 339 " 1 StackVar scope=1 begin=-1 end=0 name=this\n" |
341 " name=:current_context_var\n" | 340 " 2 CurrentCtx scope=0 begin=0 end=0 name=:current_context_var\n" |
342 | 341 |
343 // Outermost function neglects to save the entry context. We | 342 // Outermost function neglects to save the entry context. We |
344 // don't save the entry context if the function has no captured | 343 // don't save the entry context if the function has no captured |
345 // variables. | 344 // variables. |
346 "a\n" | 345 "a\n" |
347 " 0 CurrentCtx scope=0 begin=0 end=0" | 346 " 0 ContextLevel level=0 begin=0 end=14\n" |
348 " name=:current_context_var\n" | 347 " 1 CurrentCtx scope=0 begin=0 end=0 name=:current_context_var\n" |
349 " 1 StackVar scope=2 begin=6 end=46 name=b\n", | 348 " 2 StackVar scope=2 begin=6 end=46 name=b\n", |
350 vars); | 349 vars); |
351 free(vars); | 350 free(vars); |
352 } | 351 } |
353 | 352 |
354 | 353 |
355 TEST_CASE(Parser_AllocateVariables_TwoChains) { | 354 TEST_CASE(Parser_AllocateVariables_TwoChains) { |
356 const char* kScriptChars = | 355 const char* kScriptChars = |
357 "int a() {\n" | 356 "int a() {\n" |
358 " var value1 = 11;\n" | 357 " var value1 = 11;\n" |
359 " int b() {\n" | 358 " int b() {\n" |
360 " int aa() {\n" | 359 " int aa() {\n" |
361 " var value2 = 12;\n" | 360 " var value2 = 12;\n" |
362 " int bb() {\n" | 361 " int bb() {\n" |
363 " return value2;\n" // line 7 | 362 " return value2;\n" // line 7 |
364 " }\n" | 363 " }\n" |
365 " return bb();\n" | 364 " return bb();\n" |
366 " }\n" | 365 " }\n" |
367 " return value1 + aa();\n" | 366 " return value1 + aa();\n" |
368 " }\n" | 367 " }\n" |
369 " return b();\n" | 368 " return b();\n" |
370 "}\n"; | 369 "}\n"; |
371 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 370 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
372 EXPECT_VALID(lib); | 371 EXPECT_VALID(lib); |
373 | 372 |
374 char* vars = CaptureVarsAtLine(lib, "a", 7); | 373 char* vars = CaptureVarsAtLine(lib, "a", 7); |
375 EXPECT_STREQ( | 374 EXPECT_STREQ( |
376 // bb captures only value2 from aa. No others. | 375 // bb captures only value2 from aa. No others. |
377 "a.b.aa.bb\n" | 376 "a.b.aa.bb\n" |
378 " 0 ContextVar level=0 begin=34 end=44 name=value2\n" | 377 " 0 ContextLevel level=0 begin=0 end=10\n" |
379 " 1 CurrentCtx scope=0 begin=0 end=0" | 378 " 1 ContextVar level=0 begin=34 end=44 name=value2\n" |
| 379 " 2 CurrentCtx scope=0 begin=0 end=0" |
380 " name=:current_context_var\n" | 380 " name=:current_context_var\n" |
381 | 381 |
382 // Closure call saves current context. | 382 // Closure call saves current context. |
383 "_Closure.call\n" | 383 "_Closure.call\n" |
384 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 384 " 0 ContextLevel level=0 begin=0 end=8\n" |
385 " 1 CurrentCtx scope=0 begin=0 end=0" | 385 " 1 StackVar scope=1 begin=-1 end=0 name=this\n" |
| 386 " 2 CurrentCtx scope=0 begin=0 end=0" |
386 " name=:current_context_var\n" | 387 " name=:current_context_var\n" |
387 | 388 |
388 // aa shares value2. Notice that we save the entry ctx instead | 389 // aa shares value2. Notice that we save the entry ctx instead |
389 // of chaining from b. This keeps us from holding onto closures | 390 // of chaining from b. This keeps us from holding onto closures |
390 // that we would never access. | 391 // that we would never access. |
391 "a.b.aa\n" | 392 "a.b.aa\n" |
392 " 0 CurrentCtx scope=0 begin=0 end=0" | 393 " 0 ContextLevel level=0 begin=0 end=6\n" |
393 " name=:current_context_var\n" | 394 " 1 ContextLevel level=1 begin=8 end=16\n" |
394 " 1 ContextLevel level=1 scope=2 begin=22 end=53\n" | 395 " 2 CurrentCtx scope=0 begin=0 end=0 name=:current_context_var\n" |
395 " 2 ContextVar level=1 begin=29 end=53 name=value2\n" | 396 " 3 ContextVar level=1 begin=29 end=53 name=value2\n" |
396 " 3 StackVar scope=2 begin=31 end=53 name=bb\n" | 397 " 4 StackVar scope=2 begin=31 end=53 name=bb\n" |
397 | 398 |
398 // Closure call saves current context. | 399 // Closure call saves current context. |
399 "_Closure.call\n" | 400 "_Closure.call\n" |
400 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 401 " 0 ContextLevel level=0 begin=0 end=8\n" |
401 " 1 CurrentCtx scope=0 begin=0 end=0" | 402 " 1 StackVar scope=1 begin=-1 end=0 name=this\n" |
| 403 " 2 CurrentCtx scope=0 begin=0 end=0" |
402 " name=:current_context_var\n" | 404 " name=:current_context_var\n" |
403 | 405 |
404 // b captures value1 from a. | 406 // b captures value1 from a. |
405 "a.b\n" | 407 "a.b\n" |
406 " 0 ContextVar level=0 begin=14 end=63 name=value1\n" | 408 " 0 ContextLevel level=0 begin=0 end=16\n" |
407 " 1 CurrentCtx scope=0 begin=0 end=0" | 409 " 1 ContextVar level=0 begin=14 end=63 name=value1\n" |
| 410 " 2 CurrentCtx scope=0 begin=0 end=0" |
408 " name=:current_context_var\n" | 411 " name=:current_context_var\n" |
409 " 2 StackVar scope=2 begin=18 end=63 name=aa\n" | 412 " 3 StackVar scope=2 begin=18 end=63 name=aa\n" |
410 | 413 |
411 // Closure call saves current context. | 414 // Closure call saves current context. |
412 "_Closure.call\n" | 415 "_Closure.call\n" |
413 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 416 " 0 ContextLevel level=0 begin=0 end=8\n" |
414 " 1 CurrentCtx scope=0 begin=0 end=0" | 417 " 1 StackVar scope=1 begin=-1 end=0 name=this\n" |
| 418 " 2 CurrentCtx scope=0 begin=0 end=0" |
415 " name=:current_context_var\n" | 419 " name=:current_context_var\n" |
416 | 420 |
417 // a shares value1, saves entry ctx. | 421 // a shares value1, saves entry ctx. |
418 "a\n" | 422 "a\n" |
419 " 0 CurrentCtx scope=0 begin=0 end=0" | 423 " 0 ContextLevel level=0 begin=0 end=6\n" |
| 424 " 1 ContextLevel level=1 begin=8 end=16\n" |
| 425 " 2 CurrentCtx scope=0 begin=0 end=0" |
420 " name=:current_context_var\n" | 426 " name=:current_context_var\n" |
421 " 1 ContextLevel level=1 scope=2 begin=4 end=71\n" | 427 " 3 ContextVar level=1 begin=10 end=71 name=value1\n" |
422 " 2 ContextVar level=1 begin=10 end=71 name=value1\n" | 428 " 4 StackVar scope=2 begin=12 end=71 name=b\n", |
423 " 3 StackVar scope=2 begin=12 end=71 name=b\n", | |
424 vars); | 429 vars); |
425 free(vars); | 430 free(vars); |
426 } | 431 } |
427 | 432 |
428 | 433 |
429 TEST_CASE(Parser_AllocateVariables_Issue7681) { | 434 TEST_CASE(Parser_AllocateVariables_Issue7681) { |
430 // This is a distilled version of the program from Issue 7681. | 435 // This is a distilled version of the program from Issue 7681. |
431 // | 436 // |
432 // When we create the closure at line 11, we need to make sure to | 437 // When we create the closure at line 11, we need to make sure to |
433 // save the entry context instead of chaining to the parent context. | 438 // save the entry context instead of chaining to the parent context. |
(...skipping 17 matching lines...) Expand all Loading... |
451 " };\n" | 456 " };\n" |
452 " };\n" | 457 " };\n" |
453 " x.onX(new Y());\n" | 458 " x.onX(new Y());\n" |
454 "}\n"; | 459 "}\n"; |
455 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 460 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
456 EXPECT_VALID(lib); | 461 EXPECT_VALID(lib); |
457 char* vars = CaptureVarsAtLine(lib, "doIt", 12); | 462 char* vars = CaptureVarsAtLine(lib, "doIt", 12); |
458 EXPECT_STREQ( | 463 EXPECT_STREQ( |
459 // This frame saves the entry context instead of chaining. Good. | 464 // This frame saves the entry context instead of chaining. Good. |
460 "doIt.<anonymous closure>\n" | 465 "doIt.<anonymous closure>\n" |
461 " 0 ContextLevel level=1 scope=1 begin=41 end=65\n" | 466 " 0 ContextLevel level=0 begin=0 end=0\n" |
462 " 1 ContextVar level=1 begin=42 end=65 name=y\n" | 467 " 1 ContextLevel level=1 begin=4 end=12\n" |
463 " 2 CurrentCtx scope=0 begin=0 end=0" | 468 " 2 ContextVar level=1 begin=42 end=65 name=y\n" |
464 " name=:current_context_var\n" | 469 " 3 CurrentCtx scope=0 begin=0 end=0 name=:current_context_var\n" |
465 | 470 |
466 // Closure call saves current context. | 471 // Closure call saves current context. |
467 "_Closure.call\n" | 472 "_Closure.call\n" |
468 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 473 " 0 ContextLevel level=0 begin=0 end=8\n" |
469 " 1 CurrentCtx scope=0 begin=0 end=0" | 474 " 1 StackVar scope=1 begin=-1 end=0 name=this\n" |
470 " name=:current_context_var\n" | 475 " 2 CurrentCtx scope=0 begin=0 end=0 name=:current_context_var\n" |
471 | 476 |
472 "X.onX\n" | 477 "X.onX\n" |
473 " 0 StackVar scope=1 begin=0 end=0 name=this\n" | 478 " 0 ContextLevel level=0 begin=0 end=10\n" |
474 " 1 CurrentCtx scope=0 begin=0 end=0" | 479 " 1 StackVar scope=1 begin=-1 end=0 name=this\n" |
475 " name=:current_context_var\n" | 480 " 2 CurrentCtx scope=0 begin=0 end=0 name=:current_context_var\n" |
476 | 481 |
477 // No context is saved here since no vars are captured. | 482 // No context is saved here since no vars are captured. |
478 "doIt\n" | 483 "doIt\n" |
479 " 0 CurrentCtx scope=0 begin=0 end=0" | 484 " 0 ContextLevel level=0 begin=0 end=18\n" |
480 " name=:current_context_var\n" | 485 " 1 CurrentCtx scope=0 begin=0 end=0 name=:current_context_var\n" |
481 " 1 StackVar scope=2 begin=35 end=80 name=x\n", | 486 " 2 StackVar scope=2 begin=35 end=80 name=x\n", |
482 vars); | 487 vars); |
483 free(vars); | 488 free(vars); |
484 } | 489 } |
485 | 490 |
486 | 491 |
487 TEST_CASE(Parser_AllocateVariables_CaptureLoopVar) { | 492 TEST_CASE(Parser_AllocateVariables_CaptureLoopVar) { |
488 // This test verifies that... | 493 // This test verifies that... |
489 // | 494 // |
490 // https://code.google.com/p/dart/issues/detail?id=18561 | 495 // https://code.google.com/p/dart/issues/detail?id=18561 |
491 // | 496 // |
492 // ...stays fixed. | 497 // ...stays fixed. |
493 const char* kScriptChars = | 498 const char* kScriptChars = |
494 "int outer() {\n" | 499 "int outer() {\n" |
495 " for(int i = 0; i < 1; i++) {\n" | 500 " for(int i = 0; i < 1; i++) {\n" |
496 " var value = 11 + i;\n" | 501 " var value = 11 + i;\n" |
497 " int inner() {\n" | 502 " int inner() {\n" |
498 " return value;\n" // line 5 | 503 " return value;\n" // line 5 |
499 " }\n" | 504 " }\n" |
500 " return inner();\n" | 505 " return inner();\n" |
501 " }\n" | 506 " }\n" |
502 "}\n"; | 507 "}\n"; |
503 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 508 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
504 EXPECT_VALID(lib); | 509 EXPECT_VALID(lib); |
505 char* vars = CaptureVarsAtLine(lib, "outer", 5); | 510 char* vars = CaptureVarsAtLine(lib, "outer", 5); |
506 EXPECT_STREQ( | 511 EXPECT_STREQ( |
507 // inner function captures variable value. That's fine. | 512 // inner function captures variable value. That's fine. |
508 "outer.inner\n" | 513 "outer.inner\n" |
509 " 0 ContextVar level=0 begin=33 end=43 name=value\n" | 514 " 0 ContextLevel level=0 begin=0 end=10\n" |
510 " 1 CurrentCtx scope=0 begin=0 end=0" | 515 " 1 ContextVar level=0 begin=33 end=43 name=value\n" |
511 " name=:current_context_var\n" | 516 " 2 CurrentCtx scope=0 begin=0 end=0 name=:current_context_var\n" |
512 | 517 |
513 // Closure call saves current context. | 518 // Closure call saves current context. |
514 "_Closure.call\n" | 519 "_Closure.call\n" |
515 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 520 " 0 ContextLevel level=0 begin=0 end=8\n" |
516 " 1 CurrentCtx scope=0 begin=0 end=0" | 521 " 1 StackVar scope=1 begin=-1 end=0 name=this\n" |
517 " name=:current_context_var\n" | 522 " 2 CurrentCtx scope=0 begin=0 end=0 name=:current_context_var\n" |
518 | 523 |
519 // The outer function saves the entry context, even though the | 524 // The outer function saves the entry context, even though the |
520 // captured variable is in a loop. Good. | 525 // captured variable is in a loop. Good. |
521 "outer\n" | 526 "outer\n" |
522 " 0 CurrentCtx scope=0 begin=0 end=0" | 527 " 0 ContextLevel level=0 begin=0 end=8\n" |
523 " name=:current_context_var\n" | 528 " 1 ContextLevel level=1 begin=10 end=18\n" |
524 " 1 StackVar scope=3 begin=12 end=52 name=i\n" | 529 " 2 ContextLevel level=0 begin=20 end=34\n" |
525 " 2 ContextLevel level=1 scope=4 begin=20 end=52\n" | 530 " 3 CurrentCtx scope=0 begin=0 end=0 name=:current_context_var\n" |
526 " 3 ContextVar level=1 begin=28 end=52 name=value\n" | 531 " 4 StackVar scope=3 begin=12 end=52 name=i\n" |
527 " 4 StackVar scope=4 begin=30 end=52 name=inner\n", | 532 " 5 ContextVar level=1 begin=28 end=52 name=value\n" |
| 533 " 6 StackVar scope=4 begin=30 end=52 name=inner\n", |
528 vars); | 534 vars); |
529 free(vars); | 535 free(vars); |
530 } | 536 } |
531 | 537 |
532 TEST_CASE(Parser_AllocateVariables_MiddleChain) { | 538 TEST_CASE(Parser_AllocateVariables_MiddleChain) { |
533 const char* kScriptChars = | 539 const char* kScriptChars = |
534 "a() {\n" | 540 "a() {\n" |
535 " int x = 11;\n" | 541 " int x = 11;\n" |
536 " b() {\n" | 542 " b() {\n" |
537 " for (int i = 0; i < 1; i++) {\n" | 543 " for (int i = 0; i < 1; i++) {\n" |
538 " int d() {\n" | 544 " int d() {\n" |
539 " return i;\n" | 545 " return i;\n" |
540 " }\n" | 546 " }\n" |
541 " }\n" | 547 " }\n" |
542 " int c() {\n" | 548 " int c() {\n" |
543 " return x + 1;\n" // line 10 | 549 " return x + 1;\n" // line 10 |
544 " }\n" | 550 " }\n" |
545 " return c();\n" | 551 " return c();\n" |
546 " }\n" | 552 " }\n" |
547 " return b();\n" | 553 " return b();\n" |
548 "}\n"; | 554 "}\n"; |
549 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 555 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
550 EXPECT_VALID(lib); | 556 EXPECT_VALID(lib); |
551 char* vars = CaptureVarsAtLine(lib, "a", 10); | 557 char* vars = CaptureVarsAtLine(lib, "a", 10); |
552 EXPECT_STREQ( | 558 EXPECT_STREQ( |
553 "a.b.c\n" | 559 "a.b.c\n" |
554 " 0 ContextVar level=0 begin=51 end=64 name=x\n" | 560 " 0 ContextLevel level=0 begin=0 end=12\n" |
555 " 1 CurrentCtx scope=0 begin=0 end=0" | 561 " 1 ContextVar level=0 begin=51 end=64 name=x\n" |
556 " name=:current_context_var\n" | 562 " 2 CurrentCtx scope=0 begin=0 end=0 name=:current_context_var\n" |
| 563 |
557 "_Closure.call\n" | 564 "_Closure.call\n" |
558 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 565 " 0 ContextLevel level=0 begin=0 end=8\n" |
559 " 1 CurrentCtx scope=0 begin=0 end=0" | 566 " 1 StackVar scope=1 begin=-1 end=0 name=this\n" |
560 " name=:current_context_var\n" | 567 " 2 CurrentCtx scope=0 begin=0 end=0 name=:current_context_var\n" |
561 | 568 |
562 // Doesn't save the entry context. Chains to parent instead. | 569 // Doesn't save the entry context. Chains to parent instead. |
563 "a.b\n" | 570 "a.b\n" |
564 " 0 ContextVar level=0 begin=12 end=73 name=x\n" | 571 " 0 ContextLevel level=0 begin=0 end=6\n" |
565 " 1 CurrentCtx scope=0 begin=0 end=0" | 572 " 1 ContextLevel level=1 begin=8 end=32\n" |
566 " name=:current_context_var\n" | 573 " 2 ContextLevel level=0 begin=34 end=40\n" |
567 " 2 StackVar scope=2 begin=48 end=73 name=c\n" | 574 " 3 ContextVar level=0 begin=12 end=73 name=x\n" |
568 " 3 ContextLevel level=1 scope=3 begin=18 end=48\n" | 575 " 4 CurrentCtx scope=0 begin=0 end=0 name=:current_context_var\n" |
569 " 4 ContextVar level=1 begin=22 end=48 name=i\n" | 576 " 5 StackVar scope=2 begin=48 end=73 name=c\n" |
570 " 5 StackVar scope=4 begin=33 end=48 name=d\n" | 577 " 6 ContextVar level=1 begin=22 end=48 name=i\n" |
| 578 " 7 StackVar scope=4 begin=33 end=48 name=d\n" |
571 | 579 |
572 "_Closure.call\n" | 580 "_Closure.call\n" |
573 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 581 " 0 ContextLevel level=0 begin=0 end=8\n" |
574 " 1 CurrentCtx scope=0 begin=0 end=0" | 582 " 1 StackVar scope=1 begin=-1 end=0 name=this\n" |
575 " name=:current_context_var\n" | 583 " 2 CurrentCtx scope=0 begin=0 end=0 name=:current_context_var\n" |
576 | 584 |
577 "a\n" | 585 "a\n" |
578 " 0 CurrentCtx scope=0 begin=0 end=0" | 586 " 0 ContextLevel level=0 begin=0 end=6\n" |
579 " name=:current_context_var\n" | 587 " 1 ContextLevel level=1 begin=8 end=16\n" |
580 " 1 ContextLevel level=1 scope=2 begin=3 end=81\n" | 588 " 2 CurrentCtx scope=0 begin=0 end=0 name=:current_context_var\n" |
581 " 2 ContextVar level=1 begin=9 end=81 name=x\n" | 589 " 3 ContextVar level=1 begin=9 end=81 name=x\n" |
582 " 3 StackVar scope=2 begin=11 end=81 name=b\n", | 590 " 4 StackVar scope=2 begin=11 end=81 name=b\n", |
583 vars); | 591 vars); |
584 free(vars); | 592 free(vars); |
585 } | 593 } |
586 | 594 |
587 #endif // !PRODUCT | 595 #endif // !PRODUCT |
588 | 596 |
589 } // namespace dart | 597 } // namespace dart |
OLD | NEW |