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 3709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3720 "(c, a.b) => {}", | 3720 "(c, a.b) => {}", |
3721 "(a['b'], c) => {}", | 3721 "(a['b'], c) => {}", |
3722 "(c, a['b']) => {}", | 3722 "(c, a['b']) => {}", |
3723 NULL | 3723 NULL |
3724 }; | 3724 }; |
3725 | 3725 |
3726 // The test is quite slow, so run it with a reduced set of flags. | 3726 // The test is quite slow, so run it with a reduced set of flags. |
3727 static const ParserFlag flags[] = {kAllowLazy}; | 3727 static const ParserFlag flags[] = {kAllowLazy}; |
3728 RunParserSyncTest(context_data, statement_data, kError, flags, | 3728 RunParserSyncTest(context_data, statement_data, kError, flags, |
3729 arraysize(flags)); | 3729 arraysize(flags)); |
| 3730 |
| 3731 // In a context where a concise arrow body is parsed with [~In] variant, |
| 3732 // ensure that an error is reported in both full parser and preparser. |
| 3733 const char* loop_context_data[][2] = {{"for (", "; 0;);"}, |
| 3734 {nullptr, nullptr}}; |
| 3735 const char* loop_expr_data[] = {"f => 'key' in {}", nullptr}; |
| 3736 RunParserSyncTest(loop_context_data, loop_expr_data, kError, flags, |
| 3737 arraysize(flags)); |
3730 } | 3738 } |
3731 | 3739 |
3732 | 3740 |
3733 TEST(NoErrorsArrowFunctions) { | 3741 TEST(NoErrorsArrowFunctions) { |
3734 // Tests that parser and preparser accept valid arrow functions syntax. | 3742 // Tests that parser and preparser accept valid arrow functions syntax. |
3735 const char* context_data[][2] = { | 3743 const char* context_data[][2] = { |
3736 {"", ";"}, | 3744 {"", ";"}, |
3737 {"bar ? (", ") : baz;"}, | 3745 {"bar ? (", ") : baz;"}, |
3738 {"bar ? baz : (", ");"}, | 3746 {"bar ? baz : (", ");"}, |
3739 {"bar, ", ";"}, | 3747 {"bar, ", ";"}, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3794 "({a = 42}) => {}", | 3802 "({a = 42}) => {}", |
3795 "([x = 0]) => {}", | 3803 "([x = 0]) => {}", |
3796 NULL | 3804 NULL |
3797 }; | 3805 }; |
3798 | 3806 |
3799 static const ParserFlag always_flags[] = {kAllowHarmonyDefaultParameters, | 3807 static const ParserFlag always_flags[] = {kAllowHarmonyDefaultParameters, |
3800 kAllowHarmonyRestParameters, | 3808 kAllowHarmonyRestParameters, |
3801 kAllowHarmonyDestructuring}; | 3809 kAllowHarmonyDestructuring}; |
3802 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | 3810 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, |
3803 always_flags, arraysize(always_flags)); | 3811 always_flags, arraysize(always_flags)); |
| 3812 |
| 3813 static const ParserFlag flags[] = {kAllowLazy}; |
| 3814 // In a context where a concise arrow body is parsed with [~In] variant, |
| 3815 // ensure that nested expressions can still use the 'in' operator, |
| 3816 const char* loop_context_data[][2] = {{"for (", "; 0;);"}, |
| 3817 {nullptr, nullptr}}; |
| 3818 const char* loop_expr_data[] = {"f => ('key' in {})", nullptr}; |
| 3819 RunParserSyncTest(loop_context_data, loop_expr_data, kSuccess, flags, |
| 3820 arraysize(flags)); |
3804 } | 3821 } |
3805 | 3822 |
3806 | 3823 |
3807 TEST(ArrowFunctionsSloppyParameterNames) { | 3824 TEST(ArrowFunctionsSloppyParameterNames) { |
3808 const char* strong_context_data[][2] = { | 3825 const char* strong_context_data[][2] = { |
3809 {"'use strong'; ", ";"}, | 3826 {"'use strong'; ", ";"}, |
3810 {"'use strong'; bar ? (", ") : baz;"}, | 3827 {"'use strong'; bar ? (", ") : baz;"}, |
3811 {"'use strong'; bar ? baz : (", ");"}, | 3828 {"'use strong'; bar ? baz : (", ");"}, |
3812 {"'use strong'; bar, ", ";"}, | 3829 {"'use strong'; bar, ", ";"}, |
3813 {"'use strong'; ", ", bar;"}, | 3830 {"'use strong'; ", ", bar;"}, |
(...skipping 3420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7234 NULL | 7251 NULL |
7235 }; | 7252 }; |
7236 // clang-format on | 7253 // clang-format on |
7237 | 7254 |
7238 static const ParserFlag fail_flags[] = { | 7255 static const ParserFlag fail_flags[] = { |
7239 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kNoLegacyConst, | 7256 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kNoLegacyConst, |
7240 kAllowHarmonyDestructuring}; | 7257 kAllowHarmonyDestructuring}; |
7241 RunParserSyncTest(context_data, fail_data, kError, NULL, 0, fail_flags, | 7258 RunParserSyncTest(context_data, fail_data, kError, NULL, 0, fail_flags, |
7242 arraysize(fail_flags)); | 7259 arraysize(fail_flags)); |
7243 } | 7260 } |
OLD | NEW |