Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: test/cctest/test-parsing.cc

Issue 1077153005: Allow eval/arguments in arrow functions (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/preparser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }",
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
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 "(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
3625 TEST(SuperNoErrors) { 3688 TEST(SuperNoErrors) {
3626 // Tests that parser and preparser accept 'super' keyword in right places. 3689 // Tests that parser and preparser accept 'super' keyword in right places.
3627 const char* context_data[][2] = { 3690 const char* context_data[][2] = {
3628 {"class C { m() { ", "; } }"}, 3691 {"class C { m() { ", "; } }"},
3629 {"class C { m() { k = ", "; } }"}, 3692 {"class C { m() { k = ", "; } }"},
3630 {"class C { m() { foo(", "); } }"}, 3693 {"class C { m() { foo(", "); } }"},
3631 {"class C { m() { () => ", "; } }"}, 3694 {"class C { m() { () => ", "; } }"},
3632 {NULL, NULL} 3695 {NULL, NULL}
3633 }; 3696 };
3634 3697
(...skipping 2541 matching lines...) Expand 10 before | Expand all | Expand 10 after
6176 v8::Script::Compile(v8_str(script3)); 6239 v8::Script::Compile(v8_str(script3));
6177 CHECK(try_catch2.HasCaught()); 6240 CHECK(try_catch2.HasCaught());
6178 v8::String::Utf8Value exception(try_catch2.Exception()); 6241 v8::String::Utf8Value exception(try_catch2.Exception());
6179 CHECK_EQ(0, 6242 CHECK_EQ(0,
6180 strcmp( 6243 strcmp(
6181 "ReferenceError: In strong mode, using an undeclared global " 6244 "ReferenceError: In strong mode, using an undeclared global "
6182 "variable 'not_there3' is not allowed", 6245 "variable 'not_there3' is not allowed",
6183 *exception)); 6246 *exception));
6184 } 6247 }
6185 } 6248 }
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698