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 // Tests that parser and preparser generate same errors for 'super'. | |
3689 const char* context_data[][2] = {{"class C { m() { ", "; } }"}, | |
3690 {"class C { m() { k = ", "; } }"}, | |
3691 {"class C { m() { foo(", "); } }"}, | |
3692 {"class C { m() { () => ", "; } }"}, | |
marja
2015/02/10 17:10:56
Maybe an interesting test case to add:
class C {
arv (Not doing code reviews)
2015/02/10 17:38:34
Yes. That should be an error. Adding a case to Sup
| |
3693 {NULL, NULL}}; | |
3694 | |
3695 const char* statement_data[] = { | |
3696 "super", | |
3697 "super = x", | |
3698 "y = super", | |
3699 "f(super)", | |
3650 "new super", | 3700 "new super", |
3651 "new super()", | 3701 "new super()", |
3652 "new super(12, 45)", | 3702 "new super(12, 45)", |
3653 "new new super", | 3703 "new new super", |
3654 "new new super()", | 3704 "new new super()", |
3655 "new new super()()", | 3705 "new new super()()", |
3656 "z.super", // Ok, property lookup. | |
3657 NULL}; | 3706 NULL}; |
3658 | 3707 |
3659 static const ParserFlag always_flags[] = {kAllowHarmonyClasses}; | 3708 static const ParserFlag always_flags[] = { |
3660 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | 3709 kAllowHarmonyClasses, |
3661 always_flags, arraysize(always_flags)); | 3710 kAllowHarmonyObjectLiterals, |
3662 } | 3711 kAllowHarmonySloppy |
3663 | 3712 }; |
3664 | 3713 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, |
3665 TEST(ErrorsSuper) { | 3714 always_flags, arraysize(always_flags)); |
3666 // Tests that parser and preparser generate same errors for 'super'. | 3715 } |
3716 | |
3717 | |
3718 TEST(SuperCall) { | |
3719 const char* context_data[][2] = {{"", ""}, | |
3720 {NULL, NULL}}; | |
3721 | |
3722 const char* succes_data[] = { | |
3723 "class C { constructor() { super(); } }", | |
3724 "class C extends B { constructor() { super(); } }", | |
3725 "class C extends B { constructor() { () => super(); } }", | |
3726 NULL | |
3727 }; | |
3728 | |
3729 static const ParserFlag always_flags[] = { | |
3730 kAllowHarmonyArrowFunctions, | |
3731 kAllowHarmonyClasses, | |
3732 kAllowHarmonyObjectLiterals, | |
3733 kAllowHarmonySloppy | |
3734 }; | |
3735 RunParserSyncTest(context_data, succes_data, kSuccess, NULL, 0, | |
3736 always_flags, arraysize(always_flags)); | |
3737 | |
3738 const char* error_data[] = { | |
3739 "class C { method() { super(); } }", | |
3740 "class C { method() { () => super(); } }", | |
3741 "class C { *method() { super(); } }", | |
3742 "class C { get x() { super(); } }", | |
3743 "class C { set x(_) { super(); } }", | |
3744 "({ method() { super(); } })", | |
3745 "({ *method() { super(); } })", | |
3746 "({ get x() { super(); } })", | |
3747 "({ set x(_) { super(); } })", | |
3748 "({ f: function() { super(); } })", | |
3749 "(function() { super(); })", | |
3750 "var f = function() { super(); }", | |
3751 "({ f: function*() { super(); } })", | |
3752 "(function*() { super(); })", | |
3753 "var f = function*() { super(); }", | |
3754 NULL | |
3755 }; | |
3756 | |
3757 RunParserSyncTest(context_data, error_data, kError, NULL, 0, | |
3758 always_flags, arraysize(always_flags)); | |
3759 } | |
3760 | |
3761 | |
3762 TEST(SuperNew) { | |
3763 const char* context_data[][2] = { | |
3764 {"class C { constructor() { ", " } }"}, | |
3765 {"class C { *method() { ", " } }"}, | |
3766 {"class C { get x() { ", " } }"}, | |
3767 {"class C { set x(_) { ", " } }"}, | |
3768 {"({ method() { ", " } })"}, | |
3769 {"({ *method() { ", " } })"}, | |
3770 {"({ get x() { ", " } })"}, | |
3771 {"({ set x(_) { ", " } })"}, | |
3772 {NULL, NULL} | |
3773 }; | |
3774 | |
3775 const char* succes_data[] = { | |
marja
2015/02/10 17:10:56
typo
arv (Not doing code reviews)
2015/02/10 17:38:34
Done.
| |
3776 "new super.x;", | |
3777 "new super.x();", | |
3778 "() => new super.x;", | |
3779 "() => new super.x();", | |
3780 NULL | |
3781 }; | |
3782 | |
3783 static const ParserFlag always_flags[] = { | |
3784 kAllowHarmonyArrowFunctions, | |
3785 kAllowHarmonyClasses, | |
3786 kAllowHarmonyObjectLiterals, | |
3787 kAllowHarmonySloppy | |
3788 }; | |
3789 RunParserSyncTest(context_data, succes_data, kSuccess, NULL, 0, | |
3790 always_flags, arraysize(always_flags)); | |
3791 | |
3792 const char* error_data[] = { | |
arv (Not doing code reviews)
2015/02/10 17:38:34
I screwed this up as well. I'll fix.
| |
3793 "class C { method() { new super; } }", | |
3794 "class C { method() { new super(); } }", | |
3795 "class C { *method() { new super; } }", | |
3796 "class C { *method() { new super(); } }", | |
3797 "class C { get x() { new super; } }", | |
3798 "class C { get x() { new super(); } }", | |
3799 "class C { set x(_) { new super; } }", | |
3800 "class C { set x(_) { new super(); } }", | |
3801 "({ method() { new super; } })", | |
3802 "({ method() { new super(); } })", | |
3803 "({ *method() { new super; } })", | |
3804 "({ *method() { new super(); } })", | |
3805 "({ get x() { new super; } })", | |
3806 "({ get x() { new super(); } })", | |
3807 "({ set x(_) { new super; } })", | |
3808 "({ set x(_) { new super(); } })", | |
3809 "({ f: function() { new super; } })", | |
3810 "({ f: function() { new super(); } })", | |
3811 "(function() { new super; })", | |
3812 "(function() { new super(); })", | |
3813 "var f = function() { new super; }", | |
3814 "var f = function() { new super(); }", | |
3815 "({ f: function*() { new super; } })", | |
3816 "({ f: function*() { new super(); } })", | |
3817 "(function*() { new super; })", | |
3818 "(function*() { new super(); })", | |
3819 "var f = function*() { new super; }", | |
3820 "var f = function*() { new super(); }", | |
3821 NULL | |
3822 }; | |
3823 | |
3824 RunParserSyncTest(context_data, error_data, kError, NULL, 0, | |
3825 always_flags, arraysize(always_flags)); | |
3826 } | |
3827 | |
3828 | |
3829 TEST(SuperErrorsNonMethods) { | |
3830 // super is only allowed in methods, accessors and constructors. | |
3667 const char* context_data[][2] = {{"", ";"}, | 3831 const char* context_data[][2] = {{"", ";"}, |
3668 {"k = ", ";"}, | 3832 {"k = ", ";"}, |
3669 {"foo(", ");"}, | 3833 {"foo(", ");"}, |
3834 {"if (", ") {}"}, | |
3835 {"if (true) {", "}"}, | |
3836 {"if (false) {} else {", "}"}, | |
3837 {"while (true) {", "}"}, | |
3838 {"function f() {", "}"}, | |
3839 {"class C extends (", ") {}"}, | |
3670 {NULL, NULL}}; | 3840 {NULL, NULL}}; |
3671 | 3841 |
3672 const char* statement_data[] = { | 3842 const char* statement_data[] = { |
3843 "super", | |
3673 "super = x", | 3844 "super = x", |
3674 "y = super", | 3845 "y = super", |
3675 "f(super)", | 3846 "f(super)", |
3847 "super.x", | |
3848 "super[27]", | |
3849 "super.x()", | |
3850 "super[27]()", | |
3851 "super()", | |
3852 "new super.x", | |
3853 "new super.x()", | |
3854 "new super[27]", | |
3855 "new super[27]()", | |
3676 NULL}; | 3856 NULL}; |
3677 | 3857 |
3678 static const ParserFlag always_flags[] = {kAllowHarmonyClasses}; | 3858 static const ParserFlag always_flags[] = { |
3859 kAllowHarmonyClasses, | |
3860 kAllowHarmonyObjectLiterals, | |
3861 kAllowHarmonySloppy | |
3862 }; | |
3679 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, | 3863 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, |
3680 always_flags, arraysize(always_flags)); | 3864 always_flags, arraysize(always_flags)); |
3681 } | 3865 } |
3682 | 3866 |
3683 | 3867 |
3684 TEST(NoErrorsMethodDefinition) { | 3868 TEST(NoErrorsMethodDefinition) { |
3685 const char* context_data[][2] = {{"({", "});"}, | 3869 const char* context_data[][2] = {{"({", "});"}, |
3686 {"'use strict'; ({", "});"}, | 3870 {"'use strict'; ({", "});"}, |
3687 {"({*", "});"}, | 3871 {"({*", "});"}, |
3688 {"'use strict'; ({*", "});"}, | 3872 {"'use strict'; ({*", "});"}, |
(...skipping 1453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5142 "class C {static set arguments(_) {}}", | 5326 "class C {static set arguments(_) {}}", |
5143 | 5327 |
5144 NULL}; | 5328 NULL}; |
5145 | 5329 |
5146 static const ParserFlag always_flags[] = { | 5330 static const ParserFlag always_flags[] = { |
5147 kAllowHarmonyClasses, kAllowHarmonyObjectLiterals, kAllowHarmonyScoping, | 5331 kAllowHarmonyClasses, kAllowHarmonyObjectLiterals, kAllowHarmonyScoping, |
5148 kAllowStrongMode}; | 5332 kAllowStrongMode}; |
5149 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | 5333 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, |
5150 always_flags, arraysize(always_flags)); | 5334 always_flags, arraysize(always_flags)); |
5151 } | 5335 } |
OLD | NEW |