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 2094463002: Allow trailing commas in function parameter lists (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: update grammar comment for FormalParameters to include trailing commas Created 4 years, 6 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/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) {
adamk 2016/06/23 22:08:49 Please add test cases with more than one parameter
jwolfe 2016/06/27 23:28:21 Done.
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 "(b,) => {};",
7839 "a(1,);",
7840 "a(...[],);",
7841 NULL
7842 };
7843 // clang-format on
7844
7845 static const ParserFlag always_flags[] = {
7846 kAllowHarmonyTrailingCommasInParameters};
7847 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
7848 arraysize(always_flags));
7849 }
7850
7851 TEST(TrailingCommasInParametersErrors) {
adamk 2016/06/23 22:08:49 Same here as above, please add tests with more tha
jwolfe 2016/06/27 23:28:21 Done.
7852 // clang-format off
7853 const char* context_data[][2] = {
7854 { "", "" },
7855 { "'use strict';", "" },
7856 { "function foo() {", "}" },
7857 { "function foo() {'use strict';", "}" },
7858 { NULL, NULL }
7859 };
7860
7861 const char* data[] = {
7862 // too many trailing commas
7863 " function a(b,,) {}",
7864 " function* a(b,,) {}",
7865 "(function a(b,,) {});",
7866 "(function* a(b,,) {});",
7867 "(function (b,,) {});",
7868 "(function* (b,,) {});",
7869 "(b,,) => {};",
7870 "a(1,,);",
7871 // only a trailing comma and no parameters
7872 " function a1(,) {}",
7873 " function* a2(,) {}",
7874 "(function a3(,) {});",
7875 "(function* a4(,) {});",
7876 "(function (,) {});",
7877 "(function* (,) {});",
7878 "(,) => {};",
7879 "a1(,);",
7880 // no trailing commas after rest parameter declaration
7881 " function a(...b,) {}",
7882 " function* a(...b,) {}",
7883 "(function a(...b,) {});",
7884 "(function* a(...b,) {});",
7885 "(function (...b,) {});",
7886 "(function* (...b,) {});",
7887 "(...b,) => {};",
7888 NULL
7889 };
7890 // clang-format on
7891
7892 static const ParserFlag always_flags[] = {
7893 kAllowHarmonyTrailingCommasInParameters};
7894 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
7895 arraysize(always_flags));
7896 }
OLDNEW
« no previous file with comments | « src/parsing/parser-base.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698