Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 { "'use strict';", "" }, | |
|
jwolfe
2016/06/22 18:04:41
Is this unnecessary? It looked like other tests we
jwolfe
2016/06/23 18:43:00
Never mind. I've changed this in a later patch.
| |
| 7825 { "", "" }, | |
| 7826 { NULL, NULL } | |
| 7827 }; | |
| 7828 | |
| 7829 const char* data[] = { | |
| 7830 " function a(b,) {}", | |
| 7831 " function* a(b,) {}", | |
| 7832 "(function a(b,) {});", | |
| 7833 "(function* a(b,) {});", | |
| 7834 "(function (b,) {});", | |
| 7835 "(function* (b,) {});", | |
| 7836 "(b,) => {};", | |
| 7837 "a(1,);", | |
| 7838 "a(...[],);", | |
| 7839 NULL | |
| 7840 }; | |
| 7841 // clang-format on | |
| 7842 | |
| 7843 static const ParserFlag always_flags[] = { | |
| 7844 kAllowHarmonyTrailingCommasInParameters}; | |
| 7845 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, | |
| 7846 arraysize(always_flags)); | |
| 7847 } | |
| 7848 | |
| 7849 TEST(TrailingCommasInParametersErrors) { | |
|
jwolfe
2016/06/22 18:04:41
should i combine these two tests? (effectively del
| |
| 7850 // clang-format off | |
| 7851 const char* context_data[][2] = { | |
| 7852 { "'use strict';", "" }, | |
| 7853 { "", "" }, | |
| 7854 { NULL, NULL } | |
| 7855 }; | |
| 7856 | |
| 7857 const char* data[] = { | |
| 7858 // too many trailing commas | |
| 7859 " function a(b,,) {}", | |
| 7860 " function* a(b,,) {}", | |
| 7861 "(function a(b,,) {});", | |
| 7862 "(function* a(b,,) {});", | |
| 7863 "(function (b,,) {});", | |
| 7864 "(function* (b,,) {});", | |
| 7865 "(b,,) => {};", | |
| 7866 "a(1,,);", | |
| 7867 // only a trailing comma and no parameters | |
| 7868 " function a1(,) {}", | |
| 7869 " function* a2(,) {}", | |
| 7870 "(function a3(,) {});", | |
| 7871 "(function* a4(,) {});", | |
| 7872 "(function (,) {});", | |
| 7873 "(function* (,) {});", | |
| 7874 "(,) => {};", | |
| 7875 "a1(,);", | |
| 7876 // no trailing commas after rest parameter declaration | |
| 7877 " function a(...b,) {}", | |
| 7878 " function* a(...b,) {}", | |
| 7879 "(function a(...b,) {});", | |
| 7880 "(function* a(...b,) {});", | |
| 7881 "(function (...b,) {});", | |
| 7882 "(function* (...b,) {});", | |
| 7883 "(...b,) => {};", | |
| 7884 NULL | |
| 7885 }; | |
| 7886 // clang-format on | |
| 7887 | |
| 7888 static const ParserFlag always_flags[] = { | |
| 7889 kAllowHarmonyTrailingCommasInParameters}; | |
| 7890 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | |
| 7891 arraysize(always_flags)); | |
| 7892 } | |
| OLD | NEW |