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

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

Issue 2620943002: [ESnext] Implement Object Rest (Closed)
Patch Set: fix nits Created 3 years, 11 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/runtime/runtime-object.cc ('k') | test/mjsunit/harmony/object-rest-basic.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 1266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 return result; 1277 return result;
1278 } 1278 }
1279 1279
1280 enum ParserFlag { 1280 enum ParserFlag {
1281 kAllowLazy, 1281 kAllowLazy,
1282 kAllowNatives, 1282 kAllowNatives,
1283 kAllowHarmonyFunctionSent, 1283 kAllowHarmonyFunctionSent,
1284 kAllowHarmonyRestrictiveGenerators, 1284 kAllowHarmonyRestrictiveGenerators,
1285 kAllowHarmonyTrailingCommas, 1285 kAllowHarmonyTrailingCommas,
1286 kAllowHarmonyClassFields, 1286 kAllowHarmonyClassFields,
1287 kAllowHarmonyObjectSpread, 1287 kAllowHarmonyObjectRestSpread,
1288 }; 1288 };
1289 1289
1290 enum ParserSyncTestResult { 1290 enum ParserSyncTestResult {
1291 kSuccessOrError, 1291 kSuccessOrError,
1292 kSuccess, 1292 kSuccess,
1293 kError 1293 kError
1294 }; 1294 };
1295 1295
1296 void SetGlobalFlags(i::EnumSet<ParserFlag> flags) { 1296 void SetGlobalFlags(i::EnumSet<ParserFlag> flags) {
1297 i::FLAG_allow_natives_syntax = flags.Contains(kAllowNatives); 1297 i::FLAG_allow_natives_syntax = flags.Contains(kAllowNatives);
1298 i::FLAG_harmony_function_sent = flags.Contains(kAllowHarmonyFunctionSent); 1298 i::FLAG_harmony_function_sent = flags.Contains(kAllowHarmonyFunctionSent);
1299 i::FLAG_harmony_restrictive_generators = 1299 i::FLAG_harmony_restrictive_generators =
1300 flags.Contains(kAllowHarmonyRestrictiveGenerators); 1300 flags.Contains(kAllowHarmonyRestrictiveGenerators);
1301 i::FLAG_harmony_trailing_commas = flags.Contains(kAllowHarmonyTrailingCommas); 1301 i::FLAG_harmony_trailing_commas = flags.Contains(kAllowHarmonyTrailingCommas);
1302 i::FLAG_harmony_class_fields = flags.Contains(kAllowHarmonyClassFields); 1302 i::FLAG_harmony_class_fields = flags.Contains(kAllowHarmonyClassFields);
1303 i::FLAG_harmony_object_spread = flags.Contains(kAllowHarmonyObjectSpread); 1303 i::FLAG_harmony_object_rest_spread =
1304 flags.Contains(kAllowHarmonyObjectRestSpread);
1304 } 1305 }
1305 1306
1306 void SetParserFlags(i::PreParser* parser, i::EnumSet<ParserFlag> flags) { 1307 void SetParserFlags(i::PreParser* parser, i::EnumSet<ParserFlag> flags) {
1307 parser->set_allow_natives(flags.Contains(kAllowNatives)); 1308 parser->set_allow_natives(flags.Contains(kAllowNatives));
1308 parser->set_allow_harmony_function_sent( 1309 parser->set_allow_harmony_function_sent(
1309 flags.Contains(kAllowHarmonyFunctionSent)); 1310 flags.Contains(kAllowHarmonyFunctionSent));
1310 parser->set_allow_harmony_restrictive_generators( 1311 parser->set_allow_harmony_restrictive_generators(
1311 flags.Contains(kAllowHarmonyRestrictiveGenerators)); 1312 flags.Contains(kAllowHarmonyRestrictiveGenerators));
1312 parser->set_allow_harmony_trailing_commas( 1313 parser->set_allow_harmony_trailing_commas(
1313 flags.Contains(kAllowHarmonyTrailingCommas)); 1314 flags.Contains(kAllowHarmonyTrailingCommas));
1314 parser->set_allow_harmony_class_fields( 1315 parser->set_allow_harmony_class_fields(
1315 flags.Contains(kAllowHarmonyClassFields)); 1316 flags.Contains(kAllowHarmonyClassFields));
1316 parser->set_allow_harmony_object_spread( 1317 parser->set_allow_harmony_object_rest_spread(
1317 flags.Contains(kAllowHarmonyObjectSpread)); 1318 flags.Contains(kAllowHarmonyObjectRestSpread));
1318 } 1319 }
1319 1320
1320 void TestParserSyncWithFlags(i::Handle<i::String> source, 1321 void TestParserSyncWithFlags(i::Handle<i::String> source,
1321 i::EnumSet<ParserFlag> flags, 1322 i::EnumSet<ParserFlag> flags,
1322 ParserSyncTestResult result, 1323 ParserSyncTestResult result,
1323 bool is_module = false, 1324 bool is_module = false,
1324 bool test_preparser = true) { 1325 bool test_preparser = true) {
1325 i::Isolate* isolate = CcTest::i_isolate(); 1326 i::Isolate* isolate = CcTest::i_isolate();
1326 i::Factory* factory = isolate->factory(); 1327 i::Factory* factory = isolate->factory();
1327 1328
(...skipping 5275 matching lines...) Expand 10 before | Expand all | Expand 10 after
6603 "{ ...1}", 6604 "{ ...1}",
6604 "{ ...null}", 6605 "{ ...null}",
6605 "{ ...undefined}", 6606 "{ ...undefined}",
6606 "{ ...1 in {}}", 6607 "{ ...1 in {}}",
6607 "{ ...[]}", 6608 "{ ...[]}",
6608 "{ ...async function() { }}", 6609 "{ ...async function() { }}",
6609 "{ ...async () => { }}", 6610 "{ ...async () => { }}",
6610 "{ ...new Foo()}", 6611 "{ ...new Foo()}",
6611 NULL}; 6612 NULL};
6612 6613
6613 static const ParserFlag flags[] = {kAllowHarmonyObjectSpread}; 6614 static const ParserFlag flags[] = {kAllowHarmonyObjectRestSpread};
6614 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, flags, 6615 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, flags,
6615 arraysize(flags)); 6616 arraysize(flags));
6616 } 6617 }
6617 6618
6618 TEST(ObjectSpreadNegativeTests) { 6619 TEST(ObjectSpreadNegativeTests) {
6619 { 6620 const char* context_data[][2] = {{"x = ", ""},
6620 const char* context_data[][2] = {{"x = ", ""}, 6621 {"'use strict'; x = ", ""},
6621 {"'use strict'; x = ", ""}, 6622 {NULL, NULL}};
6622 {NULL, NULL}};
6623 6623
6624 // clang-format off 6624 // clang-format off
6625 const char* data[] = { 6625 const char* data[] = {
6626 "{ ...var z = y}", 6626 "{ ...var z = y}",
6627 "{ ...var}", 6627 "{ ...var}",
6628 "{ ...foo bar}", 6628 "{ ...foo bar}",
6629 NULL}; 6629 NULL};
6630 6630
6631 static const ParserFlag flags[] = {kAllowHarmonyObjectSpread}; 6631 static const ParserFlag flags[] = {kAllowHarmonyObjectRestSpread};
6632 RunParserSyncTest(context_data, data, kError, NULL, 0, flags, 6632 RunParserSyncTest(context_data, data, kError, NULL, 0, flags,
6633 arraysize(flags)); 6633 arraysize(flags));
6634 }
6635
6636 // Destructuring tests
6637 {
6638 const char* context_data[][2] = {
6639 {"var ", " = {};"},
6640 {"( ", " = {});"},
6641 {"'use strict'; const ", " = {};"},
6642 {"function f(", ") {}"},
6643 {"function f(argument1, ", ") {}"},
6644 {"var f = (", ") => {};"},
6645 {"var f = (argument1,", ") => {};"},
6646 {"try {} catch(", ") {}"},
6647 {NULL, NULL}};
6648
6649 // clang-format off
6650 const char* data[] = {
6651 "{ ...y }",
6652 "{ a: 1, ...y }",
6653 "{ b: 1, ...y }",
6654 "{ y, ...y}",
6655 "{ ...z = y}",
6656 "{ ...y, y }",
6657 "{ ...y, ...y}",
6658 "{ a: 1, ...y, b: 1}",
6659 "{ ...y, b: 1}",
6660 "{ ...1}",
6661 "{ ...null}",
6662 "{ ...undefined}",
6663 "{ ...unknown}",
6664 "{ ...var z = y}",
6665 "({ ...z = {})",
6666 NULL};
6667
6668 static const ParserFlag flags[] = {kAllowHarmonyObjectSpread};
6669 RunParserSyncTest(context_data, data, kError, NULL, 0, flags,
6670 arraysize(flags));
6671 }
6672 } 6634 }
6673 6635
6674 TEST(DestructuringPositiveTests) { 6636 TEST(DestructuringPositiveTests) {
6675 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, 6637 const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
6676 {"var ", " = {};"}, 6638 {"var ", " = {};"},
6677 {"'use strict'; const ", " = {};"}, 6639 {"'use strict'; const ", " = {};"},
6678 {"function f(", ") {}"}, 6640 {"function f(", ") {}"},
6679 {"function f(argument1, ", ") {}"}, 6641 {"function f(argument1, ", ") {}"},
6680 {"var f = (", ") => {};"}, 6642 {"var f = (", ") => {};"},
6681 {"var f = (argument1,", ") => {};"}, 6643 {"var f = (argument1,", ") => {};"},
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
6717 "{[1+1] : z}", 6679 "{[1+1] : z}",
6718 "{[foo()] : z}", 6680 "{[foo()] : z}",
6719 "{}", 6681 "{}",
6720 "[...rest]", 6682 "[...rest]",
6721 "[a,b,...rest]", 6683 "[a,b,...rest]",
6722 "[a,,...rest]", 6684 "[a,,...rest]",
6723 "{ __proto__: x, __proto__: y}", 6685 "{ __proto__: x, __proto__: y}",
6724 "{arguments: x}", 6686 "{arguments: x}",
6725 "{eval: x}", 6687 "{eval: x}",
6726 NULL}; 6688 NULL};
6689
6690 const char* rest_data[] = {
6691 "{ x : y, ...z }",
6692 "{ x : y = 1, ...z }",
6693 "{ x : x, y : y, ...z }",
6694 "{ x : x = 1, y : y, ...z }",
6695 "{ x : x, y : y = 42, ...z }",
6696 "[{x:x, y:y, ...z}, [a,b,c]]",
6697 "[{x:x = 1, y:y = 2, ...z}, [a = 3, b = 4, c = 5]]",
6698 "{...x}",
6699 "{...{ x = 5} }",
6700 "{x, ...y}",
6701 "{x = 42, y = 15, ...z}",
6702 "{42 : x = 42, ...y}",
6703 "{'hi' : x, ...z}",
6704 "{'hi' : x = 42, ...z}",
6705 "{var: x = 42, ...z}",
6706 "{[x] : z, ...y}",
6707 "{[1+1] : z, ...x}",
6708 "{arguments: x, ...z}",
6709 "{ __proto__: x, __proto__: y, ...z}",
6710 NULL};
6711
6727 // clang-format on 6712 // clang-format on
6728 RunParserSyncTest(context_data, data, kSuccess); 6713 RunParserSyncTest(context_data, data, kSuccess);
6714 RunParserSyncTest(context_data, rest_data, kError);
6715
6716 static const ParserFlag flags[] = {kAllowHarmonyObjectRestSpread};
6717 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, flags,
6718 arraysize(flags));
6719 RunParserSyncTest(context_data, rest_data, kSuccess, NULL, 0, flags,
6720 arraysize(flags));
6729 6721
6730 // v8:5201 6722 // v8:5201
6731 { 6723 {
6732 // clang-format off 6724 // clang-format off
6733 const char* sloppy_context_data[][2] = { 6725 const char* sloppy_context_data[][2] = {
6734 {"var ", " = {};"}, 6726 {"var ", " = {};"},
6735 {"function f(", ") {}"}, 6727 {"function f(", ") {}"},
6736 {"function f(argument1, ", ") {}"}, 6728 {"function f(argument1, ", ") {}"},
6737 {"var f = (", ") => {};"}, 6729 {"var f = (", ") => {};"},
6738 {"var f = (argument1,", ") => {};"}, 6730 {"var f = (argument1,", ") => {};"},
6739 {"try {} catch(", ") {}"}, 6731 {"try {} catch(", ") {}"},
6740 {NULL, NULL} 6732 {NULL, NULL}
6741 }; 6733 };
6734
6735 const char* rest_data[] = {
6736 "{...arguments}",
6737 "{...eval}",
6738 NULL
6739 };
6740
6742 const char* data[] = { 6741 const char* data[] = {
6743 "{arguments}", 6742 "{arguments}",
6744 "{eval}", 6743 "{eval}",
6745 "{x: arguments}", 6744 "{x: arguments}",
6746 "{x: eval}", 6745 "{x: eval}",
6747 "{arguments = false}", 6746 "{arguments = false}",
6748 "{eval = false}", 6747 "{eval = false}",
6749 NULL 6748 NULL
6750 }; 6749 };
6751 // clang-format on 6750 // clang-format on
6752 RunParserSyncTest(sloppy_context_data, data, kSuccess); 6751 RunParserSyncTest(sloppy_context_data, data, kSuccess);
6752 RunParserSyncTest(sloppy_context_data, rest_data, kError);
6753 static const ParserFlag flags[] = {kAllowHarmonyObjectRestSpread};
6754 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, flags,
6755 arraysize(flags));
6756 RunParserSyncTest(sloppy_context_data, rest_data, kSuccess, NULL, 0, flags,
6757 arraysize(flags));
6753 } 6758 }
6754 } 6759 }
6755 6760
6756 6761
6757 TEST(DestructuringNegativeTests) { 6762 TEST(DestructuringNegativeTests) {
6758 { // All modes. 6763 { // All modes.
6759 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, 6764 const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
6760 {"var ", " = {};"}, 6765 {"var ", " = {};"},
6761 {"'use strict'; const ", " = {};"}, 6766 {"'use strict'; const ", " = {};"},
6762 {"function f(", ") {}"}, 6767 {"function f(", ") {}"},
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
6831 "[...[z] = [1]]", 6836 "[...[z] = [1]]",
6832 "{ x : 3 }", 6837 "{ x : 3 }",
6833 "{ x : 'foo' }", 6838 "{ x : 'foo' }",
6834 "{ x : /foo/ }", 6839 "{ x : /foo/ }",
6835 "{ x : `foo` }", 6840 "{ x : `foo` }",
6836 "{ get a() {} }", 6841 "{ get a() {} }",
6837 "{ set a() {} }", 6842 "{ set a() {} }",
6838 "{ method() {} }", 6843 "{ method() {} }",
6839 "{ *method() {} }", 6844 "{ *method() {} }",
6840 NULL}; 6845 NULL};
6846
6847 const char* rest_data[] = {
6848 "...a++",
6849 "...++a",
6850 "...typeof a",
6851 "...[a++]",
6852 "...(x => y)",
6853 "{ ...x, }",
6854 "{ ...x, y }",
6855 "{ y, ...x, y }",
6856 "{ ...x, ...y }",
6857 "{ ...x, ...x }",
6858 "{ ...x, ...x = {} }",
6859 "{ ...x, ...x = ...x }",
6860 "{ ...x, ...x = ...{ x } }",
6861 "{ ,, ...x }",
6862 "{ ...get a() {} }",
6863 "{ ...set a() {} }",
6864 "{ ...method() {} }",
6865 "{ ...function() {} }",
6866 "{ ...*method() {} }",
6867 NULL
6868 };
6869
6841 // clang-format on 6870 // clang-format on
6842 RunParserSyncTest(context_data, data, kError); 6871 RunParserSyncTest(context_data, data, kError);
6872 RunParserSyncTest(context_data, rest_data, kError);
6873 static const ParserFlag flags[] = {kAllowHarmonyObjectRestSpread};
6874 RunParserSyncTest(context_data, data, kError, NULL, 0, flags,
6875 arraysize(flags));
6876 RunParserSyncTest(context_data, rest_data, kError, NULL, 0, flags,
6877 arraysize(flags));
6843 } 6878 }
6844 6879
6845 { // All modes. 6880 { // All modes.
6846 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, 6881 const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
6847 {"var ", " = {};"}, 6882 {"var ", " = {};"},
6848 {"'use strict'; const ", " = {};"}, 6883 {"'use strict'; const ", " = {};"},
6849 {"function f(", ") {}"}, 6884 {"function f(", ") {}"},
6850 {"function f(argument1, ", ") {}"}, 6885 {"function f(argument1, ", ") {}"},
6851 {"var f = (", ") => {};"}, 6886 {"var f = (", ") => {};"},
6852 {"var f = (argument1,", ") => {};"}, 6887 {"var f = (argument1,", ") => {};"},
(...skipping 25 matching lines...) Expand all
6878 "{ a : eval }", 6913 "{ a : eval }",
6879 "[public]", 6914 "[public]",
6880 "{ x : private }", 6915 "{ x : private }",
6881 "{ x : arguments }", 6916 "{ x : arguments }",
6882 "{ x : eval }", 6917 "{ x : eval }",
6883 "{ arguments }", 6918 "{ arguments }",
6884 "{ eval }", 6919 "{ eval }",
6885 "{ arguments = false }" 6920 "{ arguments = false }"
6886 "{ eval = false }", 6921 "{ eval = false }",
6887 NULL}; 6922 NULL};
6923
6924 const char* rest_data[] = {
6925 "{ ...eval }",
6926 "{ ...arguments }",
6927 NULL};
6928
6888 // clang-format on 6929 // clang-format on
6889 RunParserSyncTest(context_data, data, kError); 6930 RunParserSyncTest(context_data, data, kError);
6931 RunParserSyncTest(context_data, rest_data, kError);
6932 static const ParserFlag flags[] = {kAllowHarmonyObjectRestSpread};
6933 RunParserSyncTest(context_data, data, kError, NULL, 0, flags,
6934 arraysize(flags));
6935 RunParserSyncTest(context_data, rest_data, kError, NULL, 0, flags,
6936 arraysize(flags));
6890 } 6937 }
6891 6938
6892 { // 'yield' in generators. 6939 { // 'yield' in generators.
6893 const char* context_data[][2] = { 6940 const char* context_data[][2] = {
6894 {"function*() { var ", " = {};"}, 6941 {"function*() { var ", " = {};"},
6895 {"function*() { 'use strict'; let ", " = {};"}, 6942 {"function*() { 'use strict'; let ", " = {};"},
6896 {"function*() { 'use strict'; const ", " = {};"}, 6943 {"function*() { 'use strict'; const ", " = {};"},
6897 {NULL, NULL}}; 6944 {NULL, NULL}};
6898 6945
6899 // clang-format off 6946 // clang-format off
(...skipping 19 matching lines...) Expand all
6919 {"for (var ", ";;) {}"}, 6966 {"for (var ", ";;) {}"},
6920 {"for (let ", ";;) {}"}, 6967 {"for (let ", ";;) {}"},
6921 {"for (const ", ";;) {}"}, 6968 {"for (const ", ";;) {}"},
6922 {NULL, NULL}}; 6969 {NULL, NULL}};
6923 6970
6924 // clang-format off 6971 // clang-format off
6925 const char* data[] = { 6972 const char* data[] = {
6926 "{ a }", 6973 "{ a }",
6927 "[ a ]", 6974 "[ a ]",
6928 NULL}; 6975 NULL};
6976 const char* rest_data[] = {
6977 "{ ...a }",
6978 NULL};
6929 // clang-format on 6979 // clang-format on
6930 RunParserSyncTest(context_data, data, kError); 6980 RunParserSyncTest(context_data, data, kError);
6981 RunParserSyncTest(context_data, rest_data, kError);
6982 static const ParserFlag flags[] = {kAllowHarmonyObjectRestSpread};
6983 RunParserSyncTest(context_data, data, kError, NULL, 0, flags,
6984 arraysize(flags));
6985 RunParserSyncTest(context_data, rest_data, kError, NULL, 0, flags,
6986 arraysize(flags));
6931 } 6987 }
6932 } 6988 }
6933 6989
6934 6990
6935 TEST(DestructuringAssignmentPositiveTests) { 6991 TEST(DestructuringAssignmentPositiveTests) {
6936 const char* context_data[][2] = { 6992 const char* context_data[][2] = {
6937 {"'use strict'; let x, y, z; (", " = {});"}, 6993 {"'use strict'; let x, y, z; (", " = {});"},
6938 {"var x, y, z; (", " = {});"}, 6994 {"var x, y, z; (", " = {});"},
6939 {"'use strict'; let x, y, z; for (x in ", " = {});"}, 6995 {"'use strict'; let x, y, z; for (x in ", " = {});"},
6940 {"'use strict'; let x, y, z; for (x of ", " = {});"}, 6996 {"'use strict'; let x, y, z; for (x of ", " = {});"},
(...skipping 1944 matching lines...) Expand 10 before | Expand all | Expand 10 after
8885 DCHECK_NULL(scope->sibling()); 8941 DCHECK_NULL(scope->sibling());
8886 DCHECK(scope->is_function_scope()); 8942 DCHECK(scope->is_function_scope());
8887 const i::AstRawString* var_name = 8943 const i::AstRawString* var_name =
8888 info.ast_value_factory()->GetOneByteString("my_var"); 8944 info.ast_value_factory()->GetOneByteString("my_var");
8889 i::Variable* var = scope->Lookup(var_name); 8945 i::Variable* var = scope->Lookup(var_name);
8890 CHECK_EQ(inners[i].ctxt_allocate, 8946 CHECK_EQ(inners[i].ctxt_allocate,
8891 i::ScopeTestHelper::MustAllocateInContext(var)); 8947 i::ScopeTestHelper::MustAllocateInContext(var));
8892 } 8948 }
8893 } 8949 }
8894 } 8950 }
OLDNEW
« no previous file with comments | « src/runtime/runtime-object.cc ('k') | test/mjsunit/harmony/object-rest-basic.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698