Chromium Code Reviews

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

Issue 2620943002: [ESnext] Implement Object Rest (Closed)
Patch Set: add todo and test Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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 1259 matching lines...)
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 kAllowHarmonyRestrictiveGenerators, 1277 kAllowHarmonyRestrictiveGenerators,
1278 kAllowHarmonyTrailingCommas, 1278 kAllowHarmonyTrailingCommas,
1279 kAllowHarmonyClassFields, 1279 kAllowHarmonyClassFields,
1280 kAllowHarmonyObjectSpread, 1280 kAllowHarmonyObjectRestSpread,
1281 }; 1281 };
1282 1282
1283 enum ParserSyncTestResult { 1283 enum ParserSyncTestResult {
1284 kSuccessOrError, 1284 kSuccessOrError,
1285 kSuccess, 1285 kSuccess,
1286 kError 1286 kError
1287 }; 1287 };
1288 1288
1289 void SetGlobalFlags(i::EnumSet<ParserFlag> flags) { 1289 void SetGlobalFlags(i::EnumSet<ParserFlag> flags) {
1290 i::FLAG_allow_natives_syntax = flags.Contains(kAllowNatives); 1290 i::FLAG_allow_natives_syntax = flags.Contains(kAllowNatives);
1291 i::FLAG_harmony_function_sent = flags.Contains(kAllowHarmonyFunctionSent); 1291 i::FLAG_harmony_function_sent = flags.Contains(kAllowHarmonyFunctionSent);
1292 i::FLAG_harmony_restrictive_generators = 1292 i::FLAG_harmony_restrictive_generators =
1293 flags.Contains(kAllowHarmonyRestrictiveGenerators); 1293 flags.Contains(kAllowHarmonyRestrictiveGenerators);
1294 i::FLAG_harmony_trailing_commas = flags.Contains(kAllowHarmonyTrailingCommas); 1294 i::FLAG_harmony_trailing_commas = flags.Contains(kAllowHarmonyTrailingCommas);
1295 i::FLAG_harmony_class_fields = flags.Contains(kAllowHarmonyClassFields); 1295 i::FLAG_harmony_class_fields = flags.Contains(kAllowHarmonyClassFields);
1296 i::FLAG_harmony_object_spread = flags.Contains(kAllowHarmonyObjectSpread); 1296 i::FLAG_harmony_object_rest_spread =
1297 flags.Contains(kAllowHarmonyObjectRestSpread);
1297 } 1298 }
1298 1299
1299 void SetParserFlags(i::PreParser* parser, i::EnumSet<ParserFlag> flags) { 1300 void SetParserFlags(i::PreParser* parser, i::EnumSet<ParserFlag> flags) {
1300 parser->set_allow_natives(flags.Contains(kAllowNatives)); 1301 parser->set_allow_natives(flags.Contains(kAllowNatives));
1301 parser->set_allow_harmony_function_sent( 1302 parser->set_allow_harmony_function_sent(
1302 flags.Contains(kAllowHarmonyFunctionSent)); 1303 flags.Contains(kAllowHarmonyFunctionSent));
1303 parser->set_allow_harmony_restrictive_generators( 1304 parser->set_allow_harmony_restrictive_generators(
1304 flags.Contains(kAllowHarmonyRestrictiveGenerators)); 1305 flags.Contains(kAllowHarmonyRestrictiveGenerators));
1305 parser->set_allow_harmony_trailing_commas( 1306 parser->set_allow_harmony_trailing_commas(
1306 flags.Contains(kAllowHarmonyTrailingCommas)); 1307 flags.Contains(kAllowHarmonyTrailingCommas));
1307 parser->set_allow_harmony_class_fields( 1308 parser->set_allow_harmony_class_fields(
1308 flags.Contains(kAllowHarmonyClassFields)); 1309 flags.Contains(kAllowHarmonyClassFields));
1309 parser->set_allow_harmony_object_spread( 1310 parser->set_allow_harmony_object_rest_spread(
1310 flags.Contains(kAllowHarmonyObjectSpread)); 1311 flags.Contains(kAllowHarmonyObjectRestSpread));
1311 } 1312 }
1312 1313
1313 void TestParserSyncWithFlags(i::Handle<i::String> source, 1314 void TestParserSyncWithFlags(i::Handle<i::String> source,
1314 i::EnumSet<ParserFlag> flags, 1315 i::EnumSet<ParserFlag> flags,
1315 ParserSyncTestResult result, 1316 ParserSyncTestResult result,
1316 bool is_module = false, 1317 bool is_module = false,
1317 bool test_preparser = true) { 1318 bool test_preparser = true) {
1318 i::Isolate* isolate = CcTest::i_isolate(); 1319 i::Isolate* isolate = CcTest::i_isolate();
1319 i::Factory* factory = isolate->factory(); 1320 i::Factory* factory = isolate->factory();
1320 1321
(...skipping 5211 matching lines...)
6532 "{ ...1}", 6533 "{ ...1}",
6533 "{ ...null}", 6534 "{ ...null}",
6534 "{ ...undefined}", 6535 "{ ...undefined}",
6535 "{ ...1 in {}}", 6536 "{ ...1 in {}}",
6536 "{ ...[]}", 6537 "{ ...[]}",
6537 "{ ...async function() { }}", 6538 "{ ...async function() { }}",
6538 "{ ...async () => { }}", 6539 "{ ...async () => { }}",
6539 "{ ...new Foo()}", 6540 "{ ...new Foo()}",
6540 NULL}; 6541 NULL};
6541 6542
6542 static const ParserFlag flags[] = {kAllowHarmonyObjectSpread}; 6543 static const ParserFlag flags[] = {kAllowHarmonyObjectRestSpread};
6543 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, flags, 6544 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, flags,
6544 arraysize(flags)); 6545 arraysize(flags));
6545 } 6546 }
6546 6547
6547 TEST(ObjectSpreadNegativeTests) { 6548 TEST(ObjectSpreadNegativeTests) {
6548 { 6549 const char* context_data[][2] = {{"x = ", ""},
6549 const char* context_data[][2] = {{"x = ", ""}, 6550 {"'use strict'; x = ", ""},
6550 {"'use strict'; x = ", ""}, 6551 {NULL, NULL}};
6551 {NULL, NULL}};
6552 6552
6553 // clang-format off 6553 // clang-format off
6554 const char* data[] = { 6554 const char* data[] = {
6555 "{ ...var z = y}", 6555 "{ ...var z = y}",
6556 "{ ...var}", 6556 "{ ...var}",
6557 "{ ...foo bar}", 6557 "{ ...foo bar}",
6558 NULL}; 6558 NULL};
6559 6559
6560 static const ParserFlag flags[] = {kAllowHarmonyObjectSpread}; 6560 static const ParserFlag flags[] = {kAllowHarmonyObjectRestSpread};
6561 RunParserSyncTest(context_data, data, kError, NULL, 0, flags, 6561 RunParserSyncTest(context_data, data, kError, NULL, 0, flags,
6562 arraysize(flags)); 6562 arraysize(flags));
6563 }
6564
6565 // Destructuring tests
6566 {
6567 const char* context_data[][2] = {
6568 {"var ", " = {};"},
6569 {"( ", " = {});"},
6570 {"'use strict'; const ", " = {};"},
6571 {"function f(", ") {}"},
6572 {"function f(argument1, ", ") {}"},
6573 {"var f = (", ") => {};"},
6574 {"var f = (argument1,", ") => {};"},
6575 {"try {} catch(", ") {}"},
6576 {NULL, NULL}};
6577
6578 // clang-format off
6579 const char* data[] = {
6580 "{ ...y }",
6581 "{ a: 1, ...y }",
6582 "{ b: 1, ...y }",
6583 "{ y, ...y}",
6584 "{ ...z = y}",
6585 "{ ...y, y }",
6586 "{ ...y, ...y}",
6587 "{ a: 1, ...y, b: 1}",
6588 "{ ...y, b: 1}",
6589 "{ ...1}",
6590 "{ ...null}",
6591 "{ ...undefined}",
6592 "{ ...unknown}",
6593 "{ ...var z = y}",
6594 "({ ...z = {})",
6595 NULL};
6596
6597 static const ParserFlag flags[] = {kAllowHarmonyObjectSpread};
6598 RunParserSyncTest(context_data, data, kError, NULL, 0, flags,
6599 arraysize(flags));
6600 }
6601 } 6563 }
6602 6564
6603 TEST(DestructuringPositiveTests) { 6565 TEST(DestructuringPositiveTests) {
6604 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, 6566 const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
6605 {"var ", " = {};"}, 6567 {"var ", " = {};"},
6606 {"'use strict'; const ", " = {};"}, 6568 {"'use strict'; const ", " = {};"},
6607 {"function f(", ") {}"}, 6569 {"function f(", ") {}"},
6608 {"function f(argument1, ", ") {}"}, 6570 {"function f(argument1, ", ") {}"},
6609 {"var f = (", ") => {};"}, 6571 {"var f = (", ") => {};"},
6610 {"var f = (argument1,", ") => {};"}, 6572 {"var f = (argument1,", ") => {};"},
6611 {"try {} catch(", ") {}"}, 6573 {"try {} catch(", ") {}"},
6612 {NULL, NULL}}; 6574 {NULL, NULL}};
6613 6575
6614 // clang-format off 6576 // clang-format off
6615 const char* data[] = { 6577 const char* data[] = {
6616 "a", 6578 "a",
6617 "{ x : y }", 6579 "{ x : y }",
6580 "{ x : y, ...z }",
adamk 2017/01/12 22:43:08 Rather than interleaving the new tests and always
gsathya 2017/01/17 19:28:59 Done.
6618 "{ x : y = 1 }", 6581 "{ x : y = 1 }",
6582 "{ x : y = 1, ...z }",
6619 "{ get, set }", 6583 "{ get, set }",
6620 "{ get = 1, set = 2 }", 6584 "{ get = 1, set = 2 }",
6621 "[a]", 6585 "[a]",
6622 "[a = 1]", 6586 "[a = 1]",
6623 "[a,b,c]", 6587 "[a,b,c]",
6624 "[a, b = 42, c]", 6588 "[a, b = 42, c]",
6625 "{ x : x, y : y }", 6589 "{ x : x, y : y }",
6590 "{ x : x, y : y, ...z }",
6626 "{ x : x = 1, y : y }", 6591 "{ x : x = 1, y : y }",
6592 "{ x : x = 1, y : y, ...z }",
6627 "{ x : x, y : y = 42 }", 6593 "{ x : x, y : y = 42 }",
6594 "{ x : x, y : y = 42, ...z }",
6628 "[]", 6595 "[]",
6629 "{}", 6596 "{}",
6630 "[{x:x, y:y}, [a,b,c]]", 6597 "[{x:x, y:y}, [a,b,c]]",
6598 "[{x:x, y:y, ...z}, [a,b,c]]",
6631 "[{x:x = 1, y:y = 2}, [a = 3, b = 4, c = 5]]", 6599 "[{x:x = 1, y:y = 2}, [a = 3, b = 4, c = 5]]",
6632 "{x}", 6600 "[{x:x = 1, y:y = 2, ...z}, [a = 3, b = 4, c = 5]]",
6601 "{...x}",
6602 "{...{ x = 5} }",
6633 "{x, y}", 6603 "{x, y}",
6604 "{x, ...y}",
6634 "{x = 42, y = 15}", 6605 "{x = 42, y = 15}",
6606 "{x = 42, y = 15, ...z}",
6635 "[a,,b]", 6607 "[a,,b]",
6636 "{42 : x}", 6608 "{42 : x}",
6637 "{42 : x = 42}", 6609 "{42 : x = 42}",
6610 "{42 : x = 42, ...y}",
6638 "{42e-2 : x}", 6611 "{42e-2 : x}",
6639 "{42e-2 : x = 42}", 6612 "{42e-2 : x = 42}",
6640 "{x : y, x : z}", 6613 "{x : y, x : z}",
6641 "{'hi' : x}", 6614 "{'hi' : x}",
6615 "{'hi' : x, ...z}",
6642 "{'hi' : x = 42}", 6616 "{'hi' : x = 42}",
6617 "{'hi' : x = 42, ...z}",
6643 "{var: x}", 6618 "{var: x}",
6644 "{var: x = 42}", 6619 "{var: x = 42}",
6620 "{var: x = 42, ...z}",
6645 "{[x] : z}", 6621 "{[x] : z}",
6622 "{[x] : z, ...y}",
6646 "{[1+1] : z}", 6623 "{[1+1] : z}",
6624 "{[1+1] : z, ...x}",
6647 "{[foo()] : z}", 6625 "{[foo()] : z}",
6648 "{}", 6626 "{}",
6649 "[...rest]", 6627 "[...rest]",
6650 "[a,b,...rest]", 6628 "[a,b,...rest]",
6651 "[a,,...rest]", 6629 "[a,,...rest]",
6652 "{ __proto__: x, __proto__: y}", 6630 "{ __proto__: x, __proto__: y}",
6631 "{ __proto__: x, __proto__: y, ...z}",
6653 "{arguments: x}", 6632 "{arguments: x}",
6633 "{arguments: x, ...z}",
6654 "{eval: x}", 6634 "{eval: x}",
6655 NULL}; 6635 NULL};
6656 // clang-format on 6636 // clang-format on
6657 RunParserSyncTest(context_data, data, kSuccess); 6637 static const ParserFlag flags[] = {kAllowHarmonyObjectRestSpread};
6638 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, flags,
6639 arraysize(flags));
6658 6640
6659 // v8:5201 6641 // v8:5201
6660 { 6642 {
6661 // clang-format off 6643 // clang-format off
6662 const char* sloppy_context_data[][2] = { 6644 const char* sloppy_context_data[][2] = {
6663 {"var ", " = {};"}, 6645 {"var ", " = {};"},
6664 {"function f(", ") {}"}, 6646 {"function f(", ") {}"},
6665 {"function f(argument1, ", ") {}"}, 6647 {"function f(argument1, ", ") {}"},
6666 {"var f = (", ") => {};"}, 6648 {"var f = (", ") => {};"},
6667 {"var f = (argument1,", ") => {};"}, 6649 {"var f = (argument1,", ") => {};"},
6668 {"try {} catch(", ") {}"}, 6650 {"try {} catch(", ") {}"},
6669 {NULL, NULL} 6651 {NULL, NULL}
6670 }; 6652 };
6671 const char* data[] = { 6653 const char* data[] = {
6672 "{arguments}", 6654 "{arguments}",
6673 "{eval}", 6655 "{eval}",
6674 "{x: arguments}", 6656 "{x: arguments}",
6675 "{x: eval}", 6657 "{x: eval}",
6676 "{arguments = false}", 6658 "{arguments = false}",
6677 "{eval = false}", 6659 "{eval = false}",
6660 "{...arguments}",
6661 "{...eval}",
6662 "{z, ...z,}",
6678 NULL 6663 NULL
6679 }; 6664 };
6680 // clang-format on 6665 // clang-format on
6681 RunParserSyncTest(sloppy_context_data, data, kSuccess); 6666 static const ParserFlag flags[] = {kAllowHarmonyObjectRestSpread};
6667 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, flags,
6668 arraysize(flags));
6682 } 6669 }
6683 } 6670 }
6684 6671
6685 6672
6686 TEST(DestructuringNegativeTests) { 6673 TEST(DestructuringNegativeTests) {
6687 { // All modes. 6674 { // All modes.
6688 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, 6675 const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
6689 {"var ", " = {};"}, 6676 {"var ", " = {};"},
6690 {"'use strict'; const ", " = {};"}, 6677 {"'use strict'; const ", " = {};"},
6691 {"function f(", ") {}"}, 6678 {"function f(", ") {}"},
6692 {"function f(argument1, ", ") {}"}, 6679 {"function f(argument1, ", ") {}"},
6693 {"var f = (", ") => {};"}, 6680 {"var f = (", ") => {};"},
6694 {"var f = ", " => {};"}, 6681 {"var f = ", " => {};"},
6695 {"var f = (argument1,", ") => {};"}, 6682 {"var f = (argument1,", ") => {};"},
6696 {"try {} catch(", ") {}"}, 6683 {"try {} catch(", ") {}"},
6697 {NULL, NULL}}; 6684 {NULL, NULL}};
6698 6685
6699 // clang-format off 6686 // clang-format off
6700 const char* data[] = { 6687 const char* data[] = {
6701 "a++", 6688 "a++",
6689 "...a++",
6702 "++a", 6690 "++a",
6691 "...++a",
6703 "delete a", 6692 "delete a",
6704 "void a", 6693 "void a",
6705 "typeof a", 6694 "typeof a",
6695 "...typeof a",
6706 "--a", 6696 "--a",
6707 "+a", 6697 "+a",
6708 "-a", 6698 "-a",
6709 "~a", 6699 "~a",
6710 "!a", 6700 "!a",
6711 "{ x : y++ }", 6701 "{ x : y++ }",
6712 "[a++]", 6702 "[a++]",
6703 "...[a++]",
6713 "(x => y)", 6704 "(x => y)",
6705 "...(x => y)",
6714 "a[i]", "a()", 6706 "a[i]", "a()",
6715 "a.b", 6707 "a.b",
6716 "new a", 6708 "new a",
6717 "a + a", 6709 "a + a",
6718 "a - a", 6710 "a - a",
6719 "a * a", 6711 "a * a",
6720 "a / a", 6712 "a / a",
6721 "a == a", 6713 "a == a",
6722 "a != a", 6714 "a != a",
6723 "a > a", 6715 "a > a",
(...skipping 27 matching lines...)
6751 "[...rest,]", 6743 "[...rest,]",
6752 "[a,b,...rest,]", 6744 "[a,b,...rest,]",
6753 "[a,,...rest,]", 6745 "[a,,...rest,]",
6754 "[...rest,...rest1]", 6746 "[...rest,...rest1]",
6755 "[a,b,...rest,...rest1]", 6747 "[a,b,...rest,...rest1]",
6756 "[a,,..rest,...rest1]", 6748 "[a,,..rest,...rest1]",
6757 "[x, y, ...z = 1]", 6749 "[x, y, ...z = 1]",
6758 "[...z = 1]", 6750 "[...z = 1]",
6759 "[x, y, ...[z] = [1]]", 6751 "[x, y, ...[z] = [1]]",
6760 "[...[z] = [1]]", 6752 "[...[z] = [1]]",
6753 "{ ...x, }",
6754 "{ ...x, y }",
6755 "{ y, ...x, y }",
6756 "{ ...x, ...y }",
6757 "{ ...x, ...x }",
6758 "{ ...x, ...x = {} }",
6759 "{ ...x, ...x = ...x }",
6760 "{ ...x, ...x = ...{ x } }",
6761 "{ ,, ...x }",
6761 "{ x : 3 }", 6762 "{ x : 3 }",
6762 "{ x : 'foo' }", 6763 "{ x : 'foo' }",
6763 "{ x : /foo/ }", 6764 "{ x : /foo/ }",
6764 "{ x : `foo` }", 6765 "{ x : `foo` }",
6765 "{ get a() {} }", 6766 "{ get a() {} }",
6767 "{ ...get a() {} }",
6766 "{ set a() {} }", 6768 "{ set a() {} }",
6769 "{ ...set a() {} }",
6767 "{ method() {} }", 6770 "{ method() {} }",
6771 "{ ...method() {} }",
6772 "{ ...function() {} }",
6768 "{ *method() {} }", 6773 "{ *method() {} }",
6774 "{ ...*method() {} }",
6769 NULL}; 6775 NULL};
6770 // clang-format on 6776 // clang-format on
6771 RunParserSyncTest(context_data, data, kError); 6777 static const ParserFlag flags[] = {kAllowHarmonyObjectRestSpread};
6778 RunParserSyncTest(context_data, data, kError, NULL, 0, flags,
6779 arraysize(flags));
6772 } 6780 }
6773 6781
6774 { // All modes. 6782 { // All modes.
6775 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, 6783 const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
6776 {"var ", " = {};"}, 6784 {"var ", " = {};"},
6777 {"'use strict'; const ", " = {};"}, 6785 {"'use strict'; const ", " = {};"},
6778 {"function f(", ") {}"}, 6786 {"function f(", ") {}"},
6779 {"function f(argument1, ", ") {}"}, 6787 {"function f(argument1, ", ") {}"},
6780 {"var f = (", ") => {};"}, 6788 {"var f = (", ") => {};"},
6781 {"var f = (argument1,", ") => {};"}, 6789 {"var f = (argument1,", ") => {};"},
(...skipping 2053 matching lines...)
8835 DCHECK_NOT_NULL(scope); 8843 DCHECK_NOT_NULL(scope);
8836 DCHECK_NULL(scope->sibling()); 8844 DCHECK_NULL(scope->sibling());
8837 DCHECK(scope->is_function_scope()); 8845 DCHECK(scope->is_function_scope());
8838 const i::AstRawString* var_name = 8846 const i::AstRawString* var_name =
8839 info.ast_value_factory()->GetOneByteString("my_var"); 8847 info.ast_value_factory()->GetOneByteString("my_var");
8840 i::Variable* var = scope->Lookup(var_name); 8848 i::Variable* var = scope->Lookup(var_name);
8841 CHECK_EQ(inners[i].ctxt_allocate, 8849 CHECK_EQ(inners[i].ctxt_allocate,
8842 i::ScopeTestHelper::MustAllocateInContext(var)); 8850 i::ScopeTestHelper::MustAllocateInContext(var));
8843 } 8851 }
8844 } 8852 }
OLDNEW

Powered by Google App Engine