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 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} = {}) => {}", | |
|
wingo
2015/08/24 16:01:47
Perhaps add a pattern for ({a=42})=>{} too? Unles
rossberg
2015/08/24 17:01:41
Done.
| |
| 3733 NULL | 3751 NULL |
| 3734 }; | 3752 }; |
| 3735 | 3753 |
| 3736 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions}; | 3754 static const ParserFlag always_flags[] = { |
| 3755 kAllowHarmonyArrowFunctions, kAllowHarmonyDefaultParameters, | |
| 3756 kAllowHarmonyRestParameters, kAllowHarmonyDestructuring}; | |
| 3737 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | 3757 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, |
| 3738 always_flags, arraysize(always_flags)); | 3758 always_flags, arraysize(always_flags)); |
| 3739 } | 3759 } |
| 3740 | 3760 |
| 3741 | 3761 |
| 3742 TEST(ArrowFunctionsSloppyParameterNames) { | 3762 TEST(ArrowFunctionsSloppyParameterNames) { |
| 3743 const char* strong_context_data[][2] = { | 3763 const char* strong_context_data[][2] = { |
| 3744 {"'use strong'; ", ";"}, | 3764 {"'use strong'; ", ";"}, |
| 3745 {"'use strong'; bar ? (", ") : baz;"}, | 3765 {"'use strong'; bar ? (", ") : baz;"}, |
| 3746 {"'use strong'; bar ? baz : (", ");"}, | 3766 {"'use strong'; bar ? baz : (", ");"}, |
| (...skipping 3125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6872 "for (let x of []) {}", | 6892 "for (let x of []) {}", |
| 6873 NULL | 6893 NULL |
| 6874 }; | 6894 }; |
| 6875 // clang-format on | 6895 // clang-format on |
| 6876 | 6896 |
| 6877 static const ParserFlag always_flags[] = {kAllowHarmonySloppy, | 6897 static const ParserFlag always_flags[] = {kAllowHarmonySloppy, |
| 6878 kAllowHarmonySloppyLet}; | 6898 kAllowHarmonySloppyLet}; |
| 6879 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, | 6899 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, |
| 6880 arraysize(always_flags)); | 6900 arraysize(always_flags)); |
| 6881 } | 6901 } |
| OLD | NEW |