Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: test/cctest/test-parsing.cc

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

Powered by Google App Engine
This is Rietveld 408576698