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 3484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3495 | 3495 |
3496 // Parameter lists with extra parens should be recognized as errors. | 3496 // Parameter lists with extra parens should be recognized as errors. |
3497 "(()) => 0", | 3497 "(()) => 0", |
3498 "((x)) => 0", | 3498 "((x)) => 0", |
3499 "((x, y)) => 0", | 3499 "((x, y)) => 0", |
3500 "(x, (y)) => 0", | 3500 "(x, (y)) => 0", |
3501 "((x, y, z)) => 0", | 3501 "((x, y, z)) => 0", |
3502 "(x, (y, z)) => 0", | 3502 "(x, (y, z)) => 0", |
3503 "((x, y), z) => 0", | 3503 "((x, y), z) => 0", |
3504 | 3504 |
3505 // Parameter lists are always validated as strict, so those are errors. | 3505 // Arrow function formal parameters are parsed as StrictFormalParameters, |
3506 "eval => {}", | 3506 // which confusingly only implies that there are no duplicates. Words |
3507 "arguments => {}", | 3507 // reserved in strict mode, and eval or arguments, are indeed valid in |
3508 "yield => {}", | 3508 // sloppy mode. |
3509 "interface => {}", | 3509 "eval => { \"use strict\"; 0 }", |
arv (Not doing code reviews)
2015/04/13 18:26:38
\" -> ' for readability
| |
3510 "(eval) => {}", | 3510 "arguments => { \"use strict\"; 0 }", |
3511 "(arguments) => {}", | 3511 "yield => { \"use strict\"; 0 }", |
3512 "(yield) => {}", | 3512 "interface => { \"use strict\"; 0 }", |
3513 "(interface) => {}", | 3513 "(eval) => { \"use strict\"; 0 }", |
3514 "(eval, bar) => {}", | 3514 "(arguments) => { \"use strict\"; 0 }", |
3515 "(bar, eval) => {}", | 3515 "(yield) => { \"use strict\"; 0 }", |
3516 "(bar, arguments) => {}", | 3516 "(interface) => { \"use strict\"; 0 }", |
3517 "(bar, yield) => {}", | 3517 "(eval, bar) => { \"use strict\"; 0 }", |
3518 "(bar, interface) => {}", | 3518 "(bar, eval) => { \"use strict\"; 0 }", |
3519 "(bar, arguments) => { \"use strict\"; 0 }", | |
3520 "(bar, yield) => { \"use strict\"; 0 }", | |
3521 "(bar, interface) => { \"use strict\"; 0 }", | |
3519 // TODO(aperez): Detecting duplicates does not work in PreParser. | 3522 // TODO(aperez): Detecting duplicates does not work in PreParser. |
3520 // "(bar, bar) => {}", | 3523 // "(bar, bar) => {}", |
3521 | 3524 |
3522 // The parameter list is parsed as an expression, but only | 3525 // The parameter list is parsed as an expression, but only |
3523 // a comma-separated list of identifier is valid. | 3526 // a comma-separated list of identifier is valid. |
3524 "32 => {}", | 3527 "32 => {}", |
3525 "(32) => {}", | 3528 "(32) => {}", |
3526 "(a, 32) => {}", | 3529 "(a, 32) => {}", |
3527 "if => {}", | 3530 "if => {}", |
3528 "(if) => {}", | 3531 "(if) => {}", |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3615 "foo ? bar : baz => {}", | 3618 "foo ? bar : baz => {}", |
3616 NULL | 3619 NULL |
3617 }; | 3620 }; |
3618 | 3621 |
3619 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions}; | 3622 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions}; |
3620 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | 3623 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, |
3621 always_flags, arraysize(always_flags)); | 3624 always_flags, arraysize(always_flags)); |
3622 } | 3625 } |
3623 | 3626 |
3624 | 3627 |
3628 TEST(ArrowFunctionsSloppyParameterNames) { | |
3629 const char* strong_context_data[][2] = { | |
3630 {"\"use strong\"; ", ";"}, | |
3631 {"\"use strong\"; bar ? (", ") : baz;"}, | |
3632 {"\"use strong\"; bar ? baz : (", ");"}, | |
3633 {"\"use strong\"; bar, ", ";"}, | |
3634 {"\"use strong\"; ", ", bar;"}, | |
3635 {NULL, NULL} | |
3636 }; | |
3637 | |
3638 const char* strict_context_data[][2] = { | |
3639 {"\"use strict\"; ", ";"}, | |
3640 {"\"use strict\"; bar ? (", ") : baz;"}, | |
3641 {"\"use strict\"; bar ? baz : (", ");"}, | |
3642 {"\"use strict\"; bar, ", ";"}, | |
3643 {"\"use strict\"; ", ", bar;"}, | |
3644 {NULL, NULL} | |
3645 }; | |
3646 | |
3647 const char* sloppy_context_data[][2] = { | |
3648 {"", ";"}, | |
3649 {"bar ? (", ") : baz;"}, | |
3650 {"bar ? baz : (", ");"}, | |
3651 {"bar, ", ";"}, | |
3652 {"", ", bar;"}, | |
3653 {NULL, NULL} | |
3654 }; | |
3655 | |
3656 const char* statement_data[] = { | |
3657 "eval => {}", | |
3658 "arguments => {}", | |
3659 "yield => {}", | |
3660 "interface => {}", | |
3661 "(eval) => {}", | |
3662 "(arguments) => {}", | |
3663 "(yield) => {}", | |
3664 "(interface) => {}", | |
3665 "(eval, bar) => {}", | |
3666 "(bar, eval) => {}", | |
3667 "(bar, arguments) => {}", | |
3668 "(bar, yield) => {}", | |
3669 "(bar, interface) => {}", | |
3670 NULL | |
3671 }; | |
3672 | |
3673 static const ParserFlag always_flags[] = { kAllowHarmonyArrowFunctions, | |
3674 kAllowStrongMode}; | |
3675 RunParserSyncTest(strong_context_data, statement_data, kError, NULL, 0, | |
3676 always_flags, arraysize(always_flags)); | |
3677 RunParserSyncTest(strict_context_data, statement_data, kError, NULL, 0, | |
3678 always_flags, arraysize(always_flags)); | |
3679 RunParserSyncTest(sloppy_context_data, statement_data, kSuccess, NULL, 0, | |
3680 always_flags, arraysize(always_flags)); | |
3681 } | |
3682 | |
3683 | |
3625 TEST(SuperNoErrors) { | 3684 TEST(SuperNoErrors) { |
3626 // Tests that parser and preparser accept 'super' keyword in right places. | 3685 // Tests that parser and preparser accept 'super' keyword in right places. |
3627 const char* context_data[][2] = { | 3686 const char* context_data[][2] = { |
3628 {"class C { m() { ", "; } }"}, | 3687 {"class C { m() { ", "; } }"}, |
3629 {"class C { m() { k = ", "; } }"}, | 3688 {"class C { m() { k = ", "; } }"}, |
3630 {"class C { m() { foo(", "); } }"}, | 3689 {"class C { m() { foo(", "); } }"}, |
3631 {"class C { m() { () => ", "; } }"}, | 3690 {"class C { m() { () => ", "; } }"}, |
3632 {NULL, NULL} | 3691 {NULL, NULL} |
3633 }; | 3692 }; |
3634 | 3693 |
(...skipping 2435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6070 v8::Script::Compile(v8_str(script3)); | 6129 v8::Script::Compile(v8_str(script3)); |
6071 CHECK(try_catch2.HasCaught()); | 6130 CHECK(try_catch2.HasCaught()); |
6072 v8::String::Utf8Value exception(try_catch2.Exception()); | 6131 v8::String::Utf8Value exception(try_catch2.Exception()); |
6073 CHECK_EQ(0, | 6132 CHECK_EQ(0, |
6074 strcmp( | 6133 strcmp( |
6075 "ReferenceError: In strong mode, using an undeclared global " | 6134 "ReferenceError: In strong mode, using an undeclared global " |
6076 "variable 'not_there3' is not allowed", | 6135 "variable 'not_there3' is not allowed", |
6077 *exception)); | 6136 *exception)); |
6078 } | 6137 } |
6079 } | 6138 } |
OLD | NEW |