| 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 3492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3503 "const y = 1;\n" | 3503 "const y = 1;\n" |
| 3504 "function bar() {\n" | 3504 "function bar() {\n" |
| 3505 " const z = 1; var baz = 1;\n" | 3505 " const z = 1; var baz = 1;\n" |
| 3506 " function q() { const k = 42; }\n" | 3506 " function q() { const k = 42; }\n" |
| 3507 "}"); | 3507 "}"); |
| 3508 // Optimizing will double-count because the source is parsed twice. | 3508 // Optimizing will double-count because the source is parsed twice. |
| 3509 CHECK_EQ(i::FLAG_always_opt ? 8 : 4, use_counts[v8::Isolate::kLegacyConst]); | 3509 CHECK_EQ(i::FLAG_always_opt ? 8 : 4, use_counts[v8::Isolate::kLegacyConst]); |
| 3510 } | 3510 } |
| 3511 | 3511 |
| 3512 | 3512 |
| 3513 TEST(ErrorsArrowFormalParameters) { |
| 3514 const char* context_data[][2] = { |
| 3515 { "()", "=>{}" }, |
| 3516 { "()", "=>{};" }, |
| 3517 { "var x = ()", "=>{}" }, |
| 3518 { "var x = ()", "=>{};" }, |
| 3519 |
| 3520 { "a", "=>{}" }, |
| 3521 { "a", "=>{};" }, |
| 3522 { "var x = a", "=>{}" }, |
| 3523 { "var x = a", "=>{};" }, |
| 3524 |
| 3525 { "(a)", "=>{}" }, |
| 3526 { "(a)", "=>{};" }, |
| 3527 { "var x = (a)", "=>{}" }, |
| 3528 { "var x = (a)", "=>{};" }, |
| 3529 |
| 3530 { "(...a)", "=>{}" }, |
| 3531 { "(...a)", "=>{};" }, |
| 3532 { "var x = (...a)", "=>{}" }, |
| 3533 { "var x = (...a)", "=>{};" }, |
| 3534 |
| 3535 { "(a,b)", "=>{}" }, |
| 3536 { "(a,b)", "=>{};" }, |
| 3537 { "var x = (a,b)", "=>{}" }, |
| 3538 { "var x = (a,b)", "=>{};" }, |
| 3539 |
| 3540 { "(a,...b)", "=>{}" }, |
| 3541 { "(a,...b)", "=>{};" }, |
| 3542 { "var x = (a,...b)", "=>{}" }, |
| 3543 { "var x = (a,...b)", "=>{};" }, |
| 3544 |
| 3545 { nullptr, nullptr } |
| 3546 }; |
| 3547 const char* assignment_expression_suffix_data[] = { |
| 3548 "?c:d=>{}", |
| 3549 "=c=>{}", |
| 3550 "()", |
| 3551 "(c)", |
| 3552 "[1]", |
| 3553 "[c]", |
| 3554 ".c", |
| 3555 "-c", |
| 3556 "+c", |
| 3557 "c++", |
| 3558 "`c`", |
| 3559 "`${c}`", |
| 3560 "`template-head${c}`", |
| 3561 "`${c}template-tail`", |
| 3562 "`template-head${c}template-tail`", |
| 3563 "`${c}template-tail`", |
| 3564 nullptr |
| 3565 }; |
| 3566 |
| 3567 static const ParserFlag always_flags[] = { kAllowHarmonyArrowFunctions, |
| 3568 kAllowHarmonyRestParameters }; |
| 3569 RunParserSyncTest(context_data, assignment_expression_suffix_data, kError, |
| 3570 NULL, 0, always_flags, arraysize(always_flags)); |
| 3571 } |
| 3572 |
| 3573 |
| 3513 TEST(ErrorsArrowFunctions) { | 3574 TEST(ErrorsArrowFunctions) { |
| 3514 // Tests that parser and preparser generate the same kind of errors | 3575 // Tests that parser and preparser generate the same kind of errors |
| 3515 // on invalid arrow function syntax. | 3576 // on invalid arrow function syntax. |
| 3516 const char* context_data[][2] = { | 3577 const char* context_data[][2] = { |
| 3517 {"", ";"}, | 3578 {"", ";"}, |
| 3518 {"v = ", ";"}, | 3579 {"v = ", ";"}, |
| 3519 {"bar ? (", ") : baz;"}, | 3580 {"bar ? (", ") : baz;"}, |
| 3520 {"bar ? baz : (", ");"}, | 3581 {"bar ? baz : (", ");"}, |
| 3521 {"bar[", "];"}, | 3582 {"bar[", "];"}, |
| 3522 {"bar, ", ";"}, | 3583 {"bar, ", ";"}, |
| (...skipping 3288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6811 "for (let x of []) {}", | 6872 "for (let x of []) {}", |
| 6812 NULL | 6873 NULL |
| 6813 }; | 6874 }; |
| 6814 // clang-format on | 6875 // clang-format on |
| 6815 | 6876 |
| 6816 static const ParserFlag always_flags[] = {kAllowHarmonySloppy, | 6877 static const ParserFlag always_flags[] = {kAllowHarmonySloppy, |
| 6817 kAllowHarmonySloppyLet}; | 6878 kAllowHarmonySloppyLet}; |
| 6818 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, | 6879 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, |
| 6819 arraysize(always_flags)); | 6880 arraysize(always_flags)); |
| 6820 } | 6881 } |
| OLD | NEW |