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

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

Issue 722203006: Disable classes in sloppy mode unless --harmony-sloppy is set (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Introduce harmony-sloppy flag Created 6 years, 1 month 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
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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 const char* program = programs[i]; 312 const char* program = programs[i];
313 i::Utf8ToUtf16CharacterStream stream( 313 i::Utf8ToUtf16CharacterStream stream(
314 reinterpret_cast<const i::byte*>(program), 314 reinterpret_cast<const i::byte*>(program),
315 static_cast<unsigned>(strlen(program))); 315 static_cast<unsigned>(strlen(program)));
316 i::CompleteParserRecorder log; 316 i::CompleteParserRecorder log;
317 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 317 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
318 scanner.Initialize(&stream); 318 scanner.Initialize(&stream);
319 319
320 i::PreParser preparser(&scanner, &log, stack_limit); 320 i::PreParser preparser(&scanner, &log, stack_limit);
321 preparser.set_allow_lazy(true); 321 preparser.set_allow_lazy(true);
322 preparser.set_allow_natives_syntax(true); 322 preparser.set_allow_natives(true);
323 preparser.set_allow_arrow_functions(true); 323 preparser.set_allow_harmony_arrow_functions(true);
324 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 324 i::PreParser::PreParseResult result = preparser.PreParseProgram();
325 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 325 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
326 CHECK(!log.HasError()); 326 CHECK(!log.HasError());
327 } 327 }
328 } 328 }
329 329
330 330
331 TEST(StandAlonePreParserNoNatives) { 331 TEST(StandAlonePreParserNoNatives) {
332 v8::V8::Initialize(); 332 v8::V8::Initialize();
333 333
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 492
493 i::Utf8ToUtf16CharacterStream stream( 493 i::Utf8ToUtf16CharacterStream stream(
494 reinterpret_cast<const i::byte*>(program.get()), 494 reinterpret_cast<const i::byte*>(program.get()),
495 static_cast<unsigned>(kProgramSize)); 495 static_cast<unsigned>(kProgramSize));
496 i::CompleteParserRecorder log; 496 i::CompleteParserRecorder log;
497 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 497 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
498 scanner.Initialize(&stream); 498 scanner.Initialize(&stream);
499 499
500 i::PreParser preparser(&scanner, &log, stack_limit); 500 i::PreParser preparser(&scanner, &log, stack_limit);
501 preparser.set_allow_lazy(true); 501 preparser.set_allow_lazy(true);
502 preparser.set_allow_arrow_functions(true); 502 preparser.set_allow_harmony_arrow_functions(true);
503 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 503 i::PreParser::PreParseResult result = preparser.PreParseProgram();
504 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result); 504 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result);
505 } 505 }
506 506
507 507
508 class TestExternalResource: public v8::String::ExternalStringResource { 508 class TestExternalResource: public v8::String::ExternalStringResource {
509 public: 509 public:
510 explicit TestExternalResource(uint16_t* data, int length) 510 explicit TestExternalResource(uint16_t* data, int length)
511 : data_(data), length_(static_cast<size_t>(length)) { } 511 : data_(data), length_(static_cast<size_t>(length)) { }
512 512
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 source_data[i].body, surroundings[j].suffix); 1010 source_data[i].body, surroundings[j].suffix);
1011 i::Handle<i::String> source = 1011 i::Handle<i::String> source =
1012 factory->NewStringFromUtf8(i::CStrVector(program.start())) 1012 factory->NewStringFromUtf8(i::CStrVector(program.start()))
1013 .ToHandleChecked(); 1013 .ToHandleChecked();
1014 i::Handle<i::Script> script = factory->NewScript(source); 1014 i::Handle<i::Script> script = factory->NewScript(source);
1015 i::CompilationInfoWithZone info(script); 1015 i::CompilationInfoWithZone info(script);
1016 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), 1016 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(),
1017 isolate->heap()->HashSeed(), 1017 isolate->heap()->HashSeed(),
1018 isolate->unicode_cache()}; 1018 isolate->unicode_cache()};
1019 i::Parser parser(&info, &parse_info); 1019 i::Parser parser(&info, &parse_info);
1020 parser.set_allow_arrow_functions(true); 1020 parser.set_allow_harmony_arrow_functions(true);
1021 parser.set_allow_classes(true); 1021 parser.set_allow_harmony_classes(true);
1022 parser.set_allow_harmony_scoping(true); 1022 parser.set_allow_harmony_scoping(true);
1023 info.MarkAsGlobal(); 1023 info.MarkAsGlobal();
1024 parser.Parse(); 1024 parser.Parse();
1025 CHECK(i::Rewriter::Rewrite(&info)); 1025 CHECK(i::Rewriter::Rewrite(&info));
1026 CHECK(i::Scope::Analyze(&info)); 1026 CHECK(i::Scope::Analyze(&info));
1027 CHECK(info.function() != NULL); 1027 CHECK(info.function() != NULL);
1028 1028
1029 i::Scope* script_scope = info.function()->scope(); 1029 i::Scope* script_scope = info.function()->scope();
1030 CHECK(script_scope->is_script_scope()); 1030 CHECK(script_scope->is_script_scope());
1031 CHECK_EQ(1, script_scope->inner_scopes()->length()); 1031 CHECK_EQ(1, script_scope->inner_scopes()->length());
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 i::CStrVector(program.start())).ToHandleChecked(); 1258 i::CStrVector(program.start())).ToHandleChecked();
1259 CHECK_EQ(source->length(), kProgramSize); 1259 CHECK_EQ(source->length(), kProgramSize);
1260 i::Handle<i::Script> script = factory->NewScript(source); 1260 i::Handle<i::Script> script = factory->NewScript(source);
1261 i::CompilationInfoWithZone info(script); 1261 i::CompilationInfoWithZone info(script);
1262 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), 1262 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(),
1263 isolate->heap()->HashSeed(), 1263 isolate->heap()->HashSeed(),
1264 isolate->unicode_cache()}; 1264 isolate->unicode_cache()};
1265 i::Parser parser(&info, &parse_info); 1265 i::Parser parser(&info, &parse_info);
1266 parser.set_allow_lazy(true); 1266 parser.set_allow_lazy(true);
1267 parser.set_allow_harmony_scoping(true); 1267 parser.set_allow_harmony_scoping(true);
1268 parser.set_allow_arrow_functions(true); 1268 parser.set_allow_harmony_arrow_functions(true);
1269 info.MarkAsGlobal(); 1269 info.MarkAsGlobal();
1270 info.SetStrictMode(source_data[i].strict_mode); 1270 info.SetStrictMode(source_data[i].strict_mode);
1271 parser.Parse(); 1271 parser.Parse();
1272 CHECK(info.function() != NULL); 1272 CHECK(info.function() != NULL);
1273 1273
1274 // Check scope types and positions. 1274 // Check scope types and positions.
1275 i::Scope* scope = info.function()->scope(); 1275 i::Scope* scope = info.function()->scope();
1276 CHECK(scope->is_script_scope()); 1276 CHECK(scope->is_script_scope());
1277 CHECK_EQ(scope->start_position(), 0); 1277 CHECK_EQ(scope->start_position(), 0);
1278 CHECK_EQ(scope->end_position(), kProgramSize); 1278 CHECK_EQ(scope->end_position(), kProgramSize);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 CHECK(result->IsString()); 1332 CHECK(result->IsString());
1333 i::DeleteArray(message); 1333 i::DeleteArray(message);
1334 i::DeleteArray(arg); 1334 i::DeleteArray(arg);
1335 data.Dispose(); 1335 data.Dispose();
1336 return i::Handle<i::String>::cast(result); 1336 return i::Handle<i::String>::cast(result);
1337 } 1337 }
1338 1338
1339 1339
1340 enum ParserFlag { 1340 enum ParserFlag {
1341 kAllowLazy, 1341 kAllowLazy,
1342 kAllowNativesSyntax, 1342 kAllowNatives,
1343 kAllowHarmonyScoping, 1343 kAllowHarmonyScoping,
1344 kAllowModules, 1344 kAllowHarmonyModules,
1345 kAllowHarmonyNumericLiterals, 1345 kAllowHarmonyNumericLiterals,
1346 kAllowArrowFunctions, 1346 kAllowHarmonyArrowFunctions,
1347 kAllowClasses, 1347 kAllowHarmonyClasses,
1348 kAllowHarmonyObjectLiterals, 1348 kAllowHarmonyObjectLiterals,
1349 kAllowHarmonyTemplates 1349 kAllowHarmonyTemplates,
1350 kAllowHarmonySloppy
1350 }; 1351 };
1351 1352
1352 1353
1353 enum ParserSyncTestResult { 1354 enum ParserSyncTestResult {
1354 kSuccessOrError, 1355 kSuccessOrError,
1355 kSuccess, 1356 kSuccess,
1356 kError 1357 kError
1357 }; 1358 };
1358 1359
1359 template <typename Traits> 1360 template <typename Traits>
1360 void SetParserFlags(i::ParserBase<Traits>* parser, 1361 void SetParserFlags(i::ParserBase<Traits>* parser,
1361 i::EnumSet<ParserFlag> flags) { 1362 i::EnumSet<ParserFlag> flags) {
1362 parser->set_allow_lazy(flags.Contains(kAllowLazy)); 1363 parser->set_allow_lazy(flags.Contains(kAllowLazy));
1363 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax)); 1364 parser->set_allow_natives(flags.Contains(kAllowNatives));
1364 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); 1365 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping));
1365 parser->set_allow_modules(flags.Contains(kAllowModules)); 1366 parser->set_allow_harmony_modules(flags.Contains(kAllowHarmonyModules));
1366 parser->set_allow_harmony_numeric_literals( 1367 parser->set_allow_harmony_numeric_literals(
1367 flags.Contains(kAllowHarmonyNumericLiterals)); 1368 flags.Contains(kAllowHarmonyNumericLiterals));
1368 parser->set_allow_harmony_object_literals( 1369 parser->set_allow_harmony_object_literals(
1369 flags.Contains(kAllowHarmonyObjectLiterals)); 1370 flags.Contains(kAllowHarmonyObjectLiterals));
1370 parser->set_allow_arrow_functions(flags.Contains(kAllowArrowFunctions)); 1371 parser->set_allow_harmony_arrow_functions(
1371 parser->set_allow_classes(flags.Contains(kAllowClasses)); 1372 flags.Contains(kAllowHarmonyArrowFunctions));
1373 parser->set_allow_harmony_classes(flags.Contains(kAllowHarmonyClasses));
1372 parser->set_allow_harmony_templates(flags.Contains(kAllowHarmonyTemplates)); 1374 parser->set_allow_harmony_templates(flags.Contains(kAllowHarmonyTemplates));
1375 printf("SetParserFlags: %d\n", flags.Contains(kAllowHarmonySloppy));
arv (Not doing code reviews) 2014/11/19 16:51:04 Remove?
rossberg 2014/11/19 17:23:43 Oops.
1376 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy));
1373 } 1377 }
1374 1378
1375 1379
1376 void TestParserSyncWithFlags(i::Handle<i::String> source, 1380 void TestParserSyncWithFlags(i::Handle<i::String> source,
1377 i::EnumSet<ParserFlag> flags, 1381 i::EnumSet<ParserFlag> flags,
1378 ParserSyncTestResult result) { 1382 ParserSyncTestResult result) {
1379 i::Isolate* isolate = CcTest::i_isolate(); 1383 i::Isolate* isolate = CcTest::i_isolate();
1380 i::Factory* factory = isolate->factory(); 1384 i::Factory* factory = isolate->factory();
1381 1385
1382 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); 1386 uintptr_t stack_limit = isolate->stack_guard()->real_climit();
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1475 CHECK(false); 1479 CHECK(false);
1476 } 1480 }
1477 } 1481 }
1478 1482
1479 1483
1480 void TestParserSync(const char* source, 1484 void TestParserSync(const char* source,
1481 const ParserFlag* varying_flags, 1485 const ParserFlag* varying_flags,
1482 size_t varying_flags_length, 1486 size_t varying_flags_length,
1483 ParserSyncTestResult result = kSuccessOrError, 1487 ParserSyncTestResult result = kSuccessOrError,
1484 const ParserFlag* always_true_flags = NULL, 1488 const ParserFlag* always_true_flags = NULL,
1485 size_t always_true_flags_length = 0) { 1489 size_t always_true_flags_length = 0,
1490 const ParserFlag* always_false_flags = NULL,
1491 size_t always_false_flags_length = 0) {
1486 i::Handle<i::String> str = 1492 i::Handle<i::String> str =
1487 CcTest::i_isolate()->factory()->NewStringFromAsciiChecked(source); 1493 CcTest::i_isolate()->factory()->NewStringFromAsciiChecked(source);
1488 for (int bits = 0; bits < (1 << varying_flags_length); bits++) { 1494 for (int bits = 0; bits < (1 << varying_flags_length); bits++) {
1489 i::EnumSet<ParserFlag> flags; 1495 i::EnumSet<ParserFlag> flags;
1490 for (size_t flag_index = 0; flag_index < varying_flags_length; 1496 for (size_t flag_index = 0; flag_index < varying_flags_length;
1491 ++flag_index) { 1497 ++flag_index) {
1492 if ((bits & (1 << flag_index)) != 0) flags.Add(varying_flags[flag_index]); 1498 if ((bits & (1 << flag_index)) != 0) flags.Add(varying_flags[flag_index]);
1493 } 1499 }
1494 for (size_t flag_index = 0; flag_index < always_true_flags_length; 1500 for (size_t flag_index = 0; flag_index < always_true_flags_length;
1495 ++flag_index) { 1501 ++flag_index) {
1496 flags.Add(always_true_flags[flag_index]); 1502 flags.Add(always_true_flags[flag_index]);
1497 } 1503 }
1504 for (size_t flag_index = 0; flag_index < always_false_flags_length;
1505 ++flag_index) {
1506 flags.Remove(always_false_flags[flag_index]);
1507 }
1498 TestParserSyncWithFlags(str, flags, result); 1508 TestParserSyncWithFlags(str, flags, result);
1499 } 1509 }
1500 } 1510 }
1501 1511
1502 1512
1503 TEST(ParserSync) { 1513 TEST(ParserSync) {
1504 const char* context_data[][2] = { 1514 const char* context_data[][2] = {
1505 { "", "" }, 1515 { "", "" },
1506 { "{", "}" }, 1516 { "{", "}" },
1507 { "if (true) ", " else {}" }, 1517 { "if (true) ", " else {}" },
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1571 }; 1581 };
1572 1582
1573 v8::HandleScope handles(CcTest::isolate()); 1583 v8::HandleScope handles(CcTest::isolate());
1574 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 1584 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
1575 v8::Context::Scope context_scope(context); 1585 v8::Context::Scope context_scope(context);
1576 1586
1577 CcTest::i_isolate()->stack_guard()->SetStackLimit( 1587 CcTest::i_isolate()->stack_guard()->SetStackLimit(
1578 i::GetCurrentStackPosition() - 128 * 1024); 1588 i::GetCurrentStackPosition() - 128 * 1024);
1579 1589
1580 static const ParserFlag flags1[] = { 1590 static const ParserFlag flags1[] = {
1581 kAllowArrowFunctions, 1591 kAllowHarmonyArrowFunctions,
1582 kAllowClasses, 1592 kAllowHarmonyClasses,
1583 kAllowHarmonyNumericLiterals, 1593 kAllowHarmonyNumericLiterals,
1584 kAllowHarmonyObjectLiterals, 1594 kAllowHarmonyObjectLiterals,
1585 kAllowHarmonyScoping, 1595 kAllowHarmonyScoping,
1596 kAllowHarmonyModules,
1597 kAllowHarmonySloppy,
1586 kAllowLazy, 1598 kAllowLazy,
1587 kAllowModules,
1588 }; 1599 };
1589 1600
1590 for (int i = 0; context_data[i][0] != NULL; ++i) { 1601 for (int i = 0; context_data[i][0] != NULL; ++i) {
1591 for (int j = 0; statement_data[j] != NULL; ++j) { 1602 for (int j = 0; statement_data[j] != NULL; ++j) {
1592 for (int k = 0; termination_data[k] != NULL; ++k) { 1603 for (int k = 0; termination_data[k] != NULL; ++k) {
1593 int kPrefixLen = i::StrLength(context_data[i][0]); 1604 int kPrefixLen = i::StrLength(context_data[i][0]);
1594 int kStatementLen = i::StrLength(statement_data[j]); 1605 int kStatementLen = i::StrLength(statement_data[j]);
1595 int kTerminationLen = i::StrLength(termination_data[k]); 1606 int kTerminationLen = i::StrLength(termination_data[k]);
1596 int kSuffixLen = i::StrLength(context_data[i][1]); 1607 int kSuffixLen = i::StrLength(context_data[i][1]);
1597 int kProgramSize = kPrefixLen + kStatementLen + kTerminationLen 1608 int kProgramSize = kPrefixLen + kStatementLen + kTerminationLen
(...skipping 13 matching lines...) Expand all
1611 } 1622 }
1612 } 1623 }
1613 1624
1614 // Neither Harmony numeric literals nor our natives syntax have any 1625 // Neither Harmony numeric literals nor our natives syntax have any
1615 // interaction with the flags above, so test these separately to reduce 1626 // interaction with the flags above, so test these separately to reduce
1616 // the combinatorial explosion. 1627 // the combinatorial explosion.
1617 static const ParserFlag flags2[] = { kAllowHarmonyNumericLiterals }; 1628 static const ParserFlag flags2[] = { kAllowHarmonyNumericLiterals };
1618 TestParserSync("0o1234", flags2, arraysize(flags2)); 1629 TestParserSync("0o1234", flags2, arraysize(flags2));
1619 TestParserSync("0b1011", flags2, arraysize(flags2)); 1630 TestParserSync("0b1011", flags2, arraysize(flags2));
1620 1631
1621 static const ParserFlag flags3[] = { kAllowNativesSyntax }; 1632 static const ParserFlag flags3[] = { kAllowNatives };
1622 TestParserSync("%DebugPrint(123)", flags3, arraysize(flags3)); 1633 TestParserSync("%DebugPrint(123)", flags3, arraysize(flags3));
1623 } 1634 }
1624 1635
1625 1636
1626 TEST(StrictOctal) { 1637 TEST(StrictOctal) {
1627 // Test that syntax error caused by octal literal is reported correctly as 1638 // Test that syntax error caused by octal literal is reported correctly as
1628 // such (issue 2220). 1639 // such (issue 2220).
1629 v8::V8::Initialize(); 1640 v8::V8::Initialize();
1630 v8::HandleScope scope(CcTest::isolate()); 1641 v8::HandleScope scope(CcTest::isolate());
1631 v8::Context::Scope context_scope( 1642 v8::Context::Scope context_scope(
(...skipping 13 matching lines...) Expand all
1645 *exception); 1656 *exception);
1646 } 1657 }
1647 1658
1648 1659
1649 void RunParserSyncTest(const char* context_data[][2], 1660 void RunParserSyncTest(const char* context_data[][2],
1650 const char* statement_data[], 1661 const char* statement_data[],
1651 ParserSyncTestResult result, 1662 ParserSyncTestResult result,
1652 const ParserFlag* flags = NULL, 1663 const ParserFlag* flags = NULL,
1653 int flags_len = 0, 1664 int flags_len = 0,
1654 const ParserFlag* always_true_flags = NULL, 1665 const ParserFlag* always_true_flags = NULL,
1655 int always_true_flags_len = 0) { 1666 int always_true_len = 0,
1667 const ParserFlag* always_false_flags = NULL,
1668 int always_false_len = 0) {
1656 v8::HandleScope handles(CcTest::isolate()); 1669 v8::HandleScope handles(CcTest::isolate());
1657 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 1670 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
1658 v8::Context::Scope context_scope(context); 1671 v8::Context::Scope context_scope(context);
1659 1672
1660 CcTest::i_isolate()->stack_guard()->SetStackLimit( 1673 CcTest::i_isolate()->stack_guard()->SetStackLimit(
1661 i::GetCurrentStackPosition() - 128 * 1024); 1674 i::GetCurrentStackPosition() - 128 * 1024);
1662 1675
1663 static const ParserFlag default_flags[] = { 1676 static const ParserFlag default_flags[] = {
1664 kAllowArrowFunctions, 1677 kAllowHarmonyArrowFunctions,
1665 kAllowClasses, 1678 kAllowHarmonyClasses,
1666 kAllowHarmonyNumericLiterals, 1679 kAllowHarmonyNumericLiterals,
1667 kAllowHarmonyObjectLiterals, 1680 kAllowHarmonyObjectLiterals,
1668 kAllowHarmonyScoping, 1681 kAllowHarmonyScoping,
1682 kAllowHarmonyModules,
1683 kAllowHarmonyTemplates,
1684 kAllowHarmonySloppy,
1669 kAllowLazy, 1685 kAllowLazy,
1670 kAllowModules, 1686 kAllowNatives,
1671 kAllowNativesSyntax,
1672 kAllowHarmonyTemplates
1673 }; 1687 };
1674 ParserFlag* generated_flags = NULL; 1688 ParserFlag* generated_flags = NULL;
1675 if (flags == NULL) { 1689 if (flags == NULL) {
1676 flags = default_flags; 1690 flags = default_flags;
1677 flags_len = arraysize(default_flags); 1691 flags_len = arraysize(default_flags);
1678 if (always_true_flags != NULL) { 1692 if (always_true_flags != NULL || always_false_flags != NULL) {
1679 // Remove always_true_flags from default_flags. 1693 // Remove always_true/false_flags from default_flags.
1680 CHECK(always_true_flags_len < flags_len); 1694 CHECK((always_true_flags != NULL) == (always_true_len > 0));
1681 generated_flags = new ParserFlag[flags_len - always_true_flags_len]; 1695 CHECK((always_false_flags != NULL) == (always_false_len > 0));
1696 CHECK(always_true_flags == NULL || always_true_len < flags_len);
1697 CHECK(always_false_flags == NULL || always_false_len < flags_len);
1698 generated_flags =
1699 new ParserFlag[flags_len - always_true_len - always_false_len];
1682 int flag_index = 0; 1700 int flag_index = 0;
1683 for (int i = 0; i < flags_len; ++i) { 1701 for (int i = 0; i < flags_len; ++i) {
1684 bool use_flag = true; 1702 bool use_flag = true;
1685 for (int j = 0; j < always_true_flags_len; ++j) { 1703 for (int j = 0; use_flag && j < always_true_len; ++j) {
1686 if (flags[i] == always_true_flags[j]) { 1704 if (flags[i] == always_true_flags[j]) use_flag = false;
1687 use_flag = false; 1705 }
1688 break; 1706 for (int j = 0; use_flag && j < always_false_len; ++j) {
1689 } 1707 if (flags[i] == always_false_flags[j]) use_flag = false;
1690 } 1708 }
1691 if (use_flag) generated_flags[flag_index++] = flags[i]; 1709 if (use_flag) generated_flags[flag_index++] = flags[i];
1692 } 1710 }
1693 CHECK(flag_index == flags_len - always_true_flags_len); 1711 CHECK(flag_index == flags_len - always_true_len - always_false_len);
1694 flags_len = flag_index; 1712 flags_len = flag_index;
1695 flags = generated_flags; 1713 flags = generated_flags;
1696 } 1714 }
1697 } 1715 }
1698 for (int i = 0; context_data[i][0] != NULL; ++i) { 1716 for (int i = 0; context_data[i][0] != NULL; ++i) {
1699 for (int j = 0; statement_data[j] != NULL; ++j) { 1717 for (int j = 0; statement_data[j] != NULL; ++j) {
1700 int kPrefixLen = i::StrLength(context_data[i][0]); 1718 int kPrefixLen = i::StrLength(context_data[i][0]);
1701 int kStatementLen = i::StrLength(statement_data[j]); 1719 int kStatementLen = i::StrLength(statement_data[j]);
1702 int kSuffixLen = i::StrLength(context_data[i][1]); 1720 int kSuffixLen = i::StrLength(context_data[i][1]);
1703 int kProgramSize = kPrefixLen + kStatementLen + kSuffixLen; 1721 int kProgramSize = kPrefixLen + kStatementLen + kSuffixLen;
1704 1722
1705 // Plug the source code pieces together. 1723 // Plug the source code pieces together.
1706 i::ScopedVector<char> program(kProgramSize + 1); 1724 i::ScopedVector<char> program(kProgramSize + 1);
1707 int length = i::SNPrintF(program, 1725 int length = i::SNPrintF(program,
1708 "%s%s%s", 1726 "%s%s%s",
1709 context_data[i][0], 1727 context_data[i][0],
1710 statement_data[j], 1728 statement_data[j],
1711 context_data[i][1]); 1729 context_data[i][1]);
1712 CHECK(length == kProgramSize); 1730 CHECK(length == kProgramSize);
1713 TestParserSync(program.start(), 1731 TestParserSync(program.start(),
1714 flags, 1732 flags,
1715 flags_len, 1733 flags_len,
1716 result, 1734 result,
1717 always_true_flags, 1735 always_true_flags,
1718 always_true_flags_len); 1736 always_true_len,
1737 always_false_flags,
1738 always_false_len);
1719 } 1739 }
1720 } 1740 }
1721 delete[] generated_flags; 1741 delete[] generated_flags;
1722 } 1742 }
1723 1743
1724 1744
1725 TEST(ErrorsEvalAndArguments) { 1745 TEST(ErrorsEvalAndArguments) {
1726 // Tests that both preparsing and parsing produce the right kind of errors for 1746 // Tests that both preparsing and parsing produce the right kind of errors for
1727 // using "eval" and "arguments" as identifiers. Without the strict mode, it's 1747 // using "eval" and "arguments" as identifiers. Without the strict mode, it's
1728 // ok to use "eval" or "arguments" as identifiers. With the strict mode, it 1748 // ok to use "eval" or "arguments" as identifiers. With the strict mode, it
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1815 "arguments;", 1835 "arguments;",
1816 "var foo = eval;", 1836 "var foo = eval;",
1817 "var foo = arguments;", 1837 "var foo = arguments;",
1818 "var foo = { eval: 1 };", 1838 "var foo = { eval: 1 };",
1819 "var foo = { arguments: 1 };", 1839 "var foo = { arguments: 1 };",
1820 "var foo = { }; foo.eval = {};", 1840 "var foo = { }; foo.eval = {};",
1821 "var foo = { }; foo.arguments = {};", 1841 "var foo = { }; foo.arguments = {};",
1822 NULL 1842 NULL
1823 }; 1843 };
1824 1844
1825 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; 1845 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions};
1826 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, 1846 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
1827 always_flags, arraysize(always_flags)); 1847 always_flags, arraysize(always_flags));
1828 } 1848 }
1829 1849
1830 1850
1831 #define FUTURE_STRICT_RESERVED_WORDS(V) \ 1851 #define FUTURE_STRICT_RESERVED_WORDS(V) \
1832 V(implements) \ 1852 V(implements) \
1833 V(interface) \ 1853 V(interface) \
1834 V(let) \ 1854 V(let) \
1835 V(package) \ 1855 V(package) \
(...skipping 29 matching lines...) Expand all
1865 { "function test_func() {\"use strict\"; ", "}"}, 1885 { "function test_func() {\"use strict\"; ", "}"},
1866 { "() => { \"use strict\"; ", "}" }, 1886 { "() => { \"use strict\"; ", "}" },
1867 { NULL, NULL } 1887 { NULL, NULL }
1868 }; 1888 };
1869 1889
1870 const char* statement_data[] { 1890 const char* statement_data[] {
1871 FUTURE_STRICT_RESERVED_WORDS(FUTURE_STRICT_RESERVED_STATEMENTS) 1891 FUTURE_STRICT_RESERVED_WORDS(FUTURE_STRICT_RESERVED_STATEMENTS)
1872 NULL 1892 NULL
1873 }; 1893 };
1874 1894
1875 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; 1895 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions};
1876 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, always_flags, 1896 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, always_flags,
1877 arraysize(always_flags)); 1897 arraysize(always_flags));
1878 1898
1879 static const ParserFlag classes_flags[] = { 1899 static const ParserFlag classes_flags[] = {
1880 kAllowArrowFunctions, kAllowClasses, kAllowHarmonyScoping}; 1900 kAllowHarmonyArrowFunctions, kAllowHarmonyClasses, kAllowHarmonyScoping};
1881 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, 1901 RunParserSyncTest(context_data, statement_data, kError, NULL, 0,
1882 classes_flags, arraysize(classes_flags)); 1902 classes_flags, arraysize(classes_flags));
1883 } 1903 }
1884 1904
1885 1905
1886 TEST(NoErrorsFutureStrictReservedWords) { 1906 TEST(NoErrorsFutureStrictReservedWords) {
1887 const char* context_data[][2] = { 1907 const char* context_data[][2] = {
1888 { "", "" }, 1908 { "", "" },
1889 { "function test_func() {", "}"}, 1909 { "function test_func() {", "}"},
1890 { "() => {", "}" }, 1910 { "() => {", "}" },
1891 { NULL, NULL } 1911 { NULL, NULL }
1892 }; 1912 };
1893 1913
1894 const char* statement_data[] = { 1914 const char* statement_data[] = {
1895 FUTURE_STRICT_RESERVED_WORDS(FUTURE_STRICT_RESERVED_STATEMENTS) 1915 FUTURE_STRICT_RESERVED_WORDS(FUTURE_STRICT_RESERVED_STATEMENTS)
1896 NULL 1916 NULL
1897 }; 1917 };
1898 1918
1899 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; 1919 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions};
1900 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, 1920 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
1901 always_flags, arraysize(always_flags)); 1921 always_flags, arraysize(always_flags));
1902 1922
1903 static const ParserFlag classes_flags[] = { 1923 static const ParserFlag classes_flags[] = {
1904 kAllowArrowFunctions, kAllowClasses, kAllowHarmonyScoping}; 1924 kAllowHarmonyArrowFunctions, kAllowHarmonyClasses, kAllowHarmonyScoping};
1905 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, 1925 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
1906 classes_flags, arraysize(classes_flags)); 1926 classes_flags, arraysize(classes_flags));
1907 } 1927 }
1908 1928
1909 1929
1910 TEST(ErrorsReservedWords) { 1930 TEST(ErrorsReservedWords) {
1911 // Tests that both preparsing and parsing produce the right kind of errors for 1931 // Tests that both preparsing and parsing produce the right kind of errors for
1912 // using future reserved words as identifiers. These tests don't depend on the 1932 // using future reserved words as identifiers. These tests don't depend on the
1913 // strict mode. 1933 // strict mode.
1914 const char* context_data[][2] = { 1934 const char* context_data[][2] = {
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
2307 { NULL, NULL } 2327 { NULL, NULL }
2308 }; 2328 };
2309 2329
2310 const char* statement_data[] = { 2330 const char* statement_data[] = {
2311 "mylabel: while(true) { break mylabel; }", 2331 "mylabel: while(true) { break mylabel; }",
2312 "eval: while(true) { break eval; }", 2332 "eval: while(true) { break eval; }",
2313 "arguments: while(true) { break arguments; }", 2333 "arguments: while(true) { break arguments; }",
2314 NULL 2334 NULL
2315 }; 2335 };
2316 2336
2317 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; 2337 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions};
2318 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, 2338 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
2319 always_flags, arraysize(always_flags)); 2339 always_flags, arraysize(always_flags));
2320 } 2340 }
2321 2341
2322 2342
2323 TEST(NoErrorsFutureStrictReservedAsLabelsSloppy) { 2343 TEST(NoErrorsFutureStrictReservedAsLabelsSloppy) {
2324 const char* context_data[][2] = { 2344 const char* context_data[][2] = {
2325 { "", ""}, 2345 { "", ""},
2326 { "function test_func() {", "}" }, 2346 { "function test_func() {", "}" },
2327 { "() => {", "}" }, 2347 { "() => {", "}" },
2328 { NULL, NULL } 2348 { NULL, NULL }
2329 }; 2349 };
2330 2350
2331 #define LABELLED_WHILE(NAME) #NAME ": while (true) { break " #NAME "; }", 2351 #define LABELLED_WHILE(NAME) #NAME ": while (true) { break " #NAME "; }",
2332 const char* statement_data[] { 2352 const char* statement_data[] {
2333 FUTURE_STRICT_RESERVED_WORDS(LABELLED_WHILE) 2353 FUTURE_STRICT_RESERVED_WORDS(LABELLED_WHILE)
2334 NULL 2354 NULL
2335 }; 2355 };
2336 #undef LABELLED_WHILE 2356 #undef LABELLED_WHILE
2337 2357
2338 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; 2358 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions};
2339 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, 2359 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
2340 always_flags, arraysize(always_flags)); 2360 always_flags, arraysize(always_flags));
2341 } 2361 }
2342 2362
2343 2363
2344 TEST(ErrorsParenthesizedLabels) { 2364 TEST(ErrorsParenthesizedLabels) {
2345 // Parenthesized identifiers shouldn't be recognized as labels. 2365 // Parenthesized identifiers shouldn't be recognized as labels.
2346 const char* context_data[][2] = { 2366 const char* context_data[][2] = {
2347 { "", ""}, 2367 { "", ""},
2348 { "function test_func() {", "}" }, 2368 { "function test_func() {", "}" },
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
2580 const char* context_data[][2] = { 2600 const char* context_data[][2] = {
2581 {"", ""}, 2601 {"", ""},
2582 { NULL, NULL } 2602 { NULL, NULL }
2583 }; 2603 };
2584 2604
2585 const char* statement_data[] = { 2605 const char* statement_data[] = {
2586 "%someintrinsic(arg)", 2606 "%someintrinsic(arg)",
2587 NULL 2607 NULL
2588 }; 2608 };
2589 2609
2590 // This test requires kAllowNativesSyntax to succeed. 2610 // This test requires kAllowNatives to succeed.
2591 static const ParserFlag always_true_flags[] = { 2611 static const ParserFlag always_true_flags[] = {
2592 kAllowNativesSyntax 2612 kAllowNatives
2593 }; 2613 };
2594 2614
2595 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, 2615 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
2596 always_true_flags, 1); 2616 always_true_flags, 1);
2597 } 2617 }
2598 2618
2599 2619
2600 TEST(NoErrorsNewExpression) { 2620 TEST(NoErrorsNewExpression) {
2601 const char* context_data[][2] = { 2621 const char* context_data[][2] = {
2602 {"", ""}, 2622 {"", ""},
(...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after
3467 "(a = b, c) => {}", 3487 "(a = b, c) => {}",
3468 "(a, b = c) => {}", 3488 "(a, b = c) => {}",
3469 "(foo ? bar : baz) => {}", 3489 "(foo ? bar : baz) => {}",
3470 "(a, foo ? bar : baz) => {}", 3490 "(a, foo ? bar : baz) => {}",
3471 "(foo ? bar : baz, a) => {}", 3491 "(foo ? bar : baz, a) => {}",
3472 NULL 3492 NULL
3473 }; 3493 };
3474 3494
3475 // The test is quite slow, so run it with a reduced set of flags. 3495 // The test is quite slow, so run it with a reduced set of flags.
3476 static const ParserFlag flags[] = {kAllowLazy, kAllowHarmonyScoping}; 3496 static const ParserFlag flags[] = {kAllowLazy, kAllowHarmonyScoping};
3477 static const ParserFlag always_flags[] = { kAllowArrowFunctions }; 3497 static const ParserFlag always_flags[] = { kAllowHarmonyArrowFunctions };
3478 RunParserSyncTest(context_data, statement_data, kError, flags, 3498 RunParserSyncTest(context_data, statement_data, kError, flags,
3479 arraysize(flags), always_flags, arraysize(always_flags)); 3499 arraysize(flags), always_flags, arraysize(always_flags));
3480 } 3500 }
3481 3501
3482 3502
3483 TEST(NoErrorsArrowFunctions) { 3503 TEST(NoErrorsArrowFunctions) {
3484 // Tests that parser and preparser accept valid arrow functions syntax. 3504 // Tests that parser and preparser accept valid arrow functions syntax.
3485 const char* context_data[][2] = { 3505 const char* context_data[][2] = {
3486 {"", ";"}, 3506 {"", ";"},
3487 {"bar ? (", ") : baz;"}, 3507 {"bar ? (", ") : baz;"},
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
3521 "(a, b) => 0, (c, d) => 1", 3541 "(a, b) => 0, (c, d) => 1",
3522 "(a, b => {}, a => a + 1)", 3542 "(a, b => {}, a => a + 1)",
3523 "((a, b) => {}, (a => a + 1))", 3543 "((a, b) => {}, (a => a + 1))",
3524 "(a, (a, (b, c) => 0))", 3544 "(a, (a, (b, c) => 0))",
3525 3545
3526 // Arrow has more precedence, this is the same as: foo ? bar : (baz = {}) 3546 // Arrow has more precedence, this is the same as: foo ? bar : (baz = {})
3527 "foo ? bar : baz => {}", 3547 "foo ? bar : baz => {}",
3528 NULL 3548 NULL
3529 }; 3549 };
3530 3550
3531 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; 3551 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions};
3532 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, 3552 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
3533 always_flags, arraysize(always_flags)); 3553 always_flags, arraysize(always_flags));
3534 } 3554 }
3535 3555
3536 3556
3537 TEST(NoErrorsSuper) { 3557 TEST(NoErrorsSuper) {
3538 // Tests that parser and preparser accept 'super' keyword in right places. 3558 // Tests that parser and preparser accept 'super' keyword in right places.
3539 const char* context_data[][2] = {{"", ";"}, 3559 const char* context_data[][2] = {{"", ";"},
3540 {"k = ", ";"}, 3560 {"k = ", ";"},
3541 {"foo(", ");"}, 3561 {"foo(", ");"},
3542 {NULL, NULL}}; 3562 {NULL, NULL}};
3543 3563
3544 const char* statement_data[] = { 3564 const char* statement_data[] = {
3545 "super.x", 3565 "super.x",
3546 "super[27]", 3566 "super[27]",
3547 "new super", 3567 "new super",
3548 "new super()", 3568 "new super()",
3549 "new super(12, 45)", 3569 "new super(12, 45)",
3550 "new new super", 3570 "new new super",
3551 "new new super()", 3571 "new new super()",
3552 "new new super()()", 3572 "new new super()()",
3553 "z.super", // Ok, property lookup. 3573 "z.super", // Ok, property lookup.
3554 NULL}; 3574 NULL};
3555 3575
3556 static const ParserFlag always_flags[] = {kAllowClasses}; 3576 static const ParserFlag always_flags[] = {kAllowHarmonyClasses};
3557 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, 3577 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
3558 always_flags, arraysize(always_flags)); 3578 always_flags, arraysize(always_flags));
3559 } 3579 }
3560 3580
3561 3581
3562 TEST(ErrorsSuper) { 3582 TEST(ErrorsSuper) {
3563 // Tests that parser and preparser generate same errors for 'super'. 3583 // Tests that parser and preparser generate same errors for 'super'.
3564 const char* context_data[][2] = {{"", ";"}, 3584 const char* context_data[][2] = {{"", ";"},
3565 {"k = ", ";"}, 3585 {"k = ", ";"},
3566 {"foo(", ");"}, 3586 {"foo(", ");"},
3567 {NULL, NULL}}; 3587 {NULL, NULL}};
3568 3588
3569 const char* statement_data[] = { 3589 const char* statement_data[] = {
3570 "super = x", 3590 "super = x",
3571 "y = super", 3591 "y = super",
3572 "f(super)", 3592 "f(super)",
3573 NULL}; 3593 NULL};
3574 3594
3575 static const ParserFlag always_flags[] = {kAllowClasses}; 3595 static const ParserFlag always_flags[] = {kAllowHarmonyClasses};
3576 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, 3596 RunParserSyncTest(context_data, statement_data, kError, NULL, 0,
3577 always_flags, arraysize(always_flags)); 3597 always_flags, arraysize(always_flags));
3578 } 3598 }
3579 3599
3580 3600
3581 TEST(NoErrorsMethodDefinition) { 3601 TEST(NoErrorsMethodDefinition) {
3582 const char* context_data[][2] = {{"({", "});"}, 3602 const char* context_data[][2] = {{"({", "});"},
3583 {"'use strict'; ({", "});"}, 3603 {"'use strict'; ({", "});"},
3584 {"({*", "});"}, 3604 {"({*", "});"},
3585 {"'use strict'; ({*", "});"}, 3605 {"'use strict'; ({*", "});"},
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
3748 "class extends F {}", 3768 "class extends F {}",
3749 "class name extends F {}", 3769 "class name extends F {}",
3750 "class extends (F, G) {}", 3770 "class extends (F, G) {}",
3751 "class name extends (F, G) {}", 3771 "class name extends (F, G) {}",
3752 "class extends class {} {}", 3772 "class extends class {} {}",
3753 "class name extends class {} {}", 3773 "class name extends class {} {}",
3754 "class extends class base {} {}", 3774 "class extends class base {} {}",
3755 "class name extends class base {} {}", 3775 "class name extends class base {} {}",
3756 NULL}; 3776 NULL};
3757 3777
3758 static const ParserFlag always_flags[] = {kAllowClasses}; 3778 static const ParserFlag always_flags[] = {
3779 kAllowHarmonyClasses, kAllowHarmonySloppy};
3759 RunParserSyncTest(context_data, class_data, kSuccess, NULL, 0, 3780 RunParserSyncTest(context_data, class_data, kSuccess, NULL, 0,
3760 always_flags, arraysize(always_flags)); 3781 always_flags, arraysize(always_flags));
3761 } 3782 }
3762 3783
3763 3784
3764 TEST(ClassDeclarationNoErrors) { 3785 TEST(ClassDeclarationNoErrors) {
3765 const char* context_data[][2] = {{"", ""}, 3786 const char* context_data[][2] = {{"", ""},
3766 {"{", "}"}, 3787 {"{", "}"},
3767 {"if (true) {", "}"}, 3788 {"if (true) {", "}"},
3768 {NULL, NULL}}; 3789 {NULL, NULL}};
3769 const char* statement_data[] = { 3790 const char* statement_data[] = {
3770 "class name {}", 3791 "class name {}",
3771 "class name extends F {}", 3792 "class name extends F {}",
3772 "class name extends (F, G) {}", 3793 "class name extends (F, G) {}",
3773 "class name extends class {} {}", 3794 "class name extends class {} {}",
3774 "class name extends class base {} {}", 3795 "class name extends class base {} {}",
3775 NULL}; 3796 NULL};
3776 3797
3777 static const ParserFlag always_flags[] = {kAllowClasses}; 3798 static const ParserFlag always_flags[] = {
3799 kAllowHarmonyClasses, kAllowHarmonySloppy};
3778 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, 3800 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
3779 always_flags, arraysize(always_flags)); 3801 always_flags, arraysize(always_flags));
3780 } 3802 }
3781 3803
3782 3804
3783 TEST(ClassBodyNoErrors) { 3805 TEST(ClassBodyNoErrors) {
3784 // Tests that parser and preparser accept valid class syntax. 3806 // Tests that parser and preparser accept valid class syntax.
3785 const char* context_data[][2] = {{"(class {", "});"}, 3807 const char* context_data[][2] = {{"(class {", "});"},
3786 {"(class extends Base {", "});"}, 3808 {"(class extends Base {", "});"},
3787 {"class C {", "}"}, 3809 {"class C {", "}"},
(...skipping 23 matching lines...) Expand all
3811 "static static() {}", 3833 "static static() {}",
3812 "static get static() {}", 3834 "static get static() {}",
3813 "static set static(v) {}", 3835 "static set static(v) {}",
3814 "*static() {}", 3836 "*static() {}",
3815 "*get() {}", 3837 "*get() {}",
3816 "*set() {}", 3838 "*set() {}",
3817 "static *g() {}", 3839 "static *g() {}",
3818 NULL}; 3840 NULL};
3819 3841
3820 static const ParserFlag always_flags[] = { 3842 static const ParserFlag always_flags[] = {
3821 kAllowClasses, 3843 kAllowHarmonyClasses,
3822 kAllowHarmonyObjectLiterals 3844 kAllowHarmonyObjectLiterals,
3845 kAllowHarmonySloppy
3823 }; 3846 };
3824 RunParserSyncTest(context_data, class_body_data, kSuccess, NULL, 0, 3847 RunParserSyncTest(context_data, class_body_data, kSuccess, NULL, 0,
3825 always_flags, arraysize(always_flags)); 3848 always_flags, arraysize(always_flags));
3826 } 3849 }
3827 3850
3828 3851
3829 TEST(ClassPropertyNameNoErrors) { 3852 TEST(ClassPropertyNameNoErrors) {
3830 const char* context_data[][2] = {{"(class {", "() {}});"}, 3853 const char* context_data[][2] = {{"(class {", "() {}});"},
3831 {"(class { get ", "() {}});"}, 3854 {"(class { get ", "() {}});"},
3832 {"(class { set ", "(v) {}});"}, 3855 {"(class { set ", "(v) {}});"},
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
3869 "else", 3892 "else",
3870 "for", 3893 "for",
3871 "while", 3894 "while",
3872 "do", 3895 "do",
3873 "try", 3896 "try",
3874 "catch", 3897 "catch",
3875 "finally", 3898 "finally",
3876 NULL}; 3899 NULL};
3877 3900
3878 static const ParserFlag always_flags[] = { 3901 static const ParserFlag always_flags[] = {
3879 kAllowClasses, 3902 kAllowHarmonyClasses,
3880 kAllowHarmonyObjectLiterals 3903 kAllowHarmonyObjectLiterals,
3904 kAllowHarmonySloppy
3881 }; 3905 };
3882 RunParserSyncTest(context_data, name_data, kSuccess, NULL, 0, 3906 RunParserSyncTest(context_data, name_data, kSuccess, NULL, 0,
3883 always_flags, arraysize(always_flags)); 3907 always_flags, arraysize(always_flags));
3884 } 3908 }
3885 3909
3886 3910
3887 TEST(ClassExpressionErrors) { 3911 TEST(ClassExpressionErrors) {
3888 const char* context_data[][2] = {{"(", ");"}, 3912 const char* context_data[][2] = {{"(", ");"},
3889 {"var C = ", ";"}, 3913 {"var C = ", ";"},
3890 {"bar, ", ";"}, 3914 {"bar, ", ";"},
3891 {NULL, NULL}}; 3915 {NULL, NULL}};
3892 const char* class_data[] = { 3916 const char* class_data[] = {
3893 "class", 3917 "class",
3894 "class name", 3918 "class name",
3895 "class name extends", 3919 "class name extends",
3896 "class extends", 3920 "class extends",
3897 "class {", 3921 "class {",
3898 "class { m }", 3922 "class { m }",
3899 "class { m; n }", 3923 "class { m; n }",
3900 "class { m: 1 }", 3924 "class { m: 1 }",
3901 "class { m(); n() }", 3925 "class { m(); n() }",
3902 "class { get m }", 3926 "class { get m }",
3903 "class { get m() }", 3927 "class { get m() }",
3904 "class { get m() { }", 3928 "class { get m() { }",
3905 "class { set m() {} }", // Missing required parameter. 3929 "class { set m() {} }", // Missing required parameter.
3906 "class { m() {}, n() {} }", // No commas allowed. 3930 "class { m() {}, n() {} }", // No commas allowed.
3907 NULL}; 3931 NULL};
3908 3932
3909 static const ParserFlag always_flags[] = { 3933 static const ParserFlag always_flags[] = {
3910 kAllowClasses, 3934 kAllowHarmonyClasses,
3911 kAllowHarmonyObjectLiterals 3935 kAllowHarmonyObjectLiterals,
3936 kAllowHarmonySloppy
3912 }; 3937 };
3913 RunParserSyncTest(context_data, class_data, kError, NULL, 0, 3938 RunParserSyncTest(context_data, class_data, kError, NULL, 0,
3914 always_flags, arraysize(always_flags)); 3939 always_flags, arraysize(always_flags));
3915 } 3940 }
3916 3941
3917 3942
3918 TEST(ClassDeclarationErrors) { 3943 TEST(ClassDeclarationErrors) {
3919 const char* context_data[][2] = {{"", ""}, 3944 const char* context_data[][2] = {{"", ""},
3920 {"{", "}"}, 3945 {"{", "}"},
3921 {"if (true) {", "}"}, 3946 {"if (true) {", "}"},
(...skipping 15 matching lines...) Expand all
3937 "class extends base {}", 3962 "class extends base {}",
3938 "class name { *", 3963 "class name { *",
3939 "class name { * }", 3964 "class name { * }",
3940 "class name { *; }", 3965 "class name { *; }",
3941 "class name { *get x() {} }", 3966 "class name { *get x() {} }",
3942 "class name { *set x(_) {} }", 3967 "class name { *set x(_) {} }",
3943 "class name { *static m() {} }", 3968 "class name { *static m() {} }",
3944 NULL}; 3969 NULL};
3945 3970
3946 static const ParserFlag always_flags[] = { 3971 static const ParserFlag always_flags[] = {
3947 kAllowClasses, 3972 kAllowHarmonyClasses,
3948 kAllowHarmonyNumericLiterals 3973 kAllowHarmonyNumericLiterals,
3974 kAllowHarmonySloppy
3949 }; 3975 };
3950 RunParserSyncTest(context_data, class_data, kError, NULL, 0, 3976 RunParserSyncTest(context_data, class_data, kError, NULL, 0,
3951 always_flags, arraysize(always_flags)); 3977 always_flags, arraysize(always_flags));
3952 } 3978 }
3953 3979
3954 3980
3955 TEST(ClassNameErrors) { 3981 TEST(ClassNameErrors) {
3956 const char* context_data[][2] = {{"class ", "{}"}, 3982 const char* context_data[][2] = {{"class ", "{}"},
3957 {"(class ", "{});"}, 3983 {"(class ", "{});"},
3958 {"'use strict'; class ", "{}"}, 3984 {"'use strict'; class ", "{}"},
3959 {"'use strict'; (class ", "{});"}, 3985 {"'use strict'; (class ", "{});"},
3960 {NULL, NULL}}; 3986 {NULL, NULL}};
3961 const char* class_name[] = { 3987 const char* class_name[] = {
3962 "arguments", 3988 "arguments",
3963 "eval", 3989 "eval",
3964 "implements", 3990 "implements",
3965 "interface", 3991 "interface",
3966 "let", 3992 "let",
3967 "package", 3993 "package",
3968 "private", 3994 "private",
3969 "protected", 3995 "protected",
3970 "public", 3996 "public",
3971 "static", 3997 "static",
3972 "var", 3998 "var",
3973 "yield", 3999 "yield",
3974 NULL}; 4000 NULL};
3975 4001
3976 static const ParserFlag always_flags[] = { 4002 static const ParserFlag always_flags[] = {
3977 kAllowClasses, 4003 kAllowHarmonyClasses,
3978 kAllowHarmonyObjectLiterals 4004 kAllowHarmonyObjectLiterals,
4005 kAllowHarmonySloppy
3979 }; 4006 };
3980 RunParserSyncTest(context_data, class_name, kError, NULL, 0, 4007 RunParserSyncTest(context_data, class_name, kError, NULL, 0,
3981 always_flags, arraysize(always_flags)); 4008 always_flags, arraysize(always_flags));
3982 } 4009 }
3983 4010
3984 4011
3985 TEST(ClassGetterParamNameErrors) { 4012 TEST(ClassGetterParamNameErrors) {
3986 const char* context_data[][2] = { 4013 const char* context_data[][2] = {
3987 {"class C { get name(", ") {} }"}, 4014 {"class C { get name(", ") {} }"},
3988 {"(class { get name(", ") {} });"}, 4015 {"(class { get name(", ") {} });"},
(...skipping 11 matching lines...) Expand all
4000 "package", 4027 "package",
4001 "private", 4028 "private",
4002 "protected", 4029 "protected",
4003 "public", 4030 "public",
4004 "static", 4031 "static",
4005 "var", 4032 "var",
4006 "yield", 4033 "yield",
4007 NULL}; 4034 NULL};
4008 4035
4009 static const ParserFlag always_flags[] = { 4036 static const ParserFlag always_flags[] = {
4010 kAllowClasses, 4037 kAllowHarmonyClasses,
4011 kAllowHarmonyObjectLiterals 4038 kAllowHarmonyObjectLiterals,
4039 kAllowHarmonySloppy
4012 }; 4040 };
4013 RunParserSyncTest(context_data, class_name, kError, NULL, 0, 4041 RunParserSyncTest(context_data, class_name, kError, NULL, 0,
4014 always_flags, arraysize(always_flags)); 4042 always_flags, arraysize(always_flags));
4015 } 4043 }
4016 4044
4017 4045
4018 TEST(ClassStaticPrototypeErrors) { 4046 TEST(ClassStaticPrototypeErrors) {
4019 const char* context_data[][2] = {{"class C {", "}"}, 4047 const char* context_data[][2] = {{"class C {", "}"},
4020 {"(class {", "});"}, 4048 {"(class {", "});"},
4021 {NULL, NULL}}; 4049 {NULL, NULL}};
4022 4050
4023 const char* class_body_data[] = { 4051 const char* class_body_data[] = {
4024 "static prototype() {}", 4052 "static prototype() {}",
4025 "static get prototype() {}", 4053 "static get prototype() {}",
4026 "static set prototype(_) {}", 4054 "static set prototype(_) {}",
4027 "static *prototype() {}", 4055 "static *prototype() {}",
4028 "static 'prototype'() {}", 4056 "static 'prototype'() {}",
4029 "static *'prototype'() {}", 4057 "static *'prototype'() {}",
4030 "static prot\\u006ftype() {}", 4058 "static prot\\u006ftype() {}",
4031 "static 'prot\\u006ftype'() {}", 4059 "static 'prot\\u006ftype'() {}",
4032 "static get 'prot\\u006ftype'() {}", 4060 "static get 'prot\\u006ftype'() {}",
4033 "static set 'prot\\u006ftype'(_) {}", 4061 "static set 'prot\\u006ftype'(_) {}",
4034 "static *'prot\\u006ftype'() {}", 4062 "static *'prot\\u006ftype'() {}",
4035 NULL}; 4063 NULL};
4036 4064
4037 static const ParserFlag always_flags[] = { 4065 static const ParserFlag always_flags[] = {
4038 kAllowClasses, 4066 kAllowHarmonyClasses,
4039 kAllowHarmonyObjectLiterals 4067 kAllowHarmonyObjectLiterals,
4068 kAllowHarmonySloppy
4040 }; 4069 };
4041 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0, 4070 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0,
4042 always_flags, arraysize(always_flags)); 4071 always_flags, arraysize(always_flags));
4043 } 4072 }
4044 4073
4045 4074
4046 TEST(ClassSpecialConstructorErrors) { 4075 TEST(ClassSpecialConstructorErrors) {
4047 const char* context_data[][2] = {{"class C {", "}"}, 4076 const char* context_data[][2] = {{"class C {", "}"},
4048 {"(class {", "});"}, 4077 {"(class {", "});"},
4049 {NULL, NULL}}; 4078 {NULL, NULL}};
4050 4079
4051 const char* class_body_data[] = { 4080 const char* class_body_data[] = {
4052 "get constructor() {}", 4081 "get constructor() {}",
4053 "get constructor(_) {}", 4082 "get constructor(_) {}",
4054 "*constructor() {}", 4083 "*constructor() {}",
4055 "get 'constructor'() {}", 4084 "get 'constructor'() {}",
4056 "*'constructor'() {}", 4085 "*'constructor'() {}",
4057 "get c\\u006fnstructor() {}", 4086 "get c\\u006fnstructor() {}",
4058 "*c\\u006fnstructor() {}", 4087 "*c\\u006fnstructor() {}",
4059 "get 'c\\u006fnstructor'() {}", 4088 "get 'c\\u006fnstructor'() {}",
4060 "get 'c\\u006fnstructor'(_) {}", 4089 "get 'c\\u006fnstructor'(_) {}",
4061 "*'c\\u006fnstructor'() {}", 4090 "*'c\\u006fnstructor'() {}",
4062 NULL}; 4091 NULL};
4063 4092
4064 static const ParserFlag always_flags[] = { 4093 static const ParserFlag always_flags[] = {
4065 kAllowClasses, 4094 kAllowHarmonyClasses,
4066 kAllowHarmonyObjectLiterals 4095 kAllowHarmonyObjectLiterals,
4096 kAllowHarmonySloppy
4067 }; 4097 };
4068 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0, 4098 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0,
4069 always_flags, arraysize(always_flags)); 4099 always_flags, arraysize(always_flags));
4070 } 4100 }
4071 4101
4072 4102
4073 TEST(ClassConstructorNoErrors) { 4103 TEST(ClassConstructorNoErrors) {
4074 const char* context_data[][2] = {{"class C {", "}"}, 4104 const char* context_data[][2] = {{"class C {", "}"},
4075 {"(class {", "});"}, 4105 {"(class {", "});"},
4076 {NULL, NULL}}; 4106 {NULL, NULL}};
4077 4107
4078 const char* class_body_data[] = { 4108 const char* class_body_data[] = {
4079 "constructor() {}", 4109 "constructor() {}",
4080 "static constructor() {}", 4110 "static constructor() {}",
4081 "static get constructor() {}", 4111 "static get constructor() {}",
4082 "static set constructor(_) {}", 4112 "static set constructor(_) {}",
4083 "static *constructor() {}", 4113 "static *constructor() {}",
4084 NULL}; 4114 NULL};
4085 4115
4086 static const ParserFlag always_flags[] = { 4116 static const ParserFlag always_flags[] = {
4087 kAllowClasses, 4117 kAllowHarmonyClasses,
4088 kAllowHarmonyObjectLiterals 4118 kAllowHarmonyObjectLiterals,
4119 kAllowHarmonySloppy
4089 }; 4120 };
4090 RunParserSyncTest(context_data, class_body_data, kSuccess, NULL, 0, 4121 RunParserSyncTest(context_data, class_body_data, kSuccess, NULL, 0,
4091 always_flags, arraysize(always_flags)); 4122 always_flags, arraysize(always_flags));
4092 } 4123 }
4093 4124
4094 4125
4095 TEST(ClassMultipleConstructorErrors) { 4126 TEST(ClassMultipleConstructorErrors) {
4096 const char* context_data[][2] = {{"class C {", "}"}, 4127 const char* context_data[][2] = {{"class C {", "}"},
4097 {"(class {", "});"}, 4128 {"(class {", "});"},
4098 {NULL, NULL}}; 4129 {NULL, NULL}};
4099 4130
4100 const char* class_body_data[] = { 4131 const char* class_body_data[] = {
4101 "constructor() {}; constructor() {}", 4132 "constructor() {}; constructor() {}",
4102 NULL}; 4133 NULL};
4103 4134
4104 static const ParserFlag always_flags[] = { 4135 static const ParserFlag always_flags[] = {
4105 kAllowClasses, 4136 kAllowHarmonyClasses,
4106 kAllowHarmonyObjectLiterals 4137 kAllowHarmonyObjectLiterals,
4138 kAllowHarmonySloppy
4107 }; 4139 };
4108 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0, 4140 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0,
4109 always_flags, arraysize(always_flags)); 4141 always_flags, arraysize(always_flags));
4110 } 4142 }
4111 4143
4112 4144
4113 TEST(ClassMultiplePropertyNamesNoErrors) { 4145 TEST(ClassMultiplePropertyNamesNoErrors) {
4114 const char* context_data[][2] = {{"class C {", "}"}, 4146 const char* context_data[][2] = {{"class C {", "}"},
4115 {"(class {", "});"}, 4147 {"(class {", "});"},
4116 {NULL, NULL}}; 4148 {NULL, NULL}};
4117 4149
4118 const char* class_body_data[] = { 4150 const char* class_body_data[] = {
4119 "constructor() {}; static constructor() {}", 4151 "constructor() {}; static constructor() {}",
4120 "m() {}; static m() {}", 4152 "m() {}; static m() {}",
4121 "m() {}; m() {}", 4153 "m() {}; m() {}",
4122 "static m() {}; static m() {}", 4154 "static m() {}; static m() {}",
4123 "get m() {}; set m(_) {}; get m() {}; set m(_) {};", 4155 "get m() {}; set m(_) {}; get m() {}; set m(_) {};",
4124 NULL}; 4156 NULL};
4125 4157
4126 static const ParserFlag always_flags[] = { 4158 static const ParserFlag always_flags[] = {
4127 kAllowClasses, 4159 kAllowHarmonyClasses,
4128 kAllowHarmonyObjectLiterals 4160 kAllowHarmonyObjectLiterals,
4161 kAllowHarmonySloppy
4129 }; 4162 };
4130 RunParserSyncTest(context_data, class_body_data, kSuccess, NULL, 0, 4163 RunParserSyncTest(context_data, class_body_data, kSuccess, NULL, 0,
4131 always_flags, arraysize(always_flags)); 4164 always_flags, arraysize(always_flags));
4132 } 4165 }
4133 4166
4134 4167
4135 TEST(ClassesAreStrictErrors) { 4168 TEST(ClassesAreStrictErrors) {
4136 const char* context_data[][2] = {{"", ""}, 4169 const char* context_data[][2] = {{"", ""},
4137 {"(", ");"}, 4170 {"(", ");"},
4138 {NULL, NULL}}; 4171 {NULL, NULL}};
4139 4172
4140 const char* class_body_data[] = { 4173 const char* class_body_data[] = {
4141 "class C { method() { with ({}) {} } }", 4174 "class C { method() { with ({}) {} } }",
4142 "class C extends function() { with ({}) {} } {}", 4175 "class C extends function() { with ({}) {} } {}",
4143 "class C { *method() { with ({}) {} } }", 4176 "class C { *method() { with ({}) {} } }",
4144 NULL}; 4177 NULL};
4145 4178
4146 static const ParserFlag always_flags[] = { 4179 static const ParserFlag always_flags[] = {
4147 kAllowClasses, 4180 kAllowHarmonyClasses,
4148 kAllowHarmonyObjectLiterals 4181 kAllowHarmonyObjectLiterals,
4182 kAllowHarmonySloppy
4149 }; 4183 };
4150 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0, 4184 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0,
4151 always_flags, arraysize(always_flags)); 4185 always_flags, arraysize(always_flags));
4152 } 4186 }
4153 4187
4154 4188
4155 TEST(ObjectLiteralPropertyShorthandKeywordsError) { 4189 TEST(ObjectLiteralPropertyShorthandKeywordsError) {
4156 const char* context_data[][2] = {{"({", "});"}, 4190 const char* context_data[][2] = {{"({", "});"},
4157 {"'use strict'; ({", "});"}, 4191 {"'use strict'; ({", "});"},
4158 {NULL, NULL}}; 4192 {NULL, NULL}};
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
4438 const char* context_data[][2] = { 4472 const char* context_data[][2] = {
4439 {"", ""}, 4473 {"", ""},
4440 {"function f() {", "}"}, 4474 {"function f() {", "}"},
4441 {"{", "}"}, 4475 {"{", "}"},
4442 {NULL, NULL}}; 4476 {NULL, NULL}};
4443 const char* bad_data[] = { 4477 const char* bad_data[] = {
4444 "let x = 1;", 4478 "let x = 1;",
4445 "for(let x = 1;;){}", 4479 "for(let x = 1;;){}",
4446 "for(let x of []){}", 4480 "for(let x of []){}",
4447 "for(let x in []){}", 4481 "for(let x in []){}",
4482 "class C {}",
4483 "class C extends D {}",
4484 "(class {})",
4485 "(class extends D {})",
4486 "(class C {})",
4487 "(class C extends D {})",
4448 NULL}; 4488 NULL};
4449 static const ParserFlag always_flags[] = {kAllowHarmonyScoping}; 4489 static const ParserFlag always_true_flags[] = {
4450 RunParserSyncTest(context_data, bad_data, kError, NULL, 0, always_flags, 4490 kAllowHarmonyScoping, kAllowHarmonyClasses};
4451 arraysize(always_flags)); 4491 static const ParserFlag always_false_flags[] = {kAllowHarmonySloppy};
4492 RunParserSyncTest(context_data, bad_data, kError, NULL, 0,
4493 always_true_flags, arraysize(always_true_flags),
4494 always_false_flags, arraysize(always_false_flags));
4452 4495
4453 const char* good_data[] = { 4496 const char* good_data[] = {
4454 "let = 1;", 4497 "let = 1;",
4455 "for(let = 1;;){}", 4498 "for(let = 1;;){}",
4456 NULL}; 4499 NULL};
4457 RunParserSyncTest(context_data, good_data, kSuccess, NULL, 0, always_flags, 4500 RunParserSyncTest(context_data, good_data, kSuccess, NULL, 0,
4458 arraysize(always_flags)); 4501 always_true_flags, arraysize(always_true_flags),
4502 always_false_flags, arraysize(always_false_flags));
4459 } 4503 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698