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

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

Issue 2606833002: [ESnext] Implement Object spread (Closed)
Patch Set: fix build 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
« src/runtime/runtime-object.cc ('K') | « src/runtime/runtime-object.cc ('k') | no next file » | 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 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 const char* ReadString(unsigned* start) { 1261 const char* ReadString(unsigned* start) {
1262 int length = start[0]; 1262 int length = start[0];
1263 char* result = i::NewArray<char>(length + 1); 1263 char* result = i::NewArray<char>(length + 1);
1264 for (int i = 0; i < length; i++) { 1264 for (int i = 0; i < length; i++) {
1265 result[i] = start[i + 1]; 1265 result[i] = start[i + 1];
1266 } 1266 }
1267 result[length] = '\0'; 1267 result[length] = '\0';
1268 return result; 1268 return result;
1269 } 1269 }
1270 1270
1271
1272 enum ParserFlag { 1271 enum ParserFlag {
1273 kAllowLazy, 1272 kAllowLazy,
1274 kAllowNatives, 1273 kAllowNatives,
1275 kAllowHarmonyFunctionSent, 1274 kAllowHarmonyFunctionSent,
1276 kAllowHarmonyAsyncAwait, 1275 kAllowHarmonyAsyncAwait,
1277 kAllowHarmonyRestrictiveGenerators, 1276 kAllowHarmonyRestrictiveGenerators,
1278 kAllowHarmonyTrailingCommas, 1277 kAllowHarmonyTrailingCommas,
1279 kAllowHarmonyClassFields, 1278 kAllowHarmonyClassFields,
1279 kAllowHarmonyObjectSpread,
1280 }; 1280 };
1281 1281
1282 enum ParserSyncTestResult { 1282 enum ParserSyncTestResult {
1283 kSuccessOrError, 1283 kSuccessOrError,
1284 kSuccess, 1284 kSuccess,
1285 kError 1285 kError
1286 }; 1286 };
1287 1287
1288 void SetGlobalFlags(i::EnumSet<ParserFlag> flags) { 1288 void SetGlobalFlags(i::EnumSet<ParserFlag> flags) {
1289 i::FLAG_allow_natives_syntax = flags.Contains(kAllowNatives); 1289 i::FLAG_allow_natives_syntax = flags.Contains(kAllowNatives);
1290 i::FLAG_harmony_function_sent = flags.Contains(kAllowHarmonyFunctionSent); 1290 i::FLAG_harmony_function_sent = flags.Contains(kAllowHarmonyFunctionSent);
1291 i::FLAG_harmony_async_await = flags.Contains(kAllowHarmonyAsyncAwait); 1291 i::FLAG_harmony_async_await = flags.Contains(kAllowHarmonyAsyncAwait);
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 } 1297 }
1297 1298
1298 void SetParserFlags(i::PreParser* parser, i::EnumSet<ParserFlag> flags) { 1299 void SetParserFlags(i::PreParser* parser, i::EnumSet<ParserFlag> flags) {
1299 parser->set_allow_natives(flags.Contains(kAllowNatives)); 1300 parser->set_allow_natives(flags.Contains(kAllowNatives));
1300 parser->set_allow_harmony_function_sent( 1301 parser->set_allow_harmony_function_sent(
1301 flags.Contains(kAllowHarmonyFunctionSent)); 1302 flags.Contains(kAllowHarmonyFunctionSent));
1302 parser->set_allow_harmony_async_await( 1303 parser->set_allow_harmony_async_await(
1303 flags.Contains(kAllowHarmonyAsyncAwait)); 1304 flags.Contains(kAllowHarmonyAsyncAwait));
1304 parser->set_allow_harmony_restrictive_generators( 1305 parser->set_allow_harmony_restrictive_generators(
1305 flags.Contains(kAllowHarmonyRestrictiveGenerators)); 1306 flags.Contains(kAllowHarmonyRestrictiveGenerators));
1306 parser->set_allow_harmony_trailing_commas( 1307 parser->set_allow_harmony_trailing_commas(
1307 flags.Contains(kAllowHarmonyTrailingCommas)); 1308 flags.Contains(kAllowHarmonyTrailingCommas));
1308 parser->set_allow_harmony_class_fields( 1309 parser->set_allow_harmony_class_fields(
1309 flags.Contains(kAllowHarmonyClassFields)); 1310 flags.Contains(kAllowHarmonyClassFields));
1311 parser->set_allow_harmony_object_spread(
1312 flags.Contains(kAllowHarmonyObjectSpread));
1310 } 1313 }
1311 1314
1312 void TestParserSyncWithFlags(i::Handle<i::String> source, 1315 void TestParserSyncWithFlags(i::Handle<i::String> source,
1313 i::EnumSet<ParserFlag> flags, 1316 i::EnumSet<ParserFlag> flags,
1314 ParserSyncTestResult result, 1317 ParserSyncTestResult result,
1315 bool is_module = false, 1318 bool is_module = false,
1316 bool test_preparser = true) { 1319 bool test_preparser = true) {
1317 i::Isolate* isolate = CcTest::i_isolate(); 1320 i::Isolate* isolate = CcTest::i_isolate();
1318 i::Factory* factory = isolate->factory(); 1321 i::Factory* factory = isolate->factory();
1319 1322
(...skipping 5237 matching lines...) Expand 10 before | Expand all | Expand 10 after
6557 "(a\n=> a)(1)", 6560 "(a\n=> a)(1)",
6558 "(a/*\n*/=> a)(1)", 6561 "(a/*\n*/=> a)(1)",
6559 "((a)\n=> a)(1)", 6562 "((a)\n=> a)(1)",
6560 "((a)/*\n*/=> a)(1)", 6563 "((a)/*\n*/=> a)(1)",
6561 "((a, b)\n=> a + b)(1, 2)", 6564 "((a, b)\n=> a + b)(1, 2)",
6562 "((a, b)/*\n*/=> a + b)(1, 2)", 6565 "((a, b)/*\n*/=> a + b)(1, 2)",
6563 NULL}; 6566 NULL};
6564 RunParserSyncTest(context_data, data, kError); 6567 RunParserSyncTest(context_data, data, kError);
6565 } 6568 }
6566 6569
6570 TEST(ObjectSpreadPositiveTests) {
6571 const char* context_data[][2] = {{"'use strict'; let x = ", ""},
6572 {"var x = ", ""},
6573 {"x = ", ""},
6574 {"'use strict'; const x = ", ""},
6575 {"function f(x = ", ") {}"},
6576 {"function f(argument1, x = ", ") {}"},
6577 {"var f = (x = ", ") => {};"},
6578 {"var f = (argument1, x = ", ") => {};"},
6579 {NULL, NULL}};
6580
6581 // clang-format off
6582 const char* data[] = {
6583 "{ ...y }",
6584 "{ a: 1, ...y }",
6585 "{ b: 1, ...y }",
6586 "{ y, ...y}",
6587 "{ ...z = y}",
6588 "{ ...y, y }",
6589 "{ ...y, ...y}",
6590 "{ a: 1, ...y, b: 1}",
6591 "{ ...y, b: 1}",
6592 "{ ...1}",
6593 "{ ...null}",
6594 "{ ...undefined}",
6595 "{ ...unknown}",
6596 "{...1 in {}}",
6597 NULL};
6598
6599 static const ParserFlag flags[] = {kAllowHarmonyObjectSpread};
6600 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, flags,
6601 arraysize(flags));
6602 }
6603
6604 TEST(ObjectSpreadNegativeTests) {
6605 {
6606 const char* context_data[][2] = {
6607 {"'use strict'; let x = ", ""},
6608 {"x = ", ""},
6609 {"var x = ", ""},
6610 {"'use strict'; const x = ", ""},
6611 {"function f(argument1, x = ", ") {}"},
6612 {"function f(x = ", ") {}"},
6613 {"var f = (x = ", ") => {};"},
6614 {"var f = (argument1, x = ", ") => {};"},
6615 {NULL, NULL}};
6616
6617 // clang-format off
6618 const char* data[] = {
6619 "{ ...var z = y}",
6620 NULL};
6621
6622 static const ParserFlag flags[] = {kAllowHarmonyObjectSpread};
6623 RunParserSyncTest(context_data, data, kError, NULL, 0, flags,
6624 arraysize(flags));
6625 }
6626
6627 // Destructuring tests
6628 {
6629 const char* context_data[][2] = {
6630 {"var ", " = {};"},
6631 {"'use strict'; const ", " = {};"},
6632 {"function f(", ") {}"},
6633 {"function f(argument1, ", ") {}"},
6634 {"var f = (", ") => {};"},
6635 {"var f = (argument1,", ") => {};"},
6636 {"try {} catch(", ") {}"},
6637 {NULL, NULL}};
6638
6639 // clang-format off
6640 const char* data[] = {
6641 "{ ...y }",
6642 "{ ...y } = {} ",
adamk 2016/12/29 18:32:46 Rather than doing this here, you could cover every
gsathya 2017/01/05 22:18:36 Done.
6643 "{ a: 1, ...y }",
6644 "{ b: 1, ...y }",
6645 "{ y, ...y}",
6646 "{ ...z = y}",
6647 "{ ...y, y }",
6648 "{ ...y, ...y}",
6649 "{ a: 1, ...y, b: 1}",
6650 "{ ...y, b: 1}",
6651 "{ ...1}",
6652 "{ ...null}",
6653 "{ ...undefined}",
6654 "{ ...unknown}",
6655 "{ ...var z = y}",
6656 "({ ...z = {})",
6657 NULL};
6658
6659 static const ParserFlag flags[] = {kAllowHarmonyObjectSpread};
6660 RunParserSyncTest(context_data, data, kError, NULL, 0, flags,
6661 arraysize(flags));
6662 }
6663 }
6567 6664
6568 TEST(DestructuringPositiveTests) { 6665 TEST(DestructuringPositiveTests) {
6569 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, 6666 const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
6570 {"var ", " = {};"}, 6667 {"var ", " = {};"},
6571 {"'use strict'; const ", " = {};"}, 6668 {"'use strict'; const ", " = {};"},
6572 {"function f(", ") {}"}, 6669 {"function f(", ") {}"},
6573 {"function f(argument1, ", ") {}"}, 6670 {"function f(argument1, ", ") {}"},
6574 {"var f = (", ") => {};"}, 6671 {"var f = (", ") => {};"},
6575 {"var f = (argument1,", ") => {};"}, 6672 {"var f = (argument1,", ") => {};"},
6576 {"try {} catch(", ") {}"}, 6673 {"try {} catch(", ") {}"},
(...skipping 2118 matching lines...) Expand 10 before | Expand all | Expand 10 after
8695 DCHECK_NOT_NULL(scope); 8792 DCHECK_NOT_NULL(scope);
8696 DCHECK_NULL(scope->sibling()); 8793 DCHECK_NULL(scope->sibling());
8697 DCHECK(scope->is_function_scope()); 8794 DCHECK(scope->is_function_scope());
8698 const i::AstRawString* var_name = 8795 const i::AstRawString* var_name =
8699 info.ast_value_factory()->GetOneByteString("my_var"); 8796 info.ast_value_factory()->GetOneByteString("my_var");
8700 i::Variable* var = scope->Lookup(var_name); 8797 i::Variable* var = scope->Lookup(var_name);
8701 CHECK_EQ(inners[i].ctxt_allocate, 8798 CHECK_EQ(inners[i].ctxt_allocate,
8702 i::ScopeTestHelper::MustAllocateInContext(var)); 8799 i::ScopeTestHelper::MustAllocateInContext(var));
8703 } 8800 }
8704 } 8801 }
OLDNEW
« src/runtime/runtime-object.cc ('K') | « src/runtime/runtime-object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698