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

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

Issue 2315733003: Class fields, part 1 (parsing and infrastructure) (Closed)
Patch Set: 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
« src/ast/ast.h ('K') | « 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 NULL
4643 };
4644 // clang-format on
4645
4646 static const ParserFlag without_async[] = {kAllowHarmonyClassFields};
4647 RunParserSyncTest(context_data, class_body_data, kSuccess, NULL, 0,
4648 without_async, arraysize(without_async));
4649
4650 // clang-format off
4651 const char* async_data[] = {
4652 "async;",
4653 "async = 0;",
4654 "static async;"
4655 "async",
4656 "async = 0",
4657 "static async",
4658 "async\n a(){}", // a field named async, and a method named a.
4659 "async\n a",
Dan Ehrenberg 2016/09/06 23:55:59 How about some fields called await?
bakkot 2016/09/07 19:30:12 Done.
4660 NULL
4661 };
4662 // clang-format on
4663
4664 static const ParserFlag with_async[] = {kAllowHarmonyClassFields,
4665 kAllowHarmonyAsyncAwait};
4666 RunParserSyncTest(context_data, async_data, kSuccess, NULL, 0, with_async,
4667 arraysize(with_async));
4668 }
4669
4670 TEST(ClassFieldsErrors) {
4671 // clang-format off
4672 // Tests proposed class fields syntax.
4673 const char* context_data[][2] = {{"(class {", "});"},
4674 {"(class extends Base {", "});"},
4675 {"class C {", "}"},
4676 {"class C extends Base {", "}"},
4677 {NULL, NULL}};
4678 const char* class_body_data[] = {
4679 "a : 0",
4680 "a =",
4681 "*a = 0",
4682 "*a",
4683 "get a",
4684 "a : 0;",
4685 "a =;",
4686 "*a = 0;",
4687 "*a;",
4688 "get a;",
4689
4690 // ASI requires a linebreak
4691 "a b",
4692 "a = 0 b",
4693
4694 // ASI requires that the next token is not part of any legal production
4695 "a = 0\n *b(){}",
4696 "a = 0\n ['b'](){}",
4697 "get\n a",
Dan Ehrenberg 2016/09/06 23:55:59 How about some fields called yield?
bakkot 2016/09/07 19:30:12 Done. Though these are just property names, and ca
4698 NULL
4699 };
4700 // clang-format on
4701
4702 static const ParserFlag without_async[] = {kAllowHarmonyClassFields};
4703 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0,
4704 without_async, arraysize(without_async));
4705
4706 // clang-format off
4707 const char* async_data[] = {
4708 "async a = 0",
4709 "async a",
4710 NULL
4711 };
4712 // clang-format on
4713
4714 static const ParserFlag with_async[] = {kAllowHarmonyClassFields,
4715 kAllowHarmonyAsyncAwait};
4716 RunParserSyncTest(context_data, async_data, kError, NULL, 0, with_async,
4717 arraysize(with_async));
4718 }
4572 4719
4573 TEST(ClassExpressionErrors) { 4720 TEST(ClassExpressionErrors) {
4574 const char* context_data[][2] = {{"(", ");"}, 4721 const char* context_data[][2] = {{"(", ");"},
4575 {"var C = ", ";"}, 4722 {"var C = ", ";"},
4576 {"bar, ", ";"}, 4723 {"bar, ", ";"},
4577 {NULL, NULL}}; 4724 {NULL, NULL}};
4578 const char* class_data[] = { 4725 const char* class_data[] = {
4579 "class", 4726 "class",
4580 "class name", 4727 "class name",
4581 "class name extends", 4728 "class name extends",
(...skipping 3741 matching lines...) Expand 10 before | Expand all | Expand 10 after
8323 "(a,);", 8470 "(a,);",
8324 "(a,b,c,);", 8471 "(a,b,c,);",
8325 NULL 8472 NULL
8326 }; 8473 };
8327 // clang-format on 8474 // clang-format on
8328 8475
8329 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas}; 8476 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas};
8330 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 8477 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
8331 arraysize(always_flags)); 8478 arraysize(always_flags));
8332 } 8479 }
OLDNEW
« src/ast/ast.h ('K') | « src/parsing/preparser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698