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

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

Issue 1776683003: Remove destructuring and default arguments runtime flags (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased Created 4 years, 9 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/parsing/preparser.cc ('k') | test/message/default-parameter-tdz.js » ('j') | 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 1485 matching lines...) Expand 10 before | Expand all | Expand 10 after
1496 arg_object = isolate->factory()->undefined_value(); 1496 arg_object = isolate->factory()->undefined_value();
1497 } 1497 }
1498 1498
1499 data.Dispose(); 1499 data.Dispose();
1500 return i::MessageTemplate::FormatMessage(isolate, message, arg_object); 1500 return i::MessageTemplate::FormatMessage(isolate, message, arg_object);
1501 } 1501 }
1502 1502
1503 enum ParserFlag { 1503 enum ParserFlag {
1504 kAllowLazy, 1504 kAllowLazy,
1505 kAllowNatives, 1505 kAllowNatives,
1506 kAllowHarmonyDefaultParameters,
1507 kAllowHarmonySloppy, 1506 kAllowHarmonySloppy,
1508 kAllowHarmonySloppyLet, 1507 kAllowHarmonySloppyLet,
1509 kAllowHarmonyDestructuring,
1510 kAllowHarmonyDestructuringAssignment,
1511 kAllowHarmonyNewTarget, 1508 kAllowHarmonyNewTarget,
1512 kNoLegacyConst, 1509 kNoLegacyConst,
1513 kAllowHarmonyFunctionSent, 1510 kAllowHarmonyFunctionSent,
1514 kAllowHarmonyRestrictiveDeclarations, 1511 kAllowHarmonyRestrictiveDeclarations,
1515 }; 1512 };
1516 1513
1517 enum ParserSyncTestResult { 1514 enum ParserSyncTestResult {
1518 kSuccessOrError, 1515 kSuccessOrError,
1519 kSuccess, 1516 kSuccess,
1520 kError 1517 kError
1521 }; 1518 };
1522 1519
1523 template <typename Traits> 1520 template <typename Traits>
1524 void SetParserFlags(i::ParserBase<Traits>* parser, 1521 void SetParserFlags(i::ParserBase<Traits>* parser,
1525 i::EnumSet<ParserFlag> flags) { 1522 i::EnumSet<ParserFlag> flags) {
1526 parser->set_allow_lazy(flags.Contains(kAllowLazy)); 1523 parser->set_allow_lazy(flags.Contains(kAllowLazy));
1527 parser->set_allow_natives(flags.Contains(kAllowNatives)); 1524 parser->set_allow_natives(flags.Contains(kAllowNatives));
1528 parser->set_allow_harmony_default_parameters(
1529 flags.Contains(kAllowHarmonyDefaultParameters));
1530 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); 1525 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy));
1531 parser->set_allow_harmony_sloppy_let(flags.Contains(kAllowHarmonySloppyLet)); 1526 parser->set_allow_harmony_sloppy_let(flags.Contains(kAllowHarmonySloppyLet));
1532 parser->set_allow_harmony_destructuring_bind(
1533 flags.Contains(kAllowHarmonyDestructuring));
1534 parser->set_allow_harmony_destructuring_assignment(
1535 flags.Contains(kAllowHarmonyDestructuringAssignment));
1536 parser->set_allow_legacy_const(!flags.Contains(kNoLegacyConst)); 1527 parser->set_allow_legacy_const(!flags.Contains(kNoLegacyConst));
1537 parser->set_allow_harmony_function_sent( 1528 parser->set_allow_harmony_function_sent(
1538 flags.Contains(kAllowHarmonyFunctionSent)); 1529 flags.Contains(kAllowHarmonyFunctionSent));
1539 parser->set_allow_harmony_restrictive_declarations( 1530 parser->set_allow_harmony_restrictive_declarations(
1540 flags.Contains(kAllowHarmonyRestrictiveDeclarations)); 1531 flags.Contains(kAllowHarmonyRestrictiveDeclarations));
1541 } 1532 }
1542 1533
1543 1534
1544 void TestParserSyncWithFlags(i::Handle<i::String> source, 1535 void TestParserSyncWithFlags(i::Handle<i::String> source,
1545 i::EnumSet<ParserFlag> flags, 1536 i::EnumSet<ParserFlag> flags,
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after
2343 "yield, yield", 2334 "yield, yield",
2344 "yield; yield", 2335 "yield; yield",
2345 "(yield) ? yield : yield", 2336 "(yield) ? yield : yield",
2346 "(yield) \n ? yield : yield", 2337 "(yield) \n ? yield : yield",
2347 // If there is a newline before the next token, we don't look for RHS. 2338 // If there is a newline before the next token, we don't look for RHS.
2348 "yield\nfor (;;) {}", 2339 "yield\nfor (;;) {}",
2349 NULL 2340 NULL
2350 }; 2341 };
2351 // clang-format on 2342 // clang-format on
2352 2343
2353 static const ParserFlag always_flags[] = { 2344 RunParserSyncTest(context_data, statement_data, kSuccess);
2354 kAllowHarmonyDestructuringAssignment};
2355 RunParserSyncTest(context_data, statement_data, kSuccess, nullptr, 0,
2356 always_flags, arraysize(always_flags));
2357 } 2345 }
2358 2346
2359 2347
2360 TEST(ErrorsYieldGenerator) { 2348 TEST(ErrorsYieldGenerator) {
2361 // clang-format off 2349 // clang-format off
2362 const char* context_data[][2] = { 2350 const char* context_data[][2] = {
2363 { "function * gen() {", "}" }, 2351 { "function * gen() {", "}" },
2364 { "\"use strict\"; function * gen() {", "}" }, 2352 { "\"use strict\"; function * gen() {", "}" },
2365 { NULL, NULL } 2353 { NULL, NULL }
2366 }; 2354 };
(...skipping 1368 matching lines...) Expand 10 before | Expand all | Expand 10 after
3735 "(a, b - c) => {}", 3723 "(a, b - c) => {}",
3736 "\"a\" => {}", 3724 "\"a\" => {}",
3737 "(\"a\") => {}", 3725 "(\"a\") => {}",
3738 "(\"a\", b) => {}", 3726 "(\"a\", b) => {}",
3739 "(a, \"b\") => {}", 3727 "(a, \"b\") => {}",
3740 "-a => {}", 3728 "-a => {}",
3741 "(-a) => {}", 3729 "(-a) => {}",
3742 "(-a, b) => {}", 3730 "(-a, b) => {}",
3743 "(a, -b) => {}", 3731 "(a, -b) => {}",
3744 "{} => {}", 3732 "{} => {}",
3745 "({}) => {}",
3746 "(a, {}) => {}",
3747 "({}, a) => {}",
3748 "a++ => {}", 3733 "a++ => {}",
3749 "(a++) => {}", 3734 "(a++) => {}",
3750 "(a++, b) => {}", 3735 "(a++, b) => {}",
3751 "(a, b++) => {}", 3736 "(a, b++) => {}",
3752 "[] => {}", 3737 "[] => {}",
3753 "([]) => {}",
3754 "(a, []) => {}",
3755 "([], a) => {}",
3756 "(a = b) => {}",
3757 "(a = b, c) => {}",
3758 "(a, b = c) => {}",
3759 "(foo ? bar : baz) => {}", 3738 "(foo ? bar : baz) => {}",
3760 "(a, foo ? bar : baz) => {}", 3739 "(a, foo ? bar : baz) => {}",
3761 "(foo ? bar : baz, a) => {}", 3740 "(foo ? bar : baz, a) => {}",
3762 "(a.b, c) => {}", 3741 "(a.b, c) => {}",
3763 "(c, a.b) => {}", 3742 "(c, a.b) => {}",
3764 "(a['b'], c) => {}", 3743 "(a['b'], c) => {}",
3765 "(c, a['b']) => {}", 3744 "(c, a['b']) => {}",
3766 3745
3767 // crbug.com/582626 3746 // crbug.com/582626
3768 "(...rest - a) => b", 3747 "(...rest - a) => b",
(...skipping 13 matching lines...) Expand all
3782 const char* loop_context_data[][2] = {{"for (", "; 0;);"}, 3761 const char* loop_context_data[][2] = {{"for (", "; 0;);"},
3783 {nullptr, nullptr}}; 3762 {nullptr, nullptr}};
3784 const char* loop_expr_data[] = {"f => 'key' in {}", nullptr}; 3763 const char* loop_expr_data[] = {"f => 'key' in {}", nullptr};
3785 RunParserSyncTest(loop_context_data, loop_expr_data, kError, flags, 3764 RunParserSyncTest(loop_context_data, loop_expr_data, kError, flags,
3786 arraysize(flags)); 3765 arraysize(flags));
3787 } 3766 }
3788 3767
3789 3768
3790 TEST(NoErrorsArrowFunctions) { 3769 TEST(NoErrorsArrowFunctions) {
3791 // Tests that parser and preparser accept valid arrow functions syntax. 3770 // Tests that parser and preparser accept valid arrow functions syntax.
3771 // clang-format off
3792 const char* context_data[][2] = { 3772 const char* context_data[][2] = {
3793 {"", ";"}, 3773 {"", ";"},
3794 {"bar ? (", ") : baz;"}, 3774 {"bar ? (", ") : baz;"},
3795 {"bar ? baz : (", ");"}, 3775 {"bar ? baz : (", ");"},
3796 {"bar, ", ";"}, 3776 {"bar, ", ";"},
3797 {"", ", bar;"}, 3777 {"", ", bar;"},
3798 {NULL, NULL} 3778 {NULL, NULL}
3799 }; 3779 };
3800 3780
3801 const char* statement_data[] = { 3781 const char* statement_data[] = {
(...skipping 25 matching lines...) Expand all
3827 "(a, b, (c, d) => 0)", 3807 "(a, b, (c, d) => 0)",
3828 "(a, b) => 0, (c, d) => 1", 3808 "(a, b) => 0, (c, d) => 1",
3829 "(a, b => {}, a => a + 1)", 3809 "(a, b => {}, a => a + 1)",
3830 "((a, b) => {}, (a => a + 1))", 3810 "((a, b) => {}, (a => a + 1))",
3831 "(a, (a, (b, c) => 0))", 3811 "(a, (a, (b, c) => 0))",
3832 3812
3833 // Arrow has more precedence, this is the same as: foo ? bar : (baz = {}) 3813 // Arrow has more precedence, this is the same as: foo ? bar : (baz = {})
3834 "foo ? bar : baz => {}", 3814 "foo ? bar : baz => {}",
3835 3815
3836 // Arrows with non-simple parameters. 3816 // Arrows with non-simple parameters.
3817 "({}) => {}",
3818 "(a, {}) => {}",
3819 "({}, a) => {}",
3820 "([]) => {}",
3821 "(a, []) => {}",
3822 "([], a) => {}",
3823 "(a = b) => {}",
3824 "(a = b, c) => {}",
3825 "(a, b = c) => {}",
3837 "({a}) => {}", 3826 "({a}) => {}",
3838 "(x = 9) => {}", 3827 "(x = 9) => {}",
3839 "(x, y = 9) => {}", 3828 "(x, y = 9) => {}",
3840 "(x = 9, y) => {}", 3829 "(x = 9, y) => {}",
3841 "(x, y = 9, z) => {}", 3830 "(x, y = 9, z) => {}",
3842 "(x, y = 9, z = 8) => {}", 3831 "(x, y = 9, z = 8) => {}",
3843 "(...a) => {}", 3832 "(...a) => {}",
3844 "(x, ...a) => {}", 3833 "(x, ...a) => {}",
3845 "(x = 9, ...a) => {}", 3834 "(x = 9, ...a) => {}",
3846 "(x, y = 9, ...a) => {}", 3835 "(x, y = 9, ...a) => {}",
3847 "(x, y = 9, {b}, z = 8, ...a) => {}", 3836 "(x, y = 9, {b}, z = 8, ...a) => {}",
3848 // TODO(wingo, rossberg): This is not accepted right now. 3837 "({a} = {}) => {}",
3849 // "({a} = {}) => {}", 3838 "([x] = []) => {}",
3850 // "([x] = []) => {}",
3851 "({a = 42}) => {}", 3839 "({a = 42}) => {}",
3852 "([x = 0]) => {}", 3840 "([x = 0]) => {}",
3853 NULL 3841 NULL
3854 }; 3842 };
3843 // clang-format on
3855 3844
3856 static const ParserFlag always_flags[] = {kAllowHarmonyDefaultParameters, 3845 RunParserSyncTest(context_data, statement_data, kSuccess);
3857 kAllowHarmonyDestructuring};
3858 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
3859 always_flags, arraysize(always_flags));
3860 3846
3861 static const ParserFlag flags[] = {kAllowLazy}; 3847 static const ParserFlag flags[] = {kAllowLazy};
3862 // In a context where a concise arrow body is parsed with [~In] variant, 3848 // In a context where a concise arrow body is parsed with [~In] variant,
3863 // ensure that nested expressions can still use the 'in' operator, 3849 // ensure that nested expressions can still use the 'in' operator,
3864 const char* loop_context_data[][2] = {{"for (", "; 0;);"}, 3850 const char* loop_context_data[][2] = {{"for (", "; 0;);"},
3865 {nullptr, nullptr}}; 3851 {nullptr, nullptr}};
3866 const char* loop_expr_data[] = {"f => ('key' in {})", nullptr}; 3852 const char* loop_expr_data[] = {"f => ('key' in {})", nullptr};
3867 RunParserSyncTest(loop_context_data, loop_expr_data, kSuccess, flags, 3853 RunParserSyncTest(loop_context_data, loop_expr_data, kSuccess, flags,
3868 arraysize(flags)); 3854 arraysize(flags));
3869 } 3855 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
3936 "(yield) => {}", 3922 "(yield) => {}",
3937 "(a, yield) => {}", 3923 "(a, yield) => {}",
3938 "(yield, a) => {}", 3924 "(yield, a) => {}",
3939 "(yield, ...a) => {}", 3925 "(yield, ...a) => {}",
3940 "(a, ...yield) => {}", 3926 "(a, ...yield) => {}",
3941 "({yield}) => {}", 3927 "({yield}) => {}",
3942 "([yield]) => {}", 3928 "([yield]) => {}",
3943 NULL 3929 NULL
3944 }; 3930 };
3945 3931
3946 static const ParserFlag always_flags[] = { kAllowHarmonyDestructuring }; 3932 RunParserSyncTest(sloppy_function_context_data, arrow_data, kSuccess);
3947 RunParserSyncTest(sloppy_function_context_data, arrow_data, kSuccess, NULL, 0, 3933 RunParserSyncTest(strict_function_context_data, arrow_data, kError);
3948 always_flags, arraysize(always_flags)); 3934 RunParserSyncTest(generator_context_data, arrow_data, kError);
3949 RunParserSyncTest(strict_function_context_data, arrow_data, kError, NULL, 0,
3950 always_flags, arraysize(always_flags));
3951 RunParserSyncTest(generator_context_data, arrow_data, kError, NULL, 0,
3952 always_flags, arraysize(always_flags));
3953 } 3935 }
3954 3936
3955 3937
3956 TEST(SuperNoErrors) { 3938 TEST(SuperNoErrors) {
3957 // Tests that parser and preparser accept 'super' keyword in right places. 3939 // Tests that parser and preparser accept 'super' keyword in right places.
3958 const char* context_data[][2] = { 3940 const char* context_data[][2] = {
3959 {"class C { m() { ", "; } }"}, 3941 {"class C { m() { ", "; } }"},
3960 {"class C { m() { k = ", "; } }"}, 3942 {"class C { m() { k = ", "; } }"},
3961 {"class C { m() { foo(", "); } }"}, 3943 {"class C { m() { foo(", "); } }"},
3962 {"class C { m() { () => ", "; } }"}, 3944 {"class C { m() { () => ", "; } }"},
(...skipping 1406 matching lines...) Expand 10 before | Expand all | Expand 10 after
5369 "...\rargs", 5351 "...\rargs",
5370 "a, ...\rargs", 5352 "a, ...\rargs",
5371 "...\t\n\t\t\n args", 5353 "...\t\n\t\t\n args",
5372 "a, ... \n \n args", 5354 "a, ... \n \n args",
5373 "...{ length, 0: a, 1: b}", 5355 "...{ length, 0: a, 1: b}",
5374 "...{}", 5356 "...{}",
5375 "...[a, b]", 5357 "...[a, b]",
5376 "...[]", 5358 "...[]",
5377 "...[...[a, b, ...c]]", 5359 "...[...[a, b, ...c]]",
5378 NULL}; 5360 NULL};
5379 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring}; 5361 RunParserSyncTest(context_data, data, kSuccess);
5380 RunParserSyncTest(context_data, data, kSuccess, nullptr, 0, always_flags,
5381 arraysize(always_flags));
5382 } 5362 }
5383 5363
5384 5364
5385 TEST(ParseRestParametersErrors) { 5365 TEST(ParseRestParametersErrors) {
5386 const char* context_data[][2] = {{"'use strict';(function(", 5366 const char* context_data[][2] = {{"'use strict';(function(",
5387 "){ return args;}(1, [], /regexp/, 'str'," 5367 "){ return args;}(1, [], /regexp/, 'str',"
5388 "function(){});"}, 5368 "function(){});"},
5389 {"(function(", "){ return args;}(1, []," 5369 {"(function(", "){ return args;}(1, [],"
5390 "/regexp/, 'str', function(){});"}, 5370 "/regexp/, 'str', function(){});"},
5391 {NULL, NULL}}; 5371 {NULL, NULL}};
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
6020 "(a/*\n*/=> a)(1)", 6000 "(a/*\n*/=> a)(1)",
6021 "((a)\n=> a)(1)", 6001 "((a)\n=> a)(1)",
6022 "((a)/*\n*/=> a)(1)", 6002 "((a)/*\n*/=> a)(1)",
6023 "((a, b)\n=> a + b)(1, 2)", 6003 "((a, b)\n=> a + b)(1, 2)",
6024 "((a, b)/*\n*/=> a + b)(1, 2)", 6004 "((a, b)/*\n*/=> a + b)(1, 2)",
6025 NULL}; 6005 NULL};
6026 RunParserSyncTest(context_data, data, kError); 6006 RunParserSyncTest(context_data, data, kError);
6027 } 6007 }
6028 6008
6029 6009
6030 static const ParserFlag kAllDestructuringFlags[] = {
6031 kAllowHarmonyDestructuring, kAllowHarmonyDestructuringAssignment,
6032 kAllowHarmonyDefaultParameters};
6033
6034 TEST(DestructuringPositiveTests) { 6010 TEST(DestructuringPositiveTests) {
6035 i::FLAG_harmony_destructuring_bind = true;
6036
6037 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, 6011 const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
6038 {"var ", " = {};"}, 6012 {"var ", " = {};"},
6039 {"'use strict'; const ", " = {};"}, 6013 {"'use strict'; const ", " = {};"},
6040 {"function f(", ") {}"}, 6014 {"function f(", ") {}"},
6041 {"function f(argument1, ", ") {}"}, 6015 {"function f(argument1, ", ") {}"},
6042 {"var f = (", ") => {};"}, 6016 {"var f = (", ") => {};"},
6043 {"var f = (argument1,", ") => {};"}, 6017 {"var f = (argument1,", ") => {};"},
6044 {"try {} catch(", ") {}"}, 6018 {"try {} catch(", ") {}"},
6045 {NULL, NULL}}; 6019 {NULL, NULL}};
6046 6020
(...skipping 30 matching lines...) Expand all
6077 "{var: x = 42}", 6051 "{var: x = 42}",
6078 "{[x] : z}", 6052 "{[x] : z}",
6079 "{[1+1] : z}", 6053 "{[1+1] : z}",
6080 "{[foo()] : z}", 6054 "{[foo()] : z}",
6081 "{}", 6055 "{}",
6082 "[...rest]", 6056 "[...rest]",
6083 "[a,b,...rest]", 6057 "[a,b,...rest]",
6084 "[a,,...rest]", 6058 "[a,,...rest]",
6085 NULL}; 6059 NULL};
6086 // clang-format on 6060 // clang-format on
6087 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring}; 6061 RunParserSyncTest(context_data, data, kSuccess);
6088 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
6089 arraysize(always_flags));
6090 RunParserSyncTest(context_data, data, kSuccess, NULL, 0,
6091 kAllDestructuringFlags, arraysize(kAllDestructuringFlags));
6092 } 6062 }
6093 6063
6094 6064
6095 TEST(DestructuringNegativeTests) { 6065 TEST(DestructuringNegativeTests) {
6096 i::FLAG_harmony_destructuring_bind = true;
6097 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring};
6098
6099 { // All modes. 6066 { // All modes.
6100 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, 6067 const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
6101 {"var ", " = {};"}, 6068 {"var ", " = {};"},
6102 {"'use strict'; const ", " = {};"}, 6069 {"'use strict'; const ", " = {};"},
6103 {"function f(", ") {}"}, 6070 {"function f(", ") {}"},
6104 {"function f(argument1, ", ") {}"}, 6071 {"function f(argument1, ", ") {}"},
6105 {"var f = (", ") => {};"}, 6072 {"var f = (", ") => {};"},
6106 {"var f = ", " => {};"}, 6073 {"var f = ", " => {};"},
6107 {"var f = (argument1,", ") => {};"}, 6074 {"var f = (argument1,", ") => {};"},
6108 {"try {} catch(", ") {}"}, 6075 {"try {} catch(", ") {}"},
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
6173 "{ x : 3 }", 6140 "{ x : 3 }",
6174 "{ x : 'foo' }", 6141 "{ x : 'foo' }",
6175 "{ x : /foo/ }", 6142 "{ x : /foo/ }",
6176 "{ x : `foo` }", 6143 "{ x : `foo` }",
6177 "{ get a() {} }", 6144 "{ get a() {} }",
6178 "{ set a() {} }", 6145 "{ set a() {} }",
6179 "{ method() {} }", 6146 "{ method() {} }",
6180 "{ *method() {} }", 6147 "{ *method() {} }",
6181 NULL}; 6148 NULL};
6182 // clang-format on 6149 // clang-format on
6183 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 6150 RunParserSyncTest(context_data, data, kError);
6184 arraysize(always_flags));
6185 RunParserSyncTest(context_data, data, kError, NULL, 0,
6186 kAllDestructuringFlags,
6187 arraysize(kAllDestructuringFlags));
6188 } 6151 }
6189 6152
6190 { // All modes. 6153 { // All modes.
6191 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, 6154 const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
6192 {"var ", " = {};"}, 6155 {"var ", " = {};"},
6193 {"'use strict'; const ", " = {};"}, 6156 {"'use strict'; const ", " = {};"},
6194 {"function f(", ") {}"}, 6157 {"function f(", ") {}"},
6195 {"function f(argument1, ", ") {}"}, 6158 {"function f(argument1, ", ") {}"},
6196 {"var f = (", ") => {};"}, 6159 {"var f = (", ") => {};"},
6197 {"var f = (argument1,", ") => {};"}, 6160 {"var f = (argument1,", ") => {};"},
6198 {NULL, NULL}}; 6161 {NULL, NULL}};
6199 6162
6200 // clang-format off 6163 // clang-format off
6201 const char* data[] = { 6164 const char* data[] = {
6202 "x => x", 6165 "x => x",
6203 "() => x", 6166 "() => x",
6204 NULL}; 6167 NULL};
6205 // clang-format on 6168 // clang-format on
6206 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 6169 RunParserSyncTest(context_data, data, kError);
6207 arraysize(always_flags));
6208 RunParserSyncTest(context_data, data, kError, NULL, 0,
6209 kAllDestructuringFlags,
6210 arraysize(kAllDestructuringFlags));
6211 } 6170 }
6212 6171
6213 { // Strict mode. 6172 { // Strict mode.
6214 const char* context_data[][2] = { 6173 const char* context_data[][2] = {
6215 {"'use strict'; let ", " = {};"}, 6174 {"'use strict'; let ", " = {};"},
6216 {"'use strict'; const ", " = {};"}, 6175 {"'use strict'; const ", " = {};"},
6217 {"'use strict'; function f(", ") {}"}, 6176 {"'use strict'; function f(", ") {}"},
6218 {"'use strict'; function f(argument1, ", ") {}"}, 6177 {"'use strict'; function f(argument1, ", ") {}"},
6219 {NULL, NULL}}; 6178 {NULL, NULL}};
6220 6179
6221 // clang-format off 6180 // clang-format off
6222 const char* data[] = { 6181 const char* data[] = {
6223 "[eval]", 6182 "[eval]",
6224 "{ a : arguments }", 6183 "{ a : arguments }",
6225 "[public]", 6184 "[public]",
6226 "{ x : private }", 6185 "{ x : private }",
6227 NULL}; 6186 NULL};
6228 // clang-format on 6187 // clang-format on
6229 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 6188 RunParserSyncTest(context_data, data, kError);
6230 arraysize(always_flags));
6231 RunParserSyncTest(context_data, data, kError, NULL, 0,
6232 kAllDestructuringFlags,
6233 arraysize(kAllDestructuringFlags));
6234 } 6189 }
6235 6190
6236 { // 'yield' in generators. 6191 { // 'yield' in generators.
6237 const char* context_data[][2] = { 6192 const char* context_data[][2] = {
6238 {"function*() { var ", " = {};"}, 6193 {"function*() { var ", " = {};"},
6239 {"function*() { 'use strict'; let ", " = {};"}, 6194 {"function*() { 'use strict'; let ", " = {};"},
6240 {"function*() { 'use strict'; const ", " = {};"}, 6195 {"function*() { 'use strict'; const ", " = {};"},
6241 {NULL, NULL}}; 6196 {NULL, NULL}};
6242 6197
6243 // clang-format off 6198 // clang-format off
6244 const char* data[] = { 6199 const char* data[] = {
6245 "yield", 6200 "yield",
6246 "[yield]", 6201 "[yield]",
6247 "{ x : yield }", 6202 "{ x : yield }",
6248 NULL}; 6203 NULL};
6249 // clang-format on 6204 // clang-format on
6250 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 6205 RunParserSyncTest(context_data, data, kError);
6251 arraysize(always_flags));
6252 RunParserSyncTest(context_data, data, kError, NULL, 0,
6253 kAllDestructuringFlags,
6254 arraysize(kAllDestructuringFlags));
6255 } 6206 }
6256 6207
6257 { // Declaration-specific errors 6208 { // Declaration-specific errors
6258 const char* context_data[][2] = {{"'use strict'; var ", ""}, 6209 const char* context_data[][2] = {{"'use strict'; var ", ""},
6259 {"'use strict'; let ", ""}, 6210 {"'use strict'; let ", ""},
6260 {"'use strict'; const ", ""}, 6211 {"'use strict'; const ", ""},
6261 {"'use strict'; for (var ", ";;) {}"}, 6212 {"'use strict'; for (var ", ";;) {}"},
6262 {"'use strict'; for (let ", ";;) {}"}, 6213 {"'use strict'; for (let ", ";;) {}"},
6263 {"'use strict'; for (const ", ";;) {}"}, 6214 {"'use strict'; for (const ", ";;) {}"},
6264 {"var ", ""}, 6215 {"var ", ""},
6265 {"let ", ""}, 6216 {"let ", ""},
6266 {"const ", ""}, 6217 {"const ", ""},
6267 {"for (var ", ";;) {}"}, 6218 {"for (var ", ";;) {}"},
6268 {"for (let ", ";;) {}"}, 6219 {"for (let ", ";;) {}"},
6269 {"for (const ", ";;) {}"}, 6220 {"for (const ", ";;) {}"},
6270 {NULL, NULL}}; 6221 {NULL, NULL}};
6271 6222
6272 // clang-format off 6223 // clang-format off
6273 const char* data[] = { 6224 const char* data[] = {
6274 "{ a }", 6225 "{ a }",
6275 "[ a ]", 6226 "[ a ]",
6276 NULL}; 6227 NULL};
6277 // clang-format on 6228 // clang-format on
6278 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring, 6229 static const ParserFlag always_flags[] = {kAllowHarmonySloppyLet};
6279 kAllowHarmonySloppyLet};
6280 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 6230 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
6281 arraysize(always_flags)); 6231 arraysize(always_flags));
6282 } 6232 }
6283 } 6233 }
6284 6234
6285 6235
6286 TEST(DestructuringAssignmentPositiveTests) { 6236 TEST(DestructuringAssignmentPositiveTests) {
6287 const char* context_data[][2] = { 6237 const char* context_data[][2] = {
6288 {"'use strict'; let x, y, z; (", " = {});"}, 6238 {"'use strict'; let x, y, z; (", " = {});"},
6289 {"var x, y, z; (", " = {});"}, 6239 {"var x, y, z; (", " = {});"},
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
6442 "{ x: (foo['bar']) }", 6392 "{ x: (foo['bar']) }",
6443 "[ ...(a) ]", 6393 "[ ...(a) ]",
6444 "[ ...(foo['bar']) ]", 6394 "[ ...(foo['bar']) ]",
6445 "[ ...(foo.bar) ]", 6395 "[ ...(foo.bar) ]",
6446 "[ (y) ]", 6396 "[ (y) ]",
6447 "[ (foo.bar) ]", 6397 "[ (foo.bar) ]",
6448 "[ (foo['bar']) ]", 6398 "[ (foo['bar']) ]",
6449 6399
6450 NULL}; 6400 NULL};
6451 // clang-format on 6401 // clang-format on
6452 static const ParserFlag always_flags[] = { 6402 RunParserSyncTest(context_data, data, kSuccess);
6453 kAllowHarmonyDestructuringAssignment, kAllowHarmonyDestructuring,
6454 kAllowHarmonyDefaultParameters};
6455 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
6456 arraysize(always_flags));
6457 6403
6458 RunParserSyncTest(mixed_assignments_context_data, data, kSuccess, NULL, 0, 6404 RunParserSyncTest(mixed_assignments_context_data, data, kSuccess);
6459 always_flags, arraysize(always_flags));
6460 6405
6461 const char* empty_context_data[][2] = { 6406 const char* empty_context_data[][2] = {
6462 {"'use strict';", ""}, {"", ""}, {NULL, NULL}}; 6407 {"'use strict';", ""}, {"", ""}, {NULL, NULL}};
6463 6408
6464 // CoverInitializedName ambiguity handling in various contexts 6409 // CoverInitializedName ambiguity handling in various contexts
6465 const char* ambiguity_data[] = { 6410 const char* ambiguity_data[] = {
6466 "var foo = { x = 10 } = {};", 6411 "var foo = { x = 10 } = {};",
6467 "var foo = { q } = { x = 10 } = {};", 6412 "var foo = { q } = { x = 10 } = {};",
6468 "var foo; foo = { x = 10 } = {};", 6413 "var foo; foo = { x = 10 } = {};",
6469 "var foo; foo = { q } = { x = 10 } = {};", 6414 "var foo; foo = { q } = { x = 10 } = {};",
6470 "var x; ({ x = 10 } = {});", 6415 "var x; ({ x = 10 } = {});",
6471 "var q, x; ({ q } = { x = 10 } = {});", 6416 "var q, x; ({ q } = { x = 10 } = {});",
6472 "var x; [{ x = 10 } = {}]", 6417 "var x; [{ x = 10 } = {}]",
6473 "var x; (true ? { x = true } = {} : { x = false } = {})", 6418 "var x; (true ? { x = true } = {} : { x = false } = {})",
6474 "var q, x; (q, { x = 10 } = {});", 6419 "var q, x; (q, { x = 10 } = {});",
6475 "var { x = 10 } = { x = 20 } = {};", 6420 "var { x = 10 } = { x = 20 } = {};",
6476 "var { x = 10 } = (o = { x = 20 } = {});", 6421 "var { x = 10 } = (o = { x = 20 } = {});",
6477 "var x; (({ x = 10 } = { x = 20 } = {}) => x)({})", 6422 "var x; (({ x = 10 } = { x = 20 } = {}) => x)({})",
6478 NULL, 6423 NULL,
6479 }; 6424 };
6480 RunParserSyncTest(empty_context_data, ambiguity_data, kSuccess, NULL, 0, 6425 RunParserSyncTest(empty_context_data, ambiguity_data, kSuccess);
6481 always_flags, arraysize(always_flags));
6482 } 6426 }
6483 6427
6484 6428
6485 TEST(DestructuringAssignmentNegativeTests) { 6429 TEST(DestructuringAssignmentNegativeTests) {
6486 const char* context_data[][2] = { 6430 const char* context_data[][2] = {
6487 {"'use strict'; let x, y, z; (", " = {});"}, 6431 {"'use strict'; let x, y, z; (", " = {});"},
6488 {"var x, y, z; (", " = {});"}, 6432 {"var x, y, z; (", " = {});"},
6489 {"'use strict'; let x, y, z; for (x in ", " = {});"}, 6433 {"'use strict'; let x, y, z; for (x in ", " = {});"},
6490 {"'use strict'; let x, y, z; for (x of ", " = {});"}, 6434 {"'use strict'; let x, y, z; for (x of ", " = {});"},
6491 {"var x, y, z; for (x in ", " = {});"}, 6435 {"var x, y, z; for (x in ", " = {});"},
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
6570 "[ (...[a]) ]", 6514 "[ (...[a]) ]",
6571 "[ ([a] = []) ]", 6515 "[ ([a] = []) ]",
6572 "[ (++y) ]", 6516 "[ (++y) ]",
6573 "[ ...(++y) ]", 6517 "[ ...(++y) ]",
6574 6518
6575 "[ x += x ]", 6519 "[ x += x ]",
6576 "{ foo: x += x }", 6520 "{ foo: x += x }",
6577 6521
6578 NULL}; 6522 NULL};
6579 // clang-format on 6523 // clang-format on
6580 static const ParserFlag always_flags[] = { 6524 RunParserSyncTest(context_data, data, kError);
6581 kAllowHarmonyDestructuringAssignment, kAllowHarmonyDestructuring,
6582 kAllowHarmonyDefaultParameters};
6583 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
6584 arraysize(always_flags));
6585 6525
6586 const char* empty_context_data[][2] = { 6526 const char* empty_context_data[][2] = {
6587 {"'use strict';", ""}, {"", ""}, {NULL, NULL}}; 6527 {"'use strict';", ""}, {"", ""}, {NULL, NULL}};
6588 6528
6589 // CoverInitializedName ambiguity handling in various contexts 6529 // CoverInitializedName ambiguity handling in various contexts
6590 const char* ambiguity_data[] = { 6530 const char* ambiguity_data[] = {
6591 "var foo = { x = 10 };", 6531 "var foo = { x = 10 };",
6592 "var foo = { q } = { x = 10 };", 6532 "var foo = { q } = { x = 10 };",
6593 "var foo; foo = { x = 10 };", 6533 "var foo; foo = { x = 10 };",
6594 "var foo; foo = { q } = { x = 10 };", 6534 "var foo; foo = { q } = { x = 10 };",
6595 "var x; ({ x = 10 });", 6535 "var x; ({ x = 10 });",
6596 "var q, x; ({ q } = { x = 10 });", 6536 "var q, x; ({ q } = { x = 10 });",
6597 "var x; [{ x = 10 }]", 6537 "var x; [{ x = 10 }]",
6598 "var x; (true ? { x = true } : { x = false })", 6538 "var x; (true ? { x = true } : { x = false })",
6599 "var q, x; (q, { x = 10 });", 6539 "var q, x; (q, { x = 10 });",
6600 "var { x = 10 } = { x = 20 };", 6540 "var { x = 10 } = { x = 20 };",
6601 "var { x = 10 } = (o = { x = 20 });", 6541 "var { x = 10 } = (o = { x = 20 });",
6602 "var x; (({ x = 10 } = { x = 20 }) => x)({})", 6542 "var x; (({ x = 10 } = { x = 20 }) => x)({})",
6603 6543
6604 // Not ambiguous, but uses same context data 6544 // Not ambiguous, but uses same context data
6605 "switch([window %= []] = []) { default: }", 6545 "switch([window %= []] = []) { default: }",
6606 6546
6607 NULL, 6547 NULL,
6608 }; 6548 };
6609 RunParserSyncTest(empty_context_data, ambiguity_data, kError, NULL, 0, 6549 RunParserSyncTest(empty_context_data, ambiguity_data, kError);
6610 always_flags, arraysize(always_flags));
6611 6550
6612 // Strict mode errors 6551 // Strict mode errors
6613 const char* strict_context_data[][2] = {{"'use strict'; (", " = {})"}, 6552 const char* strict_context_data[][2] = {{"'use strict'; (", " = {})"},
6614 {"'use strict'; for (", " of {}) {}"}, 6553 {"'use strict'; for (", " of {}) {}"},
6615 {"'use strict'; for (", " in {}) {}"}, 6554 {"'use strict'; for (", " in {}) {}"},
6616 {NULL, NULL}}; 6555 {NULL, NULL}};
6617 const char* strict_data[] = {"{ eval }", 6556 const char* strict_data[] = {"{ eval }",
6618 "{ arguments }", 6557 "{ arguments }",
6619 "{ foo: eval }", 6558 "{ foo: eval }",
6620 "{ foo: arguments }", 6559 "{ foo: arguments }",
(...skipping 20 matching lines...) Expand all
6641 "[ (eval) = 0 ]", 6580 "[ (eval) = 0 ]",
6642 "[ (arguments) = 0 ]", 6581 "[ (arguments) = 0 ]",
6643 "[ ...(eval) ]", 6582 "[ ...(eval) ]",
6644 "[ ...(arguments) ]", 6583 "[ ...(arguments) ]",
6645 "[ ...(eval = 0) ]", 6584 "[ ...(eval = 0) ]",
6646 "[ ...(arguments = 0) ]", 6585 "[ ...(arguments = 0) ]",
6647 "[ ...(eval) = 0 ]", 6586 "[ ...(eval) = 0 ]",
6648 "[ ...(arguments) = 0 ]", 6587 "[ ...(arguments) = 0 ]",
6649 6588
6650 NULL}; 6589 NULL};
6651 RunParserSyncTest(strict_context_data, strict_data, kError, NULL, 0, 6590 RunParserSyncTest(strict_context_data, strict_data, kError);
6652 always_flags, arraysize(always_flags));
6653 } 6591 }
6654 6592
6655 6593
6656 TEST(DestructuringDisallowPatternsInForVarIn) { 6594 TEST(DestructuringDisallowPatternsInForVarIn) {
6657 i::FLAG_harmony_destructuring_bind = true;
6658 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring};
6659 const char* context_data[][2] = { 6595 const char* context_data[][2] = {
6660 {"", ""}, {"function f() {", "}"}, {NULL, NULL}}; 6596 {"", ""}, {"function f() {", "}"}, {NULL, NULL}};
6661 // clang-format off 6597 // clang-format off
6662 const char* error_data[] = { 6598 const char* error_data[] = {
6663 "for (let x = {} in null);", 6599 "for (let x = {} in null);",
6664 "for (let x = {} of null);", 6600 "for (let x = {} of null);",
6665 NULL}; 6601 NULL};
6666 // clang-format on 6602 // clang-format on
6667 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags, 6603 RunParserSyncTest(context_data, error_data, kError);
6668 arraysize(always_flags));
6669 6604
6670 // clang-format off 6605 // clang-format off
6671 const char* success_data[] = { 6606 const char* success_data[] = {
6672 "for (var x = {} in null);", 6607 "for (var x = {} in null);",
6673 NULL}; 6608 NULL};
6674 // clang-format on 6609 // clang-format on
6675 RunParserSyncTest(context_data, success_data, kSuccess, NULL, 0, always_flags, 6610 RunParserSyncTest(context_data, success_data, kSuccess);
6676 arraysize(always_flags));
6677 } 6611 }
6678 6612
6679 6613
6680 TEST(DestructuringDuplicateParams) { 6614 TEST(DestructuringDuplicateParams) {
6681 i::FLAG_harmony_destructuring_bind = true;
6682 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring};
6683 const char* context_data[][2] = {{"'use strict';", ""}, 6615 const char* context_data[][2] = {{"'use strict';", ""},
6684 {"function outer() { 'use strict';", "}"}, 6616 {"function outer() { 'use strict';", "}"},
6685 {nullptr, nullptr}}; 6617 {nullptr, nullptr}};
6686 6618
6687 6619
6688 // clang-format off 6620 // clang-format off
6689 const char* error_data[] = { 6621 const char* error_data[] = {
6690 "function f(x,x){}", 6622 "function f(x,x){}",
6691 "function f(x, {x : x}){}", 6623 "function f(x, {x : x}){}",
6692 "function f(x, {x}){}", 6624 "function f(x, {x}){}",
6693 "function f({x,x}) {}", 6625 "function f({x,x}) {}",
6694 "function f([x,x]) {}", 6626 "function f([x,x]) {}",
6695 "function f(x, [y,{z:x}]) {}", 6627 "function f(x, [y,{z:x}]) {}",
6696 "function f([x,{y:x}]) {}", 6628 "function f([x,{y:x}]) {}",
6697 // non-simple parameter list causes duplicates to be errors in sloppy mode. 6629 // non-simple parameter list causes duplicates to be errors in sloppy mode.
6698 "function f(x, x, {a}) {}", 6630 "function f(x, x, {a}) {}",
6699 nullptr}; 6631 nullptr};
6700 // clang-format on 6632 // clang-format on
6701 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags, 6633 RunParserSyncTest(context_data, error_data, kError);
6702 arraysize(always_flags));
6703 } 6634 }
6704 6635
6705 6636
6706 TEST(DestructuringDuplicateParamsSloppy) { 6637 TEST(DestructuringDuplicateParamsSloppy) {
6707 i::FLAG_harmony_destructuring_bind = true;
6708 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring};
6709 const char* context_data[][2] = { 6638 const char* context_data[][2] = {
6710 {"", ""}, {"function outer() {", "}"}, {nullptr, nullptr}}; 6639 {"", ""}, {"function outer() {", "}"}, {nullptr, nullptr}};
6711 6640
6712 6641
6713 // clang-format off 6642 // clang-format off
6714 const char* error_data[] = { 6643 const char* error_data[] = {
6715 // non-simple parameter list causes duplicates to be errors in sloppy mode. 6644 // non-simple parameter list causes duplicates to be errors in sloppy mode.
6716 "function f(x, {x : x}){}", 6645 "function f(x, {x : x}){}",
6717 "function f(x, {x}){}", 6646 "function f(x, {x}){}",
6718 "function f({x,x}) {}", 6647 "function f({x,x}) {}",
6719 "function f(x, x, {a}) {}", 6648 "function f(x, x, {a}) {}",
6720 nullptr}; 6649 nullptr};
6721 // clang-format on 6650 // clang-format on
6722 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags, 6651 RunParserSyncTest(context_data, error_data, kError);
6723 arraysize(always_flags));
6724 } 6652 }
6725 6653
6726 6654
6727 TEST(DestructuringDisallowPatternsInSingleParamArrows) { 6655 TEST(DestructuringDisallowPatternsInSingleParamArrows) {
6728 i::FLAG_harmony_destructuring_bind = true;
6729 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring};
6730 const char* context_data[][2] = {{"'use strict';", ""}, 6656 const char* context_data[][2] = {{"'use strict';", ""},
6731 {"function outer() { 'use strict';", "}"}, 6657 {"function outer() { 'use strict';", "}"},
6732 {"", ""}, 6658 {"", ""},
6733 {"function outer() { ", "}"}, 6659 {"function outer() { ", "}"},
6734 {nullptr, nullptr}}; 6660 {nullptr, nullptr}};
6735 6661
6736 // clang-format off 6662 // clang-format off
6737 const char* error_data[] = { 6663 const char* error_data[] = {
6738 "var f = {x} => {};", 6664 "var f = {x} => {};",
6739 "var f = {x,y} => {};", 6665 "var f = {x,y} => {};",
6740 nullptr}; 6666 nullptr};
6741 // clang-format on 6667 // clang-format on
6742 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags, 6668 RunParserSyncTest(context_data, error_data, kError);
6743 arraysize(always_flags));
6744 } 6669 }
6745 6670
6746 6671
6747 TEST(DefaultParametersYieldInInitializers) { 6672 TEST(DefaultParametersYieldInInitializers) {
6748 // clang-format off 6673 // clang-format off
6749 const char* sloppy_function_context_data[][2] = { 6674 const char* sloppy_function_context_data[][2] = {
6750 {"(function f(", ") { });"}, 6675 {"(function f(", ") { });"},
6751 {NULL, NULL} 6676 {NULL, NULL}
6752 }; 6677 };
6753 6678
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
6793 6718
6794 "{x}=(yield)", 6719 "{x}=(yield)",
6795 "[x]=(yield)", 6720 "[x]=(yield)",
6796 6721
6797 "{x}=f(yield)", 6722 "{x}=f(yield)",
6798 "[x]=f(yield)", 6723 "[x]=f(yield)",
6799 NULL 6724 NULL
6800 }; 6725 };
6801 6726
6802 // clang-format on 6727 // clang-format on
6803 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring,
6804 kAllowHarmonyDefaultParameters};
6805 6728
6806 RunParserSyncTest(sloppy_function_context_data, parameter_data, kSuccess, 6729 RunParserSyncTest(sloppy_function_context_data, parameter_data, kSuccess);
6807 NULL, 0, always_flags, arraysize(always_flags)); 6730 RunParserSyncTest(sloppy_arrow_context_data, parameter_data, kSuccess);
6808 RunParserSyncTest(sloppy_arrow_context_data, parameter_data, kSuccess, NULL,
6809 0, always_flags, arraysize(always_flags));
6810 6731
6811 RunParserSyncTest(strict_function_context_data, parameter_data, kError, NULL, 6732 RunParserSyncTest(strict_function_context_data, parameter_data, kError);
6812 0, always_flags, arraysize(always_flags)); 6733 RunParserSyncTest(strict_arrow_context_data, parameter_data, kError);
6813 RunParserSyncTest(strict_arrow_context_data, parameter_data, kError, NULL, 0,
6814 always_flags, arraysize(always_flags));
6815 6734
6816 RunParserSyncTest(generator_context_data, parameter_data, kError, NULL, 0, 6735 RunParserSyncTest(generator_context_data, parameter_data, kError);
6817 always_flags, arraysize(always_flags));
6818 } 6736 }
6819 6737
6820 6738
6821 TEST(SpreadArray) { 6739 TEST(SpreadArray) {
6822 const char* context_data[][2] = { 6740 const char* context_data[][2] = {
6823 {"'use strict';", ""}, {"", ""}, {NULL, NULL}}; 6741 {"'use strict';", ""}, {"", ""}, {NULL, NULL}};
6824 6742
6825 // clang-format off 6743 // clang-format off
6826 const char* data[] = { 6744 const char* data[] = {
6827 "[...a]", 6745 "[...a]",
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
7019 "a, b, {c, d, e}", 6937 "a, b, {c, d, e}",
7020 "initializer = true", 6938 "initializer = true",
7021 "a, b, c = 1", 6939 "a, b, c = 1",
7022 "...args", 6940 "...args",
7023 "a, b, ...rest", 6941 "a, b, ...rest",
7024 "[a, b, ...rest]", 6942 "[a, b, ...rest]",
7025 "{ bindingPattern = {} }", 6943 "{ bindingPattern = {} }",
7026 "{ initializedBindingPattern } = { initializedBindingPattern: true }", 6944 "{ initializedBindingPattern } = { initializedBindingPattern: true }",
7027 NULL}; 6945 NULL};
7028 6946
7029 static const ParserFlag always_flags[] = { 6947 static const ParserFlag always_flags[] = {kAllowHarmonySloppy};
7030 kAllowHarmonyDefaultParameters, kAllowHarmonyDestructuring,
7031 kAllowHarmonySloppy};
7032 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 6948 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
7033 arraysize(always_flags)); 6949 arraysize(always_flags));
7034 } 6950 }
7035 6951
7036 6952
7037 TEST(LetSloppyOnly) { 6953 TEST(LetSloppyOnly) {
7038 // clang-format off 6954 // clang-format off
7039 const char* context_data[][2] = { 6955 const char* context_data[][2] = {
7040 {"", ""}, 6956 {"", ""},
7041 {"{", "}"}, 6957 {"{", "}"},
(...skipping 15 matching lines...) Expand all
7057 "for (const let = 1; let < 1; let++) {}", 6973 "for (const let = 1; let < 1; let++) {}",
7058 "for (const let in {}) {}", 6974 "for (const let in {}) {}",
7059 "for (const [let] = 1; let < 1; let++) {}", 6975 "for (const [let] = 1; let < 1; let++) {}",
7060 "for (const [let] in {}) {}", 6976 "for (const [let] in {}) {}",
7061 "const let", 6977 "const let",
7062 "const [let] = []", 6978 "const [let] = []",
7063 NULL 6979 NULL
7064 }; 6980 };
7065 // clang-format on 6981 // clang-format on
7066 6982
7067 static const ParserFlag always_flags[] = { 6983 static const ParserFlag always_flags[] = {kAllowHarmonySloppy,
7068 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kAllowHarmonyDestructuring}; 6984 kAllowHarmonySloppyLet};
7069 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, 6985 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
7070 arraysize(always_flags)); 6986 arraysize(always_flags));
7071 6987
7072 // Some things should be rejected even in sloppy mode 6988 // Some things should be rejected even in sloppy mode
7073 // This addresses BUG(v8:4403). 6989 // This addresses BUG(v8:4403).
7074 6990
7075 // clang-format off 6991 // clang-format off
7076 const char* fail_data[] = { 6992 const char* fail_data[] = {
7077 "let let = 1", 6993 "let let = 1",
7078 "for (let let = 1; let < 1; let++) {}", 6994 "for (let let = 1; let < 1; let++) {}",
(...skipping 16 matching lines...) Expand all
7095 "let l\\u0065t = 1", 7011 "let l\\u0065t = 1",
7096 "const l\\u0065t = 1", 7012 "const l\\u0065t = 1",
7097 "let [l\\u0065t] = 1", 7013 "let [l\\u0065t] = 1",
7098 "const [l\\u0065t] = 1", 7014 "const [l\\u0065t] = 1",
7099 "for (let l\\u0065t in {}) {}", 7015 "for (let l\\u0065t in {}) {}",
7100 NULL 7016 NULL
7101 }; 7017 };
7102 // clang-format on 7018 // clang-format on
7103 7019
7104 static const ParserFlag fail_flags[] = { 7020 static const ParserFlag fail_flags[] = {
7105 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kNoLegacyConst, 7021 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kNoLegacyConst};
7106 kAllowHarmonyDestructuring};
7107 RunParserSyncTest(context_data, fail_data, kError, NULL, 0, fail_flags, 7022 RunParserSyncTest(context_data, fail_data, kError, NULL, 0, fail_flags,
7108 arraysize(fail_flags)); 7023 arraysize(fail_flags));
7109 } 7024 }
7110 7025
7111 7026
7112 TEST(EscapedKeywords) { 7027 TEST(EscapedKeywords) {
7113 // clang-format off 7028 // clang-format off
7114 const char* sloppy_context_data[][2] = { 7029 const char* sloppy_context_data[][2] = {
7115 {"", ""}, 7030 {"", ""},
7116 {NULL, NULL} 7031 {NULL, NULL}
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
7198 "class C { st\\u0061tic set bar() {} }", 7113 "class C { st\\u0061tic set bar() {} }",
7199 7114
7200 // TODO(adamk): These should not be errors in sloppy mode. 7115 // TODO(adamk): These should not be errors in sloppy mode.
7201 "(y\\u0069eld);", 7116 "(y\\u0069eld);",
7202 "var y\\u0069eld = 1;", 7117 "var y\\u0069eld = 1;",
7203 "var { y\\u0069eld } = {};", 7118 "var { y\\u0069eld } = {};",
7204 NULL 7119 NULL
7205 }; 7120 };
7206 // clang-format on 7121 // clang-format on
7207 7122
7208 static const ParserFlag always_flags[] = {kAllowHarmonySloppy, 7123 static const ParserFlag always_flags[] = {kAllowHarmonySloppy};
7209 kAllowHarmonyDestructuring};
7210 RunParserSyncTest(sloppy_context_data, fail_data, kError, NULL, 0, 7124 RunParserSyncTest(sloppy_context_data, fail_data, kError, NULL, 0,
7211 always_flags, arraysize(always_flags)); 7125 always_flags, arraysize(always_flags));
7212 RunParserSyncTest(strict_context_data, fail_data, kError, NULL, 0, 7126 RunParserSyncTest(strict_context_data, fail_data, kError, NULL, 0,
7213 always_flags, arraysize(always_flags)); 7127 always_flags, arraysize(always_flags));
7214 RunModuleParserSyncTest(sloppy_context_data, fail_data, kError, NULL, 0, 7128 RunModuleParserSyncTest(sloppy_context_data, fail_data, kError, NULL, 0,
7215 always_flags, arraysize(always_flags)); 7129 always_flags, arraysize(always_flags));
7216 7130
7217 // clang-format off 7131 // clang-format off
7218 const char* let_data[] = { 7132 const char* let_data[] = {
7219 "var l\\u0065t = 1;", 7133 "var l\\u0065t = 1;",
7220 "l\\u0065t = 1;", 7134 "l\\u0065t = 1;",
7221 "(l\\u0065t === 1);", 7135 "(l\\u0065t === 1);",
7222 NULL 7136 NULL
7223 }; 7137 };
7224 // clang-format on 7138 // clang-format on
7225 7139
7226 RunParserSyncTest(sloppy_context_data, let_data, kSuccess, NULL, 0, 7140 RunParserSyncTest(sloppy_context_data, let_data, kSuccess, NULL, 0,
7227 always_flags, arraysize(always_flags)); 7141 always_flags, arraysize(always_flags));
7228 RunParserSyncTest(strict_context_data, let_data, kError, NULL, 0, 7142 RunParserSyncTest(strict_context_data, let_data, kError, NULL, 0,
7229 always_flags, arraysize(always_flags)); 7143 always_flags, arraysize(always_flags));
7230 7144
7231 static const ParserFlag sloppy_let_flags[] = { 7145 static const ParserFlag sloppy_let_flags[] = {kAllowHarmonySloppy,
7232 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kAllowHarmonyDestructuring}; 7146 kAllowHarmonySloppyLet};
7233 RunParserSyncTest(sloppy_context_data, let_data, kSuccess, NULL, 0, 7147 RunParserSyncTest(sloppy_context_data, let_data, kSuccess, NULL, 0,
7234 sloppy_let_flags, arraysize(sloppy_let_flags)); 7148 sloppy_let_flags, arraysize(sloppy_let_flags));
7235 7149
7236 // Non-errors in sloppy mode 7150 // Non-errors in sloppy mode
7237 const char* valid_data[] = {"(\\u0069mplements = 1);", 7151 const char* valid_data[] = {"(\\u0069mplements = 1);",
7238 "var impl\\u0065ments = 1;", 7152 "var impl\\u0065ments = 1;",
7239 "var { impl\\u0065ments } = {};", 7153 "var { impl\\u0065ments } = {};",
7240 "(\\u0069nterface = 1);", 7154 "(\\u0069nterface = 1);",
7241 "var int\\u0065rface = 1;", 7155 "var int\\u0065rface = 1;",
7242 "var { int\\u0065rface } = {};", 7156 "var { int\\u0065rface } = {};",
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
7380 RunParserSyncTest(sloppy_context, error_data, kError); 7294 RunParserSyncTest(sloppy_context, error_data, kError);
7381 RunParserSyncTest(sloppy_context, error_data, kError, NULL, 0, 7295 RunParserSyncTest(sloppy_context, error_data, kError, NULL, 0,
7382 restrictive_flags, arraysize(restrictive_flags)); 7296 restrictive_flags, arraysize(restrictive_flags));
7383 RunParserSyncTest(sloppy_context, unrestricted_data, kSuccess); 7297 RunParserSyncTest(sloppy_context, unrestricted_data, kSuccess);
7384 RunParserSyncTest(sloppy_context, unrestricted_data, kError, NULL, 0, 7298 RunParserSyncTest(sloppy_context, unrestricted_data, kError, NULL, 0,
7385 restrictive_flags, arraysize(restrictive_flags)); 7299 restrictive_flags, arraysize(restrictive_flags));
7386 RunParserSyncTest(sloppy_context, sloppy_data, kSuccess); 7300 RunParserSyncTest(sloppy_context, sloppy_data, kSuccess);
7387 RunParserSyncTest(sloppy_context, sloppy_data, kSuccess, restrictive_flags, 7301 RunParserSyncTest(sloppy_context, sloppy_data, kSuccess, restrictive_flags,
7388 arraysize(restrictive_flags)); 7302 arraysize(restrictive_flags));
7389 } 7303 }
OLDNEW
« no previous file with comments | « src/parsing/preparser.cc ('k') | test/message/default-parameter-tdz.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698