| 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 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1268 } | 1268 } |
| 1269 result[length] = '\0'; | 1269 result[length] = '\0'; |
| 1270 return result; | 1270 return result; |
| 1271 } | 1271 } |
| 1272 | 1272 |
| 1273 enum ParserFlag { | 1273 enum ParserFlag { |
| 1274 kAllowLazy, | 1274 kAllowLazy, |
| 1275 kAllowNatives, | 1275 kAllowNatives, |
| 1276 kAllowHarmonyFunctionSent, | 1276 kAllowHarmonyFunctionSent, |
| 1277 kAllowHarmonyRestrictiveGenerators, | 1277 kAllowHarmonyRestrictiveGenerators, |
| 1278 kAllowHarmonyTrailingCommas, | |
| 1279 kAllowHarmonyClassFields, | 1278 kAllowHarmonyClassFields, |
| 1280 kAllowHarmonyObjectSpread, | 1279 kAllowHarmonyObjectSpread, |
| 1281 }; | 1280 }; |
| 1282 | 1281 |
| 1283 enum ParserSyncTestResult { | 1282 enum ParserSyncTestResult { |
| 1284 kSuccessOrError, | 1283 kSuccessOrError, |
| 1285 kSuccess, | 1284 kSuccess, |
| 1286 kError | 1285 kError |
| 1287 }; | 1286 }; |
| 1288 | 1287 |
| 1289 void SetGlobalFlags(i::EnumSet<ParserFlag> flags) { | 1288 void SetGlobalFlags(i::EnumSet<ParserFlag> flags) { |
| 1290 i::FLAG_allow_natives_syntax = flags.Contains(kAllowNatives); | 1289 i::FLAG_allow_natives_syntax = flags.Contains(kAllowNatives); |
| 1291 i::FLAG_harmony_function_sent = flags.Contains(kAllowHarmonyFunctionSent); | 1290 i::FLAG_harmony_function_sent = flags.Contains(kAllowHarmonyFunctionSent); |
| 1292 i::FLAG_harmony_restrictive_generators = | 1291 i::FLAG_harmony_restrictive_generators = |
| 1293 flags.Contains(kAllowHarmonyRestrictiveGenerators); | 1292 flags.Contains(kAllowHarmonyRestrictiveGenerators); |
| 1294 i::FLAG_harmony_trailing_commas = flags.Contains(kAllowHarmonyTrailingCommas); | |
| 1295 i::FLAG_harmony_class_fields = flags.Contains(kAllowHarmonyClassFields); | 1293 i::FLAG_harmony_class_fields = flags.Contains(kAllowHarmonyClassFields); |
| 1296 i::FLAG_harmony_object_spread = flags.Contains(kAllowHarmonyObjectSpread); | 1294 i::FLAG_harmony_object_spread = flags.Contains(kAllowHarmonyObjectSpread); |
| 1297 } | 1295 } |
| 1298 | 1296 |
| 1299 void SetParserFlags(i::PreParser* parser, i::EnumSet<ParserFlag> flags) { | 1297 void SetParserFlags(i::PreParser* parser, i::EnumSet<ParserFlag> flags) { |
| 1300 parser->set_allow_natives(flags.Contains(kAllowNatives)); | 1298 parser->set_allow_natives(flags.Contains(kAllowNatives)); |
| 1301 parser->set_allow_harmony_function_sent( | 1299 parser->set_allow_harmony_function_sent( |
| 1302 flags.Contains(kAllowHarmonyFunctionSent)); | 1300 flags.Contains(kAllowHarmonyFunctionSent)); |
| 1303 parser->set_allow_harmony_restrictive_generators( | 1301 parser->set_allow_harmony_restrictive_generators( |
| 1304 flags.Contains(kAllowHarmonyRestrictiveGenerators)); | 1302 flags.Contains(kAllowHarmonyRestrictiveGenerators)); |
| 1305 parser->set_allow_harmony_trailing_commas( | |
| 1306 flags.Contains(kAllowHarmonyTrailingCommas)); | |
| 1307 parser->set_allow_harmony_class_fields( | 1303 parser->set_allow_harmony_class_fields( |
| 1308 flags.Contains(kAllowHarmonyClassFields)); | 1304 flags.Contains(kAllowHarmonyClassFields)); |
| 1309 parser->set_allow_harmony_object_spread( | 1305 parser->set_allow_harmony_object_spread( |
| 1310 flags.Contains(kAllowHarmonyObjectSpread)); | 1306 flags.Contains(kAllowHarmonyObjectSpread)); |
| 1311 } | 1307 } |
| 1312 | 1308 |
| 1313 void TestParserSyncWithFlags(i::Handle<i::String> source, | 1309 void TestParserSyncWithFlags(i::Handle<i::String> source, |
| 1314 i::EnumSet<ParserFlag> flags, | 1310 i::EnumSet<ParserFlag> flags, |
| 1315 ParserSyncTestResult result, | 1311 ParserSyncTestResult result, |
| 1316 bool is_module = false, | 1312 bool is_module = false, |
| (...skipping 7108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8425 "(b,c,d,) => {};", | 8421 "(b,c,d,) => {};", |
| 8426 "a(1,);", | 8422 "a(1,);", |
| 8427 "a(1,2,3,);", | 8423 "a(1,2,3,);", |
| 8428 "a(...[],);", | 8424 "a(...[],);", |
| 8429 "a(1, 2, ...[],);", | 8425 "a(1, 2, ...[],);", |
| 8430 "a(...[], 2, ...[],);", | 8426 "a(...[], 2, ...[],);", |
| 8431 NULL | 8427 NULL |
| 8432 }; | 8428 }; |
| 8433 // clang-format on | 8429 // clang-format on |
| 8434 | 8430 |
| 8435 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas}; | 8431 RunParserSyncTest(context_data, data, kSuccess); |
| 8436 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, | |
| 8437 arraysize(always_flags)); | |
| 8438 } | 8432 } |
| 8439 | 8433 |
| 8440 TEST(TrailingCommasInParametersErrors) { | 8434 TEST(TrailingCommasInParametersErrors) { |
| 8441 // clang-format off | 8435 // clang-format off |
| 8442 const char* context_data[][2] = { | 8436 const char* context_data[][2] = { |
| 8443 { "", "" }, | 8437 { "", "" }, |
| 8444 { "'use strict';", "" }, | 8438 { "'use strict';", "" }, |
| 8445 { "function foo() {", "}" }, | 8439 { "function foo() {", "}" }, |
| 8446 { "function foo() {'use strict';", "}" }, | 8440 { "function foo() {'use strict';", "}" }, |
| 8447 { NULL, NULL } | 8441 { NULL, NULL } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8490 "(...b,) => {};", | 8484 "(...b,) => {};", |
| 8491 "(b, c, ...d,) => {};", | 8485 "(b, c, ...d,) => {};", |
| 8492 // parenthesized trailing comma without arrow is still an error | 8486 // parenthesized trailing comma without arrow is still an error |
| 8493 "(,);", | 8487 "(,);", |
| 8494 "(a,);", | 8488 "(a,);", |
| 8495 "(a,b,c,);", | 8489 "(a,b,c,);", |
| 8496 NULL | 8490 NULL |
| 8497 }; | 8491 }; |
| 8498 // clang-format on | 8492 // clang-format on |
| 8499 | 8493 |
| 8500 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas}; | 8494 RunParserSyncTest(context_data, data, kError); |
| 8501 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | |
| 8502 arraysize(always_flags)); | |
| 8503 } | 8495 } |
| 8504 | 8496 |
| 8505 TEST(ArgumentsRedeclaration) { | 8497 TEST(ArgumentsRedeclaration) { |
| 8506 { | 8498 { |
| 8507 // clang-format off | 8499 // clang-format off |
| 8508 const char* context_data[][2] = { | 8500 const char* context_data[][2] = { |
| 8509 { "function f(", ") {}" }, | 8501 { "function f(", ") {}" }, |
| 8510 { NULL, NULL } | 8502 { NULL, NULL } |
| 8511 }; | 8503 }; |
| 8512 const char* success_data[] = { | 8504 const char* success_data[] = { |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8835 DCHECK_NOT_NULL(scope); | 8827 DCHECK_NOT_NULL(scope); |
| 8836 DCHECK_NULL(scope->sibling()); | 8828 DCHECK_NULL(scope->sibling()); |
| 8837 DCHECK(scope->is_function_scope()); | 8829 DCHECK(scope->is_function_scope()); |
| 8838 const i::AstRawString* var_name = | 8830 const i::AstRawString* var_name = |
| 8839 info.ast_value_factory()->GetOneByteString("my_var"); | 8831 info.ast_value_factory()->GetOneByteString("my_var"); |
| 8840 i::Variable* var = scope->Lookup(var_name); | 8832 i::Variable* var = scope->Lookup(var_name); |
| 8841 CHECK_EQ(inners[i].ctxt_allocate, | 8833 CHECK_EQ(inners[i].ctxt_allocate, |
| 8842 i::ScopeTestHelper::MustAllocateInContext(var)); | 8834 i::ScopeTestHelper::MustAllocateInContext(var)); |
| 8843 } | 8835 } |
| 8844 } | 8836 } |
| OLD | NEW |