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 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1443 }; | 1443 }; |
1444 | 1444 |
1445 v8::HandleScope handles(CcTest::isolate()); | 1445 v8::HandleScope handles(CcTest::isolate()); |
1446 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 1446 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); |
1447 v8::Context::Scope context_scope(context); | 1447 v8::Context::Scope context_scope(context); |
1448 | 1448 |
1449 CcTest::i_isolate()->stack_guard()->SetStackLimit( | 1449 CcTest::i_isolate()->stack_guard()->SetStackLimit( |
1450 i::GetCurrentStackPosition() - 128 * 1024); | 1450 i::GetCurrentStackPosition() - 128 * 1024); |
1451 | 1451 |
1452 static const ParserFlag flags1[] = { | 1452 static const ParserFlag flags1[] = { |
1453 kAllowLazy, kAllowHarmonyScoping, | 1453 kAllowArrowFunctions, |
1454 kAllowModules, kAllowGenerators, | 1454 kAllowClasses, |
1455 kAllowArrowFunctions, kAllowHarmonyNumericLiterals, | 1455 kAllowGenerators, |
1456 kAllowHarmonyObjectLiterals}; | 1456 kAllowHarmonyNumericLiterals, |
1457 kAllowHarmonyObjectLiterals, | |
1458 kAllowHarmonyScoping, | |
1459 kAllowLazy, | |
1460 kAllowModules, | |
1461 }; | |
1462 | |
1457 for (int i = 0; context_data[i][0] != NULL; ++i) { | 1463 for (int i = 0; context_data[i][0] != NULL; ++i) { |
1458 for (int j = 0; statement_data[j] != NULL; ++j) { | 1464 for (int j = 0; statement_data[j] != NULL; ++j) { |
1459 for (int k = 0; termination_data[k] != NULL; ++k) { | 1465 for (int k = 0; termination_data[k] != NULL; ++k) { |
1460 int kPrefixLen = i::StrLength(context_data[i][0]); | 1466 int kPrefixLen = i::StrLength(context_data[i][0]); |
1461 int kStatementLen = i::StrLength(statement_data[j]); | 1467 int kStatementLen = i::StrLength(statement_data[j]); |
1462 int kTerminationLen = i::StrLength(termination_data[k]); | 1468 int kTerminationLen = i::StrLength(termination_data[k]); |
1463 int kSuffixLen = i::StrLength(context_data[i][1]); | 1469 int kSuffixLen = i::StrLength(context_data[i][1]); |
1464 int kProgramSize = kPrefixLen + kStatementLen + kTerminationLen | 1470 int kProgramSize = kPrefixLen + kStatementLen + kTerminationLen |
1465 + kSuffixLen + i::StrLength("label: for (;;) { }"); | 1471 + kSuffixLen + i::StrLength("label: for (;;) { }"); |
1466 | 1472 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1521 const ParserFlag* always_true_flags = NULL, | 1527 const ParserFlag* always_true_flags = NULL, |
1522 int always_true_flags_len = 0) { | 1528 int always_true_flags_len = 0) { |
1523 v8::HandleScope handles(CcTest::isolate()); | 1529 v8::HandleScope handles(CcTest::isolate()); |
1524 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 1530 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); |
1525 v8::Context::Scope context_scope(context); | 1531 v8::Context::Scope context_scope(context); |
1526 | 1532 |
1527 CcTest::i_isolate()->stack_guard()->SetStackLimit( | 1533 CcTest::i_isolate()->stack_guard()->SetStackLimit( |
1528 i::GetCurrentStackPosition() - 128 * 1024); | 1534 i::GetCurrentStackPosition() - 128 * 1024); |
1529 | 1535 |
1530 static const ParserFlag default_flags[] = { | 1536 static const ParserFlag default_flags[] = { |
1531 kAllowArrowFunctions, kAllowClasses, | 1537 kAllowArrowFunctions, |
1532 kAllowGenerators, kAllowHarmonyNumericLiterals, | 1538 kAllowClasses, |
1533 kAllowHarmonyObjectLiterals, kAllowHarmonyScoping, | 1539 kAllowGenerators, |
1534 kAllowLazy, kAllowModules, | 1540 kAllowHarmonyNumericLiterals, |
1535 kAllowNativesSyntax, | 1541 kAllowHarmonyObjectLiterals, |
1542 kAllowHarmonyScoping, | |
1543 kAllowLazy, | |
1544 kAllowModules, | |
1545 kAllowNativesSyntax, | |
1536 }; | 1546 }; |
1537 ParserFlag* generated_flags = NULL; | 1547 ParserFlag* generated_flags = NULL; |
1538 if (flags == NULL) { | 1548 if (flags == NULL) { |
1539 flags = default_flags; | 1549 flags = default_flags; |
1540 flags_len = arraysize(default_flags); | 1550 flags_len = arraysize(default_flags); |
1541 if (always_true_flags != NULL) { | 1551 if (always_true_flags != NULL) { |
1542 // Remove always_true_flags from default_flags. | 1552 // Remove always_true_flags from default_flags. |
1543 CHECK(always_true_flags_len < flags_len); | 1553 CHECK(always_true_flags_len < flags_len); |
1544 generated_flags = new ParserFlag[flags_len - always_true_flags_len]; | 1554 generated_flags = new ParserFlag[flags_len - always_true_flags_len]; |
1545 int flag_index = 0; | 1555 int flag_index = 0; |
(...skipping 2003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3549 "x() {}, 'x'() {}", | 3559 "x() {}, 'x'() {}", |
3550 "0() {}, '0'() {}", | 3560 "0() {}, '0'() {}", |
3551 "1.0() {}, 1: 1", | 3561 "1.0() {}, 1: 1", |
3552 NULL | 3562 NULL |
3553 }; | 3563 }; |
3554 | 3564 |
3555 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals}; | 3565 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals}; |
3556 RunParserSyncTest(context_data, params_data, kError, NULL, 0, | 3566 RunParserSyncTest(context_data, params_data, kError, NULL, 0, |
3557 always_flags, arraysize(always_flags)); | 3567 always_flags, arraysize(always_flags)); |
3558 } | 3568 } |
3569 | |
3570 | |
3571 TEST(NoErrorsClassExpression) { | |
3572 const char* context_data[][2] = {{"(", ");"}, | |
3573 {"var C = ", ";"}, | |
3574 {"bar, ", ";"}, | |
3575 {NULL, NULL}}; | |
3576 const char* class_data[] = { | |
3577 "class {}", | |
3578 "class name {}", | |
3579 "class extends F {}", | |
3580 "class name extends F {}", | |
3581 "class extends (F, G) {}", | |
3582 "class name extends (F, G) {}", | |
3583 "class extends class {} {}", | |
3584 "class name extends class {} {}", | |
3585 "class extends class base {} {}", | |
3586 "class name extends class base {} {}", | |
3587 NULL}; | |
3588 | |
3589 static const ParserFlag always_flags[] = {kAllowClasses}; | |
3590 RunParserSyncTest(context_data, class_data, kSuccess, NULL, 0, | |
3591 always_flags, arraysize(always_flags)); | |
3592 } | |
3593 | |
3594 | |
3595 TEST(NoErrorsClassDeclaration) { | |
3596 const char* context_data[][2] = {{"", ""}, | |
3597 {"{", "}"}, | |
3598 {"if (true) {", "}"}, | |
3599 {NULL, NULL}}; | |
3600 const char* statement_data[] = { | |
3601 "class name {}", | |
3602 "class name extends F {}", | |
3603 "class name extends (F, G) {}", | |
3604 "class name extends class {} {}", | |
3605 "class name extends class base {} {}", | |
3606 NULL}; | |
3607 | |
3608 static const ParserFlag always_flags[] = {kAllowClasses}; | |
3609 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | |
3610 always_flags, arraysize(always_flags)); | |
3611 } | |
3612 | |
3613 | |
3614 TEST(NoErrorsClassBody) { | |
3615 // Tests that parser and preparser accept valid class syntax. | |
3616 const char* context_data[][2] = {{"(class {", "});"}, | |
3617 {"(class extends Base {", "});"}, | |
3618 {"class C {", "}"}, | |
3619 {"class C extends Base {", "}"}, | |
3620 {NULL, NULL}}; | |
3621 const char* class_body_data[] = { | |
3622 ";", | |
3623 ";;", | |
3624 "m() {}", | |
3625 "m() {};", | |
3626 ";m() {}", | |
3627 "m() {}; n(x) {}", | |
3628 "get x() {}", | |
3629 "set x(v) {}", | |
3630 "get() {}", | |
3631 "set() {}", | |
3632 "static() {}", | |
3633 "static m() {}", | |
3634 "static get x() {}", | |
3635 "static set x(v) {}", | |
3636 "static get() {}", | |
3637 "static set() {}", | |
3638 "static static() {}", | |
3639 "static get static() {}", | |
3640 "static set static(v) {}", | |
3641 NULL}; | |
3642 | |
3643 static const ParserFlag always_flags[] = { | |
3644 kAllowClasses, | |
3645 kAllowHarmonyObjectLiterals | |
3646 }; | |
3647 RunParserSyncTest(context_data, class_body_data, kSuccess, NULL, 0, | |
3648 always_flags, arraysize(always_flags)); | |
3649 } | |
3650 | |
3651 | |
3652 TEST(MethodDefinitionstrictFormalParamereters) { | |
3653 const char* context_data[][2] = {{"({method(", "){}});"}, | |
3654 {NULL, NULL}}; | |
3655 | |
3656 const char* params_data[] = { | |
3657 "x, x", | |
3658 "x, y, x", | |
3659 "eval", | |
3660 "arguments", | |
3661 "var", | |
3662 "const", | |
3663 NULL | |
3664 }; | |
3665 | |
3666 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals}; | |
3667 RunParserSyncTest(context_data, params_data, kError, NULL, 0, | |
3668 always_flags, arraysize(always_flags)); | |
3669 } | |
3670 | |
3671 | |
3672 TEST(NoErrorsClassPropertyName) { | |
3673 const char* context_data[][2] = {{"(class {", "() {}});"}, | |
3674 {"(class { get ", "() {}});"}, | |
3675 {"(class { set ", "(v) {}});"}, | |
3676 {"(class { static ", "() {}});"}, | |
3677 {"(class { static get ", "() {}});"}, | |
3678 {"(class { static set ", "(v) {}});"}, | |
3679 {"class C {", "() {}}"}, | |
3680 {"class C { get ", "() {}}"}, | |
3681 {"class C { set ", "(v) {}}"}, | |
3682 {"class C { static ", "() {}}"}, | |
3683 {"class C { static get ", "() {}}"}, | |
3684 {"class C { static set ", "(v) {}}"}, | |
3685 {NULL, NULL}}; | |
3686 const char* name_data[] = { | |
3687 "42", | |
3688 "42.5", | |
3689 "42e2", | |
3690 "42e+2", | |
3691 "42e-2", | |
3692 "null", | |
3693 "false", | |
3694 "true", | |
3695 "'str'", | |
3696 "\"str\"", | |
3697 "static", | |
3698 "get", | |
3699 "set", | |
3700 "var", | |
3701 "const", | |
3702 "let", | |
3703 "this", | |
3704 "class", | |
3705 "function", | |
3706 "yield", | |
3707 "if", | |
3708 "else", | |
3709 "for", | |
3710 "while", | |
3711 "do", | |
3712 "try", | |
3713 "catch", | |
3714 "finally", | |
3715 NULL}; | |
3716 | |
3717 static const ParserFlag always_flags[] = { | |
3718 kAllowClasses, | |
3719 kAllowHarmonyObjectLiterals | |
3720 }; | |
3721 RunParserSyncTest(context_data, name_data, kSuccess, NULL, 0, | |
3722 always_flags, arraysize(always_flags)); | |
3723 } | |
3724 | |
3725 | |
3726 TEST(ErrorsClassExpression) { | |
3727 const char* context_data[][2] = {{"(", ");"}, | |
3728 {"var C = ", ";"}, | |
3729 {"bar, ", ";"}, | |
3730 {NULL, NULL}}; | |
3731 const char* class_data[] = { | |
3732 "class", | |
3733 "class name", | |
3734 "class name extends", | |
3735 "class extends", | |
3736 "class {", | |
3737 "class { m }", | |
3738 "class { m; n }", | |
3739 "class { m: 1 }", | |
3740 "class { m(); n() }", | |
3741 "class { get m }", | |
3742 "class { get m() }", | |
3743 "class { get m() { }", | |
3744 "class { set m() {} }", // Missing required parameter. | |
3745 "class { m() {}, n() {} }", // No commas allowed. | |
3746 NULL}; | |
3747 | |
3748 static const ParserFlag always_flags[] = { | |
3749 kAllowClasses, | |
3750 kAllowHarmonyObjectLiterals | |
3751 }; | |
3752 RunParserSyncTest(context_data, class_data, kError, NULL, 0, | |
3753 always_flags, arraysize(always_flags)); | |
3754 } | |
3755 | |
3756 | |
3757 TEST(ErrorsClassDeclaration) { | |
3758 const char* context_data[][2] = {{"", ""}, | |
3759 {"{", "}"}, | |
3760 {"if (true) {", "}"}, | |
3761 {NULL, NULL}}; | |
3762 const char* class_data[] = { | |
3763 "class", | |
3764 "class name", | |
3765 "class name extends", | |
3766 "class extends", | |
3767 "class name {", | |
3768 "class name { m }", | |
3769 "class name { m; n }", | |
3770 "class name { m: 1 }", | |
3771 "class name { m(); n() }", | |
3772 "class name { get m }", | |
3773 "class name { get m() }", | |
3774 "class name { set m() {) }", // missing required param | |
3775 "class {}", // Name is required for declaration | |
3776 "class extends base {}", | |
3777 NULL}; | |
3778 | |
3779 static const ParserFlag always_flags[] = { | |
3780 kAllowClasses, | |
3781 kAllowHarmonyNumericLiterals | |
3782 }; | |
3783 RunParserSyncTest(context_data, class_data, kError, NULL, 0, | |
3784 always_flags, arraysize(always_flags)); | |
3785 } | |
3786 | |
3787 | |
3788 TEST(ErrorsClassName) { | |
3789 const char* context_data[][2] = {{"class ", "{}"}, | |
3790 {"(class ", "{});"}, | |
3791 {"'use strict'; class ", "{}"}, | |
3792 {"'use strict'; (class ", "{});"}, | |
3793 {NULL, NULL}}; | |
3794 const char* class_name[] = { | |
3795 "arguments", | |
3796 "eval", | |
3797 "implements", | |
3798 "interface", | |
3799 "let", | |
3800 "package", | |
3801 "private", | |
3802 "protected", | |
3803 "public", | |
3804 "static", | |
3805 "var", | |
3806 "yield", | |
3807 NULL}; | |
3808 | |
3809 static const ParserFlag always_flags[] = { | |
3810 kAllowClasses, | |
3811 kAllowHarmonyObjectLiterals | |
3812 }; | |
3813 RunParserSyncTest(context_data, class_name, kError, NULL, 0, | |
3814 always_flags, arraysize(always_flags)); | |
3815 } | |
3816 | |
3817 | |
3818 TEST(ErrorsClassGetterParamName) { | |
3819 const char* context_data[][2] = { | |
3820 {"class C { get name(", ") {} }"}, | |
3821 {"(class { get name(", ") {} });"}, | |
3822 {"'use strict'; class C { get name(", ") {} }"}, | |
3823 {"'use strict'; (class { get name(", ") {} })"}, | |
3824 {NULL, NULL} | |
3825 }; | |
3826 | |
3827 const char* class_name[] = { | |
3828 "arguments", | |
3829 "eval", | |
3830 "implements", | |
3831 "interface", | |
3832 "let", | |
3833 "package", | |
3834 "private", | |
3835 "protected", | |
3836 "public", | |
3837 "static", | |
3838 "var", | |
3839 "yield", | |
3840 NULL}; | |
3841 | |
3842 static const ParserFlag always_flags[] = { | |
3843 kAllowClasses, | |
3844 kAllowHarmonyObjectLiterals | |
3845 }; | |
3846 RunParserSyncTest(context_data, class_name, kError, NULL, 0, | |
3847 always_flags, arraysize(always_flags)); | |
3848 } | |
3849 | |
3850 | |
3851 TEST(ErrorsClassStaticPrototype) { | |
3852 const char* context_data[][2] = {{"class C {", "}"}, | |
3853 {"(class {", "});"}, | |
3854 {NULL, NULL}}; | |
3855 | |
3856 const char* class_body_data[] = { | |
3857 "static prototype() {}", | |
3858 "static get prototype() {}", | |
3859 "static set prototype(_) {}", | |
3860 NULL}; | |
3861 | |
3862 static const ParserFlag always_flags[] = { | |
3863 kAllowClasses, | |
3864 kAllowHarmonyObjectLiterals | |
3865 }; | |
3866 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0, | |
3867 always_flags, arraysize(always_flags)); | |
3868 } | |
3869 | |
3870 | |
3871 TEST(ErrorsClassSpecialConstructor) { | |
3872 const char* context_data[][2] = {{"class C {", "}"}, | |
3873 {"(class {", "});"}, | |
3874 {NULL, NULL}}; | |
3875 | |
3876 const char* class_body_data[] = { | |
3877 "get constructor() {}", | |
3878 "get constructor(_) {}", | |
3879 NULL}; | |
3880 | |
3881 static const ParserFlag always_flags[] = { | |
3882 kAllowClasses, | |
3883 kAllowHarmonyObjectLiterals | |
3884 }; | |
3885 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0, | |
3886 always_flags, arraysize(always_flags)); | |
3887 } | |
3888 | |
3889 | |
3890 TEST(NoErrorsClassConstructor) { | |
3891 const char* context_data[][2] = {{"class C {", "}"}, | |
3892 {"(class {", "});"}, | |
3893 {NULL, NULL}}; | |
3894 | |
3895 const char* class_body_data[] = { | |
3896 "constructor() {}", | |
3897 "static constructor() {}", | |
3898 "static get constructor() {}", | |
3899 "static set constructor(_) {}", | |
rossberg
2014/09/16 15:25:40
I assume "constructor(){} static constructor(){}"
| |
3900 NULL}; | |
3901 | |
3902 static const ParserFlag always_flags[] = { | |
3903 kAllowClasses, | |
3904 kAllowHarmonyObjectLiterals | |
3905 }; | |
3906 RunParserSyncTest(context_data, class_body_data, kSuccess, NULL, 0, | |
3907 always_flags, arraysize(always_flags)); | |
3908 } | |
3909 | |
3910 | |
3911 TEST(ErrorsClassMultipleConstructor) { | |
3912 // We currently do not allow any duplicate properties in class bodies. This | |
3913 // test ensures that when we change that we still throw on duplicate | |
3914 // constructors. | |
3915 const char* context_data[][2] = {{"class C {", "}"}, | |
3916 {"(class {", "});"}, | |
3917 {NULL, NULL}}; | |
3918 | |
3919 const char* class_body_data[] = { | |
3920 "constructor() {}; constructor() {}", | |
3921 NULL}; | |
3922 | |
3923 static const ParserFlag always_flags[] = { | |
3924 kAllowClasses, | |
3925 kAllowHarmonyObjectLiterals | |
3926 }; | |
3927 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0, | |
3928 always_flags, arraysize(always_flags)); | |
3929 } | |
3930 | |
3931 | |
3932 TEST(ErrorsClassesAreStrict) { | |
3933 const char* context_data[][2] = {{"", ""}, | |
3934 {"(", ");"}, | |
3935 {NULL, NULL}}; | |
3936 | |
3937 const char* class_body_data[] = { | |
3938 "class C { method() { with ({}) {} } }", | |
3939 "class C extends function() { with ({}) {} } {}", | |
3940 NULL}; | |
3941 | |
3942 static const ParserFlag always_flags[] = { | |
3943 kAllowClasses, | |
3944 kAllowHarmonyObjectLiterals | |
3945 }; | |
3946 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0, | |
3947 always_flags, arraysize(always_flags)); | |
3948 } | |
OLD | NEW |