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 3477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3488 const i::AstRawString* var_name = | 3488 const i::AstRawString* var_name = |
3489 info->ast_value_factory()->GetOneByteString("arg"); | 3489 info->ast_value_factory()->GetOneByteString("arg"); |
3490 i::Variable* var = scope->Lookup(var_name); | 3490 i::Variable* var = scope->Lookup(var_name); |
3491 CHECK(var->is_used() || !assigned); | 3491 CHECK(var->is_used() || !assigned); |
3492 bool is_maybe_assigned = var->maybe_assigned() == i::kMaybeAssigned; | 3492 bool is_maybe_assigned = var->maybe_assigned() == i::kMaybeAssigned; |
3493 CHECK_EQ(is_maybe_assigned, assigned); | 3493 CHECK_EQ(is_maybe_assigned, assigned); |
3494 } | 3494 } |
3495 } | 3495 } |
3496 } | 3496 } |
3497 | 3497 |
3498 struct Input { | |
3499 bool assigned; | |
3500 std::string source; | |
3501 std::vector<unsigned> location; // "Directions" to the relevant scope. | |
3502 }; | |
3503 | |
3504 static void TestMaybeAssigned(i::Zone* zone, Input input, const char* variable, | |
3505 bool module, bool allow_lazy_parsing) { | |
3506 i::Factory* factory = CcTest::i_isolate()->factory(); | |
3507 i::Handle<i::String> string = | |
3508 factory->InternalizeUtf8String(input.source.c_str()); | |
3509 string->PrintOn(stdout); | |
3510 printf("\n"); | |
3511 i::Handle<i::Script> script = factory->NewScript(string); | |
3512 | |
3513 std::unique_ptr<i::ParseInfo> info; | |
3514 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(zone, script)); | |
3515 info->set_module(module); | |
3516 info->set_allow_lazy_parsing(allow_lazy_parsing); | |
3517 | |
3518 CHECK(i::parsing::ParseProgram(info.get())); | |
3519 CHECK(i::Compiler::Analyze(info.get())); | |
3520 | |
3521 CHECK_NOT_NULL(info->literal()); | |
3522 i::Scope* scope = info->literal()->scope(); | |
3523 CHECK(!scope->AsDeclarationScope()->was_lazily_parsed()); | |
3524 CHECK_NULL(scope->sibling()); | |
3525 CHECK(module ? scope->is_module_scope() : scope->is_script_scope()); | |
3526 | |
3527 i::Variable* var; | |
3528 { | |
3529 // Find the variable. | |
3530 for (auto it = input.location.begin(); it != input.location.end(); ++it) { | |
3531 unsigned n = *it; | |
3532 scope = scope->inner_scope(); | |
3533 while (n-- > 0) { | |
3534 scope = scope->sibling(); | |
3535 } | |
3536 } | |
3537 CHECK_NOT_NULL(scope); | |
3538 const i::AstRawString* var_name = | |
3539 info->ast_value_factory()->GetOneByteString(variable); | |
3540 var = scope->Lookup(var_name); | |
3541 } | |
3542 | |
3543 CHECK(var->is_used()); | |
3544 STATIC_ASSERT(true == i::kMaybeAssigned); | |
3545 CHECK_EQ(input.assigned, var->maybe_assigned() == i::kMaybeAssigned); | |
3546 } | |
3547 | |
3548 static Input wrap(Input input) { | |
3549 Input result; | |
3550 result.assigned = input.assigned; | |
3551 result.source = "function WRAPPED() { " + input.source + " }"; | |
3552 result.location.push_back(0); | |
3553 for (auto n : input.location) { | |
3554 result.location.push_back(n); | |
3555 } | |
3556 return result; | |
3557 } | |
3558 | |
3559 TEST(MaybeAssignedInsideLoop) { | |
3560 i::Isolate* isolate = CcTest::i_isolate(); | |
3561 i::HandleScope scope(isolate); | |
3562 LocalContext env; | |
3563 i::Zone zone(isolate->allocator(), ZONE_NAME); | |
3564 | |
3565 std::vector<unsigned> top; // Can't use {} in initializers below. | |
3566 | |
3567 Input module_and_script_tests[] = { | |
3568 {1, "for (j=x; j<10; ++j) { foo = j }", top}, | |
3569 {1, "for (j=x; j<10; ++j) { [foo] = [j] }", top}, | |
3570 {1, "for (j=x; j<10; ++j) { var foo = j }", top}, | |
3571 {1, "for (j=x; j<10; ++j) { var [foo] = [j] }", top}, | |
3572 {0, "for (j=x; j<10; ++j) { let foo = j }", {0}}, | |
3573 {0, "for (j=x; j<10; ++j) { let [foo] = [j] }", {0}}, | |
3574 {0, "for (j=x; j<10; ++j) { const foo = j }", {0}}, | |
3575 {0, "for (j=x; j<10; ++j) { const [foo] = [j] }", {0}}, | |
3576 {0, "for (j=x; j<10; ++j) { function foo() {return j} }", {0}}, | |
3577 | |
3578 {1, "for ({j}=x; j<10; ++j) { foo = j }", top}, | |
3579 {1, "for ({j}=x; j<10; ++j) { [foo] = [j] }", top}, | |
3580 {1, "for ({j}=x; j<10; ++j) { var foo = j }", top}, | |
3581 {1, "for ({j}=x; j<10; ++j) { var [foo] = [j] }", top}, | |
3582 {0, "for ({j}=x; j<10; ++j) { let foo = j }", {0}}, | |
3583 {0, "for ({j}=x; j<10; ++j) { let [foo] = [j] }", {0}}, | |
3584 {0, "for ({j}=x; j<10; ++j) { const foo = j }", {0}}, | |
3585 {0, "for ({j}=x; j<10; ++j) { const [foo] = [j] }", {0}}, | |
3586 {0, "for ({j}=x; j<10; ++j) { function foo() {return j} }", {0}}, | |
3587 | |
3588 {1, "for (var j=x; j<10; ++j) { foo = j }", top}, | |
3589 {1, "for (var j=x; j<10; ++j) { [foo] = [j] }", top}, | |
3590 {1, "for (var j=x; j<10; ++j) { var foo = j }", top}, | |
3591 {1, "for (var j=x; j<10; ++j) { var [foo] = [j] }", top}, | |
3592 {0, "for (var j=x; j<10; ++j) { let foo = j }", {0}}, | |
3593 {0, "for (var j=x; j<10; ++j) { let [foo] = [j] }", {0}}, | |
3594 {0, "for (var j=x; j<10; ++j) { const foo = j }", {0}}, | |
3595 {0, "for (var j=x; j<10; ++j) { const [foo] = [j] }", {0}}, | |
3596 {0, "for (var j=x; j<10; ++j) { function foo() {return j} }", {0}}, | |
3597 | |
3598 {1, "for (var {j}=x; j<10; ++j) { foo = j }", top}, | |
3599 {1, "for (var {j}=x; j<10; ++j) { [foo] = [j] }", top}, | |
3600 {1, "for (var {j}=x; j<10; ++j) { var foo = j }", top}, | |
3601 {1, "for (var {j}=x; j<10; ++j) { var [foo] = [j] }", top}, | |
3602 {0, "for (var {j}=x; j<10; ++j) { let foo = j }", {0}}, | |
3603 {0, "for (var {j}=x; j<10; ++j) { let [foo] = [j] }", {0}}, | |
3604 {0, "for (var {j}=x; j<10; ++j) { const foo = j }", {0}}, | |
3605 {0, "for (var {j}=x; j<10; ++j) { const [foo] = [j] }", {0}}, | |
3606 {0, "for (var {j}=x; j<10; ++j) { function foo() {return j} }", {0}}, | |
3607 | |
3608 {1, "for (let j=x; j<10; ++j) { foo = j }", top}, | |
3609 {1, "for (let j=x; j<10; ++j) { [foo] = [j] }", top}, | |
3610 {1, "for (let j=x; j<10; ++j) { var foo = j }", top}, | |
3611 {1, "for (let j=x; j<10; ++j) { var [foo] = [j] }", top}, | |
3612 {0, "for (let j=x; j<10; ++j) { let foo = j }", {0, 0, 0}}, | |
3613 {0, "for (let j=x; j<10; ++j) { let [foo] = [j] }", {0, 0, 0}}, | |
3614 {0, "for (let j=x; j<10; ++j) { const foo = j }", {0, 0, 0}}, | |
3615 {0, "for (let j=x; j<10; ++j) { const [foo] = [j] }", {0, 0, 0}}, | |
3616 {0, "for (let j=x; j<10; ++j) { function foo() {return j} }", {0, 0, 0}}, | |
3617 | |
3618 {1, "for (let {j}=x; j<10; ++j) { foo = j }", top}, | |
3619 {1, "for (let {j}=x; j<10; ++j) { [foo] = [j] }", top}, | |
3620 {1, "for (let {j}=x; j<10; ++j) { var foo = j }", top}, | |
3621 {1, "for (let {j}=x; j<10; ++j) { var [foo] = [j] }", top}, | |
3622 {0, "for (let {j}=x; j<10; ++j) { let foo = j }", {0, 0, 0}}, | |
3623 {0, "for (let {j}=x; j<10; ++j) { let [foo] = [j] }", {0, 0, 0}}, | |
3624 {0, "for (let {j}=x; j<10; ++j) { const foo = j }", {0, 0, 0}}, | |
3625 {0, "for (let {j}=x; j<10; ++j) { const [foo] = [j] }", {0, 0, 0}}, | |
3626 {0, "for (let {j}=x; j<10; ++j) { function foo(){return j} }", {0, 0, 0}}, | |
3627 | |
3628 {1, "for (j of x) { foo = j }", top}, | |
3629 {1, "for (j of x) { [foo] = [j] }", top}, | |
3630 {1, "for (j of x) { var foo = j }", top}, | |
3631 {1, "for (j of x) { var [foo] = [j] }", top}, | |
3632 {0, "for (j of x) { let foo = j }", {0}}, | |
3633 {0, "for (j of x) { let [foo] = [j] }", {0}}, | |
3634 {0, "for (j of x) { const foo = j }", {0}}, | |
3635 {0, "for (j of x) { const [foo] = [j] }", {0}}, | |
3636 {0, "for (j of x) { function foo() {return j} }", {0}}, | |
3637 | |
3638 {1, "for ({j} of x) { foo = j }", top}, | |
3639 {1, "for ({j} of x) { [foo] = [j] }", top}, | |
3640 {1, "for ({j} of x) { var foo = j }", top}, | |
3641 {1, "for ({j} of x) { var [foo] = [j] }", top}, | |
3642 {0, "for ({j} of x) { let foo = j }", {0}}, | |
3643 {0, "for ({j} of x) { let [foo] = [j] }", {0}}, | |
3644 {0, "for ({j} of x) { const foo = j }", {0}}, | |
3645 {0, "for ({j} of x) { const [foo] = [j] }", {0}}, | |
3646 {0, "for ({j} of x) { function foo() {return j} }", {0}}, | |
3647 | |
3648 {1, "for (var j of x) { foo = j }", top}, | |
3649 {1, "for (var j of x) { [foo] = [j] }", top}, | |
3650 {1, "for (var j of x) { var foo = j }", top}, | |
3651 {1, "for (var j of x) { var [foo] = [j] }", top}, | |
3652 {0, "for (var j of x) { let foo = j }", {0}}, | |
3653 {0, "for (var j of x) { let [foo] = [j] }", {0}}, | |
3654 {0, "for (var j of x) { const foo = j }", {0}}, | |
3655 {0, "for (var j of x) { const [foo] = [j] }", {0}}, | |
3656 {0, "for (var j of x) { function foo() {return j} }", {0}}, | |
3657 | |
3658 {1, "for (var {j} of x) { foo = j }", top}, | |
3659 {1, "for (var {j} of x) { [foo] = [j] }", top}, | |
3660 {1, "for (var {j} of x) { var foo = j }", top}, | |
3661 {1, "for (var {j} of x) { var [foo] = [j] }", top}, | |
3662 {0, "for (var {j} of x) { let foo = j }", {0}}, | |
3663 {0, "for (var {j} of x) { let [foo] = [j] }", {0}}, | |
3664 {0, "for (var {j} of x) { const foo = j }", {0}}, | |
3665 {0, "for (var {j} of x) { const [foo] = [j] }", {0}}, | |
3666 {0, "for (var {j} of x) { function foo() {return j} }", {0}}, | |
3667 | |
3668 {1, "for (let j of x) { foo = j }", top}, | |
3669 {1, "for (let j of x) { [foo] = [j] }", top}, | |
3670 {1, "for (let j of x) { var foo = j }", top}, | |
3671 {1, "for (let j of x) { var [foo] = [j] }", top}, | |
3672 {0, "for (let j of x) { let foo = j }", {0, 2, 0}}, | |
3673 {0, "for (let j of x) { let [foo] = [j] }", {0, 2, 0}}, | |
3674 {0, "for (let j of x) { const foo = j }", {0, 2, 0}}, | |
3675 {0, "for (let j of x) { const [foo] = [j] }", {0, 2, 0}}, | |
3676 {0, "for (let j of x) { function foo() {return j} }", {0, 2, 0}}, | |
3677 | |
3678 {1, "for (let {j} of x) { foo = j }", top}, | |
3679 {1, "for (let {j} of x) { [foo] = [j] }", top}, | |
3680 {1, "for (let {j} of x) { var foo = j }", top}, | |
3681 {1, "for (let {j} of x) { var [foo] = [j] }", top}, | |
3682 {0, "for (let {j} of x) { let foo = j }", {0, 2, 0}}, | |
3683 {0, "for (let {j} of x) { let [foo] = [j] }", {0, 2, 0}}, | |
3684 {0, "for (let {j} of x) { const foo = j }", {0, 2, 0}}, | |
3685 {0, "for (let {j} of x) { const [foo] = [j] }", {0, 2, 0}}, | |
3686 {0, "for (let {j} of x) { function foo() {return j} }", {0, 2, 0}}, | |
3687 | |
3688 {1, "for (const j of x) { foo = j }", top}, | |
3689 {1, "for (const j of x) { [foo] = [j] }", top}, | |
3690 {1, "for (const j of x) { var foo = j }", top}, | |
3691 {1, "for (const j of x) { var [foo] = [j] }", top}, | |
3692 {0, "for (const j of x) { let foo = j }", {0, 2, 0}}, | |
3693 {0, "for (const j of x) { let [foo] = [j] }", {0, 2, 0}}, | |
3694 {0, "for (const j of x) { const foo = j }", {0, 2, 0}}, | |
3695 {0, "for (const j of x) { const [foo] = [j] }", {0, 2, 0}}, | |
3696 {0, "for (const j of x) { function foo() {return j} }", {0, 2, 0}}, | |
3697 | |
3698 {1, "for (const {j} of x) { foo = j }", top}, | |
3699 {1, "for (const {j} of x) { [foo] = [j] }", top}, | |
3700 {1, "for (const {j} of x) { var foo = j }", top}, | |
3701 {1, "for (const {j} of x) { var [foo] = [j] }", top}, | |
3702 {0, "for (const {j} of x) { let foo = j }", {0, 2, 0}}, | |
3703 {0, "for (const {j} of x) { let [foo] = [j] }", {0, 2, 0}}, | |
3704 {0, "for (const {j} of x) { const foo = j }", {0, 2, 0}}, | |
3705 {0, "for (const {j} of x) { const [foo] = [j] }", {0, 2, 0}}, | |
3706 {0, "for (const {j} of x) { function foo() {return j} }", {0, 2, 0}}, | |
3707 | |
3708 {1, "for (j in x) { foo = j }", top}, | |
3709 {1, "for (j in x) { [foo] = [j] }", top}, | |
3710 {1, "for (j in x) { var foo = j }", top}, | |
3711 {1, "for (j in x) { var [foo] = [j] }", top}, | |
3712 {0, "for (j in x) { let foo = j }", {0}}, | |
3713 {0, "for (j in x) { let [foo] = [j] }", {0}}, | |
3714 {0, "for (j in x) { const foo = j }", {0}}, | |
3715 {0, "for (j in x) { const [foo] = [j] }", {0}}, | |
3716 {0, "for (j in x) { function foo() {return j} }", {0}}, | |
3717 | |
3718 {1, "for ({j} in x) { foo = j }", top}, | |
3719 {1, "for ({j} in x) { [foo] = [j] }", top}, | |
3720 {1, "for ({j} in x) { var foo = j }", top}, | |
3721 {1, "for ({j} in x) { var [foo] = [j] }", top}, | |
3722 {0, "for ({j} in x) { let foo = j }", {0}}, | |
3723 {0, "for ({j} in x) { let [foo] = [j] }", {0}}, | |
3724 {0, "for ({j} in x) { const foo = j }", {0}}, | |
3725 {0, "for ({j} in x) { const [foo] = [j] }", {0}}, | |
3726 {0, "for ({j} in x) { function foo() {return j} }", {0}}, | |
3727 | |
3728 {1, "for (var j in x) { foo = j }", top}, | |
3729 {1, "for (var j in x) { [foo] = [j] }", top}, | |
3730 {1, "for (var j in x) { var foo = j }", top}, | |
3731 {1, "for (var j in x) { var [foo] = [j] }", top}, | |
3732 {0, "for (var j in x) { let foo = j }", {0}}, | |
3733 {0, "for (var j in x) { let [foo] = [j] }", {0}}, | |
3734 {0, "for (var j in x) { const foo = j }", {0}}, | |
3735 {0, "for (var j in x) { const [foo] = [j] }", {0}}, | |
3736 {0, "for (var j in x) { function foo() {return j} }", {0}}, | |
3737 | |
3738 {1, "for (var {j} in x) { foo = j }", top}, | |
3739 {1, "for (var {j} in x) { [foo] = [j] }", top}, | |
3740 {1, "for (var {j} in x) { var foo = j }", top}, | |
3741 {1, "for (var {j} in x) { var [foo] = [j] }", top}, | |
3742 {0, "for (var {j} in x) { let foo = j }", {0}}, | |
3743 {0, "for (var {j} in x) { let [foo] = [j] }", {0}}, | |
3744 {0, "for (var {j} in x) { const foo = j }", {0}}, | |
3745 {0, "for (var {j} in x) { const [foo] = [j] }", {0}}, | |
3746 {0, "for (var {j} in x) { function foo() {return j} }", {0}}, | |
3747 | |
3748 {1, "for (let j in x) { foo = j }", top}, | |
3749 {1, "for (let j in x) { [foo] = [j] }", top}, | |
3750 {1, "for (let j in x) { var foo = j }", top}, | |
3751 {1, "for (let j in x) { var [foo] = [j] }", top}, | |
3752 {0, "for (let j in x) { let foo = j }", {0, 0, 0}}, | |
3753 {0, "for (let j in x) { let [foo] = [j] }", {0, 0, 0}}, | |
3754 {0, "for (let j in x) { const foo = j }", {0, 0, 0}}, | |
3755 {0, "for (let j in x) { const [foo] = [j] }", {0, 0, 0}}, | |
3756 {0, "for (let j in x) { function foo() {return j} }", {0, 0, 0}}, | |
3757 | |
3758 {1, "for (let {j} in x) { foo = j }", top}, | |
3759 {1, "for (let {j} in x) { [foo] = [j] }", top}, | |
3760 {1, "for (let {j} in x) { var foo = j }", top}, | |
3761 {1, "for (let {j} in x) { var [foo] = [j] }", top}, | |
3762 {0, "for (let {j} in x) { let foo = j }", {0, 0, 0}}, | |
3763 {0, "for (let {j} in x) { let [foo] = [j] }", {0, 0, 0}}, | |
3764 {0, "for (let {j} in x) { const foo = j }", {0, 0, 0}}, | |
3765 {0, "for (let {j} in x) { const [foo] = [j] }", {0, 0, 0}}, | |
3766 {0, "for (let {j} in x) { function foo() {return j} }", {0, 0, 0}}, | |
3767 | |
3768 {1, "for (const j in x) { foo = j }", top}, | |
3769 {1, "for (const j in x) { [foo] = [j] }", top}, | |
3770 {1, "for (const j in x) { var foo = j }", top}, | |
3771 {1, "for (const j in x) { var [foo] = [j] }", top}, | |
3772 {0, "for (const j in x) { let foo = j }", {0, 0, 0}}, | |
3773 {0, "for (const j in x) { let [foo] = [j] }", {0, 0, 0}}, | |
3774 {0, "for (const j in x) { const foo = j }", {0, 0, 0}}, | |
3775 {0, "for (const j in x) { const [foo] = [j] }", {0, 0, 0}}, | |
3776 {0, "for (const j in x) { function foo() {return j} }", {0, 0, 0}}, | |
3777 | |
3778 {1, "for (const {j} in x) { foo = j }", top}, | |
3779 {1, "for (const {j} in x) { [foo] = [j] }", top}, | |
3780 {1, "for (const {j} in x) { var foo = j }", top}, | |
3781 {1, "for (const {j} in x) { var [foo] = [j] }", top}, | |
3782 {0, "for (const {j} in x) { let foo = j }", {0, 0, 0}}, | |
3783 {0, "for (const {j} in x) { let [foo] = [j] }", {0, 0, 0}}, | |
3784 {0, "for (const {j} in x) { const foo = j }", {0, 0, 0}}, | |
3785 {0, "for (const {j} in x) { const [foo] = [j] }", {0, 0, 0}}, | |
3786 {0, "for (const {j} in x) { function foo() {return j} }", {0, 0, 0}}, | |
3787 | |
3788 {1, "while (j) { foo = j }", top}, | |
3789 {1, "while (j) { [foo] = [j] }", top}, | |
3790 {1, "while (j) { var foo = j }", top}, | |
3791 {1, "while (j) { var [foo] = [j] }", top}, | |
3792 {0, "while (j) { let foo = j }", {0}}, | |
3793 {0, "while (j) { let [foo] = [j] }", {0}}, | |
3794 {0, "while (j) { const foo = j }", {0}}, | |
3795 {0, "while (j) { const [foo] = [j] }", {0}}, | |
3796 {0, "while (j) { function foo() {return j} }", {0}}, | |
3797 | |
3798 {1, "do { foo = j } while (j)", top}, | |
3799 {1, "do { [foo] = [j] } while (j)", top}, | |
3800 {1, "do { var foo = j } while (j)", top}, | |
3801 {1, "do { var [foo] = [j] } while (j)", top}, | |
3802 {0, "do { let foo = j } while (j)", {0}}, | |
3803 {0, "do { let [foo] = [j] } while (j)", {0}}, | |
3804 {0, "do { const foo = j } while (j)", {0}}, | |
3805 {0, "do { const [foo] = [j] } while (j)", {0}}, | |
3806 {0, "do { function foo() {return j} } while (j)", {0}}, | |
3807 }; | |
3808 | |
3809 Input script_only_tests[] = { | |
3810 {1, "for (j=x; j<10; ++j) { function foo() {return j} }", top}, | |
3811 {1, "for ({j}=x; j<10; ++j) { function foo() {return j} }", top}, | |
3812 {1, "for (var j=x; j<10; ++j) { function foo() {return j} }", top}, | |
3813 {1, "for (var {j}=x; j<10; ++j) { function foo() {return j} }", top}, | |
3814 {1, "for (let j=x; j<10; ++j) { function foo() {return j} }", top}, | |
3815 {1, "for (let {j}=x; j<10; ++j) { function foo() {return j} }", top}, | |
3816 {1, "for (j of x) { function foo() {return j} }", top}, | |
3817 {1, "for ({j} of x) { function foo() {return j} }", top}, | |
3818 {1, "for (var j of x) { function foo() {return j} }", top}, | |
3819 {1, "for (var {j} of x) { function foo() {return j} }", top}, | |
3820 {1, "for (let j of x) { function foo() {return j} }", top}, | |
3821 {1, "for (let {j} of x) { function foo() {return j} }", top}, | |
3822 {1, "for (const j of x) { function foo() {return j} }", top}, | |
3823 {1, "for (const {j} of x) { function foo() {return j} }", top}, | |
3824 {1, "for (j in x) { function foo() {return j} }", top}, | |
3825 {1, "for ({j} in x) { function foo() {return j} }", top}, | |
3826 {1, "for (var j in x) { function foo() {return j} }", top}, | |
3827 {1, "for (var {j} in x) { function foo() {return j} }", top}, | |
3828 {1, "for (let j in x) { function foo() {return j} }", top}, | |
3829 {1, "for (let {j} in x) { function foo() {return j} }", top}, | |
3830 {1, "for (const j in x) { function foo() {return j} }", top}, | |
3831 {1, "for (const {j} in x) { function foo() {return j} }", top}, | |
3832 {1, "while (j) { function foo() {return j} }", top}, | |
3833 {1, "do { function foo() {return j} } while (j)", top}, | |
3834 }; | |
3835 | |
3836 for (unsigned i = 0; i < arraysize(module_and_script_tests); ++i) { | |
3837 Input input = module_and_script_tests[i]; | |
3838 for (unsigned module = 0; module <= 1; ++module) { | |
3839 for (unsigned allow_lazy_parsing = 0; allow_lazy_parsing <= 1; | |
3840 ++allow_lazy_parsing) { | |
3841 TestMaybeAssigned(&zone, input, "foo", module, allow_lazy_parsing); | |
3842 } | |
3843 TestMaybeAssigned(&zone, wrap(input), "foo", module, false); | |
3844 } | |
3845 } | |
3846 | |
3847 for (unsigned i = 0; i < arraysize(script_only_tests); ++i) { | |
3848 Input input = script_only_tests[i]; | |
3849 for (unsigned allow_lazy_parsing = 0; allow_lazy_parsing <= 1; | |
3850 ++allow_lazy_parsing) { | |
3851 TestMaybeAssigned(&zone, input, "foo", false, allow_lazy_parsing); | |
3852 } | |
3853 TestMaybeAssigned(&zone, wrap(input), "foo", false, false); | |
3854 } | |
3855 } | |
3856 | |
3857 TEST(MaybeAssignedTopLevel) { | 3498 TEST(MaybeAssignedTopLevel) { |
3858 i::Isolate* isolate = CcTest::i_isolate(); | 3499 i::Isolate* isolate = CcTest::i_isolate(); |
3859 i::HandleScope scope(isolate); | 3500 i::HandleScope scope(isolate); |
3860 LocalContext env; | 3501 LocalContext env; |
3861 i::Factory* factory = isolate->factory(); | 3502 i::Factory* factory = isolate->factory(); |
3862 | 3503 |
3863 const char* prefixes[] = { | 3504 const char* prefixes[] = { |
3864 "let foo; ", "let foo = 0; ", | 3505 "let foo; ", "let foo = 0; ", |
3865 "let [foo] = [1]; ", "let {foo} = {foo: 2}; ", | 3506 "let [foo] = [1]; ", "let {foo} = {foo: 2}; ", |
3866 "let {foo=3} = {}; ", "function foo() {}; ", | 3507 "let {foo=3} = {}; ", "function foo() {}; ", |
(...skipping 5577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9444 DCHECK_NULL(scope->sibling()); | 9085 DCHECK_NULL(scope->sibling()); |
9445 DCHECK(scope->is_function_scope()); | 9086 DCHECK(scope->is_function_scope()); |
9446 const i::AstRawString* var_name = | 9087 const i::AstRawString* var_name = |
9447 info.ast_value_factory()->GetOneByteString("my_var"); | 9088 info.ast_value_factory()->GetOneByteString("my_var"); |
9448 i::Variable* var = scope->Lookup(var_name); | 9089 i::Variable* var = scope->Lookup(var_name); |
9449 CHECK_EQ(inners[i].ctxt_allocate, | 9090 CHECK_EQ(inners[i].ctxt_allocate, |
9450 i::ScopeTestHelper::MustAllocateInContext(var)); | 9091 i::ScopeTestHelper::MustAllocateInContext(var)); |
9451 } | 9092 } |
9452 } | 9093 } |
9453 } | 9094 } |
OLD | NEW |