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

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

Issue 2315733003: Class fields, part 1 (parsing and infrastructure) (Closed)
Patch Set: whitespace Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/parsing/preparser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1472 matching lines...) Expand 10 before | Expand all | Expand 10 after
1483 1483
1484 enum ParserFlag { 1484 enum ParserFlag {
1485 kAllowLazy, 1485 kAllowLazy,
1486 kAllowNatives, 1486 kAllowNatives,
1487 kAllowHarmonyFunctionSent, 1487 kAllowHarmonyFunctionSent,
1488 kAllowHarmonyRestrictiveDeclarations, 1488 kAllowHarmonyRestrictiveDeclarations,
1489 kAllowHarmonyForIn, 1489 kAllowHarmonyForIn,
1490 kAllowHarmonyAsyncAwait, 1490 kAllowHarmonyAsyncAwait,
1491 kAllowHarmonyRestrictiveGenerators, 1491 kAllowHarmonyRestrictiveGenerators,
1492 kAllowHarmonyTrailingCommas, 1492 kAllowHarmonyTrailingCommas,
1493 kAllowHarmonyClassFields,
1493 }; 1494 };
1494 1495
1495 enum ParserSyncTestResult { 1496 enum ParserSyncTestResult {
1496 kSuccessOrError, 1497 kSuccessOrError,
1497 kSuccess, 1498 kSuccess,
1498 kError 1499 kError
1499 }; 1500 };
1500 1501
1501 template <typename Traits> 1502 template <typename Traits>
1502 void SetParserFlags(i::ParserBase<Traits>* parser, 1503 void SetParserFlags(i::ParserBase<Traits>* parser,
1503 i::EnumSet<ParserFlag> flags) { 1504 i::EnumSet<ParserFlag> flags) {
1504 parser->set_allow_lazy(flags.Contains(kAllowLazy)); 1505 parser->set_allow_lazy(flags.Contains(kAllowLazy));
1505 parser->set_allow_natives(flags.Contains(kAllowNatives)); 1506 parser->set_allow_natives(flags.Contains(kAllowNatives));
1506 parser->set_allow_harmony_function_sent( 1507 parser->set_allow_harmony_function_sent(
1507 flags.Contains(kAllowHarmonyFunctionSent)); 1508 flags.Contains(kAllowHarmonyFunctionSent));
1508 parser->set_allow_harmony_restrictive_declarations( 1509 parser->set_allow_harmony_restrictive_declarations(
1509 flags.Contains(kAllowHarmonyRestrictiveDeclarations)); 1510 flags.Contains(kAllowHarmonyRestrictiveDeclarations));
1510 parser->set_allow_harmony_for_in(flags.Contains(kAllowHarmonyForIn)); 1511 parser->set_allow_harmony_for_in(flags.Contains(kAllowHarmonyForIn));
1511 parser->set_allow_harmony_async_await( 1512 parser->set_allow_harmony_async_await(
1512 flags.Contains(kAllowHarmonyAsyncAwait)); 1513 flags.Contains(kAllowHarmonyAsyncAwait));
1513 parser->set_allow_harmony_restrictive_generators( 1514 parser->set_allow_harmony_restrictive_generators(
1514 flags.Contains(kAllowHarmonyRestrictiveGenerators)); 1515 flags.Contains(kAllowHarmonyRestrictiveGenerators));
1515 parser->set_allow_harmony_trailing_commas( 1516 parser->set_allow_harmony_trailing_commas(
1516 flags.Contains(kAllowHarmonyTrailingCommas)); 1517 flags.Contains(kAllowHarmonyTrailingCommas));
1518 parser->set_allow_harmony_class_fields(
1519 flags.Contains(kAllowHarmonyClassFields));
1517 } 1520 }
1518 1521
1519 1522
1520 void TestParserSyncWithFlags(i::Handle<i::String> source, 1523 void TestParserSyncWithFlags(i::Handle<i::String> source,
1521 i::EnumSet<ParserFlag> flags, 1524 i::EnumSet<ParserFlag> flags,
1522 ParserSyncTestResult result, 1525 ParserSyncTestResult result,
1523 bool is_module = false, 1526 bool is_module = false,
1524 bool test_preparser = true) { 1527 bool test_preparser = true) {
1525 i::Isolate* isolate = CcTest::i_isolate(); 1528 i::Isolate* isolate = CcTest::i_isolate();
1526 i::Factory* factory = isolate->factory(); 1529 i::Factory* factory = isolate->factory();
(...skipping 3035 matching lines...) Expand 10 before | Expand all | Expand 10 after
4562 "while", 4565 "while",
4563 "do", 4566 "do",
4564 "try", 4567 "try",
4565 "catch", 4568 "catch",
4566 "finally", 4569 "finally",
4567 NULL}; 4570 NULL};
4568 4571
4569 RunParserSyncTest(context_data, name_data, kSuccess); 4572 RunParserSyncTest(context_data, name_data, kSuccess);
4570 } 4573 }
4571 4574
4575 TEST(ClassFieldsNoErrors) {
4576 // clang-format off
4577 // Tests proposed class fields syntax.
4578 const char* context_data[][2] = {{"(class {", "});"},
4579 {"(class extends Base {", "});"},
4580 {"class C {", "}"},
4581 {"class C extends Base {", "}"},
4582 {NULL, NULL}};
4583 const char* class_body_data[] = {
4584 // Basic syntax
4585 "a = 0;",
4586 "a = 0; b",
4587 "a = 0; b(){}",
4588 "a = 0; *b(){}",
4589 "a = 0; ['b'](){}",
4590 "a;",
4591 "a; b;",
4592 "a; b(){}",
4593 "a; *b(){}",
4594 "a; ['b'](){}",
4595 "['a'] = 0;",
4596 "['a'] = 0; b",
4597 "['a'] = 0; b(){}",
4598 "['a'] = 0; *b(){}",
4599 "['a'] = 0; ['b'](){}",
4600 "['a'];",
4601 "['a']; b;",
4602 "['a']; b(){}",
4603 "['a']; *b(){}",
4604 "['a']; ['b'](){}",
4605
4606 "0 = 0;",
4607 "0;",
4608 "'a' = 0;",
4609 "'a';",
4610
4611 "static a = 0;",
4612 "static a;",
4613 "static ['a'] = 0",
4614 "static ['a']",
4615 "static 0 = 0;",
4616 "static 0;",
4617 "static 'a' = 0;",
4618 "static 'a';",
4619
4620 // ASI
4621 "a = 0\n",
4622 "a = 0\n b",
4623 "a = 0\n b(){}",
4624 "a\n",
4625 "a\n b\n",
4626 "a\n b(){}",
4627 "a\n *b(){}",
4628 "a\n ['b'](){}",
4629 "['a'] = 0\n",
4630 "['a'] = 0\n b",
4631 "['a'] = 0\n b(){}",
4632 "['a']\n",
4633 "['a']\n b\n",
4634 "['a']\n b(){}",
4635 "['a']\n *b(){}",
4636 "['a']\n ['b'](){}",
4637
4638 // ASI edge cases
4639 "a\n get",
4640 "get\n *a(){}",
4641 "a\n static",
4642
4643 // Misc edge cases
4644 "yield",
4645 "yield = 0",
4646 "yield\n a",
4647 NULL
4648 };
4649 // clang-format on
4650
4651 static const ParserFlag without_async[] = {kAllowHarmonyClassFields};
4652 RunParserSyncTest(context_data, class_body_data, kSuccess, NULL, 0,
4653 without_async, arraysize(without_async));
4654
4655 // clang-format off
4656 const char* async_data[] = {
4657 "async;",
4658 "async = 0;",
4659 "static async;"
4660 "async",
4661 "async = 0",
4662 "static async",
4663 "async\n a(){}", // a field named async, and a method named a.
4664 "async\n a",
4665 "await;",
4666 "await = 0;",
4667 "await\n a",
4668 NULL
4669 };
4670 // clang-format on
4671
4672 static const ParserFlag with_async[] = {kAllowHarmonyClassFields,
4673 kAllowHarmonyAsyncAwait};
4674 RunParserSyncTest(context_data, async_data, kSuccess, NULL, 0, with_async,
4675 arraysize(with_async));
4676 }
4677
4678 TEST(ClassFieldsErrors) {
4679 // clang-format off
4680 // Tests proposed class fields syntax.
4681 const char* context_data[][2] = {{"(class {", "});"},
4682 {"(class extends Base {", "});"},
4683 {"class C {", "}"},
4684 {"class C extends Base {", "}"},
4685 {NULL, NULL}};
4686 const char* class_body_data[] = {
4687 "a : 0",
4688 "a =",
4689 "*a = 0",
4690 "*a",
4691 "get a",
4692 "yield a",
4693 "a : 0;",
4694 "a =;",
4695 "*a = 0;",
4696 "*a;",
4697 "get a;",
4698 "yield a;",
4699
4700 // ASI requires a linebreak
4701 "a b",
4702 "a = 0 b",
4703
4704 // ASI requires that the next token is not part of any legal production
4705 "a = 0\n *b(){}",
4706 "a = 0\n ['b'](){}",
4707 "get\n a",
4708 NULL
4709 };
4710 // clang-format on
4711
4712 static const ParserFlag without_async[] = {kAllowHarmonyClassFields};
4713 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0,
4714 without_async, arraysize(without_async));
4715
4716 // clang-format off
4717 const char* async_data[] = {
4718 "async a = 0",
4719 "async a",
4720 NULL
4721 };
4722 // clang-format on
4723
4724 static const ParserFlag with_async[] = {kAllowHarmonyClassFields,
4725 kAllowHarmonyAsyncAwait};
4726 RunParserSyncTest(context_data, async_data, kError, NULL, 0, with_async,
4727 arraysize(with_async));
4728 }
4572 4729
4573 TEST(ClassExpressionErrors) { 4730 TEST(ClassExpressionErrors) {
4574 const char* context_data[][2] = {{"(", ");"}, 4731 const char* context_data[][2] = {{"(", ");"},
4575 {"var C = ", ";"}, 4732 {"var C = ", ";"},
4576 {"bar, ", ";"}, 4733 {"bar, ", ";"},
4577 {NULL, NULL}}; 4734 {NULL, NULL}};
4578 const char* class_data[] = { 4735 const char* class_data[] = {
4579 "class", 4736 "class",
4580 "class name", 4737 "class name",
4581 "class name extends", 4738 "class name extends",
(...skipping 3741 matching lines...) Expand 10 before | Expand all | Expand 10 after
8323 "(a,);", 8480 "(a,);",
8324 "(a,b,c,);", 8481 "(a,b,c,);",
8325 NULL 8482 NULL
8326 }; 8483 };
8327 // clang-format on 8484 // clang-format on
8328 8485
8329 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas}; 8486 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas};
8330 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 8487 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
8331 arraysize(always_flags)); 8488 arraysize(always_flags));
8332 } 8489 }
OLDNEW
« no previous file with comments | « src/parsing/preparser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698