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 1408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1419 | 1419 |
1420 data.Dispose(); | 1420 data.Dispose(); |
1421 return i::MessageTemplate::FormatMessage(isolate, message, arg_object); | 1421 return i::MessageTemplate::FormatMessage(isolate, message, arg_object); |
1422 } | 1422 } |
1423 | 1423 |
1424 | 1424 |
1425 enum ParserFlag { | 1425 enum ParserFlag { |
1426 kAllowLazy, | 1426 kAllowLazy, |
1427 kAllowNatives, | 1427 kAllowNatives, |
1428 kAllowHarmonyArrowFunctions, | 1428 kAllowHarmonyArrowFunctions, |
| 1429 kAllowHarmonyDefaultParameters, |
1429 kAllowHarmonyRestParameters, | 1430 kAllowHarmonyRestParameters, |
1430 kAllowHarmonySloppy, | 1431 kAllowHarmonySloppy, |
1431 kAllowHarmonySloppyLet, | 1432 kAllowHarmonySloppyLet, |
1432 kAllowHarmonySpreadCalls, | 1433 kAllowHarmonySpreadCalls, |
1433 kAllowHarmonyDestructuring, | 1434 kAllowHarmonyDestructuring, |
1434 kAllowHarmonySpreadArrays, | 1435 kAllowHarmonySpreadArrays, |
1435 kAllowHarmonyNewTarget, | 1436 kAllowHarmonyNewTarget, |
1436 kAllowStrongMode, | 1437 kAllowStrongMode, |
1437 kNoLegacyConst | 1438 kNoLegacyConst |
1438 }; | 1439 }; |
1439 | 1440 |
1440 | 1441 |
1441 enum ParserSyncTestResult { | 1442 enum ParserSyncTestResult { |
1442 kSuccessOrError, | 1443 kSuccessOrError, |
1443 kSuccess, | 1444 kSuccess, |
1444 kError | 1445 kError |
1445 }; | 1446 }; |
1446 | 1447 |
1447 template <typename Traits> | 1448 template <typename Traits> |
1448 void SetParserFlags(i::ParserBase<Traits>* parser, | 1449 void SetParserFlags(i::ParserBase<Traits>* parser, |
1449 i::EnumSet<ParserFlag> flags) { | 1450 i::EnumSet<ParserFlag> flags) { |
1450 parser->set_allow_lazy(flags.Contains(kAllowLazy)); | 1451 parser->set_allow_lazy(flags.Contains(kAllowLazy)); |
1451 parser->set_allow_natives(flags.Contains(kAllowNatives)); | 1452 parser->set_allow_natives(flags.Contains(kAllowNatives)); |
1452 parser->set_allow_harmony_arrow_functions( | 1453 parser->set_allow_harmony_arrow_functions( |
1453 flags.Contains(kAllowHarmonyArrowFunctions)); | 1454 flags.Contains(kAllowHarmonyArrowFunctions)); |
| 1455 parser->set_allow_harmony_default_parameters( |
| 1456 flags.Contains(kAllowHarmonyDefaultParameters)); |
1454 parser->set_allow_harmony_rest_parameters( | 1457 parser->set_allow_harmony_rest_parameters( |
1455 flags.Contains(kAllowHarmonyRestParameters)); | 1458 flags.Contains(kAllowHarmonyRestParameters)); |
1456 parser->set_allow_harmony_spreadcalls( | 1459 parser->set_allow_harmony_spreadcalls( |
1457 flags.Contains(kAllowHarmonySpreadCalls)); | 1460 flags.Contains(kAllowHarmonySpreadCalls)); |
1458 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); | 1461 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); |
1459 parser->set_allow_harmony_sloppy_let(flags.Contains(kAllowHarmonySloppyLet)); | 1462 parser->set_allow_harmony_sloppy_let(flags.Contains(kAllowHarmonySloppyLet)); |
1460 parser->set_allow_harmony_destructuring( | 1463 parser->set_allow_harmony_destructuring( |
1461 flags.Contains(kAllowHarmonyDestructuring)); | 1464 flags.Contains(kAllowHarmonyDestructuring)); |
1462 parser->set_allow_harmony_spread_arrays( | 1465 parser->set_allow_harmony_spread_arrays( |
1463 flags.Contains(kAllowHarmonySpreadArrays)); | 1466 flags.Contains(kAllowHarmonySpreadArrays)); |
(...skipping 2259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3723 "a, b => 0", | 3726 "a, b => 0", |
3724 "a, b, (c, d) => 0", | 3727 "a, b, (c, d) => 0", |
3725 "(a, b, (c, d) => 0)", | 3728 "(a, b, (c, d) => 0)", |
3726 "(a, b) => 0, (c, d) => 1", | 3729 "(a, b) => 0, (c, d) => 1", |
3727 "(a, b => {}, a => a + 1)", | 3730 "(a, b => {}, a => a + 1)", |
3728 "((a, b) => {}, (a => a + 1))", | 3731 "((a, b) => {}, (a => a + 1))", |
3729 "(a, (a, (b, c) => 0))", | 3732 "(a, (a, (b, c) => 0))", |
3730 | 3733 |
3731 // Arrow has more precedence, this is the same as: foo ? bar : (baz = {}) | 3734 // Arrow has more precedence, this is the same as: foo ? bar : (baz = {}) |
3732 "foo ? bar : baz => {}", | 3735 "foo ? bar : baz => {}", |
| 3736 |
| 3737 // Arrows with non-simple parameters. |
| 3738 "({a}) => {}", |
| 3739 "(x = 9) => {}", |
| 3740 "(x, y = 9) => {}", |
| 3741 "(x = 9, y) => {}", |
| 3742 "(x, y = 9, z) => {}", |
| 3743 "(x, y = 9, z = 8) => {}", |
| 3744 "(...a) => {}", |
| 3745 "(x, ...a) => {}", |
| 3746 "(x = 9, ...a) => {}", |
| 3747 "(x, y = 9, ...a) => {}", |
| 3748 "(x, y = 9, {b}, z = 8, ...a) => {}", |
| 3749 // TODO(wingo, rossberg): This is not accepted right now. |
| 3750 // "({a} = {}) => {}", |
| 3751 // "([x] = []) => {}", |
| 3752 "({a = 42}) => {}", |
| 3753 "([x = 0]) => {}", |
3733 NULL | 3754 NULL |
3734 }; | 3755 }; |
3735 | 3756 |
3736 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions}; | 3757 static const ParserFlag always_flags[] = { |
| 3758 kAllowHarmonyArrowFunctions, kAllowHarmonyDefaultParameters, |
| 3759 kAllowHarmonyRestParameters, kAllowHarmonyDestructuring}; |
3737 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | 3760 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, |
3738 always_flags, arraysize(always_flags)); | 3761 always_flags, arraysize(always_flags)); |
3739 } | 3762 } |
3740 | 3763 |
3741 | 3764 |
3742 TEST(ArrowFunctionsSloppyParameterNames) { | 3765 TEST(ArrowFunctionsSloppyParameterNames) { |
3743 const char* strong_context_data[][2] = { | 3766 const char* strong_context_data[][2] = { |
3744 {"'use strong'; ", ";"}, | 3767 {"'use strong'; ", ";"}, |
3745 {"'use strong'; bar ? (", ") : baz;"}, | 3768 {"'use strong'; bar ? (", ") : baz;"}, |
3746 {"'use strong'; bar ? baz : (", ");"}, | 3769 {"'use strong'; bar ? baz : (", ");"}, |
(...skipping 3125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6872 "for (let x of []) {}", | 6895 "for (let x of []) {}", |
6873 NULL | 6896 NULL |
6874 }; | 6897 }; |
6875 // clang-format on | 6898 // clang-format on |
6876 | 6899 |
6877 static const ParserFlag always_flags[] = {kAllowHarmonySloppy, | 6900 static const ParserFlag always_flags[] = {kAllowHarmonySloppy, |
6878 kAllowHarmonySloppyLet}; | 6901 kAllowHarmonySloppyLet}; |
6879 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, | 6902 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, |
6880 arraysize(always_flags)); | 6903 arraysize(always_flags)); |
6881 } | 6904 } |
OLD | NEW |