| 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 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1267 result[i] = start[i + 1]; | 1267 result[i] = start[i + 1]; |
| 1268 } | 1268 } |
| 1269 result[length] = '\0'; | 1269 result[length] = '\0'; |
| 1270 return result; | 1270 return result; |
| 1271 } | 1271 } |
| 1272 | 1272 |
| 1273 enum ParserFlag { | 1273 enum ParserFlag { |
| 1274 kAllowLazy, | 1274 kAllowLazy, |
| 1275 kAllowNatives, | 1275 kAllowNatives, |
| 1276 kAllowHarmonyFunctionSent, | 1276 kAllowHarmonyFunctionSent, |
| 1277 kAllowHarmonyAsyncAwait, | |
| 1278 kAllowHarmonyRestrictiveGenerators, | 1277 kAllowHarmonyRestrictiveGenerators, |
| 1279 kAllowHarmonyTrailingCommas, | 1278 kAllowHarmonyTrailingCommas, |
| 1280 kAllowHarmonyClassFields, | 1279 kAllowHarmonyClassFields, |
| 1281 kAllowHarmonyObjectSpread, | 1280 kAllowHarmonyObjectSpread, |
| 1282 }; | 1281 }; |
| 1283 | 1282 |
| 1284 enum ParserSyncTestResult { | 1283 enum ParserSyncTestResult { |
| 1285 kSuccessOrError, | 1284 kSuccessOrError, |
| 1286 kSuccess, | 1285 kSuccess, |
| 1287 kError | 1286 kError |
| 1288 }; | 1287 }; |
| 1289 | 1288 |
| 1290 void SetGlobalFlags(i::EnumSet<ParserFlag> flags) { | 1289 void SetGlobalFlags(i::EnumSet<ParserFlag> flags) { |
| 1291 i::FLAG_allow_natives_syntax = flags.Contains(kAllowNatives); | 1290 i::FLAG_allow_natives_syntax = flags.Contains(kAllowNatives); |
| 1292 i::FLAG_harmony_function_sent = flags.Contains(kAllowHarmonyFunctionSent); | 1291 i::FLAG_harmony_function_sent = flags.Contains(kAllowHarmonyFunctionSent); |
| 1293 i::FLAG_harmony_async_await = flags.Contains(kAllowHarmonyAsyncAwait); | |
| 1294 i::FLAG_harmony_restrictive_generators = | 1292 i::FLAG_harmony_restrictive_generators = |
| 1295 flags.Contains(kAllowHarmonyRestrictiveGenerators); | 1293 flags.Contains(kAllowHarmonyRestrictiveGenerators); |
| 1296 i::FLAG_harmony_trailing_commas = flags.Contains(kAllowHarmonyTrailingCommas); | 1294 i::FLAG_harmony_trailing_commas = flags.Contains(kAllowHarmonyTrailingCommas); |
| 1297 i::FLAG_harmony_class_fields = flags.Contains(kAllowHarmonyClassFields); | 1295 i::FLAG_harmony_class_fields = flags.Contains(kAllowHarmonyClassFields); |
| 1298 i::FLAG_harmony_object_spread = flags.Contains(kAllowHarmonyObjectSpread); | 1296 i::FLAG_harmony_object_spread = flags.Contains(kAllowHarmonyObjectSpread); |
| 1299 } | 1297 } |
| 1300 | 1298 |
| 1301 void SetParserFlags(i::PreParser* parser, i::EnumSet<ParserFlag> flags) { | 1299 void SetParserFlags(i::PreParser* parser, i::EnumSet<ParserFlag> flags) { |
| 1302 parser->set_allow_natives(flags.Contains(kAllowNatives)); | 1300 parser->set_allow_natives(flags.Contains(kAllowNatives)); |
| 1303 parser->set_allow_harmony_function_sent( | 1301 parser->set_allow_harmony_function_sent( |
| 1304 flags.Contains(kAllowHarmonyFunctionSent)); | 1302 flags.Contains(kAllowHarmonyFunctionSent)); |
| 1305 parser->set_allow_harmony_async_await( | |
| 1306 flags.Contains(kAllowHarmonyAsyncAwait)); | |
| 1307 parser->set_allow_harmony_restrictive_generators( | 1303 parser->set_allow_harmony_restrictive_generators( |
| 1308 flags.Contains(kAllowHarmonyRestrictiveGenerators)); | 1304 flags.Contains(kAllowHarmonyRestrictiveGenerators)); |
| 1309 parser->set_allow_harmony_trailing_commas( | 1305 parser->set_allow_harmony_trailing_commas( |
| 1310 flags.Contains(kAllowHarmonyTrailingCommas)); | 1306 flags.Contains(kAllowHarmonyTrailingCommas)); |
| 1311 parser->set_allow_harmony_class_fields( | 1307 parser->set_allow_harmony_class_fields( |
| 1312 flags.Contains(kAllowHarmonyClassFields)); | 1308 flags.Contains(kAllowHarmonyClassFields)); |
| 1313 parser->set_allow_harmony_object_spread( | 1309 parser->set_allow_harmony_object_spread( |
| 1314 flags.Contains(kAllowHarmonyObjectSpread)); | 1310 flags.Contains(kAllowHarmonyObjectSpread)); |
| 1315 } | 1311 } |
| 1316 | 1312 |
| (...skipping 1403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2720 "*x", | 2716 "*x", |
| 2721 "*get x(){}", | 2717 "*get x(){}", |
| 2722 "*set x(y){}", | 2718 "*set x(y){}", |
| 2723 "get *x(){}", | 2719 "get *x(){}", |
| 2724 "set *x(y){}", | 2720 "set *x(y){}", |
| 2725 "get x*(){}", | 2721 "get x*(){}", |
| 2726 "set x*(y){}", | 2722 "set x*(y){}", |
| 2727 "x = 0", | 2723 "x = 0", |
| 2728 "* *x(){}", | 2724 "* *x(){}", |
| 2729 "x*(){}", | 2725 "x*(){}", |
| 2730 // This should fail without --harmony-async-await | |
| 2731 "async x(){}", | |
| 2732 NULL | |
| 2733 }; | |
| 2734 // clang-format on | |
| 2735 | |
| 2736 RunParserSyncTest(context_data, statement_data, kError); | |
| 2737 | |
| 2738 // clang-format off | |
| 2739 const char* async_data[] = { | |
| 2740 "static async x(){}", | 2726 "static async x(){}", |
| 2741 "static async x : 0", | 2727 "static async x : 0", |
| 2742 "static async get x : 0", | 2728 "static async get x : 0", |
| 2743 "async static x(){}", | 2729 "async static x(){}", |
| 2744 "*async x(){}", | 2730 "*async x(){}", |
| 2745 "async *x(){}", | 2731 "async *x(){}", |
| 2746 "async x*(){}", | 2732 "async x*(){}", |
| 2747 "async x : 0", | 2733 "async x : 0", |
| 2748 "async 0 : 0", | 2734 "async 0 : 0", |
| 2749 "async get x(){}", | 2735 "async get x(){}", |
| 2750 "async get *x(){}", | 2736 "async get *x(){}", |
| 2751 "async set x(y){}", | 2737 "async set x(y){}", |
| 2752 "async get : 0", | 2738 "async get : 0", |
| 2753 NULL | 2739 NULL |
| 2754 }; | 2740 }; |
| 2755 // clang-format on | 2741 // clang-format on |
| 2756 | 2742 |
| 2757 static const ParserFlag always_flags[] = {kAllowHarmonyAsyncAwait}; | 2743 RunParserSyncTest(context_data, statement_data, kError); |
| 2758 RunParserSyncTest(context_data, async_data, kError, NULL, 0, always_flags, | |
| 2759 arraysize(always_flags)); | |
| 2760 } | 2744 } |
| 2761 | 2745 |
| 2762 | 2746 |
| 2763 TEST(NoErrorsObjectLiteralChecking) { | 2747 TEST(NoErrorsObjectLiteralChecking) { |
| 2764 // clang-format off | 2748 // clang-format off |
| 2765 const char* context_data[][2] = { | 2749 const char* context_data[][2] = { |
| 2766 {"var myobject = {", "};"}, | 2750 {"var myobject = {", "};"}, |
| 2767 {"var myobject = {", ",};"}, | 2751 {"var myobject = {", ",};"}, |
| 2768 {"\"use strict\"; var myobject = {", "};"}, | 2752 {"\"use strict\"; var myobject = {", "};"}, |
| 2769 {"\"use strict\"; var myobject = {", ",};"}, | 2753 {"\"use strict\"; var myobject = {", ",};"}, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2823 "set : 0", | 2807 "set : 0", |
| 2824 "static : 0", | 2808 "static : 0", |
| 2825 "async : 0", | 2809 "async : 0", |
| 2826 // Keywords, future reserved and strict future reserved are also allowed as | 2810 // Keywords, future reserved and strict future reserved are also allowed as |
| 2827 // property names. | 2811 // property names. |
| 2828 "if: 4", | 2812 "if: 4", |
| 2829 "interface: 5", | 2813 "interface: 5", |
| 2830 "super: 6", | 2814 "super: 6", |
| 2831 "eval: 7", | 2815 "eval: 7", |
| 2832 "arguments: 8", | 2816 "arguments: 8", |
| 2833 NULL | |
| 2834 }; | |
| 2835 // clang-format on | |
| 2836 | |
| 2837 RunParserSyncTest(context_data, statement_data, kSuccess); | |
| 2838 | |
| 2839 // clang-format off | |
| 2840 const char* async_data[] = { | |
| 2841 "async x(){}", | 2817 "async x(){}", |
| 2842 "async 0(){}", | 2818 "async 0(){}", |
| 2843 "async get(){}", | 2819 "async get(){}", |
| 2844 "async set(){}", | 2820 "async set(){}", |
| 2845 "async static(){}", | 2821 "async static(){}", |
| 2846 "async async(){}", | 2822 "async async(){}", |
| 2847 "async : 0", | 2823 "async : 0", |
| 2848 "async(){}", | 2824 "async(){}", |
| 2849 "*async(){}", | 2825 "*async(){}", |
| 2850 NULL | 2826 NULL |
| 2851 }; | 2827 }; |
| 2852 // clang-format on | 2828 // clang-format on |
| 2853 | 2829 |
| 2854 static const ParserFlag always_flags[] = {kAllowHarmonyAsyncAwait}; | 2830 RunParserSyncTest(context_data, statement_data, kSuccess); |
| 2855 RunParserSyncTest(context_data, async_data, kSuccess, NULL, 0, always_flags, | |
| 2856 arraysize(always_flags)); | |
| 2857 } | 2831 } |
| 2858 | 2832 |
| 2859 | 2833 |
| 2860 TEST(TooManyArguments) { | 2834 TEST(TooManyArguments) { |
| 2861 const char* context_data[][2] = { | 2835 const char* context_data[][2] = { |
| 2862 {"foo(", "0)"}, | 2836 {"foo(", "0)"}, |
| 2863 { NULL, NULL } | 2837 { NULL, NULL } |
| 2864 }; | 2838 }; |
| 2865 | 2839 |
| 2866 using v8::internal::Code; | 2840 using v8::internal::Code; |
| (...skipping 1637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4504 // Escaped 'static' should be allowed anywhere | 4478 // Escaped 'static' should be allowed anywhere |
| 4505 // static-as-PropertyName is. | 4479 // static-as-PropertyName is. |
| 4506 "st\\u0061tic() {}", | 4480 "st\\u0061tic() {}", |
| 4507 "get st\\u0061tic() {}", | 4481 "get st\\u0061tic() {}", |
| 4508 "set st\\u0061tic(v) {}", | 4482 "set st\\u0061tic(v) {}", |
| 4509 "static st\\u0061tic() {}", | 4483 "static st\\u0061tic() {}", |
| 4510 "static get st\\u0061tic() {}", | 4484 "static get st\\u0061tic() {}", |
| 4511 "static set st\\u0061tic(v) {}", | 4485 "static set st\\u0061tic(v) {}", |
| 4512 "*st\\u0061tic() {}", | 4486 "*st\\u0061tic() {}", |
| 4513 "static *st\\u0061tic() {}", | 4487 "static *st\\u0061tic() {}", |
| 4514 NULL}; | |
| 4515 // clang-format on | |
| 4516 | 4488 |
| 4517 RunParserSyncTest(context_data, class_body_data, kSuccess); | |
| 4518 | |
| 4519 // clang-format off | |
| 4520 const char* async_data[] = { | |
| 4521 "static async x(){}", | 4489 "static async x(){}", |
| 4522 "static async(){}", | 4490 "static async(){}", |
| 4523 "static *async(){}", | 4491 "static *async(){}", |
| 4524 "async x(){}", | 4492 "async x(){}", |
| 4525 "async 0(){}", | 4493 "async 0(){}", |
| 4526 "async get(){}", | 4494 "async get(){}", |
| 4527 "async set(){}", | 4495 "async set(){}", |
| 4528 "async static(){}", | 4496 "async static(){}", |
| 4529 "async async(){}", | 4497 "async async(){}", |
| 4530 "async(){}", | 4498 "async(){}", |
| 4531 "*async(){}", | 4499 "*async(){}", |
| 4532 NULL | 4500 NULL}; |
| 4533 }; | |
| 4534 // clang-format on | 4501 // clang-format on |
| 4535 | 4502 |
| 4536 static const ParserFlag always_flags[] = {kAllowHarmonyAsyncAwait}; | 4503 RunParserSyncTest(context_data, class_body_data, kSuccess); |
| 4537 RunParserSyncTest(context_data, async_data, kSuccess, NULL, 0, always_flags, | |
| 4538 arraysize(always_flags)); | |
| 4539 } | 4504 } |
| 4540 | 4505 |
| 4541 | 4506 |
| 4542 TEST(ClassPropertyNameNoErrors) { | 4507 TEST(ClassPropertyNameNoErrors) { |
| 4543 const char* context_data[][2] = {{"(class {", "() {}});"}, | 4508 const char* context_data[][2] = {{"(class {", "() {}});"}, |
| 4544 {"(class { get ", "() {}});"}, | 4509 {"(class { get ", "() {}});"}, |
| 4545 {"(class { set ", "(v) {}});"}, | 4510 {"(class { set ", "(v) {}});"}, |
| 4546 {"(class { static ", "() {}});"}, | 4511 {"(class { static ", "() {}});"}, |
| 4547 {"(class { static get ", "() {}});"}, | 4512 {"(class { static get ", "() {}});"}, |
| 4548 {"(class { static set ", "(v) {}});"}, | 4513 {"(class { static set ", "(v) {}});"}, |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4656 | 4621 |
| 4657 // ASI edge cases | 4622 // ASI edge cases |
| 4658 "a\n get", | 4623 "a\n get", |
| 4659 "get\n *a(){}", | 4624 "get\n *a(){}", |
| 4660 "a\n static", | 4625 "a\n static", |
| 4661 | 4626 |
| 4662 // Misc edge cases | 4627 // Misc edge cases |
| 4663 "yield", | 4628 "yield", |
| 4664 "yield = 0", | 4629 "yield = 0", |
| 4665 "yield\n a", | 4630 "yield\n a", |
| 4666 NULL | |
| 4667 }; | |
| 4668 // clang-format on | |
| 4669 | |
| 4670 static const ParserFlag without_async[] = {kAllowHarmonyClassFields}; | |
| 4671 RunParserSyncTest(context_data, class_body_data, kSuccess, NULL, 0, | |
| 4672 without_async, arraysize(without_async)); | |
| 4673 | |
| 4674 // clang-format off | |
| 4675 const char* async_data[] = { | |
| 4676 "async;", | 4631 "async;", |
| 4677 "async = 0;", | 4632 "async = 0;", |
| 4678 "static async;" | 4633 "static async;" |
| 4679 "async", | 4634 "async", |
| 4680 "async = 0", | 4635 "async = 0", |
| 4681 "static async", | 4636 "static async", |
| 4682 "async\n a(){}", // a field named async, and a method named a. | 4637 "async\n a(){}", // a field named async, and a method named a. |
| 4683 "async\n a", | 4638 "async\n a", |
| 4684 "await;", | 4639 "await;", |
| 4685 "await = 0;", | 4640 "await = 0;", |
| 4686 "await\n a", | 4641 "await\n a", |
| 4687 NULL | 4642 NULL |
| 4688 }; | 4643 }; |
| 4689 // clang-format on | 4644 // clang-format on |
| 4690 | 4645 |
| 4691 static const ParserFlag with_async[] = {kAllowHarmonyClassFields, | 4646 static const ParserFlag always_flags[] = {kAllowHarmonyClassFields}; |
| 4692 kAllowHarmonyAsyncAwait}; | 4647 RunParserSyncTest(context_data, class_body_data, kSuccess, NULL, 0, |
| 4693 RunParserSyncTest(context_data, async_data, kSuccess, NULL, 0, with_async, | 4648 always_flags, arraysize(always_flags)); |
| 4694 arraysize(with_async)); | |
| 4695 } | 4649 } |
| 4696 | 4650 |
| 4697 TEST(ClassFieldsErrors) { | 4651 TEST(ClassFieldsErrors) { |
| 4698 // clang-format off | 4652 // clang-format off |
| 4699 // Tests proposed class fields syntax. | 4653 // Tests proposed class fields syntax. |
| 4700 const char* context_data[][2] = {{"(class {", "});"}, | 4654 const char* context_data[][2] = {{"(class {", "});"}, |
| 4701 {"(class extends Base {", "});"}, | 4655 {"(class extends Base {", "});"}, |
| 4702 {"class C {", "}"}, | 4656 {"class C {", "}"}, |
| 4703 {"class C extends Base {", "}"}, | 4657 {"class C extends Base {", "}"}, |
| 4704 {NULL, NULL}}; | 4658 {NULL, NULL}}; |
| 4705 const char* class_body_data[] = { | 4659 const char* class_body_data[] = { |
| 4706 "a : 0", | 4660 "a : 0", |
| 4707 "a =", | 4661 "a =", |
| 4708 "*a = 0", | 4662 "*a = 0", |
| 4709 "*a", | 4663 "*a", |
| 4710 "get a", | 4664 "get a", |
| 4711 "yield a", | 4665 "yield a", |
| 4712 "a : 0;", | 4666 "a : 0;", |
| 4713 "a =;", | 4667 "a =;", |
| 4714 "*a = 0;", | 4668 "*a = 0;", |
| 4715 "*a;", | 4669 "*a;", |
| 4716 "get a;", | 4670 "get a;", |
| 4717 "yield a;", | 4671 "yield a;", |
| 4672 "async a = 0", |
| 4673 "async a", |
| 4718 | 4674 |
| 4719 // ASI requires a linebreak | 4675 // ASI requires a linebreak |
| 4720 "a b", | 4676 "a b", |
| 4721 "a = 0 b", | 4677 "a = 0 b", |
| 4722 | 4678 |
| 4723 // ASI requires that the next token is not part of any legal production | 4679 // ASI requires that the next token is not part of any legal production |
| 4724 "a = 0\n *b(){}", | 4680 "a = 0\n *b(){}", |
| 4725 "a = 0\n ['b'](){}", | 4681 "a = 0\n ['b'](){}", |
| 4726 "get\n a", | 4682 "get\n a", |
| 4727 NULL | 4683 NULL |
| 4728 }; | 4684 }; |
| 4729 // clang-format on | 4685 // clang-format on |
| 4730 | 4686 |
| 4731 static const ParserFlag without_async[] = {kAllowHarmonyClassFields}; | 4687 static const ParserFlag always_flags[] = {kAllowHarmonyClassFields}; |
| 4732 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0, | 4688 RunParserSyncTest(context_data, class_body_data, kError, NULL, 0, |
| 4733 without_async, arraysize(without_async)); | 4689 always_flags, arraysize(always_flags)); |
| 4734 | |
| 4735 // clang-format off | |
| 4736 const char* async_data[] = { | |
| 4737 "async a = 0", | |
| 4738 "async a", | |
| 4739 NULL | |
| 4740 }; | |
| 4741 // clang-format on | |
| 4742 | |
| 4743 static const ParserFlag with_async[] = {kAllowHarmonyClassFields, | |
| 4744 kAllowHarmonyAsyncAwait}; | |
| 4745 RunParserSyncTest(context_data, async_data, kError, NULL, 0, with_async, | |
| 4746 arraysize(with_async)); | |
| 4747 } | 4690 } |
| 4748 | 4691 |
| 4749 TEST(ClassExpressionErrors) { | 4692 TEST(ClassExpressionErrors) { |
| 4750 const char* context_data[][2] = {{"(", ");"}, | 4693 const char* context_data[][2] = {{"(", ");"}, |
| 4751 {"var C = ", ";"}, | 4694 {"var C = ", ";"}, |
| 4752 {"bar, ", ";"}, | 4695 {"bar, ", ";"}, |
| 4753 {NULL, NULL}}; | 4696 {NULL, NULL}}; |
| 4754 const char* class_data[] = { | 4697 const char* class_data[] = { |
| 4755 "class", | 4698 "class", |
| 4756 "class name", | 4699 "class name", |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4825 "static async *(){}", | 4768 "static async *(){}", |
| 4826 "static async *x(){}", | 4769 "static async *x(){}", |
| 4827 "static async get x(){}", | 4770 "static async get x(){}", |
| 4828 "static async set x(y){}", | 4771 "static async set x(y){}", |
| 4829 "static async x : 0", | 4772 "static async x : 0", |
| 4830 "static async : 0", | 4773 "static async : 0", |
| 4831 NULL | 4774 NULL |
| 4832 }; | 4775 }; |
| 4833 // clang-format on | 4776 // clang-format on |
| 4834 | 4777 |
| 4835 // All of these are illegal whether or not async functions are permitted, | |
| 4836 // although for different reasons. | |
| 4837 RunParserSyncTest(context_data, async_data, kError); | 4778 RunParserSyncTest(context_data, async_data, kError); |
| 4838 | |
| 4839 static const ParserFlag always_flags[] = {kAllowHarmonyAsyncAwait}; | |
| 4840 RunParserSyncTest(context_data, async_data, kError, NULL, 0, always_flags, | |
| 4841 arraysize(always_flags)); | |
| 4842 } | 4779 } |
| 4843 | 4780 |
| 4844 TEST(ClassNameErrors) { | 4781 TEST(ClassNameErrors) { |
| 4845 const char* context_data[][2] = {{"class ", "{}"}, | 4782 const char* context_data[][2] = {{"class ", "{}"}, |
| 4846 {"(class ", "{});"}, | 4783 {"(class ", "{});"}, |
| 4847 {"'use strict'; class ", "{}"}, | 4784 {"'use strict'; class ", "{}"}, |
| 4848 {"'use strict'; (class ", "{});"}, | 4785 {"'use strict'; (class ", "{});"}, |
| 4849 {NULL, NULL}}; | 4786 {NULL, NULL}}; |
| 4850 const char* class_name[] = { | 4787 const char* class_name[] = { |
| 4851 "arguments", | 4788 "arguments", |
| (...skipping 1743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6595 "{ ...1}", | 6532 "{ ...1}", |
| 6596 "{ ...null}", | 6533 "{ ...null}", |
| 6597 "{ ...undefined}", | 6534 "{ ...undefined}", |
| 6598 "{ ...1 in {}}", | 6535 "{ ...1 in {}}", |
| 6599 "{ ...[]}", | 6536 "{ ...[]}", |
| 6600 "{ ...async function() { }}", | 6537 "{ ...async function() { }}", |
| 6601 "{ ...async () => { }}", | 6538 "{ ...async () => { }}", |
| 6602 "{ ...new Foo()}", | 6539 "{ ...new Foo()}", |
| 6603 NULL}; | 6540 NULL}; |
| 6604 | 6541 |
| 6605 static const ParserFlag flags[] = {kAllowHarmonyObjectSpread, | 6542 static const ParserFlag flags[] = {kAllowHarmonyObjectSpread}; |
| 6606 kAllowHarmonyAsyncAwait}; | |
| 6607 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, flags, | 6543 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, flags, |
| 6608 arraysize(flags)); | 6544 arraysize(flags)); |
| 6609 } | 6545 } |
| 6610 | 6546 |
| 6611 TEST(ObjectSpreadNegativeTests) { | 6547 TEST(ObjectSpreadNegativeTests) { |
| 6612 { | 6548 { |
| 6613 const char* context_data[][2] = {{"x = ", ""}, | 6549 const char* context_data[][2] = {{"x = ", ""}, |
| 6614 {"'use strict'; x = ", ""}, | 6550 {"'use strict'; x = ", ""}, |
| 6615 {NULL, NULL}}; | 6551 {NULL, NULL}}; |
| 6616 | 6552 |
| (...skipping 1479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8096 | 8032 |
| 8097 "var asyncFn = async({ foo = 1 }) => foo;", | 8033 "var asyncFn = async({ foo = 1 }) => foo;", |
| 8098 "var asyncFn = async({ foo = 1 } = {}) => foo;", | 8034 "var asyncFn = async({ foo = 1 } = {}) => foo;", |
| 8099 | 8035 |
| 8100 "function* g() { var f = async(yield); }", | 8036 "function* g() { var f = async(yield); }", |
| 8101 "function* g() { var f = async(x = yield); }", | 8037 "function* g() { var f = async(x = yield); }", |
| 8102 NULL | 8038 NULL |
| 8103 }; | 8039 }; |
| 8104 // clang-format on | 8040 // clang-format on |
| 8105 | 8041 |
| 8106 static const ParserFlag always_flags[] = {kAllowHarmonyAsyncAwait}; | 8042 RunParserSyncTest(context_data, data, kSuccess); |
| 8107 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, | |
| 8108 arraysize(always_flags)); | |
| 8109 | 8043 |
| 8110 // clang-format off | 8044 // clang-format off |
| 8111 const char* async_body_context_data[][2] = { | 8045 const char* async_body_context_data[][2] = { |
| 8112 { "async function f() {", "}" }, | 8046 { "async function f() {", "}" }, |
| 8113 { "var f = async function() {", "}" }, | 8047 { "var f = async function() {", "}" }, |
| 8114 { "var f = async() => {", "}" }, | 8048 { "var f = async() => {", "}" }, |
| 8115 { "var O = { async method() {", "} }" }, | 8049 { "var O = { async method() {", "} }" }, |
| 8116 { "'use strict'; async function f() {", "}" }, | 8050 { "'use strict'; async function f() {", "}" }, |
| 8117 { "'use strict'; var f = async function() {", "}" }, | 8051 { "'use strict'; var f = async function() {", "}" }, |
| 8118 { "'use strict'; var f = async() => {", "}" }, | 8052 { "'use strict'; var f = async() => {", "}" }, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8152 "var O = { method() { var await = 1; return await; } };", | 8086 "var O = { method() { var await = 1; return await; } };", |
| 8153 "var O = { method(await) { return await; } };", | 8087 "var O = { method(await) { return await; } };", |
| 8154 "var O = { *method() { var await = 1; return await; } };", | 8088 "var O = { *method() { var await = 1; return await; } };", |
| 8155 "var O = { *method(await) { return await; } };", | 8089 "var O = { *method(await) { return await; } };", |
| 8156 | 8090 |
| 8157 "(function await() {})", | 8091 "(function await() {})", |
| 8158 NULL | 8092 NULL |
| 8159 }; | 8093 }; |
| 8160 // clang-format on | 8094 // clang-format on |
| 8161 | 8095 |
| 8162 RunParserSyncTest(async_body_context_data, body_data, kSuccess, NULL, 0, | 8096 RunParserSyncTest(async_body_context_data, body_data, kSuccess); |
| 8163 always_flags, arraysize(always_flags)); | 8097 RunParserSyncTest(body_context_data, body_data, kSuccess); |
| 8164 RunParserSyncTest(body_context_data, body_data, kSuccess, NULL, 0, | |
| 8165 always_flags, arraysize(always_flags)); | |
| 8166 } | 8098 } |
| 8167 | 8099 |
| 8168 TEST(AsyncAwaitErrors) { | 8100 TEST(AsyncAwaitErrors) { |
| 8169 // clang-format off | 8101 // clang-format off |
| 8170 const char* context_data[][2] = { | 8102 const char* context_data[][2] = { |
| 8171 { "'use strict';", "" }, | 8103 { "'use strict';", "" }, |
| 8172 { "", "" }, | 8104 { "", "" }, |
| 8173 { NULL, NULL } | 8105 { NULL, NULL } |
| 8174 }; | 8106 }; |
| 8175 | 8107 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8292 "var f = async(x = async(await)) => 1;", | 8224 "var f = async(x = async(await)) => 1;", |
| 8293 "var f = async(x = { [await]: 1 }) => 1;", | 8225 "var f = async(x = { [await]: 1 }) => 1;", |
| 8294 "var f = async(x = class extends (await) { }) => 1;", | 8226 "var f = async(x = class extends (await) { }) => 1;", |
| 8295 "var f = async(x = class { static [await]() {} }) => 1;", | 8227 "var f = async(x = class { static [await]() {} }) => 1;", |
| 8296 "var f = async({ x = await }) => 1;", | 8228 "var f = async({ x = await }) => 1;", |
| 8297 | 8229 |
| 8298 NULL | 8230 NULL |
| 8299 }; | 8231 }; |
| 8300 // clang-format on | 8232 // clang-format on |
| 8301 | 8233 |
| 8302 static const ParserFlag always_flags[] = {kAllowHarmonyAsyncAwait}; | 8234 RunParserSyncTest(context_data, error_data, kError); |
| 8303 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags, | 8235 RunParserSyncTest(strict_context_data, strict_error_data, kError); |
| 8304 arraysize(always_flags)); | 8236 RunParserSyncTest(context_data, formal_parameters_data, kError); |
| 8305 RunParserSyncTest(strict_context_data, strict_error_data, kError, NULL, 0, | |
| 8306 always_flags, arraysize(always_flags)); | |
| 8307 | |
| 8308 RunParserSyncTest(context_data, formal_parameters_data, kError, NULL, 0, | |
| 8309 always_flags, arraysize(always_flags)); | |
| 8310 | 8237 |
| 8311 // clang-format off | 8238 // clang-format off |
| 8312 const char* async_body_context_data[][2] = { | 8239 const char* async_body_context_data[][2] = { |
| 8313 { "async function f() {", "}" }, | 8240 { "async function f() {", "}" }, |
| 8314 { "var f = async function() {", "}" }, | 8241 { "var f = async function() {", "}" }, |
| 8315 { "var f = async() => {", "}" }, | 8242 { "var f = async() => {", "}" }, |
| 8316 { "var O = { async method() {", "} }" }, | 8243 { "var O = { async method() {", "} }" }, |
| 8317 { "'use strict'; async function f() {", "}" }, | 8244 { "'use strict'; async function f() {", "}" }, |
| 8318 { "'use strict'; var f = async function() {", "}" }, | 8245 { "'use strict'; var f = async function() {", "}" }, |
| 8319 { "'use strict'; var f = async() => {", "}" }, | 8246 { "'use strict'; var f = async() => {", "}" }, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 8340 "var e = (await, f);", | 8267 "var e = (await, f);", |
| 8341 "var e = (await = 42)", | 8268 "var e = (await = 42)", |
| 8342 | 8269 |
| 8343 "var e = [await];", | 8270 "var e = [await];", |
| 8344 "var e = {await};", | 8271 "var e = {await};", |
| 8345 | 8272 |
| 8346 NULL | 8273 NULL |
| 8347 }; | 8274 }; |
| 8348 // clang-format on | 8275 // clang-format on |
| 8349 | 8276 |
| 8350 RunParserSyncTest(async_body_context_data, async_body_error_data, kError, | 8277 RunParserSyncTest(async_body_context_data, async_body_error_data, kError); |
| 8351 NULL, 0, always_flags, arraysize(always_flags)); | |
| 8352 } | 8278 } |
| 8353 | 8279 |
| 8354 TEST(AsyncAwaitModule) { | 8280 TEST(AsyncAwaitModule) { |
| 8355 // clang-format off | 8281 // clang-format off |
| 8356 const char* context_data[][2] = { | 8282 const char* context_data[][2] = { |
| 8357 { "", "" }, | 8283 { "", "" }, |
| 8358 { NULL, NULL } | 8284 { NULL, NULL } |
| 8359 }; | 8285 }; |
| 8360 | 8286 |
| 8361 const char* data[] = { | 8287 const char* data[] = { |
| 8362 "export default async function() { await 1; }", | 8288 "export default async function() { await 1; }", |
| 8363 "export default async function async() { await 1; }", | 8289 "export default async function async() { await 1; }", |
| 8364 "export async function async() { await 1; }", | 8290 "export async function async() { await 1; }", |
| 8365 NULL | 8291 NULL |
| 8366 }; | 8292 }; |
| 8367 // clang-format on | 8293 // clang-format on |
| 8368 | 8294 |
| 8369 static const ParserFlag always_flags[] = {kAllowHarmonyAsyncAwait}; | 8295 RunModuleParserSyncTest(context_data, data, kSuccess, NULL, 0, NULL, 0, NULL, |
| 8370 RunModuleParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, | 8296 0, false); |
| 8371 arraysize(always_flags), NULL, 0, false); | |
| 8372 } | 8297 } |
| 8373 | 8298 |
| 8374 TEST(AsyncAwaitModuleErrors) { | 8299 TEST(AsyncAwaitModuleErrors) { |
| 8375 // clang-format off | 8300 // clang-format off |
| 8376 const char* context_data[][2] = { | 8301 const char* context_data[][2] = { |
| 8377 { "", "" }, | 8302 { "", "" }, |
| 8378 { NULL, NULL } | 8303 { NULL, NULL } |
| 8379 }; | 8304 }; |
| 8380 | 8305 |
| 8381 const char* error_data[] = { | 8306 const char* error_data[] = { |
| 8382 "export default (async function await() {})", | 8307 "export default (async function await() {})", |
| 8383 "export default async function await() {}", | 8308 "export default async function await() {}", |
| 8384 "export async function await() {}", | 8309 "export async function await() {}", |
| 8385 "export async function() {}", | 8310 "export async function() {}", |
| 8386 "export async", | 8311 "export async", |
| 8387 NULL | 8312 NULL |
| 8388 }; | 8313 }; |
| 8389 // clang-format on | 8314 // clang-format on |
| 8390 | 8315 |
| 8391 static const ParserFlag always_flags[] = {kAllowHarmonyAsyncAwait}; | 8316 RunModuleParserSyncTest(context_data, error_data, kError, NULL, 0, NULL, 0, |
| 8392 RunModuleParserSyncTest(context_data, error_data, kError, NULL, 0, | 8317 NULL, 0, false); |
| 8393 always_flags, arraysize(always_flags), NULL, 0, | |
| 8394 false); | |
| 8395 } | 8318 } |
| 8396 | 8319 |
| 8397 TEST(RestrictiveForInErrors) { | 8320 TEST(RestrictiveForInErrors) { |
| 8398 // clang-format off | 8321 // clang-format off |
| 8399 const char* strict_context_data[][2] = { | 8322 const char* strict_context_data[][2] = { |
| 8400 { "'use strict'", "" }, | 8323 { "'use strict'", "" }, |
| 8401 { NULL, NULL } | 8324 { NULL, NULL } |
| 8402 }; | 8325 }; |
| 8403 const char* sloppy_context_data[][2] = { | 8326 const char* sloppy_context_data[][2] = { |
| 8404 { "", "" }, | 8327 { "", "" }, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8461 {"(function() {'use strict';", "})()"}, | 8384 {"(function() {'use strict';", "})()"}, |
| 8462 {NULL, NULL}}; | 8385 {NULL, NULL}}; |
| 8463 const char* error_data[] = {"async function x() {} async function x() {}", | 8386 const char* error_data[] = {"async function x() {} async function x() {}", |
| 8464 "function x() {} async function x() {}", | 8387 "function x() {} async function x() {}", |
| 8465 "async function x() {} function x() {}", | 8388 "async function x() {} function x() {}", |
| 8466 "function* x() {} async function x() {}", | 8389 "function* x() {} async function x() {}", |
| 8467 "function* x() {} async function x() {}", | 8390 "function* x() {} async function x() {}", |
| 8468 "async function x() {} function* x() {}", | 8391 "async function x() {} function* x() {}", |
| 8469 "function* x() {} async function x() {}", | 8392 "function* x() {} async function x() {}", |
| 8470 NULL}; | 8393 NULL}; |
| 8471 static const ParserFlag always_flags[] = {kAllowHarmonyAsyncAwait}; | |
| 8472 // The preparser doesn't enforce the restriction, so turn it off. | 8394 // The preparser doesn't enforce the restriction, so turn it off. |
| 8473 bool test_preparser = false; | 8395 bool test_preparser = false; |
| 8474 RunParserSyncTest(block_context_data, error_data, kError, NULL, 0, | 8396 RunParserSyncTest(block_context_data, error_data, kError, NULL, 0, NULL, 0, |
| 8475 always_flags, arraysize(always_flags), NULL, 0, false, | 8397 NULL, 0, false, test_preparser); |
| 8476 test_preparser); | 8398 RunParserSyncTest(top_level_context_data, error_data, kSuccess); |
| 8477 RunParserSyncTest(top_level_context_data, error_data, kSuccess, NULL, 0, | |
| 8478 always_flags, arraysize(always_flags)); | |
| 8479 } | 8399 } |
| 8480 | 8400 |
| 8481 TEST(TrailingCommasInParameters) { | 8401 TEST(TrailingCommasInParameters) { |
| 8482 // clang-format off | 8402 // clang-format off |
| 8483 const char* context_data[][2] = { | 8403 const char* context_data[][2] = { |
| 8484 { "", "" }, | 8404 { "", "" }, |
| 8485 { "'use strict';", "" }, | 8405 { "'use strict';", "" }, |
| 8486 { "function foo() {", "}" }, | 8406 { "function foo() {", "}" }, |
| 8487 { "function foo() {'use strict';", "}" }, | 8407 { "function foo() {'use strict';", "}" }, |
| 8488 { NULL, NULL } | 8408 { NULL, NULL } |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8915 DCHECK_NOT_NULL(scope); | 8835 DCHECK_NOT_NULL(scope); |
| 8916 DCHECK_NULL(scope->sibling()); | 8836 DCHECK_NULL(scope->sibling()); |
| 8917 DCHECK(scope->is_function_scope()); | 8837 DCHECK(scope->is_function_scope()); |
| 8918 const i::AstRawString* var_name = | 8838 const i::AstRawString* var_name = |
| 8919 info.ast_value_factory()->GetOneByteString("my_var"); | 8839 info.ast_value_factory()->GetOneByteString("my_var"); |
| 8920 i::Variable* var = scope->Lookup(var_name); | 8840 i::Variable* var = scope->Lookup(var_name); |
| 8921 CHECK_EQ(inners[i].ctxt_allocate, | 8841 CHECK_EQ(inners[i].ctxt_allocate, |
| 8922 i::ScopeTestHelper::MustAllocateInContext(var)); | 8842 i::ScopeTestHelper::MustAllocateInContext(var)); |
| 8923 } | 8843 } |
| 8924 } | 8844 } |
| OLD | NEW |