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 1491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1502 return i::MessageTemplate::FormatMessage(isolate, message, arg_object); | 1502 return i::MessageTemplate::FormatMessage(isolate, message, arg_object); |
1503 } | 1503 } |
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 }; | 1514 }; |
1514 | 1515 |
1515 enum ParserSyncTestResult { | 1516 enum ParserSyncTestResult { |
1516 kSuccessOrError, | 1517 kSuccessOrError, |
1517 kSuccess, | 1518 kSuccess, |
1518 kError | 1519 kError |
1519 }; | 1520 }; |
1520 | 1521 |
1521 template <typename Traits> | 1522 template <typename Traits> |
1522 void SetParserFlags(i::ParserBase<Traits>* parser, | 1523 void SetParserFlags(i::ParserBase<Traits>* parser, |
1523 i::EnumSet<ParserFlag> flags) { | 1524 i::EnumSet<ParserFlag> flags) { |
1524 parser->set_allow_lazy(flags.Contains(kAllowLazy)); | 1525 parser->set_allow_lazy(flags.Contains(kAllowLazy)); |
1525 parser->set_allow_natives(flags.Contains(kAllowNatives)); | 1526 parser->set_allow_natives(flags.Contains(kAllowNatives)); |
1526 parser->set_allow_harmony_function_sent( | 1527 parser->set_allow_harmony_function_sent( |
1527 flags.Contains(kAllowHarmonyFunctionSent)); | 1528 flags.Contains(kAllowHarmonyFunctionSent)); |
1528 parser->set_allow_harmony_restrictive_declarations( | 1529 parser->set_allow_harmony_restrictive_declarations( |
1529 flags.Contains(kAllowHarmonyRestrictiveDeclarations)); | 1530 flags.Contains(kAllowHarmonyRestrictiveDeclarations)); |
1530 parser->set_allow_harmony_exponentiation_operator( | 1531 parser->set_allow_harmony_exponentiation_operator( |
1531 flags.Contains(kAllowHarmonyExponentiationOperator)); | 1532 flags.Contains(kAllowHarmonyExponentiationOperator)); |
1532 parser->set_allow_harmony_for_in(flags.Contains(kAllowHarmonyForIn)); | 1533 parser->set_allow_harmony_for_in(flags.Contains(kAllowHarmonyForIn)); |
1533 parser->set_allow_harmony_async_await( | 1534 parser->set_allow_harmony_async_await( |
1534 flags.Contains(kAllowHarmonyAsyncAwait)); | 1535 flags.Contains(kAllowHarmonyAsyncAwait)); |
| 1536 parser->set_allow_harmony_restrictive_generators( |
| 1537 flags.Contains(kAllowHarmonyRestrictiveGenerators)); |
1535 } | 1538 } |
1536 | 1539 |
1537 | 1540 |
1538 void TestParserSyncWithFlags(i::Handle<i::String> source, | 1541 void TestParserSyncWithFlags(i::Handle<i::String> source, |
1539 i::EnumSet<ParserFlag> flags, | 1542 i::EnumSet<ParserFlag> flags, |
1540 ParserSyncTestResult result, | 1543 ParserSyncTestResult result, |
1541 bool is_module = false, | 1544 bool is_module = false, |
1542 bool test_preparser = true) { | 1545 bool test_preparser = true) { |
1543 i::Isolate* isolate = CcTest::i_isolate(); | 1546 i::Isolate* isolate = CcTest::i_isolate(); |
1544 i::Factory* factory = isolate->factory(); | 1547 i::Factory* factory = isolate->factory(); |
(...skipping 6179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7724 "for (const x = 0 in {});", | 7727 "for (const x = 0 in {});", |
7725 "for (let x = 0 in {});", | 7728 "for (let x = 0 in {});", |
7726 NULL | 7729 NULL |
7727 }; | 7730 }; |
7728 // clang-format on | 7731 // clang-format on |
7729 | 7732 |
7730 static const ParserFlag always_flags[] = {kAllowHarmonyForIn}; | 7733 static const ParserFlag always_flags[] = {kAllowHarmonyForIn}; |
7731 RunParserSyncTest(context_data, error_data, kError, nullptr, 0, always_flags, | 7734 RunParserSyncTest(context_data, error_data, kError, nullptr, 0, always_flags, |
7732 arraysize(always_flags)); | 7735 arraysize(always_flags)); |
7733 } | 7736 } |
| 7737 |
| 7738 TEST(NoDuplicateGeneratorsInBlock) { |
| 7739 const char* block_context_data[][2] = { |
| 7740 {"'use strict'; {", "}"}, |
| 7741 {"{", "}"}, |
| 7742 {"(function() { {", "} })()"}, |
| 7743 {"(function() {'use strict'; {", "} })()"}, |
| 7744 {NULL, NULL}}; |
| 7745 const char* top_level_context_data[][2] = { |
| 7746 {"'use strict';", ""}, |
| 7747 {"", ""}, |
| 7748 {"(function() {", "})()"}, |
| 7749 {"(function() {'use strict';", "})()"}, |
| 7750 {NULL, NULL}}; |
| 7751 const char* error_data[] = {"function* x() {} function* x() {}", |
| 7752 "function x() {} function* x() {}", |
| 7753 "function* x() {} function x() {}", NULL}; |
| 7754 static const ParserFlag always_flags[] = {kAllowHarmonyRestrictiveGenerators}; |
| 7755 // The preparser doesn't enforce the restriction, so turn it off. |
| 7756 bool test_preparser = false; |
| 7757 RunParserSyncTest(block_context_data, error_data, kError, NULL, 0, |
| 7758 always_flags, arraysize(always_flags), NULL, 0, false, |
| 7759 test_preparser); |
| 7760 RunParserSyncTest(top_level_context_data, error_data, kSuccess, NULL, 0, |
| 7761 always_flags, arraysize(always_flags)); |
| 7762 } |
| 7763 |
| 7764 TEST(NoDuplicateAsyncFunctionInBlock) { |
| 7765 const char* block_context_data[][2] = { |
| 7766 {"'use strict'; {", "}"}, |
| 7767 {"{", "}"}, |
| 7768 {"(function() { {", "} })()"}, |
| 7769 {"(function() {'use strict'; {", "} })()"}, |
| 7770 {NULL, NULL}}; |
| 7771 const char* top_level_context_data[][2] = { |
| 7772 {"'use strict';", ""}, |
| 7773 {"", ""}, |
| 7774 {"(function() {", "})()"}, |
| 7775 {"(function() {'use strict';", "})()"}, |
| 7776 {NULL, NULL}}; |
| 7777 const char* error_data[] = {"async function x() {} async function x() {}", |
| 7778 "function x() {} async function x() {}", |
| 7779 "async function x() {} function x() {}", |
| 7780 "function* x() {} async function x() {}", |
| 7781 "function* x() {} async function x() {}", |
| 7782 "async function x() {} function* x() {}", |
| 7783 "function* x() {} async function x() {}", |
| 7784 NULL}; |
| 7785 static const ParserFlag always_flags[] = {kAllowHarmonyAsyncAwait}; |
| 7786 // The preparser doesn't enforce the restriction, so turn it off. |
| 7787 bool test_preparser = false; |
| 7788 RunParserSyncTest(block_context_data, error_data, kError, NULL, 0, |
| 7789 always_flags, arraysize(always_flags), NULL, 0, false, |
| 7790 test_preparser); |
| 7791 RunParserSyncTest(top_level_context_data, error_data, kSuccess, NULL, 0, |
| 7792 always_flags, arraysize(always_flags)); |
| 7793 } |
OLD | NEW |