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 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
947 return character_length; | 947 return character_length; |
948 } | 948 } |
949 | 949 |
950 | 950 |
951 TEST(ScopeUsesArgumentsSuperThis) { | 951 TEST(ScopeUsesArgumentsSuperThis) { |
952 static const struct { | 952 static const struct { |
953 const char* prefix; | 953 const char* prefix; |
954 const char* suffix; | 954 const char* suffix; |
955 } surroundings[] = { | 955 } surroundings[] = { |
956 { "function f() {", "}" }, | 956 { "function f() {", "}" }, |
957 { "var f = () => {", "}" }, | 957 { "var f = () => {", "};" }, |
| 958 { "class C { constructor() {", "} }" }, |
958 }; | 959 }; |
959 | 960 |
960 enum Expected { | 961 enum Expected { |
961 NONE = 0, | 962 NONE = 0, |
962 ARGUMENTS = 1, | 963 ARGUMENTS = 1, |
963 SUPER_PROPERTY = 2, | 964 SUPER_PROPERTY = 1 << 1, |
964 SUPER_CONSTRUCTOR_CALL = 4, | 965 SUPER_CONSTRUCTOR_CALL = 1 << 2, |
965 THIS = 8, | 966 THIS = 1 << 3, |
966 INNER_ARGUMENTS = 16, | 967 INNER_ARGUMENTS = 1 << 4, |
967 INNER_SUPER_PROPERTY = 32, | 968 INNER_SUPER_PROPERTY = 1 << 5, |
968 INNER_SUPER_CONSTRUCTOR_CALL = 64, | 969 INNER_SUPER_CONSTRUCTOR_CALL = 1 << 6, |
969 INNER_THIS = 128 | 970 INNER_THIS = 1 << 7 |
970 }; | 971 }; |
971 | 972 |
972 static const struct { | 973 static const struct { |
973 const char* body; | 974 const char* body; |
974 int expected; | 975 int expected; |
975 } source_data[] = { | 976 } source_data[] = { |
976 {"", NONE}, | 977 {"", NONE}, |
977 {"return this", THIS}, | 978 {"return this", THIS}, |
978 {"return arguments", ARGUMENTS}, | 979 {"return arguments", ARGUMENTS}, |
979 {"return super()", SUPER_CONSTRUCTOR_CALL}, | 980 {"return super()", SUPER_CONSTRUCTOR_CALL}, |
980 {"return super.x", SUPER_PROPERTY}, | 981 {"return super.x", SUPER_PROPERTY}, |
981 {"return arguments[0]", ARGUMENTS}, | 982 {"return arguments[0]", ARGUMENTS}, |
982 {"return this + arguments[0]", ARGUMENTS | THIS}, | 983 {"return this + arguments[0]", ARGUMENTS | THIS}, |
983 {"return this + arguments[0] + super.x", | 984 {"return this + arguments[0] + super.x", |
984 ARGUMENTS | SUPER_PROPERTY | THIS}, | 985 ARGUMENTS | SUPER_PROPERTY | THIS}, |
985 {"return x => this + x", INNER_THIS}, | 986 {"return x => this + x", INNER_THIS}, |
986 {"return x => super() + x", INNER_SUPER_CONSTRUCTOR_CALL}, | 987 {"return x => super() + x", INNER_SUPER_CONSTRUCTOR_CALL}, |
987 {"this.foo = 42;", THIS}, | 988 {"this.foo = 42;", THIS}, |
988 {"this.foo();", THIS}, | 989 {"this.foo();", THIS}, |
989 {"if (foo()) { this.f() }", THIS}, | 990 {"if (foo()) { this.f() }", THIS}, |
990 {"if (foo()) { super.f() }", SUPER_PROPERTY}, | 991 {"if (foo()) { super.f() }", SUPER_PROPERTY}, |
991 {"if (arguments.length) { this.f() }", ARGUMENTS | THIS}, | 992 {"if (arguments.length) { this.f() }", ARGUMENTS | THIS}, |
992 {"while (true) { this.f() }", THIS}, | 993 {"while (true) { this.f() }", THIS}, |
993 {"while (true) { super.f() }", SUPER_PROPERTY}, | 994 {"while (true) { super.f() }", SUPER_PROPERTY}, |
994 {"if (true) { while (true) this.foo(arguments) }", ARGUMENTS | THIS}, | 995 {"if (true) { while (true) this.foo(arguments) }", ARGUMENTS | THIS}, |
995 // Multiple nesting levels must work as well. | 996 // Multiple nesting levels must work as well. |
996 {"while (true) { while (true) { while (true) return this } }", THIS}, | 997 {"while (true) { while (true) { while (true) return this } }", THIS}, |
997 {"while (true) { while (true) { while (true) return super() } }", | 998 {"while (true) { while (true) { while (true) return super() } }", |
998 SUPER_CONSTRUCTOR_CALL}, | 999 SUPER_CONSTRUCTOR_CALL}, |
999 {"if (1) { return () => { while (true) new this() } }", INNER_THIS}, | 1000 {"if (1) { return () => { while (true) new this() } }", INNER_THIS}, |
1000 {"if (1) { return () => { while (true) new super() } }", NONE}, | 1001 // Note that propagation of the inner_uses_this() value does not |
1001 {"if (1) { return () => { while (true) new new super() } }", NONE}, | 1002 // cross boundaries of normal functions onto parent scopes. |
1002 // Note that propagation of the inner_uses_this() value does not | 1003 {"return function (x) { return this + x }", NONE}, |
1003 // cross boundaries of normal functions onto parent scopes. | 1004 {"return { m(x) { return super.m() + x } }", NONE}, |
1004 {"return function (x) { return this + x }", NONE}, | 1005 {"var x = function () { this.foo = 42 };", NONE}, |
1005 {"return function (x) { return super() + x }", NONE}, | 1006 {"var x = { m() { super.foo = 42 } };", NONE}, |
1006 {"var x = function () { this.foo = 42 };", NONE}, | 1007 {"if (1) { return function () { while (true) new this() } }", NONE}, |
1007 {"var x = function () { super.foo = 42 };", NONE}, | 1008 {"if (1) { return { m() { while (true) super.m() } } }", NONE}, |
1008 {"if (1) { return function () { while (true) new this() } }", NONE}, | 1009 {"return function (x) { return () => this }", NONE}, |
1009 {"if (1) { return function () { while (true) new super() } }", NONE}, | 1010 {"return { m(x) { return () => super.m() } }", NONE}, |
1010 {"return function (x) { return () => this }", NONE}, | 1011 // Flags must be correctly set when using block scoping. |
1011 {"return function (x) { return () => super() }", NONE}, | 1012 {"\"use strict\"; while (true) { let x; this, arguments; }", |
1012 // Flags must be correctly set when using block scoping. | 1013 INNER_ARGUMENTS | INNER_THIS}, |
1013 {"\"use strict\"; while (true) { let x; this, arguments; }", | 1014 {"\"use strict\"; while (true) { let x; this, super(), arguments; }", |
1014 INNER_ARGUMENTS | INNER_THIS}, | 1015 INNER_ARGUMENTS | INNER_SUPER_CONSTRUCTOR_CALL | INNER_THIS}, |
1015 {"\"use strict\"; while (true) { let x; this, super(), arguments; }", | 1016 {"\"use strict\"; if (foo()) { let x; this.f() }", INNER_THIS}, |
1016 INNER_ARGUMENTS | INNER_SUPER_CONSTRUCTOR_CALL | INNER_THIS}, | 1017 {"\"use strict\"; if (foo()) { let x; super.f() }", |
1017 {"\"use strict\"; if (foo()) { let x; this.f() }", INNER_THIS}, | 1018 INNER_SUPER_PROPERTY}, |
1018 {"\"use strict\"; if (foo()) { let x; super.f() }", | 1019 {"\"use strict\"; if (1) {" |
1019 INNER_SUPER_PROPERTY}, | 1020 " let x; return { m() { return this + super.m() + arguments } }" |
1020 {"\"use strict\"; if (1) {" | 1021 "}", |
1021 " let x; return function () { return this + super() + arguments }" | 1022 NONE}, |
1022 "}", | 1023 }; |
1023 NONE}, | |
1024 }; | |
1025 | 1024 |
1026 i::Isolate* isolate = CcTest::i_isolate(); | 1025 i::Isolate* isolate = CcTest::i_isolate(); |
1027 i::Factory* factory = isolate->factory(); | 1026 i::Factory* factory = isolate->factory(); |
1028 | 1027 |
1029 v8::HandleScope handles(CcTest::isolate()); | 1028 v8::HandleScope handles(CcTest::isolate()); |
1030 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 1029 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); |
1031 v8::Context::Scope context_scope(context); | 1030 v8::Context::Scope context_scope(context); |
1032 | 1031 |
1033 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 1032 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
1034 128 * 1024); | 1033 128 * 1024); |
1035 | 1034 |
1036 for (unsigned j = 0; j < arraysize(surroundings); ++j) { | 1035 for (unsigned j = 0; j < arraysize(surroundings); ++j) { |
1037 for (unsigned i = 0; i < arraysize(source_data); ++i) { | 1036 for (unsigned i = 0; i < arraysize(source_data); ++i) { |
| 1037 // Super constructor call is only allowed in constructor. |
| 1038 // Super property is only allowed in constructor and method. |
| 1039 if (((source_data[i].expected & SUPER_CONSTRUCTOR_CALL) || |
| 1040 (source_data[i].expected & SUPER_PROPERTY) || |
| 1041 (source_data[i].expected & INNER_SUPER_CONSTRUCTOR_CALL) || |
| 1042 (source_data[i].expected & INNER_SUPER_PROPERTY) || |
| 1043 (source_data[i].expected == NONE)) && j != 2) { |
| 1044 continue; |
| 1045 } |
1038 int kProgramByteSize = i::StrLength(surroundings[j].prefix) + | 1046 int kProgramByteSize = i::StrLength(surroundings[j].prefix) + |
1039 i::StrLength(surroundings[j].suffix) + | 1047 i::StrLength(surroundings[j].suffix) + |
1040 i::StrLength(source_data[i].body); | 1048 i::StrLength(source_data[i].body); |
1041 i::ScopedVector<char> program(kProgramByteSize + 1); | 1049 i::ScopedVector<char> program(kProgramByteSize + 1); |
1042 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix, | 1050 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix, |
1043 source_data[i].body, surroundings[j].suffix); | 1051 source_data[i].body, surroundings[j].suffix); |
1044 i::Handle<i::String> source = | 1052 i::Handle<i::String> source = |
1045 factory->NewStringFromUtf8(i::CStrVector(program.start())) | 1053 factory->NewStringFromUtf8(i::CStrVector(program.start())) |
1046 .ToHandleChecked(); | 1054 .ToHandleChecked(); |
1047 i::Handle<i::Script> script = factory->NewScript(source); | 1055 i::Handle<i::Script> script = factory->NewScript(source); |
1048 i::CompilationInfoWithZone info(script); | 1056 i::CompilationInfoWithZone info(script); |
1049 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), | 1057 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), |
1050 isolate->heap()->HashSeed(), | 1058 isolate->heap()->HashSeed(), |
1051 isolate->unicode_cache()}; | 1059 isolate->unicode_cache()}; |
1052 i::Parser parser(&info, &parse_info); | 1060 i::Parser parser(&info, &parse_info); |
1053 parser.set_allow_harmony_arrow_functions(true); | 1061 parser.set_allow_harmony_arrow_functions(true); |
1054 parser.set_allow_harmony_classes(true); | 1062 parser.set_allow_harmony_classes(true); |
| 1063 parser.set_allow_harmony_object_literals(true); |
1055 parser.set_allow_harmony_scoping(true); | 1064 parser.set_allow_harmony_scoping(true); |
| 1065 parser.set_allow_harmony_sloppy(true); |
1056 info.MarkAsGlobal(); | 1066 info.MarkAsGlobal(); |
1057 parser.Parse(); | 1067 CHECK(parser.Parse()); |
1058 CHECK(i::Rewriter::Rewrite(&info)); | 1068 CHECK(i::Rewriter::Rewrite(&info)); |
1059 CHECK(i::Scope::Analyze(&info)); | 1069 CHECK(i::Scope::Analyze(&info)); |
1060 CHECK(info.function() != NULL); | 1070 CHECK(info.function() != NULL); |
1061 | 1071 |
1062 i::Scope* script_scope = info.function()->scope(); | 1072 i::Scope* script_scope = info.function()->scope(); |
1063 CHECK(script_scope->is_script_scope()); | 1073 CHECK(script_scope->is_script_scope()); |
1064 CHECK_EQ(1, script_scope->inner_scopes()->length()); | 1074 CHECK_EQ(1, script_scope->inner_scopes()->length()); |
1065 | 1075 |
1066 i::Scope* scope = script_scope->inner_scopes()->at(0); | 1076 i::Scope* scope = script_scope->inner_scopes()->at(0); |
| 1077 // Adjust for constructor scope. |
| 1078 if (j == 2) { |
| 1079 CHECK_EQ(1, scope->inner_scopes()->length()); |
| 1080 scope = scope->inner_scopes()->at(0); |
| 1081 } |
1067 CHECK_EQ((source_data[i].expected & ARGUMENTS) != 0, | 1082 CHECK_EQ((source_data[i].expected & ARGUMENTS) != 0, |
1068 scope->uses_arguments()); | 1083 scope->uses_arguments()); |
1069 CHECK_EQ((source_data[i].expected & SUPER_PROPERTY) != 0, | 1084 CHECK_EQ((source_data[i].expected & SUPER_PROPERTY) != 0, |
1070 scope->uses_super_property()); | 1085 scope->uses_super_property()); |
1071 CHECK_EQ((source_data[i].expected & SUPER_CONSTRUCTOR_CALL) != 0, | 1086 CHECK_EQ((source_data[i].expected & SUPER_CONSTRUCTOR_CALL) != 0, |
1072 scope->uses_super_constructor_call()); | 1087 scope->uses_super_constructor_call()); |
1073 CHECK_EQ((source_data[i].expected & THIS) != 0, scope->uses_this()); | 1088 CHECK_EQ((source_data[i].expected & THIS) != 0, scope->uses_this()); |
1074 CHECK_EQ((source_data[i].expected & INNER_ARGUMENTS) != 0, | 1089 CHECK_EQ((source_data[i].expected & INNER_ARGUMENTS) != 0, |
1075 scope->inner_uses_arguments()); | 1090 scope->inner_uses_arguments()); |
1076 CHECK_EQ((source_data[i].expected & INNER_SUPER_PROPERTY) != 0, | 1091 CHECK_EQ((source_data[i].expected & INNER_SUPER_PROPERTY) != 0, |
(...skipping 2553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3630 "foo ? bar : baz => {}", | 3645 "foo ? bar : baz => {}", |
3631 NULL | 3646 NULL |
3632 }; | 3647 }; |
3633 | 3648 |
3634 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions}; | 3649 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions}; |
3635 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | 3650 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, |
3636 always_flags, arraysize(always_flags)); | 3651 always_flags, arraysize(always_flags)); |
3637 } | 3652 } |
3638 | 3653 |
3639 | 3654 |
3640 TEST(NoErrorsSuper) { | 3655 TEST(SuperNoErrors) { |
3641 // Tests that parser and preparser accept 'super' keyword in right places. | 3656 // Tests that parser and preparser accept 'super' keyword in right places. |
3642 const char* context_data[][2] = {{"", ";"}, | 3657 const char* context_data[][2] = { |
3643 {"k = ", ";"}, | 3658 {"class C { m() { ", "; } }"}, |
3644 {"foo(", ");"}, | 3659 {"class C { m() { k = ", "; } }"}, |
3645 {NULL, NULL}}; | 3660 {"class C { m() { foo(", "); } }"}, |
| 3661 {"class C { m() { () => ", "; } }"}, |
| 3662 {NULL, NULL} |
| 3663 }; |
3646 | 3664 |
3647 const char* statement_data[] = { | 3665 const char* statement_data[] = { |
3648 "super.x", | 3666 "super.x", |
3649 "super[27]", | 3667 "super[27]", |
| 3668 "new super.x", |
| 3669 "new super.x()", |
| 3670 "new super[27]", |
| 3671 "new super[27]()", |
| 3672 "z.super", // Ok, property lookup. |
| 3673 NULL |
| 3674 }; |
| 3675 |
| 3676 static const ParserFlag always_flags[] = { |
| 3677 kAllowHarmonyArrowFunctions, |
| 3678 kAllowHarmonyClasses, |
| 3679 kAllowHarmonyObjectLiterals, |
| 3680 kAllowHarmonySloppy |
| 3681 }; |
| 3682 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, |
| 3683 always_flags, arraysize(always_flags)); |
| 3684 } |
| 3685 |
| 3686 |
| 3687 TEST(SuperErrors) { |
| 3688 const char* context_data[][2] = { |
| 3689 {"class C { m() { ", "; } }"}, |
| 3690 {"class C { m() { k = ", "; } }"}, |
| 3691 {"class C { m() { foo(", "); } }"}, |
| 3692 {"class C { m() { () => ", "; } }"}, |
| 3693 {NULL, NULL} |
| 3694 }; |
| 3695 |
| 3696 const char* expression_data[] = { |
| 3697 "super", |
| 3698 "super = x", |
| 3699 "y = super", |
| 3700 "f(super)", |
3650 "new super", | 3701 "new super", |
3651 "new super()", | 3702 "new super()", |
3652 "new super(12, 45)", | 3703 "new super(12, 45)", |
3653 "new new super", | 3704 "new new super", |
3654 "new new super()", | 3705 "new new super()", |
3655 "new new super()()", | 3706 "new new super()()", |
3656 "z.super", // Ok, property lookup. | 3707 NULL |
3657 NULL}; | 3708 }; |
3658 | 3709 |
3659 static const ParserFlag always_flags[] = {kAllowHarmonyClasses}; | 3710 static const ParserFlag always_flags[] = { |
3660 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | 3711 kAllowHarmonyClasses, |
3661 always_flags, arraysize(always_flags)); | 3712 kAllowHarmonyObjectLiterals, |
3662 } | 3713 kAllowHarmonySloppy |
3663 | 3714 }; |
3664 | 3715 RunParserSyncTest(context_data, expression_data, kError, NULL, 0, |
3665 TEST(ErrorsSuper) { | 3716 always_flags, arraysize(always_flags)); |
3666 // Tests that parser and preparser generate same errors for 'super'. | 3717 } |
3667 const char* context_data[][2] = {{"", ";"}, | 3718 |
3668 {"k = ", ";"}, | 3719 |
3669 {"foo(", ");"}, | 3720 TEST(SuperCall) { |
| 3721 const char* context_data[][2] = {{"", ""}, |
3670 {NULL, NULL}}; | 3722 {NULL, NULL}}; |
3671 | 3723 |
| 3724 const char* success_data[] = { |
| 3725 "class C { constructor() { super(); } }", |
| 3726 "class C extends B { constructor() { super(); } }", |
| 3727 "class C extends B { constructor() { () => super(); } }", |
| 3728 NULL |
| 3729 }; |
| 3730 |
| 3731 static const ParserFlag always_flags[] = { |
| 3732 kAllowHarmonyArrowFunctions, |
| 3733 kAllowHarmonyClasses, |
| 3734 kAllowHarmonyObjectLiterals, |
| 3735 kAllowHarmonySloppy |
| 3736 }; |
| 3737 RunParserSyncTest(context_data, success_data, kSuccess, NULL, 0, |
| 3738 always_flags, arraysize(always_flags)); |
| 3739 |
| 3740 const char* error_data[] = { |
| 3741 "class C { method() { super(); } }", |
| 3742 "class C { method() { () => super(); } }", |
| 3743 "class C { *method() { super(); } }", |
| 3744 "class C { get x() { super(); } }", |
| 3745 "class C { set x(_) { super(); } }", |
| 3746 "({ method() { super(); } })", |
| 3747 "({ *method() { super(); } })", |
| 3748 "({ get x() { super(); } })", |
| 3749 "({ set x(_) { super(); } })", |
| 3750 "({ f: function() { super(); } })", |
| 3751 "(function() { super(); })", |
| 3752 "var f = function() { super(); }", |
| 3753 "({ f: function*() { super(); } })", |
| 3754 "(function*() { super(); })", |
| 3755 "var f = function*() { super(); }", |
| 3756 NULL |
| 3757 }; |
| 3758 |
| 3759 RunParserSyncTest(context_data, error_data, kError, NULL, 0, |
| 3760 always_flags, arraysize(always_flags)); |
| 3761 } |
| 3762 |
| 3763 |
| 3764 TEST(SuperNewNoErrors) { |
| 3765 const char* context_data[][2] = { |
| 3766 {"class C { constructor() { ", " } }"}, |
| 3767 {"class C { *method() { ", " } }"}, |
| 3768 {"class C { get x() { ", " } }"}, |
| 3769 {"class C { set x(_) { ", " } }"}, |
| 3770 {"({ method() { ", " } })"}, |
| 3771 {"({ *method() { ", " } })"}, |
| 3772 {"({ get x() { ", " } })"}, |
| 3773 {"({ set x(_) { ", " } })"}, |
| 3774 {NULL, NULL} |
| 3775 }; |
| 3776 |
| 3777 const char* expression_data[] = { |
| 3778 "new super.x;", |
| 3779 "new super.x();", |
| 3780 "() => new super.x;", |
| 3781 "() => new super.x();", |
| 3782 NULL |
| 3783 }; |
| 3784 |
| 3785 static const ParserFlag always_flags[] = { |
| 3786 kAllowHarmonyArrowFunctions, |
| 3787 kAllowHarmonyClasses, |
| 3788 kAllowHarmonyObjectLiterals, |
| 3789 kAllowHarmonySloppy |
| 3790 }; |
| 3791 RunParserSyncTest(context_data, expression_data, kSuccess, NULL, 0, |
| 3792 always_flags, arraysize(always_flags)); |
| 3793 } |
| 3794 |
| 3795 |
| 3796 TEST(SuperNewErrors) { |
| 3797 const char* context_data[][2] = { |
| 3798 {"class C { method() { ", " } }"}, |
| 3799 {"class C { *method() { ", " } }"}, |
| 3800 {"class C { get x() { ", " } }"}, |
| 3801 {"class C { set x(_) { ", " } }"}, |
| 3802 {"({ method() { ", " } })"}, |
| 3803 {"({ *method() { ", " } })"}, |
| 3804 {"({ get x() { ", " } })"}, |
| 3805 {"({ set x(_) { ", " } })"}, |
| 3806 {"({ f: function() { ", " } })"}, |
| 3807 {"(function() { ", " })"}, |
| 3808 {"var f = function() { ", " }"}, |
| 3809 {"({ f: function*() { ", " } })"}, |
| 3810 {"(function*() { ", " })"}, |
| 3811 {"var f = function*() { ", " }"}, |
| 3812 {NULL, NULL} |
| 3813 }; |
| 3814 |
3672 const char* statement_data[] = { | 3815 const char* statement_data[] = { |
| 3816 "new super;", |
| 3817 "new super();", |
| 3818 "() => new super;", |
| 3819 "() => new super();", |
| 3820 NULL |
| 3821 }; |
| 3822 |
| 3823 static const ParserFlag always_flags[] = { |
| 3824 kAllowHarmonyArrowFunctions, |
| 3825 kAllowHarmonyClasses, |
| 3826 kAllowHarmonyObjectLiterals, |
| 3827 kAllowHarmonySloppy |
| 3828 }; |
| 3829 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, |
| 3830 always_flags, arraysize(always_flags)); |
| 3831 } |
| 3832 |
| 3833 |
| 3834 TEST(SuperErrorsNonMethods) { |
| 3835 // super is only allowed in methods, accessors and constructors. |
| 3836 const char* context_data[][2] = { |
| 3837 {"", ";"}, |
| 3838 {"k = ", ";"}, |
| 3839 {"foo(", ");"}, |
| 3840 {"if (", ") {}"}, |
| 3841 {"if (true) {", "}"}, |
| 3842 {"if (false) {} else {", "}"}, |
| 3843 {"while (true) {", "}"}, |
| 3844 {"function f() {", "}"}, |
| 3845 {"class C extends (", ") {}"}, |
| 3846 {"class C { m() { function f() {", "} } }"}, |
| 3847 {"({ m() { function f() {", "} } })"}, |
| 3848 {NULL, NULL} |
| 3849 }; |
| 3850 |
| 3851 const char* statement_data[] = { |
| 3852 "super", |
3673 "super = x", | 3853 "super = x", |
3674 "y = super", | 3854 "y = super", |
3675 "f(super)", | 3855 "f(super)", |
3676 NULL}; | 3856 "super.x", |
3677 | 3857 "super[27]", |
3678 static const ParserFlag always_flags[] = {kAllowHarmonyClasses}; | 3858 "super.x()", |
| 3859 "super[27]()", |
| 3860 "super()", |
| 3861 "new super.x", |
| 3862 "new super.x()", |
| 3863 "new super[27]", |
| 3864 "new super[27]()", |
| 3865 NULL |
| 3866 }; |
| 3867 |
| 3868 static const ParserFlag always_flags[] = { |
| 3869 kAllowHarmonyClasses, |
| 3870 kAllowHarmonyObjectLiterals, |
| 3871 kAllowHarmonySloppy |
| 3872 }; |
3679 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, | 3873 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, |
3680 always_flags, arraysize(always_flags)); | 3874 always_flags, arraysize(always_flags)); |
3681 } | 3875 } |
3682 | 3876 |
3683 | 3877 |
3684 TEST(NoErrorsMethodDefinition) { | 3878 TEST(NoErrorsMethodDefinition) { |
3685 const char* context_data[][2] = {{"({", "});"}, | 3879 const char* context_data[][2] = {{"({", "});"}, |
3686 {"'use strict'; ({", "});"}, | 3880 {"'use strict'; ({", "});"}, |
3687 {"({*", "});"}, | 3881 {"({*", "});"}, |
3688 {"'use strict'; ({*", "});"}, | 3882 {"'use strict'; ({*", "});"}, |
(...skipping 1453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5142 "class C {static set arguments(_) {}}", | 5336 "class C {static set arguments(_) {}}", |
5143 | 5337 |
5144 NULL}; | 5338 NULL}; |
5145 | 5339 |
5146 static const ParserFlag always_flags[] = { | 5340 static const ParserFlag always_flags[] = { |
5147 kAllowHarmonyClasses, kAllowHarmonyObjectLiterals, kAllowHarmonyScoping, | 5341 kAllowHarmonyClasses, kAllowHarmonyObjectLiterals, kAllowHarmonyScoping, |
5148 kAllowStrongMode}; | 5342 kAllowStrongMode}; |
5149 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | 5343 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, |
5150 always_flags, arraysize(always_flags)); | 5344 always_flags, arraysize(always_flags)); |
5151 } | 5345 } |
OLD | NEW |