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

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

Issue 1213813003: [es6] Remove harmony-classes flag (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove empty flags field from json Created 5 years, 5 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
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/js-perf-test/JSTests.json » ('j') | 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 for (int i = 0; (key_token = keywords[i]).keyword != NULL; i++) { 66 for (int i = 0; (key_token = keywords[i]).keyword != NULL; i++) {
67 const i::byte* keyword = 67 const i::byte* keyword =
68 reinterpret_cast<const i::byte*>(key_token.keyword); 68 reinterpret_cast<const i::byte*>(key_token.keyword);
69 int length = i::StrLength(key_token.keyword); 69 int length = i::StrLength(key_token.keyword);
70 CHECK(static_cast<int>(sizeof(buffer)) >= length); 70 CHECK(static_cast<int>(sizeof(buffer)) >= length);
71 { 71 {
72 i::Utf8ToUtf16CharacterStream stream(keyword, length); 72 i::Utf8ToUtf16CharacterStream stream(keyword, length);
73 i::Scanner scanner(&unicode_cache); 73 i::Scanner scanner(&unicode_cache);
74 // The scanner should parse Harmony keywords for this test. 74 // The scanner should parse Harmony keywords for this test.
75 scanner.SetHarmonyModules(true); 75 scanner.SetHarmonyModules(true);
76 scanner.SetHarmonyClasses(true);
77 scanner.Initialize(&stream); 76 scanner.Initialize(&stream);
78 CHECK_EQ(key_token.token, scanner.Next()); 77 CHECK_EQ(key_token.token, scanner.Next());
79 CHECK_EQ(i::Token::EOS, scanner.Next()); 78 CHECK_EQ(i::Token::EOS, scanner.Next());
80 } 79 }
81 // Removing characters will make keyword matching fail. 80 // Removing characters will make keyword matching fail.
82 { 81 {
83 i::Utf8ToUtf16CharacterStream stream(keyword, length - 1); 82 i::Utf8ToUtf16CharacterStream stream(keyword, length - 1);
84 i::Scanner scanner(&unicode_cache); 83 i::Scanner scanner(&unicode_cache);
85 scanner.Initialize(&stream); 84 scanner.Initialize(&stream);
86 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); 85 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next());
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix, 1059 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix,
1061 source_data[i].body, surroundings[j].suffix); 1060 source_data[i].body, surroundings[j].suffix);
1062 i::Handle<i::String> source = 1061 i::Handle<i::String> source =
1063 factory->NewStringFromUtf8(i::CStrVector(program.start())) 1062 factory->NewStringFromUtf8(i::CStrVector(program.start()))
1064 .ToHandleChecked(); 1063 .ToHandleChecked();
1065 i::Handle<i::Script> script = factory->NewScript(source); 1064 i::Handle<i::Script> script = factory->NewScript(source);
1066 i::Zone zone; 1065 i::Zone zone;
1067 i::ParseInfo info(&zone, script); 1066 i::ParseInfo info(&zone, script);
1068 i::Parser parser(&info); 1067 i::Parser parser(&info);
1069 parser.set_allow_harmony_arrow_functions(true); 1068 parser.set_allow_harmony_arrow_functions(true);
1070 parser.set_allow_harmony_classes(true);
1071 parser.set_allow_harmony_sloppy(true); 1069 parser.set_allow_harmony_sloppy(true);
1072 info.set_global(); 1070 info.set_global();
1073 CHECK(parser.Parse(&info)); 1071 CHECK(parser.Parse(&info));
1074 CHECK(i::Rewriter::Rewrite(&info)); 1072 CHECK(i::Rewriter::Rewrite(&info));
1075 CHECK(i::Scope::Analyze(&info)); 1073 CHECK(i::Scope::Analyze(&info));
1076 CHECK(info.function() != NULL); 1074 CHECK(info.function() != NULL);
1077 1075
1078 i::Scope* script_scope = info.function()->scope(); 1076 i::Scope* script_scope = info.function()->scope();
1079 CHECK(script_scope->is_script_scope()); 1077 CHECK(script_scope->is_script_scope());
1080 CHECK_EQ(1, script_scope->inner_scopes()->length()); 1078 CHECK_EQ(1, script_scope->inner_scopes()->length());
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 data.Dispose(); 1369 data.Dispose();
1372 return i::MessageTemplate::FormatMessage(isolate, message, arg_object); 1370 return i::MessageTemplate::FormatMessage(isolate, message, arg_object);
1373 } 1371 }
1374 1372
1375 1373
1376 enum ParserFlag { 1374 enum ParserFlag {
1377 kAllowLazy, 1375 kAllowLazy,
1378 kAllowNatives, 1376 kAllowNatives,
1379 kAllowHarmonyModules, 1377 kAllowHarmonyModules,
1380 kAllowHarmonyArrowFunctions, 1378 kAllowHarmonyArrowFunctions,
1381 kAllowHarmonyClasses,
1382 kAllowHarmonyRestParameters, 1379 kAllowHarmonyRestParameters,
1383 kAllowHarmonySloppy, 1380 kAllowHarmonySloppy,
1384 kAllowHarmonyUnicode, 1381 kAllowHarmonyUnicode,
1385 kAllowHarmonyComputedPropertyNames, 1382 kAllowHarmonyComputedPropertyNames,
1386 kAllowHarmonySpreadCalls, 1383 kAllowHarmonySpreadCalls,
1387 kAllowHarmonyDestructuring, 1384 kAllowHarmonyDestructuring,
1388 kAllowHarmonySpreadArrays, 1385 kAllowHarmonySpreadArrays,
1389 kAllowHarmonyNewTarget, 1386 kAllowHarmonyNewTarget,
1390 kAllowStrongMode 1387 kAllowStrongMode
1391 }; 1388 };
1392 1389
1393 1390
1394 enum ParserSyncTestResult { 1391 enum ParserSyncTestResult {
1395 kSuccessOrError, 1392 kSuccessOrError,
1396 kSuccess, 1393 kSuccess,
1397 kError 1394 kError
1398 }; 1395 };
1399 1396
1400 template <typename Traits> 1397 template <typename Traits>
1401 void SetParserFlags(i::ParserBase<Traits>* parser, 1398 void SetParserFlags(i::ParserBase<Traits>* parser,
1402 i::EnumSet<ParserFlag> flags) { 1399 i::EnumSet<ParserFlag> flags) {
1403 parser->set_allow_lazy(flags.Contains(kAllowLazy)); 1400 parser->set_allow_lazy(flags.Contains(kAllowLazy));
1404 parser->set_allow_natives(flags.Contains(kAllowNatives)); 1401 parser->set_allow_natives(flags.Contains(kAllowNatives));
1405 parser->set_allow_harmony_modules(flags.Contains(kAllowHarmonyModules)); 1402 parser->set_allow_harmony_modules(flags.Contains(kAllowHarmonyModules));
1406 parser->set_allow_harmony_arrow_functions( 1403 parser->set_allow_harmony_arrow_functions(
1407 flags.Contains(kAllowHarmonyArrowFunctions)); 1404 flags.Contains(kAllowHarmonyArrowFunctions));
1408 parser->set_allow_harmony_classes(flags.Contains(kAllowHarmonyClasses));
1409 parser->set_allow_harmony_rest_params( 1405 parser->set_allow_harmony_rest_params(
1410 flags.Contains(kAllowHarmonyRestParameters)); 1406 flags.Contains(kAllowHarmonyRestParameters));
1411 parser->set_allow_harmony_spreadcalls( 1407 parser->set_allow_harmony_spreadcalls(
1412 flags.Contains(kAllowHarmonySpreadCalls)); 1408 flags.Contains(kAllowHarmonySpreadCalls));
1413 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); 1409 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy));
1414 parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode)); 1410 parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode));
1415 parser->set_allow_harmony_computed_property_names( 1411 parser->set_allow_harmony_computed_property_names(
1416 flags.Contains(kAllowHarmonyComputedPropertyNames)); 1412 flags.Contains(kAllowHarmonyComputedPropertyNames));
1417 parser->set_allow_harmony_destructuring( 1413 parser->set_allow_harmony_destructuring(
1418 flags.Contains(kAllowHarmonyDestructuring)); 1414 flags.Contains(kAllowHarmonyDestructuring));
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
1965 1961
1966 const char* statement_data[] = { 1962 const char* statement_data[] = {
1967 FUTURE_STRICT_RESERVED_WORDS(FUTURE_STRICT_RESERVED_STATEMENTS) 1963 FUTURE_STRICT_RESERVED_WORDS(FUTURE_STRICT_RESERVED_STATEMENTS)
1968 NULL 1964 NULL
1969 }; 1965 };
1970 1966
1971 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions}; 1967 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions};
1972 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, 1968 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
1973 always_flags, arraysize(always_flags)); 1969 always_flags, arraysize(always_flags));
1974 1970
1975 static const ParserFlag classes_flags[] = {kAllowHarmonyArrowFunctions, 1971 static const ParserFlag classes_flags[] = {kAllowHarmonyArrowFunctions};
1976 kAllowHarmonyClasses};
1977 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, 1972 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
1978 classes_flags, arraysize(classes_flags)); 1973 classes_flags, arraysize(classes_flags));
1979 } 1974 }
1980 1975
1981 1976
1982 TEST(ErrorsReservedWords) { 1977 TEST(ErrorsReservedWords) {
1983 // Tests that both preparsing and parsing produce the right kind of errors for 1978 // Tests that both preparsing and parsing produce the right kind of errors for
1984 // using future reserved words as identifiers. These tests don't depend on the 1979 // using future reserved words as identifiers. These tests don't depend on the
1985 // strict mode. 1980 // strict mode.
1986 const char* context_data[][2] = { 1981 const char* context_data[][2] = {
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after
2979 const char* statement_data[] = { 2974 const char* statement_data[] = {
2980 "function f() { }", 2975 "function f() { }",
2981 "class C { }", 2976 "class C { }",
2982 "class C extends Q {}", 2977 "class C extends Q {}",
2983 "function f() { } class C {}", 2978 "function f() { } class C {}",
2984 "function f() { }; class C {}", 2979 "function f() { }; class C {}",
2985 "class C {}; function f() {}", 2980 "class C {}; function f() {}",
2986 nullptr 2981 nullptr
2987 }; 2982 };
2988 2983
2989 static const ParserFlag always_flags[] = {kAllowHarmonyClasses}; 2984 RunParserSyncTest(context_data, statement_data, kSuccess);
2990
2991 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
2992 always_flags, arraysize(always_flags));
2993 } 2985 }
2994 2986
2995 2987
2996 TEST(InvalidLeftHandSide) { 2988 TEST(InvalidLeftHandSide) {
2997 const char* assignment_context_data[][2] = { 2989 const char* assignment_context_data[][2] = {
2998 {"", " = 1;"}, 2990 {"", " = 1;"},
2999 {"\"use strict\"; ", " = 1;"}, 2991 {"\"use strict\"; ", " = 1;"},
3000 { NULL, NULL } 2992 { NULL, NULL }
3001 }; 2993 };
3002 2994
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
3714 "new super.x", 3706 "new super.x",
3715 "new super.x()", 3707 "new super.x()",
3716 "new super[27]", 3708 "new super[27]",
3717 "new super[27]()", 3709 "new super[27]()",
3718 "z.super", // Ok, property lookup. 3710 "z.super", // Ok, property lookup.
3719 NULL 3711 NULL
3720 }; 3712 };
3721 3713
3722 static const ParserFlag always_flags[] = { 3714 static const ParserFlag always_flags[] = {
3723 kAllowHarmonyArrowFunctions, 3715 kAllowHarmonyArrowFunctions,
3724 kAllowHarmonyClasses,
3725 kAllowHarmonySloppy 3716 kAllowHarmonySloppy
3726 }; 3717 };
3727 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, 3718 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
3728 always_flags, arraysize(always_flags)); 3719 always_flags, arraysize(always_flags));
3729 } 3720 }
3730 3721
3731 3722
3732 TEST(SuperErrors) { 3723 TEST(SuperErrors) {
3733 const char* context_data[][2] = { 3724 const char* context_data[][2] = {
3734 {"class C { m() { ", "; } }"}, 3725 {"class C { m() { ", "; } }"},
(...skipping 10 matching lines...) Expand all
3745 "f(super)", 3736 "f(super)",
3746 "new super", 3737 "new super",
3747 "new super()", 3738 "new super()",
3748 "new super(12, 45)", 3739 "new super(12, 45)",
3749 "new new super", 3740 "new new super",
3750 "new new super()", 3741 "new new super()",
3751 "new new super()()", 3742 "new new super()()",
3752 NULL 3743 NULL
3753 }; 3744 };
3754 3745
3755 static const ParserFlag always_flags[] = { 3746 static const ParserFlag always_flags[] = {kAllowHarmonySloppy};
3756 kAllowHarmonyClasses,
3757 kAllowHarmonySloppy
3758 };
3759 RunParserSyncTest(context_data, expression_data, kError, NULL, 0, 3747 RunParserSyncTest(context_data, expression_data, kError, NULL, 0,
3760 always_flags, arraysize(always_flags)); 3748 always_flags, arraysize(always_flags));
3761 } 3749 }
3762 3750
3763 3751
3764 TEST(SuperCall) { 3752 TEST(SuperCall) {
3765 const char* context_data[][2] = {{"", ""}, 3753 const char* context_data[][2] = {{"", ""},
3766 {NULL, NULL}}; 3754 {NULL, NULL}};
3767 3755
3768 const char* success_data[] = { 3756 const char* success_data[] = {
3769 "class C extends B { constructor() { super(); } }", 3757 "class C extends B { constructor() { super(); } }",
3770 "class C extends B { constructor() { () => super(); } }", 3758 "class C extends B { constructor() { () => super(); } }",
3771 NULL 3759 NULL
3772 }; 3760 };
3773 3761
3774 static const ParserFlag always_flags[] = { 3762 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions,
3775 kAllowHarmonyArrowFunctions, 3763 kAllowHarmonySloppy};
3776 kAllowHarmonyClasses,
3777 kAllowHarmonySloppy
3778 };
3779 RunParserSyncTest(context_data, success_data, kSuccess, NULL, 0, 3764 RunParserSyncTest(context_data, success_data, kSuccess, NULL, 0,
3780 always_flags, arraysize(always_flags)); 3765 always_flags, arraysize(always_flags));
3781 3766
3782 const char* error_data[] = { 3767 const char* error_data[] = {
3783 "class C { constructor() { super(); } }", 3768 "class C { constructor() { super(); } }",
3784 "class C { method() { super(); } }", 3769 "class C { method() { super(); } }",
3785 "class C { method() { () => super(); } }", 3770 "class C { method() { () => super(); } }",
3786 "class C { *method() { super(); } }", 3771 "class C { *method() { super(); } }",
3787 "class C { get x() { super(); } }", 3772 "class C { get x() { super(); } }",
3788 "class C { set x(_) { super(); } }", 3773 "class C { set x(_) { super(); } }",
(...skipping 29 matching lines...) Expand all
3818 }; 3803 };
3819 3804
3820 const char* expression_data[] = { 3805 const char* expression_data[] = {
3821 "new super.x;", 3806 "new super.x;",
3822 "new super.x();", 3807 "new super.x();",
3823 "() => new super.x;", 3808 "() => new super.x;",
3824 "() => new super.x();", 3809 "() => new super.x();",
3825 NULL 3810 NULL
3826 }; 3811 };
3827 3812
3828 static const ParserFlag always_flags[] = { 3813 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions,
3829 kAllowHarmonyArrowFunctions, 3814 kAllowHarmonySloppy};
3830 kAllowHarmonyClasses,
3831 kAllowHarmonySloppy
3832 };
3833 RunParserSyncTest(context_data, expression_data, kSuccess, NULL, 0, 3815 RunParserSyncTest(context_data, expression_data, kSuccess, NULL, 0,
3834 always_flags, arraysize(always_flags)); 3816 always_flags, arraysize(always_flags));
3835 } 3817 }
3836 3818
3837 3819
3838 TEST(SuperNewErrors) { 3820 TEST(SuperNewErrors) {
3839 const char* context_data[][2] = { 3821 const char* context_data[][2] = {
3840 {"class C { method() { ", " } }"}, 3822 {"class C { method() { ", " } }"},
3841 {"class C { *method() { ", " } }"}, 3823 {"class C { *method() { ", " } }"},
3842 {"class C { get x() { ", " } }"}, 3824 {"class C { get x() { ", " } }"},
(...skipping 12 matching lines...) Expand all
3855 }; 3837 };
3856 3838
3857 const char* statement_data[] = { 3839 const char* statement_data[] = {
3858 "new super;", 3840 "new super;",
3859 "new super();", 3841 "new super();",
3860 "() => new super;", 3842 "() => new super;",
3861 "() => new super();", 3843 "() => new super();",
3862 NULL 3844 NULL
3863 }; 3845 };
3864 3846
3865 static const ParserFlag always_flags[] = { 3847 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions,
3866 kAllowHarmonyArrowFunctions, 3848 kAllowHarmonySloppy};
3867 kAllowHarmonyClasses,
3868 kAllowHarmonySloppy
3869 };
3870 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, 3849 RunParserSyncTest(context_data, statement_data, kError, NULL, 0,
3871 always_flags, arraysize(always_flags)); 3850 always_flags, arraysize(always_flags));
3872 } 3851 }
3873 3852
3874 3853
3875 TEST(SuperErrorsNonMethods) { 3854 TEST(SuperErrorsNonMethods) {
3876 // super is only allowed in methods, accessors and constructors. 3855 // super is only allowed in methods, accessors and constructors.
3877 const char* context_data[][2] = { 3856 const char* context_data[][2] = {
3878 {"", ";"}, 3857 {"", ";"},
3879 {"k = ", ";"}, 3858 {"k = ", ";"},
(...skipping 20 matching lines...) Expand all
3900 "super[27]()", 3879 "super[27]()",
3901 "super()", 3880 "super()",
3902 "new super.x", 3881 "new super.x",
3903 "new super.x()", 3882 "new super.x()",
3904 "new super[27]", 3883 "new super[27]",
3905 "new super[27]()", 3884 "new super[27]()",
3906 NULL 3885 NULL
3907 }; 3886 };
3908 3887
3909 static const ParserFlag always_flags[] = { 3888 static const ParserFlag always_flags[] = {
3910 kAllowHarmonyClasses,
3911 kAllowHarmonySloppy 3889 kAllowHarmonySloppy
3912 }; 3890 };
3913 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, 3891 RunParserSyncTest(context_data, statement_data, kError, NULL, 0,
3914 always_flags, arraysize(always_flags)); 3892 always_flags, arraysize(always_flags));
3915 } 3893 }
3916 3894
3917 3895
3918 TEST(NoErrorsMethodDefinition) { 3896 TEST(NoErrorsMethodDefinition) {
3919 const char* context_data[][2] = {{"({", "});"}, 3897 const char* context_data[][2] = {{"({", "});"},
3920 {"'use strict'; ({", "});"}, 3898 {"'use strict'; ({", "});"},
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
4117 "class extends F {}", 4095 "class extends F {}",
4118 "class name extends F {}", 4096 "class name extends F {}",
4119 "class extends (F, G) {}", 4097 "class extends (F, G) {}",
4120 "class name extends (F, G) {}", 4098 "class name extends (F, G) {}",
4121 "class extends class {} {}", 4099 "class extends class {} {}",
4122 "class name extends class {} {}", 4100 "class name extends class {} {}",
4123 "class extends class base {} {}", 4101 "class extends class base {} {}",
4124 "class name extends class base {} {}", 4102 "class name extends class base {} {}",
4125 NULL}; 4103 NULL};
4126 4104
4127 static const ParserFlag always_flags[] = { 4105 static const ParserFlag always_flags[] = {kAllowHarmonySloppy};
4128 kAllowHarmonyClasses, kAllowHarmonySloppy};
4129 RunParserSyncTest(context_data, class_data, kSuccess, NULL, 0, 4106 RunParserSyncTest(context_data, class_data, kSuccess, NULL, 0,
4130 always_flags, arraysize(always_flags)); 4107 always_flags, arraysize(always_flags));
4131 } 4108 }
4132 4109
4133 4110
4134 TEST(ClassDeclarationNoErrors) { 4111 TEST(ClassDeclarationNoErrors) {
4135 const char* context_data[][2] = {{"'use strict'; ", ""}, 4112 const char* context_data[][2] = {{"'use strict'; ", ""},
4136 {"'use strict'; {", "}"}, 4113 {"'use strict'; {", "}"},
4137 {"'use strict'; if (true) {", "}"}, 4114 {"'use strict'; if (true) {", "}"},
4138 {NULL, NULL}}; 4115 {NULL, NULL}};
4139 const char* statement_data[] = { 4116 const char* statement_data[] = {
4140 "class name {}", 4117 "class name {}",
4141 "class name extends F {}", 4118 "class name extends F {}",
4142 "class name extends (F, G) {}", 4119 "class name extends (F, G) {}",
4143 "class name extends class {} {}", 4120 "class name extends class {} {}",
4144 "class name extends class base {} {}", 4121 "class name extends class base {} {}",
4145 NULL}; 4122 NULL};
4146 4123
4147 static const ParserFlag always_flags[] = {kAllowHarmonyClasses}; 4124 RunParserSyncTest(context_data, statement_data, kSuccess);
4148 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
4149 always_flags, arraysize(always_flags));
4150 } 4125 }
4151 4126
4152 4127
4153 TEST(ClassBodyNoErrors) { 4128 TEST(ClassBodyNoErrors) {
4154 // Tests that parser and preparser accept valid class syntax. 4129 // Tests that parser and preparser accept valid class syntax.
4155 const char* context_data[][2] = {{"(class {", "});"}, 4130 const char* context_data[][2] = {{"(class {", "});"},
4156 {"(class extends Base {", "});"}, 4131 {"(class extends Base {", "});"},
4157 {"class C {", "}"}, 4132 {"class C {", "}"},
4158 {"class C extends Base {", "}"}, 4133 {"class C extends Base {", "}"},
4159 {NULL, NULL}}; 4134 {NULL, NULL}};
(...skipping 21 matching lines...) Expand all
4181 "static static() {}", 4156 "static static() {}",
4182 "static get static() {}", 4157 "static get static() {}",
4183 "static set static(v) {}", 4158 "static set static(v) {}",
4184 "*static() {}", 4159 "*static() {}",
4185 "*get() {}", 4160 "*get() {}",
4186 "*set() {}", 4161 "*set() {}",
4187 "static *g() {}", 4162 "static *g() {}",
4188 NULL}; 4163 NULL};
4189 4164
4190 static const ParserFlag always_flags[] = { 4165 static const ParserFlag always_flags[] = {
4191 kAllowHarmonyClasses,
4192 kAllowHarmonySloppy 4166 kAllowHarmonySloppy
4193 }; 4167 };
4194 RunParserSyncTest(context_data, class_body_data, kSuccess, NULL, 0, 4168 RunParserSyncTest(context_data, class_body_data, kSuccess, NULL, 0,
4195 always_flags, arraysize(always_flags)); 4169 always_flags, arraysize(always_flags));
4196 } 4170 }
4197 4171
4198 4172
4199 TEST(ClassPropertyNameNoErrors) { 4173 TEST(ClassPropertyNameNoErrors) {
4200 const char* context_data[][2] = {{"(class {", "() {}});"}, 4174 const char* context_data[][2] = {{"(class {", "() {}});"},
4201 {"(class { get ", "() {}});"}, 4175 {"(class { get ", "() {}});"},
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
4239 "else", 4213 "else",
4240 "for", 4214 "for",
4241 "while", 4215 "while",
4242 "do", 4216 "do",
4243 "try", 4217 "try",
4244 "catch", 4218 "catch",
4245 "finally", 4219 "finally",
4246 NULL}; 4220 NULL};
4247 4221
4248 static const ParserFlag always_flags[] = { 4222 static const ParserFlag always_flags[] = {
4249 kAllowHarmonyClasses,
4250 kAllowHarmonySloppy 4223 kAllowHarmonySloppy
4251 }; 4224 };
4252 RunParserSyncTest(context_data, name_data, kSuccess, NULL, 0, 4225 RunParserSyncTest(context_data, name_data, kSuccess, NULL, 0,
4253 always_flags, arraysize(always_flags)); 4226 always_flags, arraysize(always_flags));
4254 } 4227 }
4255 4228
4256 4229
4257 TEST(ClassExpressionErrors) { 4230 TEST(ClassExpressionErrors) {
4258 const char* context_data[][2] = {{"(", ");"}, 4231 const char* context_data[][2] = {{"(", ");"},
4259 {"var C = ", ";"}, 4232 {"var C = ", ";"},
(...skipping 10 matching lines...) Expand all
4270 "class { m: 1 }", 4243 "class { m: 1 }",
4271 "class { m(); n() }", 4244 "class { m(); n() }",
4272 "class { get m }", 4245 "class { get m }",
4273 "class { get m() }", 4246 "class { get m() }",
4274 "class { get m() { }", 4247 "class { get m() { }",
4275 "class { set m() {} }", // Missing required parameter. 4248 "class { set m() {} }", // Missing required parameter.
4276 "class { m() {}, n() {} }", // No commas allowed. 4249 "class { m() {}, n() {} }", // No commas allowed.
4277 NULL}; 4250 NULL};
4278 4251
4279 static const ParserFlag always_flags[] = { 4252 static const ParserFlag always_flags[] = {
4280 kAllowHarmonyClasses,
4281 kAllowHarmonySloppy 4253 kAllowHarmonySloppy
4282 }; 4254 };
4283 RunParserSyncTest(context_data, class_data, kError, NULL, 0, 4255 RunParserSyncTest(context_data, class_data, kError, NULL, 0,
4284 always_flags, arraysize(always_flags)); 4256 always_flags, arraysize(always_flags));
4285 } 4257 }
4286 4258
4287 4259
4288 TEST(ClassDeclarationErrors) { 4260 TEST(ClassDeclarationErrors) {
4289 const char* context_data[][2] = {{"", ""}, 4261 const char* context_data[][2] = {{"", ""},
4290 {"{", "}"}, 4262 {"{", "}"},
(...skipping 16 matching lines...) Expand all
4307 "class extends base {}", 4279 "class extends base {}",
4308 "class name { *", 4280 "class name { *",
4309 "class name { * }", 4281 "class name { * }",
4310 "class name { *; }", 4282 "class name { *; }",
4311 "class name { *get x() {} }", 4283 "class name { *get x() {} }",
4312 "class name { *set x(_) {} }", 4284 "class name { *set x(_) {} }",
4313 "class name { *static m() {} }", 4285 "class name { *static m() {} }",
4314 NULL}; 4286 NULL};
4315 4287
4316 static const ParserFlag always_flags[] = { 4288 static const ParserFlag always_flags[] = {
4317 kAllowHarmonyClasses,
4318 kAllowHarmonySloppy 4289 kAllowHarmonySloppy
4319 }; 4290 };
4320 RunParserSyncTest(context_data, class_data, kError, NULL, 0, 4291 RunParserSyncTest(context_data, class_data, kError, NULL, 0,
4321 always_flags, arraysize(always_flags)); 4292 always_flags, arraysize(always_flags));
4322 } 4293 }
4323 4294
4324 4295
4325 TEST(ClassNameErrors) { 4296 TEST(ClassNameErrors) {
4326 const char* context_data[][2] = {{"class ", "{}"}, 4297 const char* context_data[][2] = {{"class ", "{}"},
4327 {"(class ", "{});"}, 4298 {"(class ", "{});"},
4328 {"'use strict'; class ", "{}"}, 4299 {"'use strict'; class ", "{}"},
4329 {"'use strict'; (class ", "{});"}, 4300 {"'use strict'; (class ", "{});"},
4330 {NULL, NULL}}; 4301 {NULL, NULL}};
4331 const char* class_name[] = { 4302 const char* class_name[] = {
4332 "arguments", 4303 "arguments",
4333 "eval", 4304 "eval",
4334 "implements", 4305 "implements",
4335 "interface", 4306 "interface",
4336 "let", 4307 "let",
4337 "package", 4308 "package",
4338 "private", 4309 "private",
4339 "protected", 4310 "protected",
4340 "public", 4311 "public",
4341 "static", 4312 "static",
4342 "var", 4313 "var",
4343 "yield", 4314 "yield",
4344 NULL}; 4315 NULL};
4345 4316
4346 static const ParserFlag always_flags[] = { 4317 static const ParserFlag always_flags[] = {
4347 kAllowHarmonyClasses,
4348 kAllowHarmonySloppy 4318 kAllowHarmonySloppy
4349 }; 4319 };
4350 RunParserSyncTest(context_data, class_name, kError, NULL, 0, 4320 RunParserSyncTest(context_data, class_name, kError, NULL, 0,
4351 always_flags, arraysize(always_flags)); 4321 always_flags, arraysize(always_flags));
4352 } 4322 }
4353 4323
4354 4324
4355 TEST(ClassGetterParamNameErrors) { 4325 TEST(ClassGetterParamNameErrors) {
4356 const char* context_data[][2] = { 4326 const char* context_data[][2] = {
4357 {"class C { get name(", ") {} }"}, 4327 {"class C { get name(", ") {} }"},
(...skipping 12 matching lines...) Expand all
4370 "package", 4340 "package",
4371 "private", 4341 "private",
4372 "protected", 4342 "protected",
4373 "public", 4343 "public",
4374 "static", 4344 "static",
4375 "var", 4345 "var",
4376 "yield", 4346 "yield",
4377 NULL}; 4347 NULL};
4378 4348
4379 static const ParserFlag always_flags[] = { 4349 static const ParserFlag always_flags[] = {
4380 kAllowHarmonyClasses,
4381 kAllowHarmonySloppy 4350 kAllowHarmonySloppy
4382 }; 4351 };
4383 RunParserSyncTest(context_data, class_name, kError, NULL, 0, 4352 RunParserSyncTest(context_data, class_name, kError, NULL, 0,
4384 always_flags, arraysize(always_flags)); 4353 always_flags, arraysize(always_flags));
4385 } 4354 }
4386 4355
4387 4356
4388 TEST(ClassStaticPrototypeErrors) { 4357 TEST(ClassStaticPrototypeErrors) {
4389 const char* context_data[][2] = {{"class C {", "}"}, 4358 const char* context_data[][2] = {{"class C {", "}"},
4390 {"(class {", "});"}, 4359 {"(class {", "});"},
4391 {NULL, NULL}}; 4360 {NULL, NULL}};
4392 4361
4393 const char* class_body_data[] = { 4362 const char* class_body_data[] = {
4394 "static prototype() {}", 4363 "static prototype() {}",
4395 "static get prototype() {}", 4364 "static get prototype() {}",
4396 "static set prototype(_) {}", 4365 "static set prototype(_) {}",
4397 "static *prototype() {}", 4366 "static *prototype() {}",
4398 "static 'prototype'() {}", 4367 "static 'prototype'() {}",
4399 "static *'prototype'() {}", 4368 "static *'prototype'() {}",
4400 "static prot\\u006ftype() {}", 4369 "static prot\\u006ftype() {}",
4401 "static 'prot\\u006ftype'() {}", 4370 "static 'prot\\u006ftype'() {}",
4402 "static get 'prot\\u006ftype'() {}", 4371 "static get 'prot\\u006ftype'() {}",
4403 "static set 'prot\\u006ftype'(_) {}", 4372 "static set 'prot\\u006ftype'(_) {}",
4404 "static *'prot\\u006ftype'() {}", 4373 "static *'prot\\u006ftype'() {}",
4405 NULL}; 4374 NULL};
4406 4375
4407 static const ParserFlag always_flags[] = { 4376 static const ParserFlag always_flags[] = {
4408 kAllowHarmonyClasses,
4409 kAllowHarmonySloppy 4377 kAllowHarmonySloppy
4410 }; 4378 };
4411 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0, 4379 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0,
4412 always_flags, arraysize(always_flags)); 4380 always_flags, arraysize(always_flags));
4413 } 4381 }
4414 4382
4415 4383
4416 TEST(ClassSpecialConstructorErrors) { 4384 TEST(ClassSpecialConstructorErrors) {
4417 const char* context_data[][2] = {{"class C {", "}"}, 4385 const char* context_data[][2] = {{"class C {", "}"},
4418 {"(class {", "});"}, 4386 {"(class {", "});"},
4419 {NULL, NULL}}; 4387 {NULL, NULL}};
4420 4388
4421 const char* class_body_data[] = { 4389 const char* class_body_data[] = {
4422 "get constructor() {}", 4390 "get constructor() {}",
4423 "get constructor(_) {}", 4391 "get constructor(_) {}",
4424 "*constructor() {}", 4392 "*constructor() {}",
4425 "get 'constructor'() {}", 4393 "get 'constructor'() {}",
4426 "*'constructor'() {}", 4394 "*'constructor'() {}",
4427 "get c\\u006fnstructor() {}", 4395 "get c\\u006fnstructor() {}",
4428 "*c\\u006fnstructor() {}", 4396 "*c\\u006fnstructor() {}",
4429 "get 'c\\u006fnstructor'() {}", 4397 "get 'c\\u006fnstructor'() {}",
4430 "get 'c\\u006fnstructor'(_) {}", 4398 "get 'c\\u006fnstructor'(_) {}",
4431 "*'c\\u006fnstructor'() {}", 4399 "*'c\\u006fnstructor'() {}",
4432 NULL}; 4400 NULL};
4433 4401
4434 static const ParserFlag always_flags[] = { 4402 static const ParserFlag always_flags[] = {
4435 kAllowHarmonyClasses,
4436 kAllowHarmonySloppy 4403 kAllowHarmonySloppy
4437 }; 4404 };
4438 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0, 4405 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0,
4439 always_flags, arraysize(always_flags)); 4406 always_flags, arraysize(always_flags));
4440 } 4407 }
4441 4408
4442 4409
4443 TEST(ClassConstructorNoErrors) { 4410 TEST(ClassConstructorNoErrors) {
4444 const char* context_data[][2] = {{"class C {", "}"}, 4411 const char* context_data[][2] = {{"class C {", "}"},
4445 {"(class {", "});"}, 4412 {"(class {", "});"},
4446 {NULL, NULL}}; 4413 {NULL, NULL}};
4447 4414
4448 const char* class_body_data[] = { 4415 const char* class_body_data[] = {
4449 "constructor() {}", 4416 "constructor() {}",
4450 "static constructor() {}", 4417 "static constructor() {}",
4451 "static get constructor() {}", 4418 "static get constructor() {}",
4452 "static set constructor(_) {}", 4419 "static set constructor(_) {}",
4453 "static *constructor() {}", 4420 "static *constructor() {}",
4454 NULL}; 4421 NULL};
4455 4422
4456 static const ParserFlag always_flags[] = { 4423 static const ParserFlag always_flags[] = {
4457 kAllowHarmonyClasses,
4458 kAllowHarmonySloppy 4424 kAllowHarmonySloppy
4459 }; 4425 };
4460 RunParserSyncTest(context_data, class_body_data, kSuccess, NULL, 0, 4426 RunParserSyncTest(context_data, class_body_data, kSuccess, NULL, 0,
4461 always_flags, arraysize(always_flags)); 4427 always_flags, arraysize(always_flags));
4462 } 4428 }
4463 4429
4464 4430
4465 TEST(ClassMultipleConstructorErrors) { 4431 TEST(ClassMultipleConstructorErrors) {
4466 const char* context_data[][2] = {{"class C {", "}"}, 4432 const char* context_data[][2] = {{"class C {", "}"},
4467 {"(class {", "});"}, 4433 {"(class {", "});"},
4468 {NULL, NULL}}; 4434 {NULL, NULL}};
4469 4435
4470 const char* class_body_data[] = { 4436 const char* class_body_data[] = {
4471 "constructor() {}; constructor() {}", 4437 "constructor() {}; constructor() {}",
4472 NULL}; 4438 NULL};
4473 4439
4474 static const ParserFlag always_flags[] = { 4440 static const ParserFlag always_flags[] = {
4475 kAllowHarmonyClasses,
4476 kAllowHarmonySloppy 4441 kAllowHarmonySloppy
4477 }; 4442 };
4478 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0, 4443 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0,
4479 always_flags, arraysize(always_flags)); 4444 always_flags, arraysize(always_flags));
4480 } 4445 }
4481 4446
4482 4447
4483 TEST(ClassMultiplePropertyNamesNoErrors) { 4448 TEST(ClassMultiplePropertyNamesNoErrors) {
4484 const char* context_data[][2] = {{"class C {", "}"}, 4449 const char* context_data[][2] = {{"class C {", "}"},
4485 {"(class {", "});"}, 4450 {"(class {", "});"},
4486 {NULL, NULL}}; 4451 {NULL, NULL}};
4487 4452
4488 const char* class_body_data[] = { 4453 const char* class_body_data[] = {
4489 "constructor() {}; static constructor() {}", 4454 "constructor() {}; static constructor() {}",
4490 "m() {}; static m() {}", 4455 "m() {}; static m() {}",
4491 "m() {}; m() {}", 4456 "m() {}; m() {}",
4492 "static m() {}; static m() {}", 4457 "static m() {}; static m() {}",
4493 "get m() {}; set m(_) {}; get m() {}; set m(_) {};", 4458 "get m() {}; set m(_) {}; get m() {}; set m(_) {};",
4494 NULL}; 4459 NULL};
4495 4460
4496 static const ParserFlag always_flags[] = { 4461 static const ParserFlag always_flags[] = {
4497 kAllowHarmonyClasses,
4498 kAllowHarmonySloppy 4462 kAllowHarmonySloppy
4499 }; 4463 };
4500 RunParserSyncTest(context_data, class_body_data, kSuccess, NULL, 0, 4464 RunParserSyncTest(context_data, class_body_data, kSuccess, NULL, 0,
4501 always_flags, arraysize(always_flags)); 4465 always_flags, arraysize(always_flags));
4502 } 4466 }
4503 4467
4504 4468
4505 TEST(ClassesAreStrictErrors) { 4469 TEST(ClassesAreStrictErrors) {
4506 const char* context_data[][2] = {{"", ""}, 4470 const char* context_data[][2] = {{"", ""},
4507 {"(", ");"}, 4471 {"(", ");"},
4508 {NULL, NULL}}; 4472 {NULL, NULL}};
4509 4473
4510 const char* class_body_data[] = { 4474 const char* class_body_data[] = {
4511 "class C { method() { with ({}) {} } }", 4475 "class C { method() { with ({}) {} } }",
4512 "class C extends function() { with ({}) {} } {}", 4476 "class C extends function() { with ({}) {} } {}",
4513 "class C { *method() { with ({}) {} } }", 4477 "class C { *method() { with ({}) {} } }",
4514 NULL}; 4478 NULL};
4515 4479
4516 static const ParserFlag always_flags[] = { 4480 static const ParserFlag always_flags[] = {
4517 kAllowHarmonyClasses,
4518 kAllowHarmonySloppy 4481 kAllowHarmonySloppy
4519 }; 4482 };
4520 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0, 4483 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0,
4521 always_flags, arraysize(always_flags)); 4484 always_flags, arraysize(always_flags));
4522 } 4485 }
4523 4486
4524 4487
4525 TEST(ObjectLiteralPropertyShorthandKeywordsError) { 4488 TEST(ObjectLiteralPropertyShorthandKeywordsError) {
4526 const char* context_data[][2] = {{"({", "});"}, 4489 const char* context_data[][2] = {{"({", "});"},
4527 {"'use strict'; ({", "});"}, 4490 {"'use strict'; ({", "});"},
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
5093 const char* context_data[][2] = { 5056 const char* context_data[][2] = {
5094 {"'use strict';({ set prop(", ") {} }).prop = 1;"}, 5057 {"'use strict';({ set prop(", ") {} }).prop = 1;"},
5095 {"'use strict';(class { static set prop(", ") {} }).prop = 1;"}, 5058 {"'use strict';(class { static set prop(", ") {} }).prop = 1;"},
5096 {"'use strict';(new (class { set prop(", ") {} })).prop = 1;"}, 5059 {"'use strict';(new (class { set prop(", ") {} })).prop = 1;"},
5097 {"({ set prop(", ") {} }).prop = 1;"}, 5060 {"({ set prop(", ") {} }).prop = 1;"},
5098 {"(class { static set prop(", ") {} }).prop = 1;"}, 5061 {"(class { static set prop(", ") {} }).prop = 1;"},
5099 {"(new (class { set prop(", ") {} })).prop = 1;"}, 5062 {"(new (class { set prop(", ") {} })).prop = 1;"},
5100 {nullptr, nullptr}}; 5063 {nullptr, nullptr}};
5101 const char* data[] = {"...a", "...arguments", "...eval", nullptr}; 5064 const char* data[] = {"...a", "...arguments", "...eval", nullptr};
5102 5065
5103 static const ParserFlag always_flags[] = { 5066 static const ParserFlag always_flags[] = {kAllowHarmonyRestParameters,
5104 kAllowHarmonyRestParameters, kAllowHarmonyClasses, kAllowHarmonySloppy}; 5067 kAllowHarmonySloppy};
5105 RunParserSyncTest(context_data, data, kError, nullptr, 0, always_flags, 5068 RunParserSyncTest(context_data, data, kError, nullptr, 0, always_flags,
5106 arraysize(always_flags)); 5069 arraysize(always_flags));
5107 } 5070 }
5108 5071
5109 5072
5110 TEST(RestParametersEvalArguments) { 5073 TEST(RestParametersEvalArguments) {
5111 const char* strict_context_data[][2] = 5074 const char* strict_context_data[][2] =
5112 {{"'use strict';(function(", 5075 {{"'use strict';(function(",
5113 "){ return;})(1, [], /regexp/, 'str',function(){});"}, 5076 "){ return;})(1, [], /regexp/, 'str',function(){});"},
5114 {NULL, NULL}}; 5077 {NULL, NULL}};
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
5217 "for(let x = 1;;){}", 5180 "for(let x = 1;;){}",
5218 "for(let x of []){}", 5181 "for(let x of []){}",
5219 "for(let x in []){}", 5182 "for(let x in []){}",
5220 "class C {}", 5183 "class C {}",
5221 "class C extends D {}", 5184 "class C extends D {}",
5222 "(class {})", 5185 "(class {})",
5223 "(class extends D {})", 5186 "(class extends D {})",
5224 "(class C {})", 5187 "(class C {})",
5225 "(class C extends D {})", 5188 "(class C extends D {})",
5226 NULL}; 5189 NULL};
5227 static const ParserFlag always_true_flags[] = {kAllowHarmonyClasses};
5228 static const ParserFlag always_false_flags[] = {kAllowHarmonySloppy}; 5190 static const ParserFlag always_false_flags[] = {kAllowHarmonySloppy};
5229 RunParserSyncTest(context_data, bad_data, kError, NULL, 0, 5191 RunParserSyncTest(context_data, bad_data, kError, NULL, 0, NULL, 0,
5230 always_true_flags, arraysize(always_true_flags),
5231 always_false_flags, arraysize(always_false_flags)); 5192 always_false_flags, arraysize(always_false_flags));
5232 5193
5233 const char* good_data[] = { 5194 const char* good_data[] = {
5234 "let = 1;", 5195 "let = 1;",
5235 "for(let = 1;;){}", 5196 "for(let = 1;;){}",
5236 NULL}; 5197 NULL};
5237 RunParserSyncTest(context_data, good_data, kSuccess, NULL, 0, 5198 RunParserSyncTest(context_data, good_data, kSuccess, NULL, 0, NULL, 0,
5238 always_true_flags, arraysize(always_true_flags),
5239 always_false_flags, arraysize(always_false_flags)); 5199 always_false_flags, arraysize(always_false_flags));
5240 } 5200 }
5241 5201
5242 5202
5243 TEST(ComputedPropertyName) { 5203 TEST(ComputedPropertyName) {
5244 const char* context_data[][2] = {{"({[", "]: 1});"}, 5204 const char* context_data[][2] = {{"({[", "]: 1});"},
5245 {"({get [", "]() {}});"}, 5205 {"({get [", "]() {}});"},
5246 {"({set [", "](_) {}});"}, 5206 {"({set [", "](_) {}});"},
5247 {"({[", "]() {}});"}, 5207 {"({[", "]() {}});"},
5248 {"({*[", "]() {}});"}, 5208 {"({*[", "]() {}});"},
5249 {"(class {get [", "]() {}});"}, 5209 {"(class {get [", "]() {}});"},
5250 {"(class {set [", "](_) {}});"}, 5210 {"(class {set [", "](_) {}});"},
5251 {"(class {[", "]() {}});"}, 5211 {"(class {[", "]() {}});"},
5252 {"(class {*[", "]() {}});"}, 5212 {"(class {*[", "]() {}});"},
5253 {NULL, NULL}}; 5213 {NULL, NULL}};
5254 const char* error_data[] = { 5214 const char* error_data[] = {
5255 "1, 2", 5215 "1, 2",
5256 "var name", 5216 "var name",
5257 NULL}; 5217 NULL};
5258 5218
5259 static const ParserFlag always_flags[] = { 5219 static const ParserFlag always_flags[] = {
5260 kAllowHarmonyClasses,
5261 kAllowHarmonyComputedPropertyNames, 5220 kAllowHarmonyComputedPropertyNames,
5262 kAllowHarmonySloppy, 5221 kAllowHarmonySloppy,
5263 }; 5222 };
5264 RunParserSyncTest(context_data, error_data, kError, NULL, 0, 5223 RunParserSyncTest(context_data, error_data, kError, NULL, 0,
5265 always_flags, arraysize(always_flags)); 5224 always_flags, arraysize(always_flags));
5266 5225
5267 const char* name_data[] = { 5226 const char* name_data[] = {
5268 "1", 5227 "1",
5269 "1 + 2", 5228 "1 + 2",
5270 "'name'", 5229 "'name'",
5271 "\"name\"", 5230 "\"name\"",
5272 "[]", 5231 "[]",
5273 "{}", 5232 "{}",
5274 NULL}; 5233 NULL};
5275 5234
5276 RunParserSyncTest(context_data, name_data, kSuccess, NULL, 0, 5235 RunParserSyncTest(context_data, name_data, kSuccess, NULL, 0,
5277 always_flags, arraysize(always_flags)); 5236 always_flags, arraysize(always_flags));
5278 } 5237 }
5279 5238
5280 5239
5281 TEST(ComputedPropertyNameShorthandError) { 5240 TEST(ComputedPropertyNameShorthandError) {
5282 const char* context_data[][2] = {{"({", "});"}, 5241 const char* context_data[][2] = {{"({", "});"},
5283 {NULL, NULL}}; 5242 {NULL, NULL}};
5284 const char* error_data[] = { 5243 const char* error_data[] = {
5285 "a: 1, [2]", 5244 "a: 1, [2]",
5286 "[1], a: 1", 5245 "[1], a: 1",
5287 NULL}; 5246 NULL};
5288 5247
5289 static const ParserFlag always_flags[] = { 5248 static const ParserFlag always_flags[] = {
5290 kAllowHarmonyClasses,
5291 kAllowHarmonyComputedPropertyNames, 5249 kAllowHarmonyComputedPropertyNames,
5292 kAllowHarmonySloppy, 5250 kAllowHarmonySloppy,
5293 }; 5251 };
5294 RunParserSyncTest(context_data, error_data, kError, NULL, 0, 5252 RunParserSyncTest(context_data, error_data, kError, NULL, 0,
5295 always_flags, arraysize(always_flags)); 5253 always_flags, arraysize(always_flags));
5296 } 5254 }
5297 5255
5298 5256
5299 TEST(BasicImportExportParsing) { 5257 TEST(BasicImportExportParsing) {
5300 const char* kSources[] = { 5258 const char* kSources[] = {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
5349 for (unsigned i = 0; i < arraysize(kSources); ++i) { 5307 for (unsigned i = 0; i < arraysize(kSources); ++i) {
5350 i::Handle<i::String> source = 5308 i::Handle<i::String> source =
5351 factory->NewStringFromAsciiChecked(kSources[i]); 5309 factory->NewStringFromAsciiChecked(kSources[i]);
5352 5310
5353 // Show that parsing as a module works 5311 // Show that parsing as a module works
5354 { 5312 {
5355 i::Handle<i::Script> script = factory->NewScript(source); 5313 i::Handle<i::Script> script = factory->NewScript(source);
5356 i::Zone zone; 5314 i::Zone zone;
5357 i::ParseInfo info(&zone, script); 5315 i::ParseInfo info(&zone, script);
5358 i::Parser parser(&info); 5316 i::Parser parser(&info);
5359 parser.set_allow_harmony_classes(true);
5360 parser.set_allow_harmony_modules(true); 5317 parser.set_allow_harmony_modules(true);
5361 info.set_module(); 5318 info.set_module();
5362 if (!parser.Parse(&info)) { 5319 if (!parser.Parse(&info)) {
5363 i::Handle<i::JSObject> exception_handle( 5320 i::Handle<i::JSObject> exception_handle(
5364 i::JSObject::cast(isolate->pending_exception())); 5321 i::JSObject::cast(isolate->pending_exception()));
5365 i::Handle<i::String> message_string = 5322 i::Handle<i::String> message_string =
5366 i::Handle<i::String>::cast(i::Object::GetProperty( 5323 i::Handle<i::String>::cast(i::Object::GetProperty(
5367 isolate, exception_handle, "message").ToHandleChecked()); 5324 isolate, exception_handle, "message").ToHandleChecked());
5368 5325
5369 v8::base::OS::Print( 5326 v8::base::OS::Print(
5370 "Parser failed on:\n" 5327 "Parser failed on:\n"
5371 "\t%s\n" 5328 "\t%s\n"
5372 "with error:\n" 5329 "with error:\n"
5373 "\t%s\n" 5330 "\t%s\n"
5374 "However, we expected no error.", 5331 "However, we expected no error.",
5375 source->ToCString().get(), message_string->ToCString().get()); 5332 source->ToCString().get(), message_string->ToCString().get());
5376 CHECK(false); 5333 CHECK(false);
5377 } 5334 }
5378 } 5335 }
5379 5336
5380 // And that parsing a script does not. 5337 // And that parsing a script does not.
5381 { 5338 {
5382 i::Handle<i::Script> script = factory->NewScript(source); 5339 i::Handle<i::Script> script = factory->NewScript(source);
5383 i::Zone zone; 5340 i::Zone zone;
5384 i::ParseInfo info(&zone, script); 5341 i::ParseInfo info(&zone, script);
5385 i::Parser parser(&info); 5342 i::Parser parser(&info);
5386 parser.set_allow_harmony_classes(true);
5387 parser.set_allow_harmony_modules(true); 5343 parser.set_allow_harmony_modules(true);
5388 info.set_global(); 5344 info.set_global();
5389 CHECK(!parser.Parse(&info)); 5345 CHECK(!parser.Parse(&info));
5390 } 5346 }
5391 } 5347 }
5392 } 5348 }
5393 5349
5394 5350
5395 TEST(ImportExportParsingErrors) { 5351 TEST(ImportExportParsingErrors) {
5396 const char* kErrorSources[] = { 5352 const char* kErrorSources[] = {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
5466 128 * 1024); 5422 128 * 1024);
5467 5423
5468 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { 5424 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) {
5469 i::Handle<i::String> source = 5425 i::Handle<i::String> source =
5470 factory->NewStringFromAsciiChecked(kErrorSources[i]); 5426 factory->NewStringFromAsciiChecked(kErrorSources[i]);
5471 5427
5472 i::Handle<i::Script> script = factory->NewScript(source); 5428 i::Handle<i::Script> script = factory->NewScript(source);
5473 i::Zone zone; 5429 i::Zone zone;
5474 i::ParseInfo info(&zone, script); 5430 i::ParseInfo info(&zone, script);
5475 i::Parser parser(&info); 5431 i::Parser parser(&info);
5476 parser.set_allow_harmony_classes(true);
5477 parser.set_allow_harmony_modules(true); 5432 parser.set_allow_harmony_modules(true);
5478 info.set_module(); 5433 info.set_module();
5479 CHECK(!parser.Parse(&info)); 5434 CHECK(!parser.Parse(&info));
5480 } 5435 }
5481 } 5436 }
5482 5437
5483 5438
5484 TEST(ModuleParsingInternals) { 5439 TEST(ModuleParsingInternals) {
5485 i::FLAG_harmony_modules = true; 5440 i::FLAG_harmony_modules = true;
5486 5441
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
5606 {"'use strong'; for (x in y)", ""}, 5561 {"'use strong'; for (x in y)", ""},
5607 {"'use strong'; do ", " while (false)"}, 5562 {"'use strong'; do ", " while (false)"},
5608 {NULL, NULL}}; 5563 {NULL, NULL}};
5609 5564
5610 const char* statement_data[] = { 5565 const char* statement_data[] = {
5611 "let x = 1;", 5566 "let x = 1;",
5612 "const x = 1;", 5567 "const x = 1;",
5613 "class C {}", 5568 "class C {}",
5614 NULL}; 5569 NULL};
5615 5570
5616 static const ParserFlag always_flags[] = {kAllowHarmonyClasses, 5571 static const ParserFlag always_flags[] = {kAllowStrongMode};
5617 kAllowStrongMode};
5618 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, 5572 RunParserSyncTest(context_data, statement_data, kError, NULL, 0,
5619 always_flags, arraysize(always_flags)); 5573 always_flags, arraysize(always_flags));
5620 } 5574 }
5621 5575
5622 5576
5623 void TestLanguageMode(const char* source, 5577 void TestLanguageMode(const char* source,
5624 i::LanguageMode expected_language_mode) { 5578 i::LanguageMode expected_language_mode) {
5625 i::Isolate* isolate = CcTest::i_isolate(); 5579 i::Isolate* isolate = CcTest::i_isolate();
5626 i::Factory* factory = isolate->factory(); 5580 i::Factory* factory = isolate->factory();
5627 v8::HandleScope handles(CcTest::isolate()); 5581 v8::HandleScope handles(CcTest::isolate());
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
5691 "class C {static arguments() {}}", 5645 "class C {static arguments() {}}",
5692 "class C {static *eval() {}}", 5646 "class C {static *eval() {}}",
5693 "class C {static *arguments() {}}", 5647 "class C {static *arguments() {}}",
5694 "class C {static get eval() {}}", 5648 "class C {static get eval() {}}",
5695 "class C {static get arguments() {}}", 5649 "class C {static get arguments() {}}",
5696 "class C {static set eval(_) {}}", 5650 "class C {static set eval(_) {}}",
5697 "class C {static set arguments(_) {}}", 5651 "class C {static set arguments(_) {}}",
5698 5652
5699 NULL}; 5653 NULL};
5700 5654
5701 static const ParserFlag always_flags[] = {kAllowHarmonyClasses, 5655 static const ParserFlag always_flags[] = {kAllowStrongMode};
5702 kAllowStrongMode};
5703 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, 5656 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
5704 always_flags, arraysize(always_flags)); 5657 always_flags, arraysize(always_flags));
5705 } 5658 }
5706 5659
5707 5660
5708 TEST(FunctionLiteralDuplicateParameters) { 5661 TEST(FunctionLiteralDuplicateParameters) {
5709 const char* strict_context_data[][2] = 5662 const char* strict_context_data[][2] =
5710 {{"'use strict';(function(", "){})();"}, 5663 {{"'use strict';(function(", "){})();"},
5711 {"(function(", ") { 'use strict'; })();"}, 5664 {"(function(", ") { 'use strict'; })();"},
5712 {"'use strict'; function fn(", ") {}; fn();"}, 5665 {"'use strict'; function fn(", ") {}; fn();"},
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
5876 "class C { constructor() { this.a = {b: 1}; this.a.b } }", 5829 "class C { constructor() { this.a = {b: 1}; this.a.b } }",
5877 "class C { constructor() { this.a = {b: 1}; this.a.b = 0 } }", 5830 "class C { constructor() { this.a = {b: 1}; this.a.b = 0 } }",
5878 "class C { constructor() { this.a = function(){}; this.a() } }", 5831 "class C { constructor() { this.a = function(){}; this.a() } }",
5879 NULL}; 5832 NULL};
5880 5833
5881 const char* success_data[] = { 5834 const char* success_data[] = {
5882 "class C { constructor() { this.a = 0; } }", 5835 "class C { constructor() { this.a = 0; } }",
5883 "class C { constructor() { label: 0; this.a = 0; this.b = 6; } }", 5836 "class C { constructor() { label: 0; this.a = 0; this.b = 6; } }",
5884 NULL}; 5837 NULL};
5885 5838
5886 static const ParserFlag always_flags[] = { 5839 static const ParserFlag always_flags[] = {kAllowStrongMode,
5887 kAllowStrongMode, kAllowHarmonyClasses, kAllowHarmonyArrowFunctions}; 5840 kAllowHarmonyArrowFunctions};
5888 RunParserSyncTest(sloppy_context_data, error_data, kError, NULL, 0, 5841 RunParserSyncTest(sloppy_context_data, error_data, kError, NULL, 0,
5889 always_flags, arraysize(always_flags)); 5842 always_flags, arraysize(always_flags));
5890 RunParserSyncTest(strict_context_data, error_data, kSuccess, NULL, 0, 5843 RunParserSyncTest(strict_context_data, error_data, kSuccess, NULL, 0,
5891 always_flags, arraysize(always_flags)); 5844 always_flags, arraysize(always_flags));
5892 RunParserSyncTest(strong_context_data, error_data, kError, NULL, 0, 5845 RunParserSyncTest(strong_context_data, error_data, kError, NULL, 0,
5893 always_flags, arraysize(always_flags)); 5846 always_flags, arraysize(always_flags));
5894 5847
5895 RunParserSyncTest(sloppy_context_data, success_data, kError, NULL, 0, 5848 RunParserSyncTest(sloppy_context_data, success_data, kError, NULL, 0,
5896 always_flags, arraysize(always_flags)); 5849 always_flags, arraysize(always_flags));
5897 RunParserSyncTest(strict_context_data, success_data, kSuccess, NULL, 0, 5850 RunParserSyncTest(strict_context_data, success_data, kSuccess, NULL, 0,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
5930 "class C extends Object { constructor() { super().a; } }", 5883 "class C extends Object { constructor() { super().a; } }",
5931 NULL}; 5884 NULL};
5932 5885
5933 const char* success_data[] = { 5886 const char* success_data[] = {
5934 "class C extends Object { constructor() { super(); } }", 5887 "class C extends Object { constructor() { super(); } }",
5935 "class C extends Object { constructor() { label: 66; super(); } }", 5888 "class C extends Object { constructor() { label: 66; super(); } }",
5936 "class C extends Object { constructor() { super(3); this.x = 0; } }", 5889 "class C extends Object { constructor() { super(3); this.x = 0; } }",
5937 "class C extends Object { constructor() { 3; super(3); this.x = 0; } }", 5890 "class C extends Object { constructor() { 3; super(3); this.x = 0; } }",
5938 NULL}; 5891 NULL};
5939 5892
5940 static const ParserFlag always_flags[] = { 5893 static const ParserFlag always_flags[] = {kAllowStrongMode,
5941 kAllowStrongMode, kAllowHarmonyClasses, kAllowHarmonyArrowFunctions}; 5894 kAllowHarmonyArrowFunctions};
5942 RunParserSyncTest(sloppy_context_data, error_data, kError, NULL, 0, 5895 RunParserSyncTest(sloppy_context_data, error_data, kError, NULL, 0,
5943 always_flags, arraysize(always_flags)); 5896 always_flags, arraysize(always_flags));
5944 RunParserSyncTest(strict_context_data, error_data, kSuccess, NULL, 0, 5897 RunParserSyncTest(strict_context_data, error_data, kSuccess, NULL, 0,
5945 always_flags, arraysize(always_flags)); 5898 always_flags, arraysize(always_flags));
5946 RunParserSyncTest(strong_context_data, error_data, kError, NULL, 0, 5899 RunParserSyncTest(strong_context_data, error_data, kError, NULL, 0,
5947 always_flags, arraysize(always_flags)); 5900 always_flags, arraysize(always_flags));
5948 5901
5949 RunParserSyncTest(sloppy_context_data, success_data, kError, NULL, 0, 5902 RunParserSyncTest(sloppy_context_data, success_data, kError, NULL, 0,
5950 always_flags, arraysize(always_flags)); 5903 always_flags, arraysize(always_flags));
5951 RunParserSyncTest(strict_context_data, success_data, kSuccess, NULL, 0, 5904 RunParserSyncTest(strict_context_data, success_data, kSuccess, NULL, 0,
(...skipping 24 matching lines...) Expand all
5976 const char* success_data[] = { 5929 const char* success_data[] = {
5977 "class C extends Object { constructor() { super(); return; } }", 5930 "class C extends Object { constructor() { super(); return; } }",
5978 "class C extends Object { constructor() { super(); { return } } }", 5931 "class C extends Object { constructor() { super(); { return } } }",
5979 "class C extends Object { constructor() { super(); if (1) return; } }", 5932 "class C extends Object { constructor() { super(); if (1) return; } }",
5980 "class C { constructor() { this.a = 0; return; } }", 5933 "class C { constructor() { this.a = 0; return; } }",
5981 "class C { constructor() { this.a = 0; { return; } } }", 5934 "class C { constructor() { this.a = 0; { return; } } }",
5982 "class C { constructor() { this.a = 0; if (0) return; 65; } }", 5935 "class C { constructor() { this.a = 0; if (0) return; 65; } }",
5983 "class C extends Array { constructor() { super(); this.a = 9; return } }", 5936 "class C extends Array { constructor() { super(); this.a = 9; return } }",
5984 NULL}; 5937 NULL};
5985 5938
5986 static const ParserFlag always_flags[] = {kAllowStrongMode, 5939 static const ParserFlag always_flags[] = {kAllowStrongMode};
5987 kAllowHarmonyClasses};
5988 RunParserSyncTest(sloppy_context_data, error_data, kError, NULL, 0, 5940 RunParserSyncTest(sloppy_context_data, error_data, kError, NULL, 0,
5989 always_flags, arraysize(always_flags)); 5941 always_flags, arraysize(always_flags));
5990 RunParserSyncTest(strict_context_data, error_data, kSuccess, NULL, 0, 5942 RunParserSyncTest(strict_context_data, error_data, kSuccess, NULL, 0,
5991 always_flags, arraysize(always_flags)); 5943 always_flags, arraysize(always_flags));
5992 RunParserSyncTest(strong_context_data, error_data, kError, NULL, 0, 5944 RunParserSyncTest(strong_context_data, error_data, kError, NULL, 0,
5993 always_flags, arraysize(always_flags)); 5945 always_flags, arraysize(always_flags));
5994 5946
5995 RunParserSyncTest(sloppy_context_data, success_data, kError, NULL, 0, 5947 RunParserSyncTest(sloppy_context_data, success_data, kError, NULL, 0,
5996 always_flags, arraysize(always_flags)); 5948 always_flags, arraysize(always_flags));
5997 RunParserSyncTest(strict_context_data, success_data, kSuccess, NULL, 0, 5949 RunParserSyncTest(strict_context_data, success_data, kSuccess, NULL, 0,
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
6741 "() => new.target", 6693 "() => new.target",
6742 "if (1) { new.target }", 6694 "if (1) { new.target }",
6743 "if (1) {} else { new.target }", 6695 "if (1) {} else { new.target }",
6744 "while (0) { new.target }", 6696 "while (0) { new.target }",
6745 "do { new.target } while (0)", 6697 "do { new.target } while (0)",
6746 NULL 6698 NULL
6747 }; 6699 };
6748 6700
6749 static const ParserFlag always_flags[] = { 6701 static const ParserFlag always_flags[] = {
6750 kAllowHarmonyArrowFunctions, 6702 kAllowHarmonyArrowFunctions,
6751 kAllowHarmonyClasses,
6752 kAllowHarmonyNewTarget, 6703 kAllowHarmonyNewTarget,
6753 kAllowHarmonySloppy, 6704 kAllowHarmonySloppy,
6754 }; 6705 };
6755 // clang-format on 6706 // clang-format on
6756 6707
6757 RunParserSyncTest(good_context_data, data, kSuccess, NULL, 0, always_flags, 6708 RunParserSyncTest(good_context_data, data, kSuccess, NULL, 0, always_flags,
6758 arraysize(always_flags)); 6709 arraysize(always_flags));
6759 RunParserSyncTest(bad_context_data, data, kError, NULL, 0, always_flags, 6710 RunParserSyncTest(bad_context_data, data, kError, NULL, 0, always_flags,
6760 arraysize(always_flags)); 6711 arraysize(always_flags));
6761 } 6712 }
OLDNEW
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/js-perf-test/JSTests.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698