| 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 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1063 i::ScopedVector<char> program(kProgramByteSize + 1); | 1063 i::ScopedVector<char> program(kProgramByteSize + 1); |
| 1064 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix, | 1064 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix, |
| 1065 source_data[i].body, surroundings[j].suffix); | 1065 source_data[i].body, surroundings[j].suffix); |
| 1066 i::Handle<i::String> source = | 1066 i::Handle<i::String> source = |
| 1067 factory->NewStringFromUtf8(i::CStrVector(program.start())) | 1067 factory->NewStringFromUtf8(i::CStrVector(program.start())) |
| 1068 .ToHandleChecked(); | 1068 .ToHandleChecked(); |
| 1069 i::Handle<i::Script> script = factory->NewScript(source); | 1069 i::Handle<i::Script> script = factory->NewScript(source); |
| 1070 i::Zone zone(CcTest::i_isolate()->allocator()); | 1070 i::Zone zone(CcTest::i_isolate()->allocator()); |
| 1071 i::ParseInfo info(&zone, script); | 1071 i::ParseInfo info(&zone, script); |
| 1072 i::Parser parser(&info); | 1072 i::Parser parser(&info); |
| 1073 parser.set_allow_harmony_sloppy(true); | |
| 1074 info.set_global(); | 1073 info.set_global(); |
| 1075 CHECK(parser.Parse(&info)); | 1074 CHECK(parser.Parse(&info)); |
| 1076 CHECK(i::Rewriter::Rewrite(&info)); | 1075 CHECK(i::Rewriter::Rewrite(&info)); |
| 1077 CHECK(i::Scope::Analyze(&info)); | 1076 CHECK(i::Scope::Analyze(&info)); |
| 1078 CHECK(info.literal() != NULL); | 1077 CHECK(info.literal() != NULL); |
| 1079 | 1078 |
| 1080 i::Scope* script_scope = info.literal()->scope(); | 1079 i::Scope* script_scope = info.literal()->scope(); |
| 1081 CHECK(script_scope->is_script_scope()); | 1080 CHECK(script_scope->is_script_scope()); |
| 1082 CHECK_EQ(1, script_scope->inner_scopes()->length()); | 1081 CHECK_EQ(1, script_scope->inner_scopes()->length()); |
| 1083 | 1082 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1115 full_source += "; }"; | 1114 full_source += "; }"; |
| 1116 | 1115 |
| 1117 i::Handle<i::String> source_code = | 1116 i::Handle<i::String> source_code = |
| 1118 factory->NewStringFromUtf8(i::CStrVector(full_source.c_str())) | 1117 factory->NewStringFromUtf8(i::CStrVector(full_source.c_str())) |
| 1119 .ToHandleChecked(); | 1118 .ToHandleChecked(); |
| 1120 | 1119 |
| 1121 i::Handle<i::Script> script = factory->NewScript(source_code); | 1120 i::Handle<i::Script> script = factory->NewScript(source_code); |
| 1122 | 1121 |
| 1123 i::ParseInfo info(handles.main_zone(), script); | 1122 i::ParseInfo info(handles.main_zone(), script); |
| 1124 i::Parser parser(&info); | 1123 i::Parser parser(&info); |
| 1125 parser.set_allow_harmony_sloppy(true); | |
| 1126 info.set_global(); | 1124 info.set_global(); |
| 1127 info.set_lazy(false); | 1125 info.set_lazy(false); |
| 1128 info.set_allow_lazy_parsing(false); | 1126 info.set_allow_lazy_parsing(false); |
| 1129 info.set_toplevel(true); | 1127 info.set_toplevel(true); |
| 1130 | 1128 |
| 1131 i::CompilationInfo compilation_info(&info); | 1129 i::CompilationInfo compilation_info(&info); |
| 1132 CHECK(i::Compiler::ParseAndAnalyze(&info)); | 1130 CHECK(i::Compiler::ParseAndAnalyze(&info)); |
| 1133 | 1131 |
| 1134 CHECK(info.scope()->declarations()->length() == 1); | 1132 CHECK(info.scope()->declarations()->length() == 1); |
| 1135 i::FunctionLiteral* fun = | 1133 i::FunctionLiteral* fun = |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1431 | 1429 |
| 1432 for (int i = 0; discard_sources[i]; i++) { | 1430 for (int i = 0; discard_sources[i]; i++) { |
| 1433 const char* source = discard_sources[i]; | 1431 const char* source = discard_sources[i]; |
| 1434 i::Handle<i::String> source_code = | 1432 i::Handle<i::String> source_code = |
| 1435 factory->NewStringFromUtf8(i::CStrVector(source)).ToHandleChecked(); | 1433 factory->NewStringFromUtf8(i::CStrVector(source)).ToHandleChecked(); |
| 1436 i::Handle<i::Script> script = factory->NewScript(source_code); | 1434 i::Handle<i::Script> script = factory->NewScript(source_code); |
| 1437 i::Zone zone(CcTest::i_isolate()->allocator()); | 1435 i::Zone zone(CcTest::i_isolate()->allocator()); |
| 1438 i::ParseInfo info(&zone, script); | 1436 i::ParseInfo info(&zone, script); |
| 1439 info.set_allow_lazy_parsing(); | 1437 info.set_allow_lazy_parsing(); |
| 1440 i::Parser parser(&info); | 1438 i::Parser parser(&info); |
| 1441 parser.set_allow_harmony_sloppy(true); | |
| 1442 parser.Parse(&info); | 1439 parser.Parse(&info); |
| 1443 function = info.literal(); | 1440 function = info.literal(); |
| 1444 CHECK_NOT_NULL(function); | 1441 CHECK_NOT_NULL(function); |
| 1445 CHECK_NOT_NULL(function->body()); | 1442 CHECK_NOT_NULL(function->body()); |
| 1446 CHECK_EQ(1, function->body()->length()); | 1443 CHECK_EQ(1, function->body()->length()); |
| 1447 i::FunctionLiteral* inner = | 1444 i::FunctionLiteral* inner = |
| 1448 function->body()->first()->AsExpressionStatement()->expression()-> | 1445 function->body()->first()->AsExpressionStatement()->expression()-> |
| 1449 AsCall()->expression()->AsFunctionLiteral(); | 1446 AsCall()->expression()->AsFunctionLiteral(); |
| 1450 i::Scope* inner_scope = inner->scope(); | 1447 i::Scope* inner_scope = inner->scope(); |
| 1451 i::FunctionLiteral* fun = nullptr; | 1448 i::FunctionLiteral* fun = nullptr; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1502 arg_object = isolate->factory()->undefined_value(); | 1499 arg_object = isolate->factory()->undefined_value(); |
| 1503 } | 1500 } |
| 1504 | 1501 |
| 1505 data.Dispose(); | 1502 data.Dispose(); |
| 1506 return i::MessageTemplate::FormatMessage(isolate, message, arg_object); | 1503 return i::MessageTemplate::FormatMessage(isolate, message, arg_object); |
| 1507 } | 1504 } |
| 1508 | 1505 |
| 1509 enum ParserFlag { | 1506 enum ParserFlag { |
| 1510 kAllowLazy, | 1507 kAllowLazy, |
| 1511 kAllowNatives, | 1508 kAllowNatives, |
| 1512 kAllowHarmonySloppy, | |
| 1513 kAllowHarmonySloppyLet, | |
| 1514 kAllowHarmonyNewTarget, | 1509 kAllowHarmonyNewTarget, |
| 1515 kAllowHarmonyFunctionSent, | 1510 kAllowHarmonyFunctionSent, |
| 1516 kAllowHarmonyRestrictiveDeclarations, | 1511 kAllowHarmonyRestrictiveDeclarations, |
| 1517 kAllowHarmonyExponentiationOperator | 1512 kAllowHarmonyExponentiationOperator |
| 1518 }; | 1513 }; |
| 1519 | 1514 |
| 1520 enum ParserSyncTestResult { | 1515 enum ParserSyncTestResult { |
| 1521 kSuccessOrError, | 1516 kSuccessOrError, |
| 1522 kSuccess, | 1517 kSuccess, |
| 1523 kError | 1518 kError |
| 1524 }; | 1519 }; |
| 1525 | 1520 |
| 1526 template <typename Traits> | 1521 template <typename Traits> |
| 1527 void SetParserFlags(i::ParserBase<Traits>* parser, | 1522 void SetParserFlags(i::ParserBase<Traits>* parser, |
| 1528 i::EnumSet<ParserFlag> flags) { | 1523 i::EnumSet<ParserFlag> flags) { |
| 1529 parser->set_allow_lazy(flags.Contains(kAllowLazy)); | 1524 parser->set_allow_lazy(flags.Contains(kAllowLazy)); |
| 1530 parser->set_allow_natives(flags.Contains(kAllowNatives)); | 1525 parser->set_allow_natives(flags.Contains(kAllowNatives)); |
| 1531 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); | |
| 1532 parser->set_allow_harmony_sloppy_let(flags.Contains(kAllowHarmonySloppyLet)); | |
| 1533 parser->set_allow_harmony_function_sent( | 1526 parser->set_allow_harmony_function_sent( |
| 1534 flags.Contains(kAllowHarmonyFunctionSent)); | 1527 flags.Contains(kAllowHarmonyFunctionSent)); |
| 1535 parser->set_allow_harmony_restrictive_declarations( | 1528 parser->set_allow_harmony_restrictive_declarations( |
| 1536 flags.Contains(kAllowHarmonyRestrictiveDeclarations)); | 1529 flags.Contains(kAllowHarmonyRestrictiveDeclarations)); |
| 1537 parser->set_allow_harmony_exponentiation_operator( | 1530 parser->set_allow_harmony_exponentiation_operator( |
| 1538 flags.Contains(kAllowHarmonyExponentiationOperator)); | 1531 flags.Contains(kAllowHarmonyExponentiationOperator)); |
| 1539 } | 1532 } |
| 1540 | 1533 |
| 1541 | 1534 |
| 1542 void TestParserSyncWithFlags(i::Handle<i::String> source, | 1535 void TestParserSyncWithFlags(i::Handle<i::String> source, |
| (...skipping 2392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3935 "super.x", | 3928 "super.x", |
| 3936 "super[27]", | 3929 "super[27]", |
| 3937 "new super.x", | 3930 "new super.x", |
| 3938 "new super.x()", | 3931 "new super.x()", |
| 3939 "new super[27]", | 3932 "new super[27]", |
| 3940 "new super[27]()", | 3933 "new super[27]()", |
| 3941 "z.super", // Ok, property lookup. | 3934 "z.super", // Ok, property lookup. |
| 3942 NULL | 3935 NULL |
| 3943 }; | 3936 }; |
| 3944 | 3937 |
| 3945 static const ParserFlag always_flags[] = { | 3938 RunParserSyncTest(context_data, statement_data, kSuccess); |
| 3946 kAllowHarmonySloppy | |
| 3947 }; | |
| 3948 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | |
| 3949 always_flags, arraysize(always_flags)); | |
| 3950 } | 3939 } |
| 3951 | 3940 |
| 3952 | 3941 |
| 3953 TEST(SuperErrors) { | 3942 TEST(SuperErrors) { |
| 3954 const char* context_data[][2] = { | 3943 const char* context_data[][2] = { |
| 3955 {"class C { m() { ", "; } }"}, | 3944 {"class C { m() { ", "; } }"}, |
| 3956 {"class C { m() { k = ", "; } }"}, | 3945 {"class C { m() { k = ", "; } }"}, |
| 3957 {"class C { m() { foo(", "); } }"}, | 3946 {"class C { m() { foo(", "); } }"}, |
| 3958 {"class C { m() { () => ", "; } }"}, | 3947 {"class C { m() { () => ", "; } }"}, |
| 3959 {NULL, NULL} | 3948 {NULL, NULL} |
| 3960 }; | 3949 }; |
| 3961 | 3950 |
| 3962 const char* expression_data[] = { | 3951 const char* expression_data[] = { |
| 3963 "super", | 3952 "super", |
| 3964 "super = x", | 3953 "super = x", |
| 3965 "y = super", | 3954 "y = super", |
| 3966 "f(super)", | 3955 "f(super)", |
| 3967 "new super", | 3956 "new super", |
| 3968 "new super()", | 3957 "new super()", |
| 3969 "new super(12, 45)", | 3958 "new super(12, 45)", |
| 3970 "new new super", | 3959 "new new super", |
| 3971 "new new super()", | 3960 "new new super()", |
| 3972 "new new super()()", | 3961 "new new super()()", |
| 3973 NULL | 3962 NULL |
| 3974 }; | 3963 }; |
| 3975 | 3964 |
| 3976 static const ParserFlag always_flags[] = {kAllowHarmonySloppy}; | 3965 RunParserSyncTest(context_data, expression_data, kError); |
| 3977 RunParserSyncTest(context_data, expression_data, kError, NULL, 0, | |
| 3978 always_flags, arraysize(always_flags)); | |
| 3979 } | 3966 } |
| 3980 | 3967 |
| 3981 | 3968 |
| 3982 TEST(SuperCall) { | 3969 TEST(SuperCall) { |
| 3983 const char* context_data[][2] = {{"", ""}, | 3970 const char* context_data[][2] = {{"", ""}, |
| 3984 {NULL, NULL}}; | 3971 {NULL, NULL}}; |
| 3985 | 3972 |
| 3986 const char* success_data[] = { | 3973 const char* success_data[] = { |
| 3987 "class C extends B { constructor() { super(); } }", | 3974 "class C extends B { constructor() { super(); } }", |
| 3988 "class C extends B { constructor() { () => super(); } }", | 3975 "class C extends B { constructor() { () => super(); } }", |
| 3989 NULL | 3976 NULL |
| 3990 }; | 3977 }; |
| 3991 | 3978 |
| 3992 static const ParserFlag always_flags[] = {kAllowHarmonySloppy}; | 3979 RunParserSyncTest(context_data, success_data, kSuccess); |
| 3993 RunParserSyncTest(context_data, success_data, kSuccess, NULL, 0, | |
| 3994 always_flags, arraysize(always_flags)); | |
| 3995 | 3980 |
| 3996 const char* error_data[] = { | 3981 const char* error_data[] = { |
| 3997 "class C { constructor() { super(); } }", | 3982 "class C { constructor() { super(); } }", |
| 3998 "class C { method() { super(); } }", | 3983 "class C { method() { super(); } }", |
| 3999 "class C { method() { () => super(); } }", | 3984 "class C { method() { () => super(); } }", |
| 4000 "class C { *method() { super(); } }", | 3985 "class C { *method() { super(); } }", |
| 4001 "class C { get x() { super(); } }", | 3986 "class C { get x() { super(); } }", |
| 4002 "class C { set x(_) { super(); } }", | 3987 "class C { set x(_) { super(); } }", |
| 4003 "({ method() { super(); } })", | 3988 "({ method() { super(); } })", |
| 4004 "({ *method() { super(); } })", | 3989 "({ *method() { super(); } })", |
| 4005 "({ get x() { super(); } })", | 3990 "({ get x() { super(); } })", |
| 4006 "({ set x(_) { super(); } })", | 3991 "({ set x(_) { super(); } })", |
| 4007 "({ f: function() { super(); } })", | 3992 "({ f: function() { super(); } })", |
| 4008 "(function() { super(); })", | 3993 "(function() { super(); })", |
| 4009 "var f = function() { super(); }", | 3994 "var f = function() { super(); }", |
| 4010 "({ f: function*() { super(); } })", | 3995 "({ f: function*() { super(); } })", |
| 4011 "(function*() { super(); })", | 3996 "(function*() { super(); })", |
| 4012 "var f = function*() { super(); }", | 3997 "var f = function*() { super(); }", |
| 4013 NULL | 3998 NULL |
| 4014 }; | 3999 }; |
| 4015 | 4000 |
| 4016 RunParserSyncTest(context_data, error_data, kError, NULL, 0, | 4001 RunParserSyncTest(context_data, error_data, kError); |
| 4017 always_flags, arraysize(always_flags)); | |
| 4018 } | 4002 } |
| 4019 | 4003 |
| 4020 | 4004 |
| 4021 TEST(SuperNewNoErrors) { | 4005 TEST(SuperNewNoErrors) { |
| 4022 const char* context_data[][2] = { | 4006 const char* context_data[][2] = { |
| 4023 {"class C { constructor() { ", " } }"}, | 4007 {"class C { constructor() { ", " } }"}, |
| 4024 {"class C { *method() { ", " } }"}, | 4008 {"class C { *method() { ", " } }"}, |
| 4025 {"class C { get x() { ", " } }"}, | 4009 {"class C { get x() { ", " } }"}, |
| 4026 {"class C { set x(_) { ", " } }"}, | 4010 {"class C { set x(_) { ", " } }"}, |
| 4027 {"({ method() { ", " } })"}, | 4011 {"({ method() { ", " } })"}, |
| 4028 {"({ *method() { ", " } })"}, | 4012 {"({ *method() { ", " } })"}, |
| 4029 {"({ get x() { ", " } })"}, | 4013 {"({ get x() { ", " } })"}, |
| 4030 {"({ set x(_) { ", " } })"}, | 4014 {"({ set x(_) { ", " } })"}, |
| 4031 {NULL, NULL} | 4015 {NULL, NULL} |
| 4032 }; | 4016 }; |
| 4033 | 4017 |
| 4034 const char* expression_data[] = { | 4018 const char* expression_data[] = { |
| 4035 "new super.x;", | 4019 "new super.x;", |
| 4036 "new super.x();", | 4020 "new super.x();", |
| 4037 "() => new super.x;", | 4021 "() => new super.x;", |
| 4038 "() => new super.x();", | 4022 "() => new super.x();", |
| 4039 NULL | 4023 NULL |
| 4040 }; | 4024 }; |
| 4041 | 4025 |
| 4042 static const ParserFlag always_flags[] = {kAllowHarmonySloppy}; | 4026 RunParserSyncTest(context_data, expression_data, kSuccess); |
| 4043 RunParserSyncTest(context_data, expression_data, kSuccess, NULL, 0, | |
| 4044 always_flags, arraysize(always_flags)); | |
| 4045 } | 4027 } |
| 4046 | 4028 |
| 4047 | 4029 |
| 4048 TEST(SuperNewErrors) { | 4030 TEST(SuperNewErrors) { |
| 4049 const char* context_data[][2] = { | 4031 const char* context_data[][2] = { |
| 4050 {"class C { method() { ", " } }"}, | 4032 {"class C { method() { ", " } }"}, |
| 4051 {"class C { *method() { ", " } }"}, | 4033 {"class C { *method() { ", " } }"}, |
| 4052 {"class C { get x() { ", " } }"}, | 4034 {"class C { get x() { ", " } }"}, |
| 4053 {"class C { set x(_) { ", " } }"}, | 4035 {"class C { set x(_) { ", " } }"}, |
| 4054 {"({ method() { ", " } })"}, | 4036 {"({ method() { ", " } })"}, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 4065 }; | 4047 }; |
| 4066 | 4048 |
| 4067 const char* statement_data[] = { | 4049 const char* statement_data[] = { |
| 4068 "new super;", | 4050 "new super;", |
| 4069 "new super();", | 4051 "new super();", |
| 4070 "() => new super;", | 4052 "() => new super;", |
| 4071 "() => new super();", | 4053 "() => new super();", |
| 4072 NULL | 4054 NULL |
| 4073 }; | 4055 }; |
| 4074 | 4056 |
| 4075 static const ParserFlag always_flags[] = {kAllowHarmonySloppy}; | 4057 RunParserSyncTest(context_data, statement_data, kError); |
| 4076 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, | |
| 4077 always_flags, arraysize(always_flags)); | |
| 4078 } | 4058 } |
| 4079 | 4059 |
| 4080 | 4060 |
| 4081 TEST(SuperErrorsNonMethods) { | 4061 TEST(SuperErrorsNonMethods) { |
| 4082 // super is only allowed in methods, accessors and constructors. | 4062 // super is only allowed in methods, accessors and constructors. |
| 4083 const char* context_data[][2] = { | 4063 const char* context_data[][2] = { |
| 4084 {"", ";"}, | 4064 {"", ";"}, |
| 4085 {"k = ", ";"}, | 4065 {"k = ", ";"}, |
| 4086 {"foo(", ");"}, | 4066 {"foo(", ");"}, |
| 4087 {"if (", ") {}"}, | 4067 {"if (", ") {}"}, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 4105 "super.x()", | 4085 "super.x()", |
| 4106 "super[27]()", | 4086 "super[27]()", |
| 4107 "super()", | 4087 "super()", |
| 4108 "new super.x", | 4088 "new super.x", |
| 4109 "new super.x()", | 4089 "new super.x()", |
| 4110 "new super[27]", | 4090 "new super[27]", |
| 4111 "new super[27]()", | 4091 "new super[27]()", |
| 4112 NULL | 4092 NULL |
| 4113 }; | 4093 }; |
| 4114 | 4094 |
| 4115 static const ParserFlag always_flags[] = { | 4095 RunParserSyncTest(context_data, statement_data, kError); |
| 4116 kAllowHarmonySloppy | |
| 4117 }; | |
| 4118 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, | |
| 4119 always_flags, arraysize(always_flags)); | |
| 4120 } | 4096 } |
| 4121 | 4097 |
| 4122 | 4098 |
| 4123 TEST(NoErrorsMethodDefinition) { | 4099 TEST(NoErrorsMethodDefinition) { |
| 4124 const char* context_data[][2] = {{"({", "});"}, | 4100 const char* context_data[][2] = {{"({", "});"}, |
| 4125 {"'use strict'; ({", "});"}, | 4101 {"'use strict'; ({", "});"}, |
| 4126 {"({*", "});"}, | 4102 {"({*", "});"}, |
| 4127 {"'use strict'; ({*", "});"}, | 4103 {"'use strict'; ({*", "});"}, |
| 4128 {NULL, NULL}}; | 4104 {NULL, NULL}}; |
| 4129 | 4105 |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4322 "class extends F {}", | 4298 "class extends F {}", |
| 4323 "class name extends F {}", | 4299 "class name extends F {}", |
| 4324 "class extends (F, G) {}", | 4300 "class extends (F, G) {}", |
| 4325 "class name extends (F, G) {}", | 4301 "class name extends (F, G) {}", |
| 4326 "class extends class {} {}", | 4302 "class extends class {} {}", |
| 4327 "class name extends class {} {}", | 4303 "class name extends class {} {}", |
| 4328 "class extends class base {} {}", | 4304 "class extends class base {} {}", |
| 4329 "class name extends class base {} {}", | 4305 "class name extends class base {} {}", |
| 4330 NULL}; | 4306 NULL}; |
| 4331 | 4307 |
| 4332 static const ParserFlag always_flags[] = {kAllowHarmonySloppy}; | 4308 RunParserSyncTest(context_data, class_data, kSuccess); |
| 4333 RunParserSyncTest(context_data, class_data, kSuccess, NULL, 0, | |
| 4334 always_flags, arraysize(always_flags)); | |
| 4335 } | 4309 } |
| 4336 | 4310 |
| 4337 | 4311 |
| 4338 TEST(ClassDeclarationNoErrors) { | 4312 TEST(ClassDeclarationNoErrors) { |
| 4339 const char* context_data[][2] = {{"'use strict'; ", ""}, | 4313 const char* context_data[][2] = {{"'use strict'; ", ""}, |
| 4340 {"'use strict'; {", "}"}, | 4314 {"'use strict'; {", "}"}, |
| 4341 {"'use strict'; if (true) {", "}"}, | 4315 {"'use strict'; if (true) {", "}"}, |
| 4342 {NULL, NULL}}; | 4316 {NULL, NULL}}; |
| 4343 const char* statement_data[] = { | 4317 const char* statement_data[] = { |
| 4344 "class name {}", | 4318 "class name {}", |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4398 "get st\\u0061tic() {}", | 4372 "get st\\u0061tic() {}", |
| 4399 "set st\\u0061tic(v) {}", | 4373 "set st\\u0061tic(v) {}", |
| 4400 "static st\\u0061tic() {}", | 4374 "static st\\u0061tic() {}", |
| 4401 "static get st\\u0061tic() {}", | 4375 "static get st\\u0061tic() {}", |
| 4402 "static set st\\u0061tic(v) {}", | 4376 "static set st\\u0061tic(v) {}", |
| 4403 "*st\\u0061tic() {}", | 4377 "*st\\u0061tic() {}", |
| 4404 "static *st\\u0061tic() {}", | 4378 "static *st\\u0061tic() {}", |
| 4405 NULL}; | 4379 NULL}; |
| 4406 // clang-format on | 4380 // clang-format on |
| 4407 | 4381 |
| 4408 static const ParserFlag always_flags[] = { | 4382 RunParserSyncTest(context_data, class_body_data, kSuccess); |
| 4409 kAllowHarmonySloppy | |
| 4410 }; | |
| 4411 RunParserSyncTest(context_data, class_body_data, kSuccess, NULL, 0, | |
| 4412 always_flags, arraysize(always_flags)); | |
| 4413 } | 4383 } |
| 4414 | 4384 |
| 4415 | 4385 |
| 4416 TEST(ClassPropertyNameNoErrors) { | 4386 TEST(ClassPropertyNameNoErrors) { |
| 4417 const char* context_data[][2] = {{"(class {", "() {}});"}, | 4387 const char* context_data[][2] = {{"(class {", "() {}});"}, |
| 4418 {"(class { get ", "() {}});"}, | 4388 {"(class { get ", "() {}});"}, |
| 4419 {"(class { set ", "(v) {}});"}, | 4389 {"(class { set ", "(v) {}});"}, |
| 4420 {"(class { static ", "() {}});"}, | 4390 {"(class { static ", "() {}});"}, |
| 4421 {"(class { static get ", "() {}});"}, | 4391 {"(class { static get ", "() {}});"}, |
| 4422 {"(class { static set ", "(v) {}});"}, | 4392 {"(class { static set ", "(v) {}});"}, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4455 "if", | 4425 "if", |
| 4456 "else", | 4426 "else", |
| 4457 "for", | 4427 "for", |
| 4458 "while", | 4428 "while", |
| 4459 "do", | 4429 "do", |
| 4460 "try", | 4430 "try", |
| 4461 "catch", | 4431 "catch", |
| 4462 "finally", | 4432 "finally", |
| 4463 NULL}; | 4433 NULL}; |
| 4464 | 4434 |
| 4465 static const ParserFlag always_flags[] = { | 4435 RunParserSyncTest(context_data, name_data, kSuccess); |
| 4466 kAllowHarmonySloppy | |
| 4467 }; | |
| 4468 RunParserSyncTest(context_data, name_data, kSuccess, NULL, 0, | |
| 4469 always_flags, arraysize(always_flags)); | |
| 4470 } | 4436 } |
| 4471 | 4437 |
| 4472 | 4438 |
| 4473 TEST(ClassExpressionErrors) { | 4439 TEST(ClassExpressionErrors) { |
| 4474 const char* context_data[][2] = {{"(", ");"}, | 4440 const char* context_data[][2] = {{"(", ");"}, |
| 4475 {"var C = ", ";"}, | 4441 {"var C = ", ";"}, |
| 4476 {"bar, ", ";"}, | 4442 {"bar, ", ";"}, |
| 4477 {NULL, NULL}}; | 4443 {NULL, NULL}}; |
| 4478 const char* class_data[] = { | 4444 const char* class_data[] = { |
| 4479 "class", | 4445 "class", |
| 4480 "class name", | 4446 "class name", |
| 4481 "class name extends", | 4447 "class name extends", |
| 4482 "class extends", | 4448 "class extends", |
| 4483 "class {", | 4449 "class {", |
| 4484 "class { m }", | 4450 "class { m }", |
| 4485 "class { m; n }", | 4451 "class { m; n }", |
| 4486 "class { m: 1 }", | 4452 "class { m: 1 }", |
| 4487 "class { m(); n() }", | 4453 "class { m(); n() }", |
| 4488 "class { get m }", | 4454 "class { get m }", |
| 4489 "class { get m() }", | 4455 "class { get m() }", |
| 4490 "class { get m() { }", | 4456 "class { get m() { }", |
| 4491 "class { set m() {} }", // Missing required parameter. | 4457 "class { set m() {} }", // Missing required parameter. |
| 4492 "class { m() {}, n() {} }", // No commas allowed. | 4458 "class { m() {}, n() {} }", // No commas allowed. |
| 4493 NULL}; | 4459 NULL}; |
| 4494 | 4460 |
| 4495 static const ParserFlag always_flags[] = { | 4461 RunParserSyncTest(context_data, class_data, kError); |
| 4496 kAllowHarmonySloppy | |
| 4497 }; | |
| 4498 RunParserSyncTest(context_data, class_data, kError, NULL, 0, | |
| 4499 always_flags, arraysize(always_flags)); | |
| 4500 } | 4462 } |
| 4501 | 4463 |
| 4502 | 4464 |
| 4503 TEST(ClassDeclarationErrors) { | 4465 TEST(ClassDeclarationErrors) { |
| 4504 const char* context_data[][2] = {{"", ""}, | 4466 const char* context_data[][2] = {{"", ""}, |
| 4505 {"{", "}"}, | 4467 {"{", "}"}, |
| 4506 {"if (true) {", "}"}, | 4468 {"if (true) {", "}"}, |
| 4507 {NULL, NULL}}; | 4469 {NULL, NULL}}; |
| 4508 const char* class_data[] = { | 4470 const char* class_data[] = { |
| 4509 "class", | 4471 "class", |
| (...skipping 11 matching lines...) Expand all Loading... |
| 4521 "class {}", // Name is required for declaration | 4483 "class {}", // Name is required for declaration |
| 4522 "class extends base {}", | 4484 "class extends base {}", |
| 4523 "class name { *", | 4485 "class name { *", |
| 4524 "class name { * }", | 4486 "class name { * }", |
| 4525 "class name { *; }", | 4487 "class name { *; }", |
| 4526 "class name { *get x() {} }", | 4488 "class name { *get x() {} }", |
| 4527 "class name { *set x(_) {} }", | 4489 "class name { *set x(_) {} }", |
| 4528 "class name { *static m() {} }", | 4490 "class name { *static m() {} }", |
| 4529 NULL}; | 4491 NULL}; |
| 4530 | 4492 |
| 4531 static const ParserFlag always_flags[] = { | 4493 RunParserSyncTest(context_data, class_data, kError); |
| 4532 kAllowHarmonySloppy | |
| 4533 }; | |
| 4534 RunParserSyncTest(context_data, class_data, kError, NULL, 0, | |
| 4535 always_flags, arraysize(always_flags)); | |
| 4536 } | 4494 } |
| 4537 | 4495 |
| 4538 | 4496 |
| 4539 TEST(ClassNameErrors) { | 4497 TEST(ClassNameErrors) { |
| 4540 const char* context_data[][2] = {{"class ", "{}"}, | 4498 const char* context_data[][2] = {{"class ", "{}"}, |
| 4541 {"(class ", "{});"}, | 4499 {"(class ", "{});"}, |
| 4542 {"'use strict'; class ", "{}"}, | 4500 {"'use strict'; class ", "{}"}, |
| 4543 {"'use strict'; (class ", "{});"}, | 4501 {"'use strict'; (class ", "{});"}, |
| 4544 {NULL, NULL}}; | 4502 {NULL, NULL}}; |
| 4545 const char* class_name[] = { | 4503 const char* class_name[] = { |
| 4546 "arguments", | 4504 "arguments", |
| 4547 "eval", | 4505 "eval", |
| 4548 "implements", | 4506 "implements", |
| 4549 "interface", | 4507 "interface", |
| 4550 "let", | 4508 "let", |
| 4551 "package", | 4509 "package", |
| 4552 "private", | 4510 "private", |
| 4553 "protected", | 4511 "protected", |
| 4554 "public", | 4512 "public", |
| 4555 "static", | 4513 "static", |
| 4556 "var", | 4514 "var", |
| 4557 "yield", | 4515 "yield", |
| 4558 NULL}; | 4516 NULL}; |
| 4559 | 4517 |
| 4560 static const ParserFlag always_flags[] = { | 4518 RunParserSyncTest(context_data, class_name, kError); |
| 4561 kAllowHarmonySloppy | |
| 4562 }; | |
| 4563 RunParserSyncTest(context_data, class_name, kError, NULL, 0, | |
| 4564 always_flags, arraysize(always_flags)); | |
| 4565 } | 4519 } |
| 4566 | 4520 |
| 4567 | 4521 |
| 4568 TEST(ClassGetterParamNameErrors) { | 4522 TEST(ClassGetterParamNameErrors) { |
| 4569 const char* context_data[][2] = { | 4523 const char* context_data[][2] = { |
| 4570 {"class C { get name(", ") {} }"}, | 4524 {"class C { get name(", ") {} }"}, |
| 4571 {"(class { get name(", ") {} });"}, | 4525 {"(class { get name(", ") {} });"}, |
| 4572 {"'use strict'; class C { get name(", ") {} }"}, | 4526 {"'use strict'; class C { get name(", ") {} }"}, |
| 4573 {"'use strict'; (class { get name(", ") {} })"}, | 4527 {"'use strict'; (class { get name(", ") {} })"}, |
| 4574 {NULL, NULL} | 4528 {NULL, NULL} |
| 4575 }; | 4529 }; |
| 4576 | 4530 |
| 4577 const char* class_name[] = { | 4531 const char* class_name[] = { |
| 4578 "arguments", | 4532 "arguments", |
| 4579 "eval", | 4533 "eval", |
| 4580 "implements", | 4534 "implements", |
| 4581 "interface", | 4535 "interface", |
| 4582 "let", | 4536 "let", |
| 4583 "package", | 4537 "package", |
| 4584 "private", | 4538 "private", |
| 4585 "protected", | 4539 "protected", |
| 4586 "public", | 4540 "public", |
| 4587 "static", | 4541 "static", |
| 4588 "var", | 4542 "var", |
| 4589 "yield", | 4543 "yield", |
| 4590 NULL}; | 4544 NULL}; |
| 4591 | 4545 |
| 4592 static const ParserFlag always_flags[] = { | 4546 RunParserSyncTest(context_data, class_name, kError); |
| 4593 kAllowHarmonySloppy | |
| 4594 }; | |
| 4595 RunParserSyncTest(context_data, class_name, kError, NULL, 0, | |
| 4596 always_flags, arraysize(always_flags)); | |
| 4597 } | 4547 } |
| 4598 | 4548 |
| 4599 | 4549 |
| 4600 TEST(ClassStaticPrototypeErrors) { | 4550 TEST(ClassStaticPrototypeErrors) { |
| 4601 const char* context_data[][2] = {{"class C {", "}"}, | 4551 const char* context_data[][2] = {{"class C {", "}"}, |
| 4602 {"(class {", "});"}, | 4552 {"(class {", "});"}, |
| 4603 {NULL, NULL}}; | 4553 {NULL, NULL}}; |
| 4604 | 4554 |
| 4605 const char* class_body_data[] = { | 4555 const char* class_body_data[] = { |
| 4606 "static prototype() {}", | 4556 "static prototype() {}", |
| 4607 "static get prototype() {}", | 4557 "static get prototype() {}", |
| 4608 "static set prototype(_) {}", | 4558 "static set prototype(_) {}", |
| 4609 "static *prototype() {}", | 4559 "static *prototype() {}", |
| 4610 "static 'prototype'() {}", | 4560 "static 'prototype'() {}", |
| 4611 "static *'prototype'() {}", | 4561 "static *'prototype'() {}", |
| 4612 "static prot\\u006ftype() {}", | 4562 "static prot\\u006ftype() {}", |
| 4613 "static 'prot\\u006ftype'() {}", | 4563 "static 'prot\\u006ftype'() {}", |
| 4614 "static get 'prot\\u006ftype'() {}", | 4564 "static get 'prot\\u006ftype'() {}", |
| 4615 "static set 'prot\\u006ftype'(_) {}", | 4565 "static set 'prot\\u006ftype'(_) {}", |
| 4616 "static *'prot\\u006ftype'() {}", | 4566 "static *'prot\\u006ftype'() {}", |
| 4617 NULL}; | 4567 NULL}; |
| 4618 | 4568 |
| 4619 static const ParserFlag always_flags[] = { | 4569 RunParserSyncTest(context_data, class_body_data, kError); |
| 4620 kAllowHarmonySloppy | |
| 4621 }; | |
| 4622 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0, | |
| 4623 always_flags, arraysize(always_flags)); | |
| 4624 } | 4570 } |
| 4625 | 4571 |
| 4626 | 4572 |
| 4627 TEST(ClassSpecialConstructorErrors) { | 4573 TEST(ClassSpecialConstructorErrors) { |
| 4628 const char* context_data[][2] = {{"class C {", "}"}, | 4574 const char* context_data[][2] = {{"class C {", "}"}, |
| 4629 {"(class {", "});"}, | 4575 {"(class {", "});"}, |
| 4630 {NULL, NULL}}; | 4576 {NULL, NULL}}; |
| 4631 | 4577 |
| 4632 const char* class_body_data[] = { | 4578 const char* class_body_data[] = { |
| 4633 "get constructor() {}", | 4579 "get constructor() {}", |
| 4634 "get constructor(_) {}", | 4580 "get constructor(_) {}", |
| 4635 "*constructor() {}", | 4581 "*constructor() {}", |
| 4636 "get 'constructor'() {}", | 4582 "get 'constructor'() {}", |
| 4637 "*'constructor'() {}", | 4583 "*'constructor'() {}", |
| 4638 "get c\\u006fnstructor() {}", | 4584 "get c\\u006fnstructor() {}", |
| 4639 "*c\\u006fnstructor() {}", | 4585 "*c\\u006fnstructor() {}", |
| 4640 "get 'c\\u006fnstructor'() {}", | 4586 "get 'c\\u006fnstructor'() {}", |
| 4641 "get 'c\\u006fnstructor'(_) {}", | 4587 "get 'c\\u006fnstructor'(_) {}", |
| 4642 "*'c\\u006fnstructor'() {}", | 4588 "*'c\\u006fnstructor'() {}", |
| 4643 NULL}; | 4589 NULL}; |
| 4644 | 4590 |
| 4645 static const ParserFlag always_flags[] = { | 4591 RunParserSyncTest(context_data, class_body_data, kError); |
| 4646 kAllowHarmonySloppy | |
| 4647 }; | |
| 4648 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0, | |
| 4649 always_flags, arraysize(always_flags)); | |
| 4650 } | 4592 } |
| 4651 | 4593 |
| 4652 | 4594 |
| 4653 TEST(ClassConstructorNoErrors) { | 4595 TEST(ClassConstructorNoErrors) { |
| 4654 const char* context_data[][2] = {{"class C {", "}"}, | 4596 const char* context_data[][2] = {{"class C {", "}"}, |
| 4655 {"(class {", "});"}, | 4597 {"(class {", "});"}, |
| 4656 {NULL, NULL}}; | 4598 {NULL, NULL}}; |
| 4657 | 4599 |
| 4658 const char* class_body_data[] = { | 4600 const char* class_body_data[] = { |
| 4659 "constructor() {}", | 4601 "constructor() {}", |
| 4660 "static constructor() {}", | 4602 "static constructor() {}", |
| 4661 "static get constructor() {}", | 4603 "static get constructor() {}", |
| 4662 "static set constructor(_) {}", | 4604 "static set constructor(_) {}", |
| 4663 "static *constructor() {}", | 4605 "static *constructor() {}", |
| 4664 NULL}; | 4606 NULL}; |
| 4665 | 4607 |
| 4666 static const ParserFlag always_flags[] = { | 4608 RunParserSyncTest(context_data, class_body_data, kSuccess); |
| 4667 kAllowHarmonySloppy | |
| 4668 }; | |
| 4669 RunParserSyncTest(context_data, class_body_data, kSuccess, NULL, 0, | |
| 4670 always_flags, arraysize(always_flags)); | |
| 4671 } | 4609 } |
| 4672 | 4610 |
| 4673 | 4611 |
| 4674 TEST(ClassMultipleConstructorErrors) { | 4612 TEST(ClassMultipleConstructorErrors) { |
| 4675 const char* context_data[][2] = {{"class C {", "}"}, | 4613 const char* context_data[][2] = {{"class C {", "}"}, |
| 4676 {"(class {", "});"}, | 4614 {"(class {", "});"}, |
| 4677 {NULL, NULL}}; | 4615 {NULL, NULL}}; |
| 4678 | 4616 |
| 4679 const char* class_body_data[] = { | 4617 const char* class_body_data[] = { |
| 4680 "constructor() {}; constructor() {}", | 4618 "constructor() {}; constructor() {}", |
| 4681 NULL}; | 4619 NULL}; |
| 4682 | 4620 |
| 4683 static const ParserFlag always_flags[] = { | 4621 RunParserSyncTest(context_data, class_body_data, kError); |
| 4684 kAllowHarmonySloppy | |
| 4685 }; | |
| 4686 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0, | |
| 4687 always_flags, arraysize(always_flags)); | |
| 4688 } | 4622 } |
| 4689 | 4623 |
| 4690 | 4624 |
| 4691 TEST(ClassMultiplePropertyNamesNoErrors) { | 4625 TEST(ClassMultiplePropertyNamesNoErrors) { |
| 4692 const char* context_data[][2] = {{"class C {", "}"}, | 4626 const char* context_data[][2] = {{"class C {", "}"}, |
| 4693 {"(class {", "});"}, | 4627 {"(class {", "});"}, |
| 4694 {NULL, NULL}}; | 4628 {NULL, NULL}}; |
| 4695 | 4629 |
| 4696 const char* class_body_data[] = { | 4630 const char* class_body_data[] = { |
| 4697 "constructor() {}; static constructor() {}", | 4631 "constructor() {}; static constructor() {}", |
| 4698 "m() {}; static m() {}", | 4632 "m() {}; static m() {}", |
| 4699 "m() {}; m() {}", | 4633 "m() {}; m() {}", |
| 4700 "static m() {}; static m() {}", | 4634 "static m() {}; static m() {}", |
| 4701 "get m() {}; set m(_) {}; get m() {}; set m(_) {};", | 4635 "get m() {}; set m(_) {}; get m() {}; set m(_) {};", |
| 4702 NULL}; | 4636 NULL}; |
| 4703 | 4637 |
| 4704 static const ParserFlag always_flags[] = { | 4638 RunParserSyncTest(context_data, class_body_data, kSuccess); |
| 4705 kAllowHarmonySloppy | |
| 4706 }; | |
| 4707 RunParserSyncTest(context_data, class_body_data, kSuccess, NULL, 0, | |
| 4708 always_flags, arraysize(always_flags)); | |
| 4709 } | 4639 } |
| 4710 | 4640 |
| 4711 | 4641 |
| 4712 TEST(ClassesAreStrictErrors) { | 4642 TEST(ClassesAreStrictErrors) { |
| 4713 const char* context_data[][2] = {{"", ""}, | 4643 const char* context_data[][2] = {{"", ""}, |
| 4714 {"(", ");"}, | 4644 {"(", ");"}, |
| 4715 {NULL, NULL}}; | 4645 {NULL, NULL}}; |
| 4716 | 4646 |
| 4717 const char* class_body_data[] = { | 4647 const char* class_body_data[] = { |
| 4718 "class C { method() { with ({}) {} } }", | 4648 "class C { method() { with ({}) {} } }", |
| 4719 "class C extends function() { with ({}) {} } {}", | 4649 "class C extends function() { with ({}) {} } {}", |
| 4720 "class C { *method() { with ({}) {} } }", | 4650 "class C { *method() { with ({}) {} } }", |
| 4721 NULL}; | 4651 NULL}; |
| 4722 | 4652 |
| 4723 static const ParserFlag always_flags[] = { | 4653 RunParserSyncTest(context_data, class_body_data, kError); |
| 4724 kAllowHarmonySloppy | |
| 4725 }; | |
| 4726 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0, | |
| 4727 always_flags, arraysize(always_flags)); | |
| 4728 } | 4654 } |
| 4729 | 4655 |
| 4730 | 4656 |
| 4731 TEST(ObjectLiteralPropertyShorthandKeywordsError) { | 4657 TEST(ObjectLiteralPropertyShorthandKeywordsError) { |
| 4732 const char* context_data[][2] = {{"({", "});"}, | 4658 const char* context_data[][2] = {{"({", "});"}, |
| 4733 {"'use strict'; ({", "});"}, | 4659 {"'use strict'; ({", "});"}, |
| 4734 {NULL, NULL}}; | 4660 {NULL, NULL}}; |
| 4735 | 4661 |
| 4736 const char* name_data[] = { | 4662 const char* name_data[] = { |
| 4737 "break", | 4663 "break", |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4855 TEST(StatementParsingInForIn) { | 4781 TEST(StatementParsingInForIn) { |
| 4856 const char* context_data[][2] = {{"", ""}, | 4782 const char* context_data[][2] = {{"", ""}, |
| 4857 {"'use strict';", ""}, | 4783 {"'use strict';", ""}, |
| 4858 {"function foo(){ 'use strict';", "}"}, | 4784 {"function foo(){ 'use strict';", "}"}, |
| 4859 {NULL, NULL}}; | 4785 {NULL, NULL}}; |
| 4860 | 4786 |
| 4861 const char* data[] = {"for(x in {}, {}) {}", "for(var x in {}, {}) {}", | 4787 const char* data[] = {"for(x in {}, {}) {}", "for(var x in {}, {}) {}", |
| 4862 "for(let x in {}, {}) {}", "for(const x in {}, {}) {}", | 4788 "for(let x in {}, {}) {}", "for(const x in {}, {}) {}", |
| 4863 NULL}; | 4789 NULL}; |
| 4864 | 4790 |
| 4865 static const ParserFlag always_flags[] = {kAllowHarmonySloppy, | 4791 RunParserSyncTest(context_data, data, kSuccess); |
| 4866 kAllowHarmonySloppyLet}; | |
| 4867 RunParserSyncTest(context_data, data, kSuccess, nullptr, 0, always_flags, | |
| 4868 arraysize(always_flags)); | |
| 4869 } | 4792 } |
| 4870 | 4793 |
| 4871 | 4794 |
| 4872 TEST(ConstParsingInForInError) { | 4795 TEST(ConstParsingInForInError) { |
| 4873 const char* context_data[][2] = {{"'use strict';", ""}, | 4796 const char* context_data[][2] = {{"'use strict';", ""}, |
| 4874 {"function foo(){ 'use strict';", "}"}, | 4797 {"function foo(){ 'use strict';", "}"}, |
| 4875 {NULL, NULL}}; | 4798 {NULL, NULL}}; |
| 4876 | 4799 |
| 4877 const char* data[] = { | 4800 const char* data[] = { |
| 4878 "for(const x,y = 1; ; ) {}", | 4801 "for(const x,y = 1; ; ) {}", |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4966 "for (let i, j in {}) {}", | 4889 "for (let i, j in {}) {}", |
| 4967 "for (let i, j in [1, 2, 3]) {}", | 4890 "for (let i, j in [1, 2, 3]) {}", |
| 4968 "for (let i, j = 1 in {}) {}", | 4891 "for (let i, j = 1 in {}) {}", |
| 4969 "for (let i, j = void 0 in [1, 2, 3]) {}", | 4892 "for (let i, j = void 0 in [1, 2, 3]) {}", |
| 4970 | 4893 |
| 4971 "for (const i, j in {}) {}", | 4894 "for (const i, j in {}) {}", |
| 4972 "for (const i, j in [1, 2, 3]) {}", | 4895 "for (const i, j in [1, 2, 3]) {}", |
| 4973 "for (const i, j = 1 in {}) {}", | 4896 "for (const i, j = 1 in {}) {}", |
| 4974 "for (const i, j = void 0 in [1, 2, 3]) {}", | 4897 "for (const i, j = void 0 in [1, 2, 3]) {}", |
| 4975 NULL}; | 4898 NULL}; |
| 4976 static const ParserFlag always_flags[] = {kAllowHarmonySloppy}; | 4899 RunParserSyncTest(context_data, data, kError); |
| 4977 RunParserSyncTest(context_data, data, kError, nullptr, 0, always_flags, | |
| 4978 arraysize(always_flags)); | |
| 4979 } | 4900 } |
| 4980 | 4901 |
| 4981 | 4902 |
| 4982 TEST(ForOfMultipleDeclarationsError) { | 4903 TEST(ForOfMultipleDeclarationsError) { |
| 4983 const char* context_data[][2] = {{"", ""}, | 4904 const char* context_data[][2] = {{"", ""}, |
| 4984 {"function foo(){", "}"}, | 4905 {"function foo(){", "}"}, |
| 4985 {"'use strict';", ""}, | 4906 {"'use strict';", ""}, |
| 4986 {"function foo(){ 'use strict';", "}"}, | 4907 {"function foo(){ 'use strict';", "}"}, |
| 4987 {NULL, NULL}}; | 4908 {NULL, NULL}}; |
| 4988 | 4909 |
| 4989 const char* data[] = { | 4910 const char* data[] = { |
| 4990 "for (var i, j of {}) {}", | 4911 "for (var i, j of {}) {}", |
| 4991 "for (var i, j of [1, 2, 3]) {}", | 4912 "for (var i, j of [1, 2, 3]) {}", |
| 4992 "for (var i, j = 1 of {}) {}", | 4913 "for (var i, j = 1 of {}) {}", |
| 4993 "for (var i, j = void 0 of [1, 2, 3]) {}", | 4914 "for (var i, j = void 0 of [1, 2, 3]) {}", |
| 4994 | 4915 |
| 4995 "for (let i, j of {}) {}", | 4916 "for (let i, j of {}) {}", |
| 4996 "for (let i, j of [1, 2, 3]) {}", | 4917 "for (let i, j of [1, 2, 3]) {}", |
| 4997 "for (let i, j = 1 of {}) {}", | 4918 "for (let i, j = 1 of {}) {}", |
| 4998 "for (let i, j = void 0 of [1, 2, 3]) {}", | 4919 "for (let i, j = void 0 of [1, 2, 3]) {}", |
| 4999 | 4920 |
| 5000 "for (const i, j of {}) {}", | 4921 "for (const i, j of {}) {}", |
| 5001 "for (const i, j of [1, 2, 3]) {}", | 4922 "for (const i, j of [1, 2, 3]) {}", |
| 5002 "for (const i, j = 1 of {}) {}", | 4923 "for (const i, j = 1 of {}) {}", |
| 5003 "for (const i, j = void 0 of [1, 2, 3]) {}", | 4924 "for (const i, j = void 0 of [1, 2, 3]) {}", |
| 5004 NULL}; | 4925 NULL}; |
| 5005 static const ParserFlag always_flags[] = {kAllowHarmonySloppy}; | 4926 RunParserSyncTest(context_data, data, kError); |
| 5006 RunParserSyncTest(context_data, data, kError, nullptr, 0, always_flags, | |
| 5007 arraysize(always_flags)); | |
| 5008 } | 4927 } |
| 5009 | 4928 |
| 5010 | 4929 |
| 5011 TEST(ForInNoDeclarationsError) { | 4930 TEST(ForInNoDeclarationsError) { |
| 5012 const char* context_data[][2] = {{"", ""}, | 4931 const char* context_data[][2] = {{"", ""}, |
| 5013 {"function foo(){", "}"}, | 4932 {"function foo(){", "}"}, |
| 5014 {"'use strict';", ""}, | 4933 {"'use strict';", ""}, |
| 5015 {"function foo(){ 'use strict';", "}"}, | 4934 {"function foo(){ 'use strict';", "}"}, |
| 5016 {NULL, NULL}}; | 4935 {NULL, NULL}}; |
| 5017 | 4936 |
| 5018 const char* data[] = { | 4937 const char* data[] = { |
| 5019 "for (var in {}) {}", | 4938 "for (var in {}) {}", |
| 5020 "for (const in {}) {}", | 4939 "for (const in {}) {}", |
| 5021 NULL}; | 4940 NULL}; |
| 5022 static const ParserFlag always_flags[] = {kAllowHarmonySloppy}; | 4941 RunParserSyncTest(context_data, data, kError); |
| 5023 RunParserSyncTest(context_data, data, kError, nullptr, 0, always_flags, | |
| 5024 arraysize(always_flags)); | |
| 5025 } | 4942 } |
| 5026 | 4943 |
| 5027 | 4944 |
| 5028 TEST(ForOfNoDeclarationsError) { | 4945 TEST(ForOfNoDeclarationsError) { |
| 5029 const char* context_data[][2] = {{"", ""}, | 4946 const char* context_data[][2] = {{"", ""}, |
| 5030 {"function foo(){", "}"}, | 4947 {"function foo(){", "}"}, |
| 5031 {"'use strict';", ""}, | 4948 {"'use strict';", ""}, |
| 5032 {"function foo(){ 'use strict';", "}"}, | 4949 {"function foo(){ 'use strict';", "}"}, |
| 5033 {NULL, NULL}}; | 4950 {NULL, NULL}}; |
| 5034 | 4951 |
| 5035 const char* data[] = { | 4952 const char* data[] = { |
| 5036 "for (var of [1, 2, 3]) {}", | 4953 "for (var of [1, 2, 3]) {}", |
| 5037 "for (const of [1, 2, 3]) {}", | 4954 "for (const of [1, 2, 3]) {}", |
| 5038 NULL}; | 4955 NULL}; |
| 5039 static const ParserFlag always_flags[] = {kAllowHarmonySloppy}; | 4956 RunParserSyncTest(context_data, data, kError); |
| 5040 RunParserSyncTest(context_data, data, kError, nullptr, 0, always_flags, | |
| 5041 arraysize(always_flags)); | |
| 5042 } | 4957 } |
| 5043 | 4958 |
| 5044 | 4959 |
| 5045 TEST(ForOfInOperator) { | 4960 TEST(ForOfInOperator) { |
| 5046 const char* context_data[][2] = {{"", ""}, | 4961 const char* context_data[][2] = {{"", ""}, |
| 5047 {"'use strict';", ""}, | 4962 {"'use strict';", ""}, |
| 5048 {"function foo(){ 'use strict';", "}"}, | 4963 {"function foo(){ 'use strict';", "}"}, |
| 5049 {NULL, NULL}}; | 4964 {NULL, NULL}}; |
| 5050 | 4965 |
| 5051 const char* data[] = { | 4966 const char* data[] = { |
| 5052 "for(x of 'foo' in {}) {}", "for(var x of 'foo' in {}) {}", | 4967 "for(x of 'foo' in {}) {}", "for(var x of 'foo' in {}) {}", |
| 5053 "for(let x of 'foo' in {}) {}", "for(const x of 'foo' in {}) {}", NULL}; | 4968 "for(let x of 'foo' in {}) {}", "for(const x of 'foo' in {}) {}", NULL}; |
| 5054 | 4969 |
| 5055 static const ParserFlag always_flags[] = {kAllowHarmonySloppy, | 4970 RunParserSyncTest(context_data, data, kSuccess); |
| 5056 kAllowHarmonySloppyLet}; | |
| 5057 RunParserSyncTest(context_data, data, kSuccess, nullptr, 0, always_flags, | |
| 5058 arraysize(always_flags)); | |
| 5059 } | 4971 } |
| 5060 | 4972 |
| 5061 | 4973 |
| 5062 TEST(ForOfYieldIdentifier) { | 4974 TEST(ForOfYieldIdentifier) { |
| 5063 const char* context_data[][2] = {{"", ""}, {NULL, NULL}}; | 4975 const char* context_data[][2] = {{"", ""}, {NULL, NULL}}; |
| 5064 | 4976 |
| 5065 const char* data[] = {"for(x of yield) {}", "for(var x of yield) {}", | 4977 const char* data[] = {"for(x of yield) {}", "for(var x of yield) {}", |
| 5066 "for(let x of yield) {}", "for(const x of yield) {}", | 4978 "for(let x of yield) {}", "for(const x of yield) {}", |
| 5067 NULL}; | 4979 NULL}; |
| 5068 | 4980 |
| 5069 static const ParserFlag always_flags[] = {kAllowHarmonySloppy, | 4981 RunParserSyncTest(context_data, data, kSuccess); |
| 5070 kAllowHarmonySloppyLet}; | |
| 5071 RunParserSyncTest(context_data, data, kSuccess, nullptr, 0, always_flags, | |
| 5072 arraysize(always_flags)); | |
| 5073 } | 4982 } |
| 5074 | 4983 |
| 5075 | 4984 |
| 5076 TEST(ForOfYieldExpression) { | 4985 TEST(ForOfYieldExpression) { |
| 5077 const char* context_data[][2] = {{"", ""}, | 4986 const char* context_data[][2] = {{"", ""}, |
| 5078 {"'use strict';", ""}, | 4987 {"'use strict';", ""}, |
| 5079 {"function foo(){ 'use strict';", "}"}, | 4988 {"function foo(){ 'use strict';", "}"}, |
| 5080 {NULL, NULL}}; | 4989 {NULL, NULL}}; |
| 5081 | 4990 |
| 5082 const char* data[] = {"function* g() { for(x of yield) {} }", | 4991 const char* data[] = {"function* g() { for(x of yield) {} }", |
| 5083 "function* g() { for(var x of yield) {} }", | 4992 "function* g() { for(var x of yield) {} }", |
| 5084 "function* g() { for(let x of yield) {} }", | 4993 "function* g() { for(let x of yield) {} }", |
| 5085 "function* g() { for(const x of yield) {} }", NULL}; | 4994 "function* g() { for(const x of yield) {} }", NULL}; |
| 5086 | 4995 |
| 5087 static const ParserFlag always_flags[] = {kAllowHarmonySloppy, | 4996 RunParserSyncTest(context_data, data, kSuccess); |
| 5088 kAllowHarmonySloppyLet}; | |
| 5089 RunParserSyncTest(context_data, data, kSuccess, nullptr, 0, always_flags, | |
| 5090 arraysize(always_flags)); | |
| 5091 } | 4997 } |
| 5092 | 4998 |
| 5093 | 4999 |
| 5094 TEST(ForOfExpressionError) { | 5000 TEST(ForOfExpressionError) { |
| 5095 const char* context_data[][2] = {{"", ""}, | 5001 const char* context_data[][2] = {{"", ""}, |
| 5096 {"'use strict';", ""}, | 5002 {"'use strict';", ""}, |
| 5097 {"function foo(){ 'use strict';", "}"}, | 5003 {"function foo(){ 'use strict';", "}"}, |
| 5098 {NULL, NULL}}; | 5004 {NULL, NULL}}; |
| 5099 | 5005 |
| 5100 const char* data[] = { | 5006 const char* data[] = { |
| 5101 "for(x of [], []) {}", "for(var x of [], []) {}", | 5007 "for(x of [], []) {}", "for(var x of [], []) {}", |
| 5102 "for(let x of [], []) {}", "for(const x of [], []) {}", | 5008 "for(let x of [], []) {}", "for(const x of [], []) {}", |
| 5103 | 5009 |
| 5104 // AssignmentExpression should be validated statically: | 5010 // AssignmentExpression should be validated statically: |
| 5105 "for(x of { y = 23 }) {}", "for(var x of { y = 23 }) {}", | 5011 "for(x of { y = 23 }) {}", "for(var x of { y = 23 }) {}", |
| 5106 "for(let x of { y = 23 }) {}", "for(const x of { y = 23 }) {}", NULL}; | 5012 "for(let x of { y = 23 }) {}", "for(const x of { y = 23 }) {}", NULL}; |
| 5107 | 5013 |
| 5108 static const ParserFlag always_flags[] = {kAllowHarmonySloppy, | 5014 RunParserSyncTest(context_data, data, kError); |
| 5109 kAllowHarmonySloppyLet}; | |
| 5110 RunParserSyncTest(context_data, data, kError, nullptr, 0, always_flags, | |
| 5111 arraysize(always_flags)); | |
| 5112 } | 5015 } |
| 5113 | 5016 |
| 5114 | 5017 |
| 5115 TEST(InvalidUnicodeEscapes) { | 5018 TEST(InvalidUnicodeEscapes) { |
| 5116 const char* context_data[][2] = {{"", ""}, | 5019 const char* context_data[][2] = {{"", ""}, |
| 5117 {"'use strict';", ""}, | 5020 {"'use strict';", ""}, |
| 5118 {NULL, NULL}}; | 5021 {NULL, NULL}}; |
| 5119 const char* data[] = { | 5022 const char* data[] = { |
| 5120 "var foob\\u123r = 0;", | 5023 "var foob\\u123r = 0;", |
| 5121 "var \\u123roo = 0;", | 5024 "var \\u123roo = 0;", |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5382 const char* context_data[][2] = { | 5285 const char* context_data[][2] = { |
| 5383 {"'use strict';({ set prop(", ") {} }).prop = 1;"}, | 5286 {"'use strict';({ set prop(", ") {} }).prop = 1;"}, |
| 5384 {"'use strict';(class { static set prop(", ") {} }).prop = 1;"}, | 5287 {"'use strict';(class { static set prop(", ") {} }).prop = 1;"}, |
| 5385 {"'use strict';(new (class { set prop(", ") {} })).prop = 1;"}, | 5288 {"'use strict';(new (class { set prop(", ") {} })).prop = 1;"}, |
| 5386 {"({ set prop(", ") {} }).prop = 1;"}, | 5289 {"({ set prop(", ") {} }).prop = 1;"}, |
| 5387 {"(class { static set prop(", ") {} }).prop = 1;"}, | 5290 {"(class { static set prop(", ") {} }).prop = 1;"}, |
| 5388 {"(new (class { set prop(", ") {} })).prop = 1;"}, | 5291 {"(new (class { set prop(", ") {} })).prop = 1;"}, |
| 5389 {nullptr, nullptr}}; | 5292 {nullptr, nullptr}}; |
| 5390 const char* data[] = {"...a", "...arguments", "...eval", nullptr}; | 5293 const char* data[] = {"...a", "...arguments", "...eval", nullptr}; |
| 5391 | 5294 |
| 5392 static const ParserFlag always_flags[] = {kAllowHarmonySloppy}; | 5295 RunParserSyncTest(context_data, data, kError); |
| 5393 RunParserSyncTest(context_data, data, kError, nullptr, 0, always_flags, | |
| 5394 arraysize(always_flags)); | |
| 5395 } | 5296 } |
| 5396 | 5297 |
| 5397 | 5298 |
| 5398 TEST(RestParametersEvalArguments) { | 5299 TEST(RestParametersEvalArguments) { |
| 5300 // clang-format off |
| 5399 const char* strict_context_data[][2] = | 5301 const char* strict_context_data[][2] = |
| 5400 {{"'use strict';(function(", | 5302 {{"'use strict';(function(", |
| 5401 "){ return;})(1, [], /regexp/, 'str',function(){});"}, | 5303 "){ return;})(1, [], /regexp/, 'str',function(){});"}, |
| 5402 {NULL, NULL}}; | 5304 {NULL, NULL}}; |
| 5403 const char* sloppy_context_data[][2] = | 5305 const char* sloppy_context_data[][2] = |
| 5404 {{"(function(", | 5306 {{"(function(", |
| 5405 "){ return;})(1, [],/regexp/, 'str', function(){});"}, | 5307 "){ return;})(1, [],/regexp/, 'str', function(){});"}, |
| 5406 {NULL, NULL}}; | 5308 {NULL, NULL}}; |
| 5407 | 5309 |
| 5408 const char* data[] = { | 5310 const char* data[] = { |
| 5409 "...eval", | 5311 "...eval", |
| 5410 "eval, ...args", | 5312 "eval, ...args", |
| 5411 "...arguments", | 5313 "...arguments", |
| 5412 "arguments, ...args", | 5314 // See https://bugs.chromium.org/p/v8/issues/detail?id=4577 |
| 5315 // "arguments, ...args", |
| 5413 NULL}; | 5316 NULL}; |
| 5317 // clang-format on |
| 5414 | 5318 |
| 5415 // Fail in strict mode | 5319 // Fail in strict mode |
| 5416 RunParserSyncTest(strict_context_data, data, kError); | 5320 RunParserSyncTest(strict_context_data, data, kError); |
| 5417 | 5321 |
| 5418 // OK in sloppy mode | 5322 // OK in sloppy mode |
| 5419 RunParserSyncTest(sloppy_context_data, data, kSuccess); | 5323 RunParserSyncTest(sloppy_context_data, data, kSuccess); |
| 5420 } | 5324 } |
| 5421 | 5325 |
| 5422 | 5326 |
| 5423 TEST(RestParametersDuplicateEvalArguments) { | 5327 TEST(RestParametersDuplicateEvalArguments) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5470 | 5374 |
| 5471 | 5375 |
| 5472 TEST(BadRestSpread) { | 5376 TEST(BadRestSpread) { |
| 5473 const char* context_data[][2] = {{"function fn() { 'use strict';", "} fn();"}, | 5377 const char* context_data[][2] = {{"function fn() { 'use strict';", "} fn();"}, |
| 5474 {"function fn() { ", "} fn();"}, | 5378 {"function fn() { ", "} fn();"}, |
| 5475 {NULL, NULL}}; | 5379 {NULL, NULL}}; |
| 5476 const char* data[] = {"return ...[1,2,3];", "var ...x = [1,2,3];", | 5380 const char* data[] = {"return ...[1,2,3];", "var ...x = [1,2,3];", |
| 5477 "var [...x,] = [1,2,3];", "var [...x, y] = [1,2,3];", | 5381 "var [...x,] = [1,2,3];", "var [...x, y] = [1,2,3];", |
| 5478 "var {...x} = [1,2,3];", "var { x } = {x: ...[1,2,3]}", | 5382 "var {...x} = [1,2,3];", "var { x } = {x: ...[1,2,3]}", |
| 5479 NULL}; | 5383 NULL}; |
| 5480 RunParserSyncTest(context_data, data, kError, NULL, 0, NULL, 0); | 5384 RunParserSyncTest(context_data, data, kError); |
| 5481 } | 5385 } |
| 5482 | 5386 |
| 5483 | 5387 |
| 5484 TEST(LexicalScopingSloppyMode) { | 5388 TEST(LexicalScopingSloppyMode) { |
| 5485 const char* context_data[][2] = { | 5389 const char* context_data[][2] = { |
| 5486 {"", ""}, | 5390 {"", ""}, |
| 5487 {"function f() {", "}"}, | 5391 {"function f() {", "}"}, |
| 5488 {"{", "}"}, | 5392 {"{", "}"}, |
| 5489 {NULL, NULL}}; | 5393 {NULL, NULL}}; |
| 5490 const char* bad_data[] = { | |
| 5491 "let x = 1;", | |
| 5492 "for(let x = 1;;){}", | |
| 5493 "for(let x of []){}", | |
| 5494 "for(let x in []){}", | |
| 5495 "class C {}", | |
| 5496 "class C extends D {}", | |
| 5497 "(class {})", | |
| 5498 "(class extends D {})", | |
| 5499 "(class C {})", | |
| 5500 "(class C extends D {})", | |
| 5501 NULL}; | |
| 5502 static const ParserFlag always_false_flags[] = {kAllowHarmonySloppy}; | |
| 5503 RunParserSyncTest(context_data, bad_data, kError, NULL, 0, NULL, 0, | |
| 5504 always_false_flags, arraysize(always_false_flags)); | |
| 5505 | 5394 |
| 5506 const char* good_data[] = { | 5395 const char* good_data[] = { |
| 5507 "let = 1;", | 5396 "let = 1;", |
| 5508 "for(let = 1;;){}", | 5397 "for(let = 1;;){}", |
| 5509 NULL}; | 5398 NULL}; |
| 5510 RunParserSyncTest(context_data, good_data, kSuccess, NULL, 0, NULL, 0, | 5399 RunParserSyncTest(context_data, good_data, kSuccess); |
| 5511 always_false_flags, arraysize(always_false_flags)); | |
| 5512 } | 5400 } |
| 5513 | 5401 |
| 5514 | 5402 |
| 5515 TEST(ComputedPropertyName) { | 5403 TEST(ComputedPropertyName) { |
| 5516 const char* context_data[][2] = {{"({[", "]: 1});"}, | 5404 const char* context_data[][2] = {{"({[", "]: 1});"}, |
| 5517 {"({get [", "]() {}});"}, | 5405 {"({get [", "]() {}});"}, |
| 5518 {"({set [", "](_) {}});"}, | 5406 {"({set [", "](_) {}});"}, |
| 5519 {"({[", "]() {}});"}, | 5407 {"({[", "]() {}});"}, |
| 5520 {"({*[", "]() {}});"}, | 5408 {"({*[", "]() {}});"}, |
| 5521 {"(class {get [", "]() {}});"}, | 5409 {"(class {get [", "]() {}});"}, |
| 5522 {"(class {set [", "](_) {}});"}, | 5410 {"(class {set [", "](_) {}});"}, |
| 5523 {"(class {[", "]() {}});"}, | 5411 {"(class {[", "]() {}});"}, |
| 5524 {"(class {*[", "]() {}});"}, | 5412 {"(class {*[", "]() {}});"}, |
| 5525 {NULL, NULL}}; | 5413 {NULL, NULL}}; |
| 5526 const char* error_data[] = { | 5414 const char* error_data[] = { |
| 5527 "1, 2", | 5415 "1, 2", |
| 5528 "var name", | 5416 "var name", |
| 5529 NULL}; | 5417 NULL}; |
| 5530 | 5418 |
| 5531 static const ParserFlag always_flags[] = { | 5419 RunParserSyncTest(context_data, error_data, kError); |
| 5532 kAllowHarmonySloppy, | |
| 5533 }; | |
| 5534 RunParserSyncTest(context_data, error_data, kError, NULL, 0, | |
| 5535 always_flags, arraysize(always_flags)); | |
| 5536 | 5420 |
| 5537 const char* name_data[] = { | 5421 const char* name_data[] = { |
| 5538 "1", | 5422 "1", |
| 5539 "1 + 2", | 5423 "1 + 2", |
| 5540 "'name'", | 5424 "'name'", |
| 5541 "\"name\"", | 5425 "\"name\"", |
| 5542 "[]", | 5426 "[]", |
| 5543 "{}", | 5427 "{}", |
| 5544 NULL}; | 5428 NULL}; |
| 5545 | 5429 |
| 5546 RunParserSyncTest(context_data, name_data, kSuccess, NULL, 0, | 5430 RunParserSyncTest(context_data, name_data, kSuccess); |
| 5547 always_flags, arraysize(always_flags)); | |
| 5548 } | 5431 } |
| 5549 | 5432 |
| 5550 | 5433 |
| 5551 TEST(ComputedPropertyNameShorthandError) { | 5434 TEST(ComputedPropertyNameShorthandError) { |
| 5552 const char* context_data[][2] = {{"({", "});"}, | 5435 const char* context_data[][2] = {{"({", "});"}, |
| 5553 {NULL, NULL}}; | 5436 {NULL, NULL}}; |
| 5554 const char* error_data[] = { | 5437 const char* error_data[] = { |
| 5555 "a: 1, [2]", | 5438 "a: 1, [2]", |
| 5556 "[1], a: 1", | 5439 "[1], a: 1", |
| 5557 NULL}; | 5440 NULL}; |
| 5558 | 5441 |
| 5559 static const ParserFlag always_flags[] = { | 5442 RunParserSyncTest(context_data, error_data, kError); |
| 5560 kAllowHarmonySloppy, | |
| 5561 }; | |
| 5562 RunParserSyncTest(context_data, error_data, kError, NULL, 0, | |
| 5563 always_flags, arraysize(always_flags)); | |
| 5564 } | 5443 } |
| 5565 | 5444 |
| 5566 | 5445 |
| 5567 TEST(BasicImportExportParsing) { | 5446 TEST(BasicImportExportParsing) { |
| 5568 // clang-format off | 5447 // clang-format off |
| 5569 const char* kSources[] = { | 5448 const char* kSources[] = { |
| 5570 "export let x = 0;", | 5449 "export let x = 0;", |
| 5571 "export var y = 0;", | 5450 "export var y = 0;", |
| 5572 "export const z = 0;", | 5451 "export const z = 0;", |
| 5573 "export function func() { };", | 5452 "export function func() { };", |
| (...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6199 {"for (let ", ";;) {}"}, | 6078 {"for (let ", ";;) {}"}, |
| 6200 {"for (const ", ";;) {}"}, | 6079 {"for (const ", ";;) {}"}, |
| 6201 {NULL, NULL}}; | 6080 {NULL, NULL}}; |
| 6202 | 6081 |
| 6203 // clang-format off | 6082 // clang-format off |
| 6204 const char* data[] = { | 6083 const char* data[] = { |
| 6205 "{ a }", | 6084 "{ a }", |
| 6206 "[ a ]", | 6085 "[ a ]", |
| 6207 NULL}; | 6086 NULL}; |
| 6208 // clang-format on | 6087 // clang-format on |
| 6209 static const ParserFlag always_flags[] = {kAllowHarmonySloppyLet}; | 6088 RunParserSyncTest(context_data, data, kError); |
| 6210 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | |
| 6211 arraysize(always_flags)); | |
| 6212 } | 6089 } |
| 6213 } | 6090 } |
| 6214 | 6091 |
| 6215 | 6092 |
| 6216 TEST(DestructuringAssignmentPositiveTests) { | 6093 TEST(DestructuringAssignmentPositiveTests) { |
| 6217 const char* context_data[][2] = { | 6094 const char* context_data[][2] = { |
| 6218 {"'use strict'; let x, y, z; (", " = {});"}, | 6095 {"'use strict'; let x, y, z; (", " = {});"}, |
| 6219 {"var x, y, z; (", " = {});"}, | 6096 {"var x, y, z; (", " = {});"}, |
| 6220 {"'use strict'; let x, y, z; for (x in ", " = {});"}, | 6097 {"'use strict'; let x, y, z; for (x in ", " = {});"}, |
| 6221 {"'use strict'; let x, y, z; for (x of ", " = {});"}, | 6098 {"'use strict'; let x, y, z; for (x of ", " = {});"}, |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6787 "{ new.target }", | 6664 "{ new.target }", |
| 6788 "() => { new.target }", | 6665 "() => { new.target }", |
| 6789 "() => new.target", | 6666 "() => new.target", |
| 6790 "if (1) { new.target }", | 6667 "if (1) { new.target }", |
| 6791 "if (1) {} else { new.target }", | 6668 "if (1) {} else { new.target }", |
| 6792 "while (0) { new.target }", | 6669 "while (0) { new.target }", |
| 6793 "do { new.target } while (0)", | 6670 "do { new.target } while (0)", |
| 6794 NULL | 6671 NULL |
| 6795 }; | 6672 }; |
| 6796 | 6673 |
| 6797 static const ParserFlag always_flags[] = { | |
| 6798 kAllowHarmonyNewTarget, | |
| 6799 kAllowHarmonySloppy, | |
| 6800 }; | |
| 6801 // clang-format on | 6674 // clang-format on |
| 6802 | 6675 |
| 6803 RunParserSyncTest(good_context_data, data, kSuccess, NULL, 0, always_flags, | 6676 RunParserSyncTest(good_context_data, data, kSuccess); |
| 6804 arraysize(always_flags)); | 6677 RunParserSyncTest(bad_context_data, data, kError); |
| 6805 RunParserSyncTest(bad_context_data, data, kError, NULL, 0, always_flags, | |
| 6806 arraysize(always_flags)); | |
| 6807 } | 6678 } |
| 6808 | 6679 |
| 6809 | 6680 |
| 6810 TEST(ConstSloppy) { | 6681 TEST(ConstSloppy) { |
| 6811 // clang-format off | 6682 // clang-format off |
| 6812 const char* context_data[][2] = { | 6683 const char* context_data[][2] = { |
| 6813 {"", ""}, | 6684 {"", ""}, |
| 6814 {"{", "}"}, | 6685 {"{", "}"}, |
| 6815 {NULL, NULL} | 6686 {NULL, NULL} |
| 6816 }; | 6687 }; |
| 6817 | 6688 |
| 6818 const char* data[] = { | 6689 const char* data[] = { |
| 6819 "const x = 1", | 6690 "const x = 1", |
| 6820 "for (const x = 1; x < 1; x++) {}", | 6691 "for (const x = 1; x < 1; x++) {}", |
| 6821 "for (const x in {}) {}", | 6692 "for (const x in {}) {}", |
| 6822 "for (const x of []) {}", | 6693 "for (const x of []) {}", |
| 6823 NULL | 6694 NULL |
| 6824 }; | 6695 }; |
| 6825 // clang-format on | 6696 // clang-format on |
| 6826 static const ParserFlag always_flags[] = {kAllowHarmonySloppy}; | 6697 RunParserSyncTest(context_data, data, kSuccess); |
| 6827 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, | |
| 6828 arraysize(always_flags)); | |
| 6829 } | 6698 } |
| 6830 | 6699 |
| 6831 | 6700 |
| 6832 TEST(LetSloppy) { | 6701 TEST(LetSloppy) { |
| 6833 // clang-format off | 6702 // clang-format off |
| 6834 const char* context_data[][2] = { | 6703 const char* context_data[][2] = { |
| 6835 {"", ""}, | 6704 {"", ""}, |
| 6836 {"'use strict';", ""}, | 6705 {"'use strict';", ""}, |
| 6837 {"{", "}"}, | 6706 {"{", "}"}, |
| 6838 {NULL, NULL} | 6707 {NULL, NULL} |
| 6839 }; | 6708 }; |
| 6840 | 6709 |
| 6841 const char* data[] = { | 6710 const char* data[] = { |
| 6842 "let x", | 6711 "let x", |
| 6843 "let x = 1", | 6712 "let x = 1", |
| 6844 "for (let x = 1; x < 1; x++) {}", | 6713 "for (let x = 1; x < 1; x++) {}", |
| 6845 "for (let x in {}) {}", | 6714 "for (let x in {}) {}", |
| 6846 "for (let x of []) {}", | 6715 "for (let x of []) {}", |
| 6847 NULL | 6716 NULL |
| 6848 }; | 6717 }; |
| 6849 // clang-format on | 6718 // clang-format on |
| 6850 | 6719 |
| 6851 static const ParserFlag always_flags[] = {kAllowHarmonySloppy, | 6720 RunParserSyncTest(context_data, data, kSuccess); |
| 6852 kAllowHarmonySloppyLet}; | |
| 6853 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, | |
| 6854 arraysize(always_flags)); | |
| 6855 } | 6721 } |
| 6856 | 6722 |
| 6857 | 6723 |
| 6858 TEST(LanguageModeDirectivesNonSimpleParameterListErrors) { | 6724 TEST(LanguageModeDirectivesNonSimpleParameterListErrors) { |
| 6859 // TC39 deemed "use strict" directives to be an error when occurring in the | 6725 // TC39 deemed "use strict" directives to be an error when occurring in the |
| 6860 // body of a function with non-simple parameter list, on 29/7/2015. | 6726 // body of a function with non-simple parameter list, on 29/7/2015. |
| 6861 // https://goo.gl/ueA7Ln | 6727 // https://goo.gl/ueA7Ln |
| 6862 const char* context_data[][2] = { | 6728 const char* context_data[][2] = { |
| 6863 {"function f(", ") { 'use strict'; }"}, | 6729 {"function f(", ") { 'use strict'; }"}, |
| 6864 {"function* g(", ") { 'use strict'; }"}, | 6730 {"function* g(", ") { 'use strict'; }"}, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 6890 "a, b, {c, d, e}", | 6756 "a, b, {c, d, e}", |
| 6891 "initializer = true", | 6757 "initializer = true", |
| 6892 "a, b, c = 1", | 6758 "a, b, c = 1", |
| 6893 "...args", | 6759 "...args", |
| 6894 "a, b, ...rest", | 6760 "a, b, ...rest", |
| 6895 "[a, b, ...rest]", | 6761 "[a, b, ...rest]", |
| 6896 "{ bindingPattern = {} }", | 6762 "{ bindingPattern = {} }", |
| 6897 "{ initializedBindingPattern } = { initializedBindingPattern: true }", | 6763 "{ initializedBindingPattern } = { initializedBindingPattern: true }", |
| 6898 NULL}; | 6764 NULL}; |
| 6899 | 6765 |
| 6900 static const ParserFlag always_flags[] = {kAllowHarmonySloppy}; | 6766 RunParserSyncTest(context_data, data, kError); |
| 6901 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | |
| 6902 arraysize(always_flags)); | |
| 6903 } | 6767 } |
| 6904 | 6768 |
| 6905 | 6769 |
| 6906 TEST(LetSloppyOnly) { | 6770 TEST(LetSloppyOnly) { |
| 6907 // clang-format off | 6771 // clang-format off |
| 6908 const char* context_data[][2] = { | 6772 const char* context_data[][2] = { |
| 6909 {"", ""}, | 6773 {"", ""}, |
| 6910 {"{", "}"}, | 6774 {"{", "}"}, |
| 6911 {"(function() {", "})()"}, | 6775 {"(function() {", "})()"}, |
| 6912 {NULL, NULL} | 6776 {NULL, NULL} |
| 6913 }; | 6777 }; |
| 6914 | 6778 |
| 6915 const char* data[] = { | 6779 const char* data[] = { |
| 6916 "let", | 6780 "let", |
| 6917 "let = 1", | 6781 "let = 1", |
| 6918 "for (let = 1; let < 1; let++) {}", | 6782 "for (let = 1; let < 1; let++) {}", |
| 6919 "for (let in {}) {}", | 6783 "for (let in {}) {}", |
| 6920 "for (var let = 1; let < 1; let++) {}", | 6784 "for (var let = 1; let < 1; let++) {}", |
| 6921 "for (var let in {}) {}", | 6785 "for (var let in {}) {}", |
| 6922 "for (var [let] = 1; let < 1; let++) {}", | 6786 "for (var [let] = 1; let < 1; let++) {}", |
| 6923 "for (var [let] in {}) {}", | 6787 "for (var [let] in {}) {}", |
| 6924 "var let", | 6788 "var let", |
| 6925 "var [let] = []", | 6789 "var [let] = []", |
| 6926 NULL | 6790 NULL |
| 6927 }; | 6791 }; |
| 6928 // clang-format on | 6792 // clang-format on |
| 6929 | 6793 |
| 6930 static const ParserFlag always_flags[] = {kAllowHarmonySloppy, | 6794 RunParserSyncTest(context_data, data, kSuccess); |
| 6931 kAllowHarmonySloppyLet}; | |
| 6932 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, | |
| 6933 arraysize(always_flags)); | |
| 6934 | 6795 |
| 6935 // Some things should be rejected even in sloppy mode | 6796 // Some things should be rejected even in sloppy mode |
| 6936 // This addresses BUG(v8:4403). | 6797 // This addresses BUG(v8:4403). |
| 6937 | 6798 |
| 6938 // clang-format off | 6799 // clang-format off |
| 6939 const char* fail_data[] = { | 6800 const char* fail_data[] = { |
| 6940 "let let = 1", | 6801 "let let = 1", |
| 6941 "for (let let = 1; let < 1; let++) {}", | 6802 "for (let let = 1; let < 1; let++) {}", |
| 6942 "for (let let in {}) {}", | 6803 "for (let let in {}) {}", |
| 6943 "for (let let of []) {}", | 6804 "for (let let of []) {}", |
| (...skipping 13 matching lines...) Expand all Loading... |
| 6957 // Sprinkle in the escaped version too. | 6818 // Sprinkle in the escaped version too. |
| 6958 "let l\\u0065t = 1", | 6819 "let l\\u0065t = 1", |
| 6959 "const l\\u0065t = 1", | 6820 "const l\\u0065t = 1", |
| 6960 "let [l\\u0065t] = 1", | 6821 "let [l\\u0065t] = 1", |
| 6961 "const [l\\u0065t] = 1", | 6822 "const [l\\u0065t] = 1", |
| 6962 "for (let l\\u0065t in {}) {}", | 6823 "for (let l\\u0065t in {}) {}", |
| 6963 NULL | 6824 NULL |
| 6964 }; | 6825 }; |
| 6965 // clang-format on | 6826 // clang-format on |
| 6966 | 6827 |
| 6967 static const ParserFlag fail_flags[] = {kAllowHarmonySloppy, | 6828 RunParserSyncTest(context_data, fail_data, kError); |
| 6968 kAllowHarmonySloppyLet}; | |
| 6969 RunParserSyncTest(context_data, fail_data, kError, NULL, 0, fail_flags, | |
| 6970 arraysize(fail_flags)); | |
| 6971 } | 6829 } |
| 6972 | 6830 |
| 6973 | 6831 |
| 6974 TEST(EscapedKeywords) { | 6832 TEST(EscapedKeywords) { |
| 6975 // clang-format off | 6833 // clang-format off |
| 6976 const char* sloppy_context_data[][2] = { | 6834 const char* sloppy_context_data[][2] = { |
| 6977 {"", ""}, | 6835 {"", ""}, |
| 6978 {NULL, NULL} | 6836 {NULL, NULL} |
| 6979 }; | 6837 }; |
| 6980 | 6838 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7060 "class C { st\\u0061tic set bar() {} }", | 6918 "class C { st\\u0061tic set bar() {} }", |
| 7061 | 6919 |
| 7062 // TODO(adamk): These should not be errors in sloppy mode. | 6920 // TODO(adamk): These should not be errors in sloppy mode. |
| 7063 "(y\\u0069eld);", | 6921 "(y\\u0069eld);", |
| 7064 "var y\\u0069eld = 1;", | 6922 "var y\\u0069eld = 1;", |
| 7065 "var { y\\u0069eld } = {};", | 6923 "var { y\\u0069eld } = {};", |
| 7066 NULL | 6924 NULL |
| 7067 }; | 6925 }; |
| 7068 // clang-format on | 6926 // clang-format on |
| 7069 | 6927 |
| 7070 static const ParserFlag always_flags[] = {kAllowHarmonySloppy}; | 6928 RunParserSyncTest(sloppy_context_data, fail_data, kError); |
| 7071 RunParserSyncTest(sloppy_context_data, fail_data, kError, NULL, 0, | 6929 RunParserSyncTest(strict_context_data, fail_data, kError); |
| 7072 always_flags, arraysize(always_flags)); | 6930 RunModuleParserSyncTest(sloppy_context_data, fail_data, kError); |
| 7073 RunParserSyncTest(strict_context_data, fail_data, kError, NULL, 0, | |
| 7074 always_flags, arraysize(always_flags)); | |
| 7075 RunModuleParserSyncTest(sloppy_context_data, fail_data, kError, NULL, 0, | |
| 7076 always_flags, arraysize(always_flags)); | |
| 7077 | 6931 |
| 7078 // clang-format off | 6932 // clang-format off |
| 7079 const char* let_data[] = { | 6933 const char* let_data[] = { |
| 7080 "var l\\u0065t = 1;", | 6934 "var l\\u0065t = 1;", |
| 7081 "l\\u0065t = 1;", | 6935 "l\\u0065t = 1;", |
| 7082 "(l\\u0065t === 1);", | 6936 "(l\\u0065t === 1);", |
| 7083 NULL | 6937 NULL |
| 7084 }; | 6938 }; |
| 7085 // clang-format on | 6939 // clang-format on |
| 7086 | 6940 |
| 7087 RunParserSyncTest(sloppy_context_data, let_data, kSuccess, NULL, 0, | 6941 RunParserSyncTest(sloppy_context_data, let_data, kSuccess); |
| 7088 always_flags, arraysize(always_flags)); | 6942 RunParserSyncTest(strict_context_data, let_data, kError); |
| 7089 RunParserSyncTest(strict_context_data, let_data, kError, NULL, 0, | |
| 7090 always_flags, arraysize(always_flags)); | |
| 7091 | |
| 7092 static const ParserFlag sloppy_let_flags[] = {kAllowHarmonySloppy, | |
| 7093 kAllowHarmonySloppyLet}; | |
| 7094 RunParserSyncTest(sloppy_context_data, let_data, kSuccess, NULL, 0, | |
| 7095 sloppy_let_flags, arraysize(sloppy_let_flags)); | |
| 7096 | 6943 |
| 7097 // Non-errors in sloppy mode | 6944 // Non-errors in sloppy mode |
| 7098 const char* valid_data[] = {"(\\u0069mplements = 1);", | 6945 const char* valid_data[] = {"(\\u0069mplements = 1);", |
| 7099 "var impl\\u0065ments = 1;", | 6946 "var impl\\u0065ments = 1;", |
| 7100 "var { impl\\u0065ments } = {};", | 6947 "var { impl\\u0065ments } = {};", |
| 7101 "(\\u0069nterface = 1);", | 6948 "(\\u0069nterface = 1);", |
| 7102 "var int\\u0065rface = 1;", | 6949 "var int\\u0065rface = 1;", |
| 7103 "var { int\\u0065rface } = {};", | 6950 "var { int\\u0065rface } = {};", |
| 7104 "(p\\u0061ckage = 1);", | 6951 "(p\\u0061ckage = 1);", |
| 7105 "var packa\\u0067e = 1;", | 6952 "var packa\\u0067e = 1;", |
| 7106 "var { packa\\u0067e } = {};", | 6953 "var { packa\\u0067e } = {};", |
| 7107 "(p\\u0072ivate = 1);", | 6954 "(p\\u0072ivate = 1);", |
| 7108 "var p\\u0072ivate;", | 6955 "var p\\u0072ivate;", |
| 7109 "var { p\\u0072ivate } = {};", | 6956 "var { p\\u0072ivate } = {};", |
| 7110 "(prot\\u0065cted);", | 6957 "(prot\\u0065cted);", |
| 7111 "var prot\\u0065cted = 1;", | 6958 "var prot\\u0065cted = 1;", |
| 7112 "var { prot\\u0065cted } = {};", | 6959 "var { prot\\u0065cted } = {};", |
| 7113 "(publ\\u0069c);", | 6960 "(publ\\u0069c);", |
| 7114 "var publ\\u0069c = 1;", | 6961 "var publ\\u0069c = 1;", |
| 7115 "var { publ\\u0069c } = {};", | 6962 "var { publ\\u0069c } = {};", |
| 7116 "(st\\u0061tic);", | 6963 "(st\\u0061tic);", |
| 7117 "var st\\u0061tic = 1;", | 6964 "var st\\u0061tic = 1;", |
| 7118 "var { st\\u0061tic } = {};", | 6965 "var { st\\u0061tic } = {};", |
| 7119 NULL}; | 6966 NULL}; |
| 7120 RunParserSyncTest(sloppy_context_data, valid_data, kSuccess, NULL, 0, | 6967 RunParserSyncTest(sloppy_context_data, valid_data, kSuccess); |
| 7121 always_flags, arraysize(always_flags)); | 6968 RunParserSyncTest(strict_context_data, valid_data, kError); |
| 7122 RunParserSyncTest(strict_context_data, valid_data, kError, NULL, 0, | 6969 RunModuleParserSyncTest(strict_context_data, valid_data, kError); |
| 7123 always_flags, arraysize(always_flags)); | |
| 7124 RunModuleParserSyncTest(strict_context_data, valid_data, kError, NULL, 0, | |
| 7125 always_flags, arraysize(always_flags)); | |
| 7126 } | 6970 } |
| 7127 | 6971 |
| 7128 | 6972 |
| 7129 TEST(MiscSyntaxErrors) { | 6973 TEST(MiscSyntaxErrors) { |
| 7130 // clang-format off | 6974 // clang-format off |
| 7131 const char* context_data[][2] = { | 6975 const char* context_data[][2] = { |
| 7132 { "'use strict'", "" }, | 6976 { "'use strict'", "" }, |
| 7133 { "", "" }, | 6977 { "", "" }, |
| 7134 { NULL, NULL } | 6978 { NULL, NULL } |
| 7135 }; | 6979 }; |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7380 // "Array() **= 10", | 7224 // "Array() **= 10", |
| 7381 NULL | 7225 NULL |
| 7382 }; | 7226 }; |
| 7383 // clang-format on | 7227 // clang-format on |
| 7384 | 7228 |
| 7385 static const ParserFlag always_flags[] = { | 7229 static const ParserFlag always_flags[] = { |
| 7386 kAllowHarmonyExponentiationOperator}; | 7230 kAllowHarmonyExponentiationOperator}; |
| 7387 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags, | 7231 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags, |
| 7388 arraysize(always_flags)); | 7232 arraysize(always_flags)); |
| 7389 } | 7233 } |
| OLD | NEW |