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 // Arrow function formal parameters are parsed as StrictFormalParameters, | 3505 // Parameter lists are always validated as strict, so those are errors. |
3506 // which confusingly only implies that there are no duplicates. Words | 3506 "eval => {}", |
3507 // reserved in strict mode, and eval or arguments, are indeed valid in | 3507 "arguments => {}", |
3508 // sloppy mode. | 3508 "yield => {}", |
3509 "eval => { 'use strict'; 0 }", | 3509 "interface => {}", |
3510 "arguments => { 'use strict'; 0 }", | 3510 "(eval) => {}", |
3511 "yield => { 'use strict'; 0 }", | 3511 "(arguments) => {}", |
3512 "interface => { 'use strict'; 0 }", | 3512 "(yield) => {}", |
3513 "(eval) => { 'use strict'; 0 }", | 3513 "(interface) => {}", |
3514 "(arguments) => { 'use strict'; 0 }", | 3514 "(eval, bar) => {}", |
3515 "(yield) => { 'use strict'; 0 }", | 3515 "(bar, eval) => {}", |
3516 "(interface) => { 'use strict'; 0 }", | 3516 "(bar, arguments) => {}", |
3517 "(eval, bar) => { 'use strict'; 0 }", | 3517 "(bar, yield) => {}", |
3518 "(bar, eval) => { 'use strict'; 0 }", | 3518 "(bar, interface) => {}", |
3519 "(bar, arguments) => { 'use strict'; 0 }", | |
3520 "(bar, yield) => { 'use strict'; 0 }", | |
3521 "(bar, interface) => { 'use strict'; 0 }", | |
3522 // TODO(aperez): Detecting duplicates does not work in PreParser. | 3519 // TODO(aperez): Detecting duplicates does not work in PreParser. |
3523 // "(bar, bar) => {}", | 3520 // "(bar, bar) => {}", |
3524 | 3521 |
3525 // The parameter list is parsed as an expression, but only | 3522 // The parameter list is parsed as an expression, but only |
3526 // a comma-separated list of identifier is valid. | 3523 // a comma-separated list of identifier is valid. |
3527 "32 => {}", | 3524 "32 => {}", |
3528 "(32) => {}", | 3525 "(32) => {}", |
3529 "(a, 32) => {}", | 3526 "(a, 32) => {}", |
3530 "if => {}", | 3527 "if => {}", |
3531 "(if) => {}", | 3528 "(if) => {}", |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3618 "foo ? bar : baz => {}", | 3615 "foo ? bar : baz => {}", |
3619 NULL | 3616 NULL |
3620 }; | 3617 }; |
3621 | 3618 |
3622 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions}; | 3619 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions}; |
3623 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | 3620 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, |
3624 always_flags, arraysize(always_flags)); | 3621 always_flags, arraysize(always_flags)); |
3625 } | 3622 } |
3626 | 3623 |
3627 | 3624 |
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 "(interface, eval) => {}", | |
3671 "(interface, arguments) => {}", | |
3672 "(eval, interface) => {}", | |
3673 "(arguments, interface) => {}", | |
3674 NULL | |
3675 }; | |
3676 | |
3677 static const ParserFlag always_flags[] = { kAllowHarmonyArrowFunctions, | |
3678 kAllowStrongMode}; | |
3679 RunParserSyncTest(strong_context_data, statement_data, kError, NULL, 0, | |
3680 always_flags, arraysize(always_flags)); | |
3681 RunParserSyncTest(strict_context_data, statement_data, kError, NULL, 0, | |
3682 always_flags, arraysize(always_flags)); | |
3683 RunParserSyncTest(sloppy_context_data, statement_data, kSuccess, NULL, 0, | |
3684 always_flags, arraysize(always_flags)); | |
3685 } | |
3686 | |
3687 | |
3688 TEST(SuperNoErrors) { | 3625 TEST(SuperNoErrors) { |
3689 // Tests that parser and preparser accept 'super' keyword in right places. | 3626 // Tests that parser and preparser accept 'super' keyword in right places. |
3690 const char* context_data[][2] = { | 3627 const char* context_data[][2] = { |
3691 {"class C { m() { ", "; } }"}, | 3628 {"class C { m() { ", "; } }"}, |
3692 {"class C { m() { k = ", "; } }"}, | 3629 {"class C { m() { k = ", "; } }"}, |
3693 {"class C { m() { foo(", "); } }"}, | 3630 {"class C { m() { foo(", "); } }"}, |
3694 {"class C { m() { () => ", "; } }"}, | 3631 {"class C { m() { () => ", "; } }"}, |
3695 {NULL, NULL} | 3632 {NULL, NULL} |
3696 }; | 3633 }; |
3697 | 3634 |
(...skipping 2536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6234 v8::Script::Compile(v8_str(script3)); | 6171 v8::Script::Compile(v8_str(script3)); |
6235 CHECK(try_catch2.HasCaught()); | 6172 CHECK(try_catch2.HasCaught()); |
6236 v8::String::Utf8Value exception(try_catch2.Exception()); | 6173 v8::String::Utf8Value exception(try_catch2.Exception()); |
6237 CHECK_EQ(0, | 6174 CHECK_EQ(0, |
6238 strcmp( | 6175 strcmp( |
6239 "ReferenceError: In strong mode, using an undeclared global " | 6176 "ReferenceError: In strong mode, using an undeclared global " |
6240 "variable 'not_there3' is not allowed", | 6177 "variable 'not_there3' is not allowed", |
6241 *exception)); | 6178 *exception)); |
6242 } | 6179 } |
6243 } | 6180 } |
OLD | NEW |