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

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

Issue 1941823003: Properly disallow 'yield' in class expressions and arrow parameters (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Better error message for yield in parameter Created 4 years, 7 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
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 2314 matching lines...) Expand 10 before | Expand all | Expand 10 after
2325 "yield // comment\n" 2325 "yield // comment\n"
2326 "(yield)", 2326 "(yield)",
2327 "[yield]", 2327 "[yield]",
2328 "{yield}", 2328 "{yield}",
2329 "yield, yield", 2329 "yield, yield",
2330 "yield; yield", 2330 "yield; yield",
2331 "(yield) ? yield : yield", 2331 "(yield) ? yield : yield",
2332 "(yield) \n ? yield : yield", 2332 "(yield) \n ? yield : yield",
2333 // If there is a newline before the next token, we don't look for RHS. 2333 // If there is a newline before the next token, we don't look for RHS.
2334 "yield\nfor (;;) {}", 2334 "yield\nfor (;;) {}",
2335 "x = class extends (yield) {}",
2336 "x = class extends f(yield) {}",
2337 "x = class extends (null, yield) { }",
2338 "x = class extends (a ? null : yield) { }",
2335 NULL 2339 NULL
2336 }; 2340 };
2337 // clang-format on 2341 // clang-format on
2338 2342
2339 RunParserSyncTest(context_data, statement_data, kSuccess); 2343 RunParserSyncTest(context_data, statement_data, kSuccess);
2340 } 2344 }
2341 2345
2342 2346
2343 TEST(ErrorsYieldGenerator) { 2347 TEST(ErrorsYieldGenerator) {
2344 // clang-format off 2348 // clang-format off
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2389 "({a: yield} = {a: 42});", 2393 "({a: yield} = {a: 42});",
2390 // Also disallow full yield expressions on LHS 2394 // Also disallow full yield expressions on LHS
2391 "var [yield 24] = [42];", 2395 "var [yield 24] = [42];",
2392 "var {foo: yield 24} = {a: 42};", 2396 "var {foo: yield 24} = {a: 42};",
2393 "[yield 24] = [42];", 2397 "[yield 24] = [42];",
2394 "({a: yield 24} = {a: 42});", 2398 "({a: yield 24} = {a: 42});",
2395 "for (yield 'x' in {});", 2399 "for (yield 'x' in {});",
2396 "for (yield 'x' of {});", 2400 "for (yield 'x' of {});",
2397 "for (yield 'x' in {} in {});", 2401 "for (yield 'x' in {} in {});",
2398 "for (yield 'x' in {} of {});", 2402 "for (yield 'x' in {} of {});",
2403 "class C extends yield { }",
2399 NULL 2404 NULL
2400 }; 2405 };
2401 // clang-format on 2406 // clang-format on
2402 2407
2403 RunParserSyncTest(context_data, statement_data, kError); 2408 RunParserSyncTest(context_data, statement_data, kError);
2404 } 2409 }
2405 2410
2406 2411
2407 TEST(ErrorsNameOfStrictFunction) { 2412 TEST(ErrorsNameOfStrictFunction) {
2408 // Tests that illegal tokens as names of a strict function produce the correct 2413 // Tests that illegal tokens as names of a strict function produce the correct
(...skipping 4314 matching lines...) Expand 10 before | Expand all | Expand 10 after
6723 }; 6728 };
6724 6729
6725 const char* strict_arrow_context_data[][2] = { 6730 const char* strict_arrow_context_data[][2] = {
6726 {"'use strict'; ((", ")=>{});"}, 6731 {"'use strict'; ((", ")=>{});"},
6727 {NULL, NULL} 6732 {NULL, NULL}
6728 }; 6733 };
6729 6734
6730 const char* generator_context_data[][2] = { 6735 const char* generator_context_data[][2] = {
6731 {"'use strict'; (function *g(", ") { });"}, 6736 {"'use strict'; (function *g(", ") { });"},
6732 {"(function *g(", ") { });"}, 6737 {"(function *g(", ") { });"},
6738 // Arrow function within generator has the same rules.
6739 {"'use strict'; (function *g() { (", ") => {} });"},
6740 {"(function *g() { (", ") => {} });"},
6733 {NULL, NULL} 6741 {NULL, NULL}
6734 }; 6742 };
6735 6743
6736 const char* parameter_data[] = { 6744 const char* parameter_data[] = {
6737 "x=yield", 6745 "x=yield",
6738 "x, y=yield", 6746 "x, y=yield",
6739 "{x=yield}", 6747 "{x=yield}",
6740 "[x=yield]", 6748 "[x=yield]",
6741 6749
6742 "x=(yield)", 6750 "x=(yield)",
(...skipping 10 matching lines...) Expand all
6753 "[x]=yield", 6761 "[x]=yield",
6754 6762
6755 "{x}=(yield)", 6763 "{x}=(yield)",
6756 "[x]=(yield)", 6764 "[x]=(yield)",
6757 6765
6758 "{x}=f(yield)", 6766 "{x}=f(yield)",
6759 "[x]=f(yield)", 6767 "[x]=f(yield)",
6760 NULL 6768 NULL
6761 }; 6769 };
6762 6770
6771 // Because classes are always in strict mode, these are always errors.
6772 const char* always_error_param_data[] = {
6773 "x = class extends (yield) { }",
6774 "x = class extends f(yield) { }",
6775 "x = class extends (null, yield) { }",
6776 "x = class extends (a ? null : yield) { }",
6777 "[x] = [class extends (a ? null : yield) { }]",
6778 "[x = class extends (a ? null : yield) { }]",
6779 "[x = class extends (a ? null : yield) { }] = [null]",
6780 NULL
6781 };
6763 // clang-format on 6782 // clang-format on
6764 6783
6765 RunParserSyncTest(sloppy_function_context_data, parameter_data, kSuccess); 6784 RunParserSyncTest(sloppy_function_context_data, parameter_data, kSuccess);
6766 RunParserSyncTest(sloppy_arrow_context_data, parameter_data, kSuccess); 6785 RunParserSyncTest(sloppy_arrow_context_data, parameter_data, kSuccess);
6767 6786
6768 RunParserSyncTest(strict_function_context_data, parameter_data, kError); 6787 RunParserSyncTest(strict_function_context_data, parameter_data, kError);
6769 RunParserSyncTest(strict_arrow_context_data, parameter_data, kError); 6788 RunParserSyncTest(strict_arrow_context_data, parameter_data, kError);
6770 6789
6771 RunParserSyncTest(generator_context_data, parameter_data, kError); 6790 RunParserSyncTest(generator_context_data, parameter_data, kError);
6791 RunParserSyncTest(generator_context_data, always_error_param_data, kError);
6772 } 6792 }
6773 6793
6774
6775 TEST(SpreadArray) { 6794 TEST(SpreadArray) {
6776 const char* context_data[][2] = { 6795 const char* context_data[][2] = {
6777 {"'use strict';", ""}, {"", ""}, {NULL, NULL}}; 6796 {"'use strict';", ""}, {"", ""}, {NULL, NULL}};
6778 6797
6779 // clang-format off 6798 // clang-format off
6780 const char* data[] = { 6799 const char* data[] = {
6781 "[...a]", 6800 "[...a]",
6782 "[a, ...b]", 6801 "[a, ...b]",
6783 "[...a,]", 6802 "[...a,]",
6784 "[...a, ,]", 6803 "[...a, ,]",
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
7430 "for (const x = 0 in {});", 7449 "for (const x = 0 in {});",
7431 "for (let x = 0 in {});", 7450 "for (let x = 0 in {});",
7432 NULL 7451 NULL
7433 }; 7452 };
7434 // clang-format on 7453 // clang-format on
7435 7454
7436 static const ParserFlag always_flags[] = {kAllowHarmonyForIn}; 7455 static const ParserFlag always_flags[] = {kAllowHarmonyForIn};
7437 RunParserSyncTest(context_data, error_data, kError, nullptr, 0, always_flags, 7456 RunParserSyncTest(context_data, error_data, kError, nullptr, 0, always_flags,
7438 arraysize(always_flags)); 7457 arraysize(always_flags));
7439 } 7458 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698