| 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 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 " return value1 + aa();\n" | 356 " return value1 + aa();\n" |
| 357 " }\n" | 357 " }\n" |
| 358 " return b();\n" | 358 " return b();\n" |
| 359 "}\n"; | 359 "}\n"; |
| 360 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 360 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 361 EXPECT_VALID(lib); | 361 EXPECT_VALID(lib); |
| 362 | 362 |
| 363 EXPECT_STREQ( | 363 EXPECT_STREQ( |
| 364 // bb captures only value2 from aa. No others. | 364 // bb captures only value2 from aa. No others. |
| 365 "a.b.aa.bb\n" | 365 "a.b.aa.bb\n" |
| 366 " 0 ContextVar level=0 begin=32 end=42 name=value2\n" | 366 " 0 ContextVar level=0 begin=33 end=43 name=value2\n" |
| 367 " 1 CurrentCtx scope=0 begin=0 end=0" | 367 " 1 CurrentCtx scope=0 begin=0 end=0" |
| 368 " name=:current_context_var\n" | 368 " name=:current_context_var\n" |
| 369 | 369 |
| 370 // Closure call saves current context. | 370 // Closure call saves current context. |
| 371 "_FunctionImpl.call\n" | 371 "_FunctionImpl.call\n" |
| 372 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 372 " 0 StackVar scope=1 begin=0 end=4 name=this\n" |
| 373 " 1 CurrentCtx scope=0 begin=0 end=0" | 373 " 1 CurrentCtx scope=0 begin=0 end=0" |
| 374 " name=:current_context_var\n" | 374 " name=:current_context_var\n" |
| 375 | 375 |
| 376 // aa shares value2. Notice that we save the entry ctx instead | 376 // aa shares value2. Notice that we save the entry ctx instead |
| 377 // of chaining from b. This keeps us from holding onto closures | 377 // of chaining from b. This keeps us from holding onto closures |
| 378 // that we would never access. | 378 // that we would never access. |
| 379 "a.b.aa\n" | 379 "a.b.aa\n" |
| 380 " 0 CurrentCtx scope=0 begin=0 end=0" | 380 " 0 CurrentCtx scope=0 begin=0 end=0" |
| 381 " name=:current_context_var\n" | 381 " name=:current_context_var\n" |
| 382 " 1 ContextLevel level=1 scope=2 begin=22 end=50\n" | 382 " 1 ContextLevel level=1 scope=2 begin=22 end=52\n" |
| 383 " 2 ContextVar level=1 begin=28 end=50 name=value2\n" | 383 " 2 ContextVar level=1 begin=28 end=52 name=value2\n" |
| 384 " 3 StackVar scope=2 begin=30 end=50 name=bb\n" | 384 " 3 StackVar scope=2 begin=30 end=52 name=bb\n" |
| 385 | 385 |
| 386 // Closure call saves current context. | 386 // Closure call saves current context. |
| 387 "_FunctionImpl.call\n" | 387 "_FunctionImpl.call\n" |
| 388 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 388 " 0 StackVar scope=1 begin=0 end=4 name=this\n" |
| 389 " 1 CurrentCtx scope=0 begin=0 end=0" | 389 " 1 CurrentCtx scope=0 begin=0 end=0" |
| 390 " name=:current_context_var\n" | 390 " name=:current_context_var\n" |
| 391 | 391 |
| 392 // b captures value1 from a. | 392 // b captures value1 from a. |
| 393 "a.b\n" | 393 "a.b\n" |
| 394 " 0 ContextVar level=0 begin=14 end=60 name=value1\n" | 394 " 0 ContextVar level=0 begin=14 end=62 name=value1\n" |
| 395 " 1 CurrentCtx scope=0 begin=0 end=0" | 395 " 1 CurrentCtx scope=0 begin=0 end=0" |
| 396 " name=:current_context_var\n" | 396 " name=:current_context_var\n" |
| 397 " 2 StackVar scope=2 begin=18 end=60 name=aa\n" | 397 " 2 StackVar scope=2 begin=18 end=62 name=aa\n" |
| 398 | 398 |
| 399 // Closure call saves current context. | 399 // Closure call saves current context. |
| 400 "_FunctionImpl.call\n" | 400 "_FunctionImpl.call\n" |
| 401 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 401 " 0 StackVar scope=1 begin=0 end=4 name=this\n" |
| 402 " 1 CurrentCtx scope=0 begin=0 end=0" | 402 " 1 CurrentCtx scope=0 begin=0 end=0" |
| 403 " name=:current_context_var\n" | 403 " name=:current_context_var\n" |
| 404 | 404 |
| 405 // a shares value1, saves entry ctx. | 405 // a shares value1, saves entry ctx. |
| 406 "a\n" | 406 "a\n" |
| 407 " 0 CurrentCtx scope=0 begin=0 end=0" | 407 " 0 CurrentCtx scope=0 begin=0 end=0" |
| 408 " name=:current_context_var\n" | 408 " name=:current_context_var\n" |
| 409 " 1 ContextLevel level=1 scope=2 begin=4 end=68\n" | 409 " 1 ContextLevel level=1 scope=2 begin=4 end=70\n" |
| 410 " 2 ContextVar level=1 begin=10 end=68 name=value1\n" | 410 " 2 ContextVar level=1 begin=10 end=70 name=value1\n" |
| 411 " 3 StackVar scope=2 begin=12 end=68 name=b\n", | 411 " 3 StackVar scope=2 begin=12 end=70 name=b\n", |
| 412 CaptureVarsAtLine(lib, "a", 7)); | 412 CaptureVarsAtLine(lib, "a", 7)); |
| 413 } | 413 } |
| 414 | 414 |
| 415 | 415 |
| 416 TEST_CASE(Parser_AllocateVariables_Issue7681) { | 416 TEST_CASE(Parser_AllocateVariables_Issue7681) { |
| 417 // This is a distilled version of the program from Issue 7681. | 417 // This is a distilled version of the program from Issue 7681. |
| 418 // | 418 // |
| 419 // When we create the closure at line 11, we need to make sure to | 419 // When we create the closure at line 11, we need to make sure to |
| 420 // save the entry context instead of chaining to the parent context. | 420 // save the entry context instead of chaining to the parent context. |
| 421 // | 421 // |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 " return x + 1;\n" // line 10 | 526 " return x + 1;\n" // line 10 |
| 527 " }\n" | 527 " }\n" |
| 528 " return c();\n" | 528 " return c();\n" |
| 529 " }\n" | 529 " }\n" |
| 530 " return b();\n" | 530 " return b();\n" |
| 531 "}\n"; | 531 "}\n"; |
| 532 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 532 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 533 EXPECT_VALID(lib); | 533 EXPECT_VALID(lib); |
| 534 EXPECT_STREQ( | 534 EXPECT_STREQ( |
| 535 "a.b.c\n" | 535 "a.b.c\n" |
| 536 " 0 ContextVar level=0 begin=48 end=60 name=x\n" | 536 " 0 ContextVar level=0 begin=50 end=62 name=x\n" |
| 537 " 1 CurrentCtx scope=0 begin=0 end=0" | 537 " 1 CurrentCtx scope=0 begin=0 end=0" |
| 538 " name=:current_context_var\n" | 538 " name=:current_context_var\n" |
| 539 "_FunctionImpl.call\n" | 539 "_FunctionImpl.call\n" |
| 540 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 540 " 0 StackVar scope=1 begin=0 end=4 name=this\n" |
| 541 " 1 CurrentCtx scope=0 begin=0 end=0" | 541 " 1 CurrentCtx scope=0 begin=0 end=0" |
| 542 " name=:current_context_var\n" | 542 " name=:current_context_var\n" |
| 543 | 543 |
| 544 // Doesn't save the entry context. Chains to parent instead. | 544 // Doesn't save the entry context. Chains to parent instead. |
| 545 "a.b\n" | 545 "a.b\n" |
| 546 " 0 ContextVar level=0 begin=12 end=68 name=x\n" | 546 " 0 ContextVar level=0 begin=12 end=71 name=x\n" |
| 547 " 1 CurrentCtx scope=0 begin=0 end=0" | 547 " 1 CurrentCtx scope=0 begin=0 end=0" |
| 548 " name=:current_context_var\n" | 548 " name=:current_context_var\n" |
| 549 " 2 StackVar scope=2 begin=46 end=68 name=c\n" | 549 " 2 StackVar scope=2 begin=47 end=71 name=c\n" |
| 550 " 3 ContextLevel level=1 scope=3 begin=18 end=46\n" | 550 " 3 ContextLevel level=1 scope=3 begin=18 end=47\n" |
| 551 " 4 ContextVar level=1 begin=22 end=46 name=i\n" | 551 " 4 ContextVar level=1 begin=22 end=47 name=i\n" |
| 552 " 5 StackVar scope=4 begin=32 end=46 name=d\n" | 552 " 5 StackVar scope=4 begin=32 end=47 name=d\n" |
| 553 | 553 |
| 554 "_FunctionImpl.call\n" | 554 "_FunctionImpl.call\n" |
| 555 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 555 " 0 StackVar scope=1 begin=0 end=4 name=this\n" |
| 556 " 1 CurrentCtx scope=0 begin=0 end=0" | 556 " 1 CurrentCtx scope=0 begin=0 end=0" |
| 557 " name=:current_context_var\n" | 557 " name=:current_context_var\n" |
| 558 | 558 |
| 559 "a\n" | 559 "a\n" |
| 560 " 0 CurrentCtx scope=0 begin=0 end=0" | 560 " 0 CurrentCtx scope=0 begin=0 end=0" |
| 561 " name=:current_context_var\n" | 561 " name=:current_context_var\n" |
| 562 " 1 ContextLevel level=1 scope=2 begin=3 end=76\n" | 562 " 1 ContextLevel level=1 scope=2 begin=3 end=79\n" |
| 563 " 2 ContextVar level=1 begin=9 end=76 name=x\n" | 563 " 2 ContextVar level=1 begin=9 end=79 name=x\n" |
| 564 " 3 StackVar scope=2 begin=11 end=76 name=b\n", | 564 " 3 StackVar scope=2 begin=11 end=79 name=b\n", |
| 565 CaptureVarsAtLine(lib, "a", 10)); | 565 CaptureVarsAtLine(lib, "a", 10)); |
| 566 } | 566 } |
| 567 | 567 |
| 568 } // namespace dart | 568 } // namespace dart |
| OLD | NEW |