OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 3498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3509 const i::AstRawString* var_name = | 3509 const i::AstRawString* var_name = |
3510 info->ast_value_factory()->GetOneByteString("arg"); | 3510 info->ast_value_factory()->GetOneByteString("arg"); |
3511 i::Variable* var = scope->Lookup(var_name); | 3511 i::Variable* var = scope->Lookup(var_name); |
3512 CHECK(var->is_used() || !assigned); | 3512 CHECK(var->is_used() || !assigned); |
3513 bool is_maybe_assigned = var->maybe_assigned() == i::kMaybeAssigned; | 3513 bool is_maybe_assigned = var->maybe_assigned() == i::kMaybeAssigned; |
3514 CHECK_EQ(is_maybe_assigned, assigned); | 3514 CHECK_EQ(is_maybe_assigned, assigned); |
3515 } | 3515 } |
3516 } | 3516 } |
3517 } | 3517 } |
3518 | 3518 |
| 3519 struct Input { |
| 3520 bool assigned; |
| 3521 std::string source; |
| 3522 std::vector<unsigned> location; // "Directions" to the relevant scope. |
| 3523 }; |
| 3524 |
| 3525 static void TestMaybeAssigned(i::Zone* zone, Input input, const char* variable, |
| 3526 bool module, bool allow_lazy_parsing) { |
| 3527 i::Factory* factory = CcTest::i_isolate()->factory(); |
| 3528 i::Handle<i::String> string = |
| 3529 factory->InternalizeUtf8String(input.source.c_str()); |
| 3530 string->PrintOn(stdout); |
| 3531 printf("\n"); |
| 3532 i::Handle<i::Script> script = factory->NewScript(string); |
| 3533 |
| 3534 std::unique_ptr<i::ParseInfo> info; |
| 3535 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(zone, script)); |
| 3536 info->set_module(module); |
| 3537 info->set_allow_lazy_parsing(allow_lazy_parsing); |
| 3538 |
| 3539 CHECK(i::parsing::ParseProgram(info.get())); |
| 3540 CHECK(i::Compiler::Analyze(info.get())); |
| 3541 |
| 3542 CHECK_NOT_NULL(info->literal()); |
| 3543 i::Scope* scope = info->literal()->scope(); |
| 3544 CHECK(!scope->AsDeclarationScope()->was_lazily_parsed()); |
| 3545 CHECK_NULL(scope->sibling()); |
| 3546 CHECK(module ? scope->is_module_scope() : scope->is_script_scope()); |
| 3547 |
| 3548 i::Variable* var; |
| 3549 { |
| 3550 // Find the variable. |
| 3551 for (auto it = input.location.begin(); it != input.location.end(); ++it) { |
| 3552 unsigned n = *it; |
| 3553 scope = scope->inner_scope(); |
| 3554 while (n-- > 0) { |
| 3555 scope = scope->sibling(); |
| 3556 } |
| 3557 } |
| 3558 CHECK_NOT_NULL(scope); |
| 3559 const i::AstRawString* var_name = |
| 3560 info->ast_value_factory()->GetOneByteString(variable); |
| 3561 var = scope->Lookup(var_name); |
| 3562 } |
| 3563 |
| 3564 CHECK(var->is_used()); |
| 3565 CHECK_EQ(input.assigned, var->maybe_assigned() == i::kMaybeAssigned); |
| 3566 } |
| 3567 |
| 3568 static Input wrap(Input input) { |
| 3569 Input result; |
| 3570 result.assigned = input.assigned; |
| 3571 result.source = "function WRAPPED() { " + input.source + " }"; |
| 3572 result.location.push_back(0); |
| 3573 for (auto n : input.location) { |
| 3574 result.location.push_back(n); |
| 3575 } |
| 3576 return result; |
| 3577 } |
| 3578 |
| 3579 TEST(MaybeAssignedInsideLoop) { |
| 3580 i::Isolate* isolate = CcTest::i_isolate(); |
| 3581 i::HandleScope scope(isolate); |
| 3582 LocalContext env; |
| 3583 i::Zone zone(isolate->allocator(), ZONE_NAME); |
| 3584 |
| 3585 std::vector<unsigned> top; // Can't use {} in initializers below. |
| 3586 |
| 3587 Input module_and_script_tests[] = { |
| 3588 {1, "for (j=x; j<10; ++j) { foo = j }", top}, |
| 3589 {1, "for (j=x; j<10; ++j) { [foo] = [j] }", top}, |
| 3590 {1, "for (j=x; j<10; ++j) { var foo = j }", top}, |
| 3591 {1, "for (j=x; j<10; ++j) { var [foo] = [j] }", top}, |
| 3592 {0, "for (j=x; j<10; ++j) { let foo = j }", {0}}, |
| 3593 {0, "for (j=x; j<10; ++j) { let [foo] = [j] }", {0}}, |
| 3594 {0, "for (j=x; j<10; ++j) { const foo = j }", {0}}, |
| 3595 {0, "for (j=x; j<10; ++j) { const [foo] = [j] }", {0}}, |
| 3596 {0, "for (j=x; j<10; ++j) { function foo() {return j} }", {0}}, |
| 3597 |
| 3598 {1, "for ({j}=x; j<10; ++j) { foo = j }", top}, |
| 3599 {1, "for ({j}=x; j<10; ++j) { [foo] = [j] }", top}, |
| 3600 {1, "for ({j}=x; j<10; ++j) { var foo = j }", top}, |
| 3601 {1, "for ({j}=x; j<10; ++j) { var [foo] = [j] }", top}, |
| 3602 {0, "for ({j}=x; j<10; ++j) { let foo = j }", {0}}, |
| 3603 {0, "for ({j}=x; j<10; ++j) { let [foo] = [j] }", {0}}, |
| 3604 {0, "for ({j}=x; j<10; ++j) { const foo = j }", {0}}, |
| 3605 {0, "for ({j}=x; j<10; ++j) { const [foo] = [j] }", {0}}, |
| 3606 {0, "for ({j}=x; j<10; ++j) { function foo() {return j} }", {0}}, |
| 3607 |
| 3608 {1, "for (var j=x; j<10; ++j) { foo = j }", top}, |
| 3609 {1, "for (var j=x; j<10; ++j) { [foo] = [j] }", top}, |
| 3610 {1, "for (var j=x; j<10; ++j) { var foo = j }", top}, |
| 3611 {1, "for (var j=x; j<10; ++j) { var [foo] = [j] }", top}, |
| 3612 {0, "for (var j=x; j<10; ++j) { let foo = j }", {0}}, |
| 3613 {0, "for (var j=x; j<10; ++j) { let [foo] = [j] }", {0}}, |
| 3614 {0, "for (var j=x; j<10; ++j) { const foo = j }", {0}}, |
| 3615 {0, "for (var j=x; j<10; ++j) { const [foo] = [j] }", {0}}, |
| 3616 {0, "for (var j=x; j<10; ++j) { function foo() {return j} }", {0}}, |
| 3617 |
| 3618 {1, "for (var {j}=x; j<10; ++j) { foo = j }", top}, |
| 3619 {1, "for (var {j}=x; j<10; ++j) { [foo] = [j] }", top}, |
| 3620 {1, "for (var {j}=x; j<10; ++j) { var foo = j }", top}, |
| 3621 {1, "for (var {j}=x; j<10; ++j) { var [foo] = [j] }", top}, |
| 3622 {0, "for (var {j}=x; j<10; ++j) { let foo = j }", {0}}, |
| 3623 {0, "for (var {j}=x; j<10; ++j) { let [foo] = [j] }", {0}}, |
| 3624 {0, "for (var {j}=x; j<10; ++j) { const foo = j }", {0}}, |
| 3625 {0, "for (var {j}=x; j<10; ++j) { const [foo] = [j] }", {0}}, |
| 3626 {0, "for (var {j}=x; j<10; ++j) { function foo() {return j} }", {0}}, |
| 3627 |
| 3628 {1, "for (let j=x; j<10; ++j) { foo = j }", top}, |
| 3629 {1, "for (let j=x; j<10; ++j) { [foo] = [j] }", top}, |
| 3630 {1, "for (let j=x; j<10; ++j) { var foo = j }", top}, |
| 3631 {1, "for (let j=x; j<10; ++j) { var [foo] = [j] }", top}, |
| 3632 {0, "for (let j=x; j<10; ++j) { let foo = j }", {0, 0, 0}}, |
| 3633 {0, "for (let j=x; j<10; ++j) { let [foo] = [j] }", {0, 0, 0}}, |
| 3634 {0, "for (let j=x; j<10; ++j) { const foo = j }", {0, 0, 0}}, |
| 3635 {0, "for (let j=x; j<10; ++j) { const [foo] = [j] }", {0, 0, 0}}, |
| 3636 {0, "for (let j=x; j<10; ++j) { function foo() {return j} }", {0, 0, 0}}, |
| 3637 |
| 3638 {1, "for (let {j}=x; j<10; ++j) { foo = j }", top}, |
| 3639 {1, "for (let {j}=x; j<10; ++j) { [foo] = [j] }", top}, |
| 3640 {1, "for (let {j}=x; j<10; ++j) { var foo = j }", top}, |
| 3641 {1, "for (let {j}=x; j<10; ++j) { var [foo] = [j] }", top}, |
| 3642 {0, "for (let {j}=x; j<10; ++j) { let foo = j }", {0, 0, 0}}, |
| 3643 {0, "for (let {j}=x; j<10; ++j) { let [foo] = [j] }", {0, 0, 0}}, |
| 3644 {0, "for (let {j}=x; j<10; ++j) { const foo = j }", {0, 0, 0}}, |
| 3645 {0, "for (let {j}=x; j<10; ++j) { const [foo] = [j] }", {0, 0, 0}}, |
| 3646 {0, "for (let {j}=x; j<10; ++j) { function foo(){return j} }", {0, 0, 0}}, |
| 3647 |
| 3648 {1, "for (j of x) { foo = j }", top}, |
| 3649 {1, "for (j of x) { [foo] = [j] }", top}, |
| 3650 {1, "for (j of x) { var foo = j }", top}, |
| 3651 {1, "for (j of x) { var [foo] = [j] }", top}, |
| 3652 {0, "for (j of x) { let foo = j }", {0}}, |
| 3653 {0, "for (j of x) { let [foo] = [j] }", {0}}, |
| 3654 {0, "for (j of x) { const foo = j }", {0}}, |
| 3655 {0, "for (j of x) { const [foo] = [j] }", {0}}, |
| 3656 {0, "for (j of x) { function foo() {return j} }", {0}}, |
| 3657 |
| 3658 {1, "for ({j} of x) { foo = j }", top}, |
| 3659 {1, "for ({j} of x) { [foo] = [j] }", top}, |
| 3660 {1, "for ({j} of x) { var foo = j }", top}, |
| 3661 {1, "for ({j} of x) { var [foo] = [j] }", top}, |
| 3662 {0, "for ({j} of x) { let foo = j }", {0}}, |
| 3663 {0, "for ({j} of x) { let [foo] = [j] }", {0}}, |
| 3664 {0, "for ({j} of x) { const foo = j }", {0}}, |
| 3665 {0, "for ({j} of x) { const [foo] = [j] }", {0}}, |
| 3666 {0, "for ({j} of x) { function foo() {return j} }", {0}}, |
| 3667 |
| 3668 {1, "for (var j of x) { foo = j }", top}, |
| 3669 {1, "for (var j of x) { [foo] = [j] }", top}, |
| 3670 {1, "for (var j of x) { var foo = j }", top}, |
| 3671 {1, "for (var j of x) { var [foo] = [j] }", top}, |
| 3672 {0, "for (var j of x) { let foo = j }", {0}}, |
| 3673 {0, "for (var j of x) { let [foo] = [j] }", {0}}, |
| 3674 {0, "for (var j of x) { const foo = j }", {0}}, |
| 3675 {0, "for (var j of x) { const [foo] = [j] }", {0}}, |
| 3676 {0, "for (var j of x) { function foo() {return j} }", {0}}, |
| 3677 |
| 3678 {1, "for (var {j} of x) { foo = j }", top}, |
| 3679 {1, "for (var {j} of x) { [foo] = [j] }", top}, |
| 3680 {1, "for (var {j} of x) { var foo = j }", top}, |
| 3681 {1, "for (var {j} of x) { var [foo] = [j] }", top}, |
| 3682 {0, "for (var {j} of x) { let foo = j }", {0}}, |
| 3683 {0, "for (var {j} of x) { let [foo] = [j] }", {0}}, |
| 3684 {0, "for (var {j} of x) { const foo = j }", {0}}, |
| 3685 {0, "for (var {j} of x) { const [foo] = [j] }", {0}}, |
| 3686 {0, "for (var {j} of x) { function foo() {return j} }", {0}}, |
| 3687 |
| 3688 {1, "for (let j of x) { foo = j }", top}, |
| 3689 {1, "for (let j of x) { [foo] = [j] }", top}, |
| 3690 {1, "for (let j of x) { var foo = j }", top}, |
| 3691 {1, "for (let j of x) { var [foo] = [j] }", top}, |
| 3692 {0, "for (let j of x) { let foo = j }", {0, 2, 0}}, |
| 3693 {0, "for (let j of x) { let [foo] = [j] }", {0, 2, 0}}, |
| 3694 {0, "for (let j of x) { const foo = j }", {0, 2, 0}}, |
| 3695 {0, "for (let j of x) { const [foo] = [j] }", {0, 2, 0}}, |
| 3696 {0, "for (let j of x) { function foo() {return j} }", {0, 2, 0}}, |
| 3697 |
| 3698 {1, "for (let {j} of x) { foo = j }", top}, |
| 3699 {1, "for (let {j} of x) { [foo] = [j] }", top}, |
| 3700 {1, "for (let {j} of x) { var foo = j }", top}, |
| 3701 {1, "for (let {j} of x) { var [foo] = [j] }", top}, |
| 3702 {0, "for (let {j} of x) { let foo = j }", {0, 2, 0}}, |
| 3703 {0, "for (let {j} of x) { let [foo] = [j] }", {0, 2, 0}}, |
| 3704 {0, "for (let {j} of x) { const foo = j }", {0, 2, 0}}, |
| 3705 {0, "for (let {j} of x) { const [foo] = [j] }", {0, 2, 0}}, |
| 3706 {0, "for (let {j} of x) { function foo() {return j} }", {0, 2, 0}}, |
| 3707 |
| 3708 {1, "for (const j of x) { foo = j }", top}, |
| 3709 {1, "for (const j of x) { [foo] = [j] }", top}, |
| 3710 {1, "for (const j of x) { var foo = j }", top}, |
| 3711 {1, "for (const j of x) { var [foo] = [j] }", top}, |
| 3712 {0, "for (const j of x) { let foo = j }", {0, 2, 0}}, |
| 3713 {0, "for (const j of x) { let [foo] = [j] }", {0, 2, 0}}, |
| 3714 {0, "for (const j of x) { const foo = j }", {0, 2, 0}}, |
| 3715 {0, "for (const j of x) { const [foo] = [j] }", {0, 2, 0}}, |
| 3716 {0, "for (const j of x) { function foo() {return j} }", {0, 2, 0}}, |
| 3717 |
| 3718 {1, "for (const {j} of x) { foo = j }", top}, |
| 3719 {1, "for (const {j} of x) { [foo] = [j] }", top}, |
| 3720 {1, "for (const {j} of x) { var foo = j }", top}, |
| 3721 {1, "for (const {j} of x) { var [foo] = [j] }", top}, |
| 3722 {0, "for (const {j} of x) { let foo = j }", {0, 2, 0}}, |
| 3723 {0, "for (const {j} of x) { let [foo] = [j] }", {0, 2, 0}}, |
| 3724 {0, "for (const {j} of x) { const foo = j }", {0, 2, 0}}, |
| 3725 {0, "for (const {j} of x) { const [foo] = [j] }", {0, 2, 0}}, |
| 3726 {0, "for (const {j} of x) { function foo() {return j} }", {0, 2, 0}}, |
| 3727 |
| 3728 {1, "for (j in x) { foo = j }", top}, |
| 3729 {1, "for (j in x) { [foo] = [j] }", top}, |
| 3730 {1, "for (j in x) { var foo = j }", top}, |
| 3731 {1, "for (j in x) { var [foo] = [j] }", top}, |
| 3732 {0, "for (j in x) { let foo = j }", {0}}, |
| 3733 {0, "for (j in x) { let [foo] = [j] }", {0}}, |
| 3734 {0, "for (j in x) { const foo = j }", {0}}, |
| 3735 {0, "for (j in x) { const [foo] = [j] }", {0}}, |
| 3736 {0, "for (j in x) { function foo() {return j} }", {0}}, |
| 3737 |
| 3738 {1, "for ({j} in x) { foo = j }", top}, |
| 3739 {1, "for ({j} in x) { [foo] = [j] }", top}, |
| 3740 {1, "for ({j} in x) { var foo = j }", top}, |
| 3741 {1, "for ({j} in x) { var [foo] = [j] }", top}, |
| 3742 {0, "for ({j} in x) { let foo = j }", {0}}, |
| 3743 {0, "for ({j} in x) { let [foo] = [j] }", {0}}, |
| 3744 {0, "for ({j} in x) { const foo = j }", {0}}, |
| 3745 {0, "for ({j} in x) { const [foo] = [j] }", {0}}, |
| 3746 {0, "for ({j} in x) { function foo() {return j} }", {0}}, |
| 3747 |
| 3748 {1, "for (var j in x) { foo = j }", top}, |
| 3749 {1, "for (var j in x) { [foo] = [j] }", top}, |
| 3750 {1, "for (var j in x) { var foo = j }", top}, |
| 3751 {1, "for (var j in x) { var [foo] = [j] }", top}, |
| 3752 {0, "for (var j in x) { let foo = j }", {0}}, |
| 3753 {0, "for (var j in x) { let [foo] = [j] }", {0}}, |
| 3754 {0, "for (var j in x) { const foo = j }", {0}}, |
| 3755 {0, "for (var j in x) { const [foo] = [j] }", {0}}, |
| 3756 {0, "for (var j in x) { function foo() {return j} }", {0}}, |
| 3757 |
| 3758 {1, "for (var {j} in x) { foo = j }", top}, |
| 3759 {1, "for (var {j} in x) { [foo] = [j] }", top}, |
| 3760 {1, "for (var {j} in x) { var foo = j }", top}, |
| 3761 {1, "for (var {j} in x) { var [foo] = [j] }", top}, |
| 3762 {0, "for (var {j} in x) { let foo = j }", {0}}, |
| 3763 {0, "for (var {j} in x) { let [foo] = [j] }", {0}}, |
| 3764 {0, "for (var {j} in x) { const foo = j }", {0}}, |
| 3765 {0, "for (var {j} in x) { const [foo] = [j] }", {0}}, |
| 3766 {0, "for (var {j} in x) { function foo() {return j} }", {0}}, |
| 3767 |
| 3768 {1, "for (let j in x) { foo = j }", top}, |
| 3769 {1, "for (let j in x) { [foo] = [j] }", top}, |
| 3770 {1, "for (let j in x) { var foo = j }", top}, |
| 3771 {1, "for (let j in x) { var [foo] = [j] }", top}, |
| 3772 {0, "for (let j in x) { let foo = j }", {0, 0, 0}}, |
| 3773 {0, "for (let j in x) { let [foo] = [j] }", {0, 0, 0}}, |
| 3774 {0, "for (let j in x) { const foo = j }", {0, 0, 0}}, |
| 3775 {0, "for (let j in x) { const [foo] = [j] }", {0, 0, 0}}, |
| 3776 {0, "for (let j in x) { function foo() {return j} }", {0, 0, 0}}, |
| 3777 |
| 3778 {1, "for (let {j} in x) { foo = j }", top}, |
| 3779 {1, "for (let {j} in x) { [foo] = [j] }", top}, |
| 3780 {1, "for (let {j} in x) { var foo = j }", top}, |
| 3781 {1, "for (let {j} in x) { var [foo] = [j] }", top}, |
| 3782 {0, "for (let {j} in x) { let foo = j }", {0, 0, 0}}, |
| 3783 {0, "for (let {j} in x) { let [foo] = [j] }", {0, 0, 0}}, |
| 3784 {0, "for (let {j} in x) { const foo = j }", {0, 0, 0}}, |
| 3785 {0, "for (let {j} in x) { const [foo] = [j] }", {0, 0, 0}}, |
| 3786 {0, "for (let {j} in x) { function foo() {return j} }", {0, 0, 0}}, |
| 3787 |
| 3788 {1, "for (const j in x) { foo = j }", top}, |
| 3789 {1, "for (const j in x) { [foo] = [j] }", top}, |
| 3790 {1, "for (const j in x) { var foo = j }", top}, |
| 3791 {1, "for (const j in x) { var [foo] = [j] }", top}, |
| 3792 {0, "for (const j in x) { let foo = j }", {0, 0, 0}}, |
| 3793 {0, "for (const j in x) { let [foo] = [j] }", {0, 0, 0}}, |
| 3794 {0, "for (const j in x) { const foo = j }", {0, 0, 0}}, |
| 3795 {0, "for (const j in x) { const [foo] = [j] }", {0, 0, 0}}, |
| 3796 {0, "for (const j in x) { function foo() {return j} }", {0, 0, 0}}, |
| 3797 |
| 3798 {1, "for (const {j} in x) { foo = j }", top}, |
| 3799 {1, "for (const {j} in x) { [foo] = [j] }", top}, |
| 3800 {1, "for (const {j} in x) { var foo = j }", top}, |
| 3801 {1, "for (const {j} in x) { var [foo] = [j] }", top}, |
| 3802 {0, "for (const {j} in x) { let foo = j }", {0, 0, 0}}, |
| 3803 {0, "for (const {j} in x) { let [foo] = [j] }", {0, 0, 0}}, |
| 3804 {0, "for (const {j} in x) { const foo = j }", {0, 0, 0}}, |
| 3805 {0, "for (const {j} in x) { const [foo] = [j] }", {0, 0, 0}}, |
| 3806 {0, "for (const {j} in x) { function foo() {return j} }", {0, 0, 0}}, |
| 3807 |
| 3808 {1, "while (j) { foo = j }", top}, |
| 3809 {1, "while (j) { [foo] = [j] }", top}, |
| 3810 {1, "while (j) { var foo = j }", top}, |
| 3811 {1, "while (j) { var [foo] = [j] }", top}, |
| 3812 {0, "while (j) { let foo = j }", {0}}, |
| 3813 {0, "while (j) { let [foo] = [j] }", {0}}, |
| 3814 {0, "while (j) { const foo = j }", {0}}, |
| 3815 {0, "while (j) { const [foo] = [j] }", {0}}, |
| 3816 {0, "while (j) { function foo() {return j} }", {0}}, |
| 3817 |
| 3818 {1, "do { foo = j } while (j)", top}, |
| 3819 {1, "do { [foo] = [j] } while (j)", top}, |
| 3820 {1, "do { var foo = j } while (j)", top}, |
| 3821 {1, "do { var [foo] = [j] } while (j)", top}, |
| 3822 {0, "do { let foo = j } while (j)", {0}}, |
| 3823 {0, "do { let [foo] = [j] } while (j)", {0}}, |
| 3824 {0, "do { const foo = j } while (j)", {0}}, |
| 3825 {0, "do { const [foo] = [j] } while (j)", {0}}, |
| 3826 {0, "do { function foo() {return j} } while (j)", {0}}, |
| 3827 }; |
| 3828 |
| 3829 Input script_only_tests[] = { |
| 3830 {1, "for (j=x; j<10; ++j) { function foo() {return j} }", top}, |
| 3831 {1, "for ({j}=x; j<10; ++j) { function foo() {return j} }", top}, |
| 3832 {1, "for (var j=x; j<10; ++j) { function foo() {return j} }", top}, |
| 3833 {1, "for (var {j}=x; j<10; ++j) { function foo() {return j} }", top}, |
| 3834 {1, "for (let j=x; j<10; ++j) { function foo() {return j} }", top}, |
| 3835 {1, "for (let {j}=x; j<10; ++j) { function foo() {return j} }", top}, |
| 3836 {1, "for (j of x) { function foo() {return j} }", top}, |
| 3837 {1, "for ({j} of x) { function foo() {return j} }", top}, |
| 3838 {1, "for (var j of x) { function foo() {return j} }", top}, |
| 3839 {1, "for (var {j} of x) { function foo() {return j} }", top}, |
| 3840 {1, "for (let j of x) { function foo() {return j} }", top}, |
| 3841 {1, "for (let {j} of x) { function foo() {return j} }", top}, |
| 3842 {1, "for (const j of x) { function foo() {return j} }", top}, |
| 3843 {1, "for (const {j} of x) { function foo() {return j} }", top}, |
| 3844 {1, "for (j in x) { function foo() {return j} }", top}, |
| 3845 {1, "for ({j} in x) { function foo() {return j} }", top}, |
| 3846 {1, "for (var j in x) { function foo() {return j} }", top}, |
| 3847 {1, "for (var {j} in x) { function foo() {return j} }", top}, |
| 3848 {1, "for (let j in x) { function foo() {return j} }", top}, |
| 3849 {1, "for (let {j} in x) { function foo() {return j} }", top}, |
| 3850 {1, "for (const j in x) { function foo() {return j} }", top}, |
| 3851 {1, "for (const {j} in x) { function foo() {return j} }", top}, |
| 3852 {1, "while (j) { function foo() {return j} }", top}, |
| 3853 {1, "do { function foo() {return j} } while (j)", top}, |
| 3854 }; |
| 3855 |
| 3856 for (unsigned i = 0; i < arraysize(module_and_script_tests); ++i) { |
| 3857 Input input = module_and_script_tests[i]; |
| 3858 for (unsigned module = 0; module <= 1; ++module) { |
| 3859 for (unsigned allow_lazy_parsing = 0; allow_lazy_parsing <= 1; |
| 3860 ++allow_lazy_parsing) { |
| 3861 TestMaybeAssigned(&zone, input, "foo", module, allow_lazy_parsing); |
| 3862 } |
| 3863 TestMaybeAssigned(&zone, wrap(input), "foo", module, false); |
| 3864 } |
| 3865 } |
| 3866 |
| 3867 for (unsigned i = 0; i < arraysize(script_only_tests); ++i) { |
| 3868 Input input = script_only_tests[i]; |
| 3869 for (unsigned allow_lazy_parsing = 0; allow_lazy_parsing <= 1; |
| 3870 ++allow_lazy_parsing) { |
| 3871 TestMaybeAssigned(&zone, input, "foo", false, allow_lazy_parsing); |
| 3872 } |
| 3873 TestMaybeAssigned(&zone, wrap(input), "foo", false, false); |
| 3874 } |
| 3875 } |
| 3876 |
3519 TEST(MaybeAssignedTopLevel) { | 3877 TEST(MaybeAssignedTopLevel) { |
3520 i::Isolate* isolate = CcTest::i_isolate(); | 3878 i::Isolate* isolate = CcTest::i_isolate(); |
3521 i::HandleScope scope(isolate); | 3879 i::HandleScope scope(isolate); |
3522 LocalContext env; | 3880 LocalContext env; |
3523 i::Factory* factory = isolate->factory(); | 3881 i::Factory* factory = isolate->factory(); |
3524 | 3882 |
3525 const char* prefixes[] = { | 3883 const char* prefixes[] = { |
3526 "let foo; ", "let foo = 0; ", | 3884 "let foo; ", "let foo = 0; ", |
3527 "let [foo] = [1]; ", "let {foo} = {foo: 2}; ", | 3885 "let [foo] = [1]; ", "let {foo} = {foo: 2}; ", |
3528 "let {foo=3} = {}; ", "function foo() {}; ", | 3886 "let {foo=3} = {}; ", "function foo() {}; ", |
(...skipping 5684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9213 } inners[] = { | 9571 } inners[] = { |
9214 // Simple cases | 9572 // Simple cases |
9215 {"", "var1;"}, | 9573 {"", "var1;"}, |
9216 {"", "var1 = 5;"}, | 9574 {"", "var1 = 5;"}, |
9217 {"", "if (true) {}"}, | 9575 {"", "if (true) {}"}, |
9218 {"", "function f1() {}"}, | 9576 {"", "function f1() {}"}, |
9219 | 9577 |
9220 // Var declarations and assignments. | 9578 // Var declarations and assignments. |
9221 {"", "var var1;"}, | 9579 {"", "var var1;"}, |
9222 {"", "var var1; var1 = 5;"}, | 9580 {"", "var var1; var1 = 5;"}, |
9223 {"", "if (true) { var var1; }"}, | 9581 /*{"", "if (true) { var var1; }"},*/ |
9224 {"", "if (true) { var var1; var1 = 5; }"}, | 9582 {"", "if (true) { var var1; var1 = 5; }"}, |
9225 {"", "var var1; function f() { var1; }"}, | 9583 {"", "var var1; function f() { var1; }"}, |
9226 {"", "var var1; var1 = 5; function f() { var1; }"}, | 9584 {"", "var var1; var1 = 5; function f() { var1; }"}, |
9227 {"", "var var1; function f() { var1 = 5; }"}, | 9585 {"", "var var1; function f() { var1 = 5; }"}, |
9228 | 9586 |
9229 // Let declarations and assignments. | 9587 // Let declarations and assignments. |
9230 {"", "let var1;"}, | 9588 {"", "let var1;"}, |
9231 {"", "let var1; var1 = 5;"}, | 9589 {"", "let var1; var1 = 5;"}, |
9232 {"", "if (true) { let var1; }"}, | 9590 {"", "if (true) { let var1; }"}, |
9233 {"", "if (true) { let var1; var1 = 5; }"}, | 9591 {"", "if (true) { let var1; var1 = 5; }"}, |
(...skipping 25 matching lines...) Expand all Loading... |
9259 {"", "const var1 = 0; if (true) { const var1 = 0; }"}, | 9617 {"", "const var1 = 0; if (true) { const var1 = 0; }"}, |
9260 | 9618 |
9261 // Variable called "arguments" | 9619 // Variable called "arguments" |
9262 {"", "arguments;"}, | 9620 {"", "arguments;"}, |
9263 {"", "arguments = 5;"}, | 9621 {"", "arguments = 5;"}, |
9264 {"", "function f() { arguments; }"}, | 9622 {"", "function f() { arguments; }"}, |
9265 {"", "function f() { arguments = 5; }"}, | 9623 {"", "function f() { arguments = 5; }"}, |
9266 | 9624 |
9267 {"", "var arguments;"}, | 9625 {"", "var arguments;"}, |
9268 {"", "var arguments; arguments = 5;"}, | 9626 {"", "var arguments; arguments = 5;"}, |
9269 {"", "if (true) { var arguments; }"}, | 9627 /*{"", "if (true) { var arguments; }"},*/ |
9270 {"", "if (true) { var arguments; arguments = 5; }"}, | 9628 {"", "if (true) { var arguments; arguments = 5; }"}, |
9271 {"", "var arguments; function f() { arguments; }"}, | 9629 {"", "var arguments; function f() { arguments; }"}, |
9272 {"", "var arguments; arguments = 5; function f() { arguments; }"}, | 9630 {"", "var arguments; arguments = 5; function f() { arguments; }"}, |
9273 {"", "var arguments; function f() { arguments = 5; }"}, | 9631 {"", "var arguments; function f() { arguments = 5; }"}, |
9274 | 9632 |
9275 {"", "let arguments;"}, | 9633 {"", "let arguments;"}, |
9276 {"", "let arguments; arguments = 5;"}, | 9634 {"", "let arguments; arguments = 5;"}, |
9277 {"", "if (true) { let arguments; }"}, | 9635 {"", "if (true) { let arguments; }"}, |
9278 {"", "if (true) { let arguments; arguments = 5; }"}, | 9636 {"", "if (true) { let arguments; arguments = 5; }"}, |
9279 {"", "let arguments; function f() { arguments; }"}, | 9637 {"", "let arguments; function f() { arguments; }"}, |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9528 eager_info.literal()->scope()->inner_scope()->inner_scope(); | 9886 eager_info.literal()->scope()->inner_scope()->inner_scope(); |
9529 DCHECK_NOT_NULL(scope); | 9887 DCHECK_NOT_NULL(scope); |
9530 DCHECK_NULL(scope->sibling()); | 9888 DCHECK_NULL(scope->sibling()); |
9531 DCHECK(scope->is_function_scope()); | 9889 DCHECK(scope->is_function_scope()); |
9532 | 9890 |
9533 size_t index = 0; | 9891 size_t index = 0; |
9534 i::ScopeTestHelper::CompareScopeToData( | 9892 i::ScopeTestHelper::CompareScopeToData( |
9535 scope, lazy_info.preparsed_scope_data(), index); | 9893 scope, lazy_info.preparsed_scope_data(), index); |
9536 } | 9894 } |
9537 } | 9895 } |
OLD | NEW |