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

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

Issue 2094463002: Allow trailing commas in function parameter lists (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: add tests with more than 1 parameter Created 4 years, 5 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/parsing/parser-base.h ('K') | « src/parsing/parser-base.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 1493 matching lines...) Expand 10 before | Expand all | Expand 10 after
1504 1504
1505 enum ParserFlag { 1505 enum ParserFlag {
1506 kAllowLazy, 1506 kAllowLazy,
1507 kAllowNatives, 1507 kAllowNatives,
1508 kAllowHarmonyFunctionSent, 1508 kAllowHarmonyFunctionSent,
1509 kAllowHarmonyRestrictiveDeclarations, 1509 kAllowHarmonyRestrictiveDeclarations,
1510 kAllowHarmonyExponentiationOperator, 1510 kAllowHarmonyExponentiationOperator,
1511 kAllowHarmonyForIn, 1511 kAllowHarmonyForIn,
1512 kAllowHarmonyAsyncAwait, 1512 kAllowHarmonyAsyncAwait,
1513 kAllowHarmonyRestrictiveGenerators, 1513 kAllowHarmonyRestrictiveGenerators,
1514 kAllowHarmonyTrailingCommasInParameters,
1514 }; 1515 };
1515 1516
1516 enum ParserSyncTestResult { 1517 enum ParserSyncTestResult {
1517 kSuccessOrError, 1518 kSuccessOrError,
1518 kSuccess, 1519 kSuccess,
1519 kError 1520 kError
1520 }; 1521 };
1521 1522
1522 template <typename Traits> 1523 template <typename Traits>
1523 void SetParserFlags(i::ParserBase<Traits>* parser, 1524 void SetParserFlags(i::ParserBase<Traits>* parser,
1524 i::EnumSet<ParserFlag> flags) { 1525 i::EnumSet<ParserFlag> flags) {
1525 parser->set_allow_lazy(flags.Contains(kAllowLazy)); 1526 parser->set_allow_lazy(flags.Contains(kAllowLazy));
1526 parser->set_allow_natives(flags.Contains(kAllowNatives)); 1527 parser->set_allow_natives(flags.Contains(kAllowNatives));
1527 parser->set_allow_harmony_function_sent( 1528 parser->set_allow_harmony_function_sent(
1528 flags.Contains(kAllowHarmonyFunctionSent)); 1529 flags.Contains(kAllowHarmonyFunctionSent));
1529 parser->set_allow_harmony_restrictive_declarations( 1530 parser->set_allow_harmony_restrictive_declarations(
1530 flags.Contains(kAllowHarmonyRestrictiveDeclarations)); 1531 flags.Contains(kAllowHarmonyRestrictiveDeclarations));
1531 parser->set_allow_harmony_exponentiation_operator( 1532 parser->set_allow_harmony_exponentiation_operator(
1532 flags.Contains(kAllowHarmonyExponentiationOperator)); 1533 flags.Contains(kAllowHarmonyExponentiationOperator));
1533 parser->set_allow_harmony_for_in(flags.Contains(kAllowHarmonyForIn)); 1534 parser->set_allow_harmony_for_in(flags.Contains(kAllowHarmonyForIn));
1534 parser->set_allow_harmony_async_await( 1535 parser->set_allow_harmony_async_await(
1535 flags.Contains(kAllowHarmonyAsyncAwait)); 1536 flags.Contains(kAllowHarmonyAsyncAwait));
1536 parser->set_allow_harmony_restrictive_generators( 1537 parser->set_allow_harmony_restrictive_generators(
1537 flags.Contains(kAllowHarmonyRestrictiveGenerators)); 1538 flags.Contains(kAllowHarmonyRestrictiveGenerators));
1539 parser->set_allow_harmony_trailing_commas_in_parameters(
1540 flags.Contains(kAllowHarmonyTrailingCommasInParameters));
1538 } 1541 }
1539 1542
1540 1543
1541 void TestParserSyncWithFlags(i::Handle<i::String> source, 1544 void TestParserSyncWithFlags(i::Handle<i::String> source,
1542 i::EnumSet<ParserFlag> flags, 1545 i::EnumSet<ParserFlag> flags,
1543 ParserSyncTestResult result, 1546 ParserSyncTestResult result,
1544 bool is_module = false, 1547 bool is_module = false,
1545 bool test_preparser = true) { 1548 bool test_preparser = true) {
1546 i::Isolate* isolate = CcTest::i_isolate(); 1549 i::Isolate* isolate = CcTest::i_isolate();
1547 i::Factory* factory = isolate->factory(); 1550 i::Factory* factory = isolate->factory();
(...skipping 6259 matching lines...) Expand 10 before | Expand all | Expand 10 after
7807 NULL}; 7810 NULL};
7808 static const ParserFlag always_flags[] = {kAllowHarmonyAsyncAwait}; 7811 static const ParserFlag always_flags[] = {kAllowHarmonyAsyncAwait};
7809 // The preparser doesn't enforce the restriction, so turn it off. 7812 // The preparser doesn't enforce the restriction, so turn it off.
7810 bool test_preparser = false; 7813 bool test_preparser = false;
7811 RunParserSyncTest(block_context_data, error_data, kError, NULL, 0, 7814 RunParserSyncTest(block_context_data, error_data, kError, NULL, 0,
7812 always_flags, arraysize(always_flags), NULL, 0, false, 7815 always_flags, arraysize(always_flags), NULL, 0, false,
7813 test_preparser); 7816 test_preparser);
7814 RunParserSyncTest(top_level_context_data, error_data, kSuccess, NULL, 0, 7817 RunParserSyncTest(top_level_context_data, error_data, kSuccess, NULL, 0,
7815 always_flags, arraysize(always_flags)); 7818 always_flags, arraysize(always_flags));
7816 } 7819 }
7820
7821 TEST(TrailingCommasInParameters) {
7822 // clang-format off
7823 const char* context_data[][2] = {
7824 { "", "" },
7825 { "'use strict';", "" },
7826 { "function foo() {", "}" },
7827 { "function foo() {'use strict';", "}" },
7828 { NULL, NULL }
7829 };
7830
7831 const char* data[] = {
7832 " function a(b,) {}",
7833 " function* a(b,) {}",
7834 "(function a(b,) {});",
7835 "(function* a(b,) {});",
7836 "(function (b,) {});",
7837 "(function* (b,) {});",
7838 " function a(b,c,d,) {}",
7839 " function* a(b,c,d,) {}",
7840 "(function a(b,c,d,) {});",
7841 "(function* a(b,c,d,) {});",
7842 "(function (b,c,d,) {});",
7843 "(function* (b,c,d,) {});",
7844 "(b,) => {};",
7845 "(b,c,d,) => {};",
7846 "a(1,);",
7847 "a(1,2,3,);",
7848 "a(...[],);",
7849 "a(1, 2, ...[],);",
7850 "a(...[], 2, ...[],);",
7851 NULL
7852 };
7853 // clang-format on
7854
7855 static const ParserFlag always_flags[] = {
7856 kAllowHarmonyTrailingCommasInParameters};
7857 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
7858 arraysize(always_flags));
7859 }
7860
7861 TEST(TrailingCommasInParametersErrors) {
7862 // clang-format off
7863 const char* context_data[][2] = {
7864 { "", "" },
7865 { "'use strict';", "" },
7866 { "function foo() {", "}" },
7867 { "function foo() {'use strict';", "}" },
7868 { NULL, NULL }
7869 };
7870
7871 const char* data[] = {
7872 // too many trailing commas
7873 " function a(b,,) {}",
7874 " function* a(b,,) {}",
7875 "(function a(b,,) {});",
7876 "(function* a(b,,) {});",
7877 "(function (b,,) {});",
7878 "(function* (b,,) {});",
7879 " function a(b,c,d,,) {}",
7880 " function* a(b,c,d,,) {}",
7881 "(function a(b,c,d,,) {});",
7882 "(function* a(b,c,d,,) {});",
7883 "(function (b,c,d,,) {});",
7884 "(function* (b,c,d,,) {});",
7885 "(b,,) => {};",
7886 "(b,c,d,,) => {};",
7887 "a(1,,);",
7888 "a(1,2,3,,);",
7889 // only a trailing comma and no parameters
7890 " function a1(,) {}",
7891 " function* a2(,) {}",
7892 "(function a3(,) {});",
7893 "(function* a4(,) {});",
7894 "(function (,) {});",
7895 "(function* (,) {});",
7896 "(,) => {};",
7897 "a1(,);",
7898 // no trailing commas after rest parameter declaration
7899 " function a(...b,) {}",
7900 " function* a(...b,) {}",
7901 "(function a(...b,) {});",
7902 "(function* a(...b,) {});",
7903 "(function (...b,) {});",
7904 "(function* (...b,) {});",
7905 " function a(b, c, ...d,) {}",
7906 " function* a(b, c, ...d,) {}",
7907 "(function a(b, c, ...d,) {});",
7908 "(function* a(b, c, ...d,) {});",
7909 "(function (b, c, ...d,) {});",
7910 "(function* (b, c, ...d,) {});",
7911 "(...b,) => {};",
7912 "(b, c, ...d,) => {};",
7913 // parenthesized trailing comma without arrow is still an error
7914 "(,);",
7915 "(a,);",
7916 "(a,b,c,);",
7917 NULL
7918 };
7919 // clang-format on
7920
7921 static const ParserFlag always_flags[] = {
7922 kAllowHarmonyTrailingCommasInParameters};
7923 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
7924 arraysize(always_flags));
7925 }
OLDNEW
« src/parsing/parser-base.h ('K') | « src/parsing/parser-base.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698