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 { set m() {) }", // missing required param | |
rossberg
2014/09/15 12:32:49
How about
class { static static() {} }
arv (Not doing code reviews)
2014/09/15 15:12:33
This has another syntax error though... fixing.
arv (Not doing code reviews)
2014/09/15 15:12:33
That is not an error. This case is covered by NoEr
| |
3744 NULL}; | |
3745 | |
3746 static const ParserFlag always_flags[] = { | |
3747 kAllowClasses, | |
3748 kAllowHarmonyObjectLiterals | |
3749 }; | |
3750 RunParserSyncTest(context_data, class_data, kError, NULL, 0, | |
3751 always_flags, arraysize(always_flags)); | |
3752 } | |
3753 | |
3754 | |
3755 TEST(ErrorsClassDeclaration) { | |
3756 const char* context_data[][2] = {{"", ""}, | |
3757 {"{", "}"}, | |
3758 {"if (true) {", "}"}, | |
3759 {NULL, NULL}}; | |
3760 const char* class_data[] = { | |
3761 "class", | |
3762 "class name", | |
3763 "class name extends", | |
3764 "class extends", | |
3765 "class name {", | |
3766 "class name { m }", | |
3767 "class name { m; n }", | |
3768 "class name { m: 1 }", | |
3769 "class name { m(); n() }", | |
3770 "class name { get m }", | |
3771 "class name { get m() }", | |
3772 "class name { set m() {) }", // missing required param | |
3773 "class {}", // Name is required for declaration | |
3774 "class extends base {}", | |
3775 NULL}; | |
3776 | |
3777 static const ParserFlag always_flags[] = { | |
3778 kAllowClasses, | |
3779 kAllowHarmonyNumericLiterals | |
3780 }; | |
3781 RunParserSyncTest(context_data, class_data, kError, NULL, 0, | |
3782 always_flags, arraysize(always_flags)); | |
3783 } | |
3784 | |
3785 | |
3786 TEST(ErrorsClassName) { | |
3787 const char* context_data[][2] = {{"class ", "{}"}, | |
3788 {"(class ", "{});"}, | |
3789 {"'use strict'; class ", "{}"}, | |
3790 {"'use strict'; (class ", "{});"}, | |
3791 {NULL, NULL}}; | |
3792 const char* class_name[] = { | |
3793 "arguments", | |
3794 "eval", | |
3795 "implements", | |
3796 "interface", | |
3797 "let", | |
3798 "package", | |
3799 "private", | |
3800 "protected", | |
3801 "public", | |
3802 "static", | |
3803 "var", | |
3804 "yield", | |
3805 NULL}; | |
3806 | |
3807 static const ParserFlag always_flags[] = { | |
3808 kAllowClasses, | |
3809 kAllowHarmonyObjectLiterals | |
3810 }; | |
3811 RunParserSyncTest(context_data, class_name, kError, NULL, 0, | |
3812 always_flags, arraysize(always_flags)); | |
3813 } | |
3814 | |
3815 | |
3816 TEST(ErrorsClassGetterParamName) { | |
3817 const char* context_data[][2] = { | |
3818 {"class C { get name(", ") {} }"}, | |
3819 {"(class { get name(", ") {} });"}, | |
3820 {"'use strict'; class C { get name(", ") {} }"}, | |
3821 {"'use strict'; (class { get name(", ") {} })"}, | |
3822 {NULL, NULL} | |
3823 }; | |
3824 | |
3825 const char* class_name[] = { | |
3826 "arguments", | |
3827 "eval", | |
3828 "implements", | |
3829 "interface", | |
3830 "let", | |
3831 "package", | |
3832 "private", | |
3833 "protected", | |
3834 "public", | |
3835 "static", | |
3836 "var", | |
3837 "yield", | |
3838 NULL}; | |
3839 | |
3840 static const ParserFlag always_flags[] = { | |
3841 kAllowClasses, | |
3842 kAllowHarmonyObjectLiterals | |
3843 }; | |
3844 RunParserSyncTest(context_data, class_name, kError, NULL, 0, | |
3845 always_flags, arraysize(always_flags)); | |
3846 } | |
3847 | |
3848 | |
3849 TEST(ErrorsClassStaticPrototype) { | |
3850 const char* context_data[][2] = {{"class C {", "}"}, | |
3851 {"(class {", "});"}, | |
3852 {NULL, NULL}}; | |
3853 | |
3854 const char* class_body_data[] = { | |
3855 "static prototype() {}", | |
3856 "static get prototype() {}", | |
3857 "static set prototype(_) {}", | |
3858 NULL}; | |
3859 | |
3860 static const ParserFlag always_flags[] = { | |
3861 kAllowClasses, | |
3862 kAllowHarmonyObjectLiterals | |
3863 }; | |
3864 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0, | |
3865 always_flags, arraysize(always_flags)); | |
3866 } | |
3867 | |
3868 | |
3869 TEST(ErrorsClassSpecialConstructor) { | |
3870 const char* context_data[][2] = {{"class C {", "}"}, | |
3871 {"(class {", "});"}, | |
3872 {NULL, NULL}}; | |
3873 | |
3874 const char* class_body_data[] = { | |
3875 "get constructor() {}", | |
3876 "get constructor(_) {}", | |
rossberg
2014/09/15 12:32:49
"static constructor"? (Or is that actually valid?
arv (Not doing code reviews)
2014/09/15 15:12:33
That is valid. Adding test.
The spec says that `s
| |
3877 NULL}; | |
3878 | |
3879 static const ParserFlag always_flags[] = { | |
3880 kAllowClasses, | |
3881 kAllowHarmonyObjectLiterals | |
3882 }; | |
3883 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0, | |
3884 always_flags, arraysize(always_flags)); | |
3885 } | |
3886 | |
3887 | |
3888 TEST(ErrorsClassMultipleConstructor) { | |
3889 // We currently do not allow any duplicate properties in class bodies. This | |
3890 // test ensures that when we change that we still throw on duplicate | |
3891 // constructors. | |
3892 const char* context_data[][2] = {{"class C {", "}"}, | |
3893 {"(class {", "});"}, | |
3894 {NULL, NULL}}; | |
3895 | |
3896 const char* class_body_data[] = { | |
3897 "constructor() {}; constructor() {}", | |
3898 NULL}; | |
3899 | |
3900 static const ParserFlag always_flags[] = { | |
3901 kAllowClasses, | |
3902 kAllowHarmonyObjectLiterals | |
3903 }; | |
3904 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0, | |
3905 always_flags, arraysize(always_flags)); | |
3906 } | |
3907 | |
3908 | |
3909 TEST(ErrorsClassesAreStrict) { | |
3910 // We currently do not allow any duplicate properties in class bodies. This | |
rossberg
2014/09/15 12:32:49
Bogus comment copy & paste?
arv (Not doing code reviews)
2014/09/15 15:12:33
Done.
| |
3911 // test ensures that when we change that we still throw on duplicate | |
3912 // constructors. | |
3913 const char* context_data[][2] = {{"", ""}, | |
3914 {"(", ");"}, | |
3915 {NULL, NULL}}; | |
3916 | |
3917 const char* class_body_data[] = { | |
3918 "class C { method() { with ({}) {} } }", | |
3919 "class C extends function() { with ({}) {} } {}", | |
3920 NULL}; | |
3921 | |
3922 static const ParserFlag always_flags[] = { | |
3923 kAllowClasses, | |
3924 kAllowHarmonyObjectLiterals | |
3925 }; | |
3926 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0, | |
3927 always_flags, arraysize(always_flags)); | |
3928 } | |
OLD | NEW |