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

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

Issue 2329703002: Private fields
Patch Set: some comments 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
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 1473 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 kAllowHarmonyClassFields,
1494 kAllowHarmonyPrivateClassFields,
1494 }; 1495 };
1495 1496
1496 enum ParserSyncTestResult { 1497 enum ParserSyncTestResult {
1497 kSuccessOrError, 1498 kSuccessOrError,
1498 kSuccess, 1499 kSuccess,
1499 kError 1500 kError
1500 }; 1501 };
1501 1502
1502 template <typename Traits> 1503 template <typename Traits>
1503 void SetParserFlags(i::ParserBase<Traits>* parser, 1504 void SetParserFlags(i::ParserBase<Traits>* parser,
1504 i::EnumSet<ParserFlag> flags) { 1505 i::EnumSet<ParserFlag> flags) {
1505 parser->set_allow_lazy(flags.Contains(kAllowLazy)); 1506 parser->set_allow_lazy(flags.Contains(kAllowLazy));
1506 parser->set_allow_natives(flags.Contains(kAllowNatives)); 1507 parser->set_allow_natives(flags.Contains(kAllowNatives));
1507 parser->set_allow_harmony_function_sent( 1508 parser->set_allow_harmony_function_sent(
1508 flags.Contains(kAllowHarmonyFunctionSent)); 1509 flags.Contains(kAllowHarmonyFunctionSent));
1509 parser->set_allow_harmony_restrictive_declarations( 1510 parser->set_allow_harmony_restrictive_declarations(
1510 flags.Contains(kAllowHarmonyRestrictiveDeclarations)); 1511 flags.Contains(kAllowHarmonyRestrictiveDeclarations));
1511 parser->set_allow_harmony_for_in(flags.Contains(kAllowHarmonyForIn)); 1512 parser->set_allow_harmony_for_in(flags.Contains(kAllowHarmonyForIn));
1512 parser->set_allow_harmony_async_await( 1513 parser->set_allow_harmony_async_await(
1513 flags.Contains(kAllowHarmonyAsyncAwait)); 1514 flags.Contains(kAllowHarmonyAsyncAwait));
1514 parser->set_allow_harmony_restrictive_generators( 1515 parser->set_allow_harmony_restrictive_generators(
1515 flags.Contains(kAllowHarmonyRestrictiveGenerators)); 1516 flags.Contains(kAllowHarmonyRestrictiveGenerators));
1516 parser->set_allow_harmony_trailing_commas( 1517 parser->set_allow_harmony_trailing_commas(
1517 flags.Contains(kAllowHarmonyTrailingCommas)); 1518 flags.Contains(kAllowHarmonyTrailingCommas));
1518 parser->set_allow_harmony_class_fields( 1519 parser->set_allow_harmony_class_fields(
1519 flags.Contains(kAllowHarmonyClassFields)); 1520 flags.Contains(kAllowHarmonyClassFields));
1521 parser->set_allow_harmony_private_class_fields(
1522 flags.Contains(kAllowHarmonyPrivateClassFields));
1520 } 1523 }
1521 1524
1522 1525
1523 void TestParserSyncWithFlags(i::Handle<i::String> source, 1526 void TestParserSyncWithFlags(i::Handle<i::String> source,
1524 i::EnumSet<ParserFlag> flags, 1527 i::EnumSet<ParserFlag> flags,
1525 ParserSyncTestResult result, 1528 ParserSyncTestResult result,
1526 bool is_module = false, 1529 bool is_module = false,
1527 bool test_preparser = true) { 1530 bool test_preparser = true) {
1528 i::Isolate* isolate = CcTest::i_isolate(); 1531 i::Isolate* isolate = CcTest::i_isolate();
1529 i::Factory* factory = isolate->factory(); 1532 i::Factory* factory = isolate->factory();
(...skipping 3190 matching lines...) Expand 10 before | Expand all | Expand 10 after
4720 NULL 4723 NULL
4721 }; 4724 };
4722 // clang-format on 4725 // clang-format on
4723 4726
4724 static const ParserFlag with_async[] = {kAllowHarmonyClassFields, 4727 static const ParserFlag with_async[] = {kAllowHarmonyClassFields,
4725 kAllowHarmonyAsyncAwait}; 4728 kAllowHarmonyAsyncAwait};
4726 RunParserSyncTest(context_data, async_data, kError, NULL, 0, with_async, 4729 RunParserSyncTest(context_data, async_data, kError, NULL, 0, with_async,
4727 arraysize(with_async)); 4730 arraysize(with_async));
4728 } 4731 }
4729 4732
4733 TEST(ClassPrivatesNoErrors) {
4734 // clang-format off
4735 // Tests proposed class private fields syntax.
4736 const char* class_body_contexts[][2] = {{"(class {", "});"},
4737 {"(class extends Base {", "});"},
4738 {"class C {", "}"},
4739 {"class C extends Base {", "}"},
4740 {NULL, NULL}};
4741 const char* class_body_data[] = {
4742 // Basic syntax
4743 "#a = 0;",
4744 "#a = 0; #b",
4745 "#a = 0; b(){}",
4746 "#a = 0; *b(){}",
4747 "#a = 0; ['b'](){}",
4748 "#a;",
4749 "#a; #b;",
4750 "#a; b(){}",
4751 "#a; *b(){}",
4752 "#a; ['b'](){}",
4753
4754 // ASI
4755 "#a = 0\n",
4756 "#a = 0\n #b",
4757 "#a = 0\n b(){}",
4758 "#a\n",
4759 "#a\n #b\n",
4760 "#a\n b(){}",
4761 "#a\n *b(){}",
4762 "#a\n ['b'](){}",
4763
4764 // Misc edge cases
4765 "#yield",
4766 "#yield = 0",
4767 "#yield\n #a",
4768 NULL
4769 };
4770 // clang-format on
4771
4772 static const ParserFlag flags[] = {kAllowHarmonyPrivateClassFields};
4773 RunParserSyncTest(class_body_contexts, class_body_data, kSuccess, NULL, 0,
4774 flags, arraysize(flags));
4775
4776 // clang-format off
4777 const char* declaration_contexts[][2] = {{"(class { #x;", "});"},
4778 {"(class extends Base { #x;", "});"},
4779 {"class C { #x;", "}"},
4780 {"class C extends Base { #x;", "}"},
4781 {"(class {", "\n#x;});"},
4782 {NULL, NULL}};
4783 const char* declaration_bodies[] = {
4784 "m(){ ++#x; return #x; }",
4785 "m(o){ ++#x; return o.#x; }",
4786 "m(){ #x = 0; }",
4787 "m(o){ o.#x = 0; }",
4788 "m(){ ({a: #x} = {a: 0}); }",
4789 "m(){ ({a: o.#x} = {a: 0}); }",
4790 "static m(){ ++#x; return #x; }",
4791 "static m(o){ ++#x; return o.#x; }",
4792 "static m(){ #x = 0; }",
4793 "static m(o){ o.#x = 0; }",
4794 "static m(){ ({a: #x} = {a: 0}); }",
4795 "static m(){ ({a: o.#x} = {a: 0}); }",
4796 NULL
4797 };
4798 // clang-format on
4799
4800 RunParserSyncTest(declaration_contexts, declaration_bodies, kSuccess, NULL, 0,
4801 flags, arraysize(flags));
4802 }
4803
4804 TEST(ClassPrivatesErrors) {
4805 // clang-format off
4806 // Tests proposed class private fields syntax.
4807 const char* context_data[][2] = {{"(class {", "});"},
4808 {"(class extends Base {", "});"},
4809 {"class C {", "}"},
4810 {"class C extends Base {", "}"},
4811 {NULL, NULL}};
4812 // clang-format off
4813 const char* class_body_data[] = {
4814 "#x = 0\n *a(){}",
4815 "#['x'] = 0;",
4816 "#['x'];",
4817 "#x; #x;",
4818 "#x = 0; #x;",
4819 "#x = 0; #x = 0",
4820 NULL
4821 };
4822 // clang-format on
4823
4824 static const ParserFlag without_async[] = {kAllowHarmonyPrivateClassFields};
4825 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0,
4826 without_async, arraysize(without_async));
4827 }
4828
4730 TEST(ClassExpressionErrors) { 4829 TEST(ClassExpressionErrors) {
4731 const char* context_data[][2] = {{"(", ");"}, 4830 const char* context_data[][2] = {{"(", ");"},
4732 {"var C = ", ";"}, 4831 {"var C = ", ";"},
4733 {"bar, ", ";"}, 4832 {"bar, ", ";"},
4734 {NULL, NULL}}; 4833 {NULL, NULL}};
4735 const char* class_data[] = { 4834 const char* class_data[] = {
4736 "class", 4835 "class",
4737 "class name", 4836 "class name",
4738 "class name extends", 4837 "class name extends",
4739 "class extends", 4838 "class extends",
(...skipping 3740 matching lines...) Expand 10 before | Expand all | Expand 10 after
8480 "(a,);", 8579 "(a,);",
8481 "(a,b,c,);", 8580 "(a,b,c,);",
8482 NULL 8581 NULL
8483 }; 8582 };
8484 // clang-format on 8583 // clang-format on
8485 8584
8486 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas}; 8585 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas};
8487 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 8586 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
8488 arraysize(always_flags)); 8587 arraysize(always_flags));
8489 } 8588 }
OLDNEW
« no previous file with comments | « test/cctest/interpreter/bytecode_expectations/Generators.golden ('k') | test/mjsunit/harmony/class-privates-delete.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698