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 3498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3509 "const y = 1;\n" | 3509 "const y = 1;\n" |
3510 "function bar() {\n" | 3510 "function bar() {\n" |
3511 " const z = 1; var baz = 1;\n" | 3511 " const z = 1; var baz = 1;\n" |
3512 " function q() { const k = 42; }\n" | 3512 " function q() { const k = 42; }\n" |
3513 "}"); | 3513 "}"); |
3514 // Optimizing will double-count because the source is parsed twice. | 3514 // Optimizing will double-count because the source is parsed twice. |
3515 CHECK_EQ(i::FLAG_always_opt ? 8 : 4, use_counts[v8::Isolate::kLegacyConst]); | 3515 CHECK_EQ(i::FLAG_always_opt ? 8 : 4, use_counts[v8::Isolate::kLegacyConst]); |
3516 } | 3516 } |
3517 | 3517 |
3518 | 3518 |
| 3519 TEST(ErrorsArrowFormalParameters) { |
| 3520 const char* context_data[][2] = { |
| 3521 { "()", "=>{}" }, |
| 3522 { "()", "=>{};" }, |
| 3523 { "var x = ()", "=>{}" }, |
| 3524 { "var x = ()", "=>{};" }, |
| 3525 |
| 3526 { "a", "=>{}" }, |
| 3527 { "a", "=>{};" }, |
| 3528 { "var x = a", "=>{}" }, |
| 3529 { "var x = a", "=>{};" }, |
| 3530 |
| 3531 { "(a)", "=>{}" }, |
| 3532 { "(a)", "=>{};" }, |
| 3533 { "var x = (a)", "=>{}" }, |
| 3534 { "var x = (a)", "=>{};" }, |
| 3535 |
| 3536 { "(...a)", "=>{}" }, |
| 3537 { "(...a)", "=>{};" }, |
| 3538 { "var x = (...a)", "=>{}" }, |
| 3539 { "var x = (...a)", "=>{};" }, |
| 3540 |
| 3541 { "(a,b)", "=>{}" }, |
| 3542 { "(a,b)", "=>{};" }, |
| 3543 { "var x = (a,b)", "=>{}" }, |
| 3544 { "var x = (a,b)", "=>{};" }, |
| 3545 |
| 3546 { "(a,...b)", "=>{}" }, |
| 3547 { "(a,...b)", "=>{};" }, |
| 3548 { "var x = (a,...b)", "=>{}" }, |
| 3549 { "var x = (a,...b)", "=>{};" }, |
| 3550 |
| 3551 { nullptr, nullptr } |
| 3552 }; |
| 3553 const char* assignment_expression_suffix_data[] = { |
| 3554 "?c:d=>{}", |
| 3555 "=c=>{}", |
| 3556 "()", |
| 3557 "(c)", |
| 3558 "[1]", |
| 3559 "[c]", |
| 3560 ".c", |
| 3561 "-c", |
| 3562 "+c", |
| 3563 "c++", |
| 3564 "`c`", |
| 3565 "`${c}`", |
| 3566 "`template-head${c}`", |
| 3567 "`${c}template-tail`", |
| 3568 "`template-head${c}template-tail`", |
| 3569 "`${c}template-tail`", |
| 3570 nullptr |
| 3571 }; |
| 3572 |
| 3573 static const ParserFlag always_flags[] = { kAllowHarmonyArrowFunctions, |
| 3574 kAllowHarmonyRestParameters }; |
| 3575 RunParserSyncTest(context_data, assignment_expression_suffix_data, kError, |
| 3576 NULL, 0, always_flags, arraysize(always_flags)); |
| 3577 } |
| 3578 |
| 3579 |
3519 TEST(ErrorsArrowFunctions) { | 3580 TEST(ErrorsArrowFunctions) { |
3520 // Tests that parser and preparser generate the same kind of errors | 3581 // Tests that parser and preparser generate the same kind of errors |
3521 // on invalid arrow function syntax. | 3582 // on invalid arrow function syntax. |
3522 const char* context_data[][2] = { | 3583 const char* context_data[][2] = { |
3523 {"", ";"}, | 3584 {"", ";"}, |
3524 {"v = ", ";"}, | 3585 {"v = ", ";"}, |
3525 {"bar ? (", ") : baz;"}, | 3586 {"bar ? (", ") : baz;"}, |
3526 {"bar ? baz : (", ");"}, | 3587 {"bar ? baz : (", ");"}, |
3527 {"bar[", "];"}, | 3588 {"bar[", "];"}, |
3528 {"bar, ", ";"}, | 3589 {"bar, ", ";"}, |
(...skipping 3254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6783 NULL | 6844 NULL |
6784 }; | 6845 }; |
6785 // clang-format on | 6846 // clang-format on |
6786 | 6847 |
6787 static const ParserFlag always_flags[] = {kNoLegacyConst}; | 6848 static const ParserFlag always_flags[] = {kNoLegacyConst}; |
6788 | 6849 |
6789 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | 6850 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
6790 arraysize(always_flags)); | 6851 arraysize(always_flags)); |
6791 RunParserSyncTest(context_data, data, kSuccess); | 6852 RunParserSyncTest(context_data, data, kSuccess); |
6792 } | 6853 } |
OLD | NEW |