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

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

Issue 2606833002: [ESnext] Implement Object spread (Closed)
Patch Set: fix test 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-spread-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 1251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 const char* ReadString(unsigned* start) { 1262 const char* ReadString(unsigned* start) {
1263 int length = start[0]; 1263 int length = start[0];
1264 char* result = i::NewArray<char>(length + 1); 1264 char* result = i::NewArray<char>(length + 1);
1265 for (int i = 0; i < length; i++) { 1265 for (int i = 0; i < length; i++) {
1266 result[i] = start[i + 1]; 1266 result[i] = start[i + 1];
1267 } 1267 }
1268 result[length] = '\0'; 1268 result[length] = '\0';
1269 return result; 1269 return result;
1270 } 1270 }
1271 1271
1272
1273 enum ParserFlag { 1272 enum ParserFlag {
1274 kAllowLazy, 1273 kAllowLazy,
1275 kAllowNatives, 1274 kAllowNatives,
1276 kAllowHarmonyFunctionSent, 1275 kAllowHarmonyFunctionSent,
1277 kAllowHarmonyAsyncAwait, 1276 kAllowHarmonyAsyncAwait,
1278 kAllowHarmonyRestrictiveGenerators, 1277 kAllowHarmonyRestrictiveGenerators,
1279 kAllowHarmonyTrailingCommas, 1278 kAllowHarmonyTrailingCommas,
1280 kAllowHarmonyClassFields, 1279 kAllowHarmonyClassFields,
1280 kAllowHarmonyObjectSpread,
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_async_await = flags.Contains(kAllowHarmonyAsyncAwait); 1292 i::FLAG_harmony_async_await = flags.Contains(kAllowHarmonyAsyncAwait);
1293 i::FLAG_harmony_restrictive_generators = 1293 i::FLAG_harmony_restrictive_generators =
1294 flags.Contains(kAllowHarmonyRestrictiveGenerators); 1294 flags.Contains(kAllowHarmonyRestrictiveGenerators);
1295 i::FLAG_harmony_trailing_commas = flags.Contains(kAllowHarmonyTrailingCommas); 1295 i::FLAG_harmony_trailing_commas = flags.Contains(kAllowHarmonyTrailingCommas);
1296 i::FLAG_harmony_class_fields = flags.Contains(kAllowHarmonyClassFields); 1296 i::FLAG_harmony_class_fields = flags.Contains(kAllowHarmonyClassFields);
1297 i::FLAG_harmony_object_spread = flags.Contains(kAllowHarmonyObjectSpread);
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_async_await( 1304 parser->set_allow_harmony_async_await(
1304 flags.Contains(kAllowHarmonyAsyncAwait)); 1305 flags.Contains(kAllowHarmonyAsyncAwait));
1305 parser->set_allow_harmony_restrictive_generators( 1306 parser->set_allow_harmony_restrictive_generators(
1306 flags.Contains(kAllowHarmonyRestrictiveGenerators)); 1307 flags.Contains(kAllowHarmonyRestrictiveGenerators));
1307 parser->set_allow_harmony_trailing_commas( 1308 parser->set_allow_harmony_trailing_commas(
1308 flags.Contains(kAllowHarmonyTrailingCommas)); 1309 flags.Contains(kAllowHarmonyTrailingCommas));
1309 parser->set_allow_harmony_class_fields( 1310 parser->set_allow_harmony_class_fields(
1310 flags.Contains(kAllowHarmonyClassFields)); 1311 flags.Contains(kAllowHarmonyClassFields));
1312 parser->set_allow_harmony_object_spread(
1313 flags.Contains(kAllowHarmonyObjectSpread));
1311 } 1314 }
1312 1315
1313 void TestParserSyncWithFlags(i::Handle<i::String> source, 1316 void TestParserSyncWithFlags(i::Handle<i::String> source,
1314 i::EnumSet<ParserFlag> flags, 1317 i::EnumSet<ParserFlag> flags,
1315 ParserSyncTestResult result, 1318 ParserSyncTestResult result,
1316 bool is_module = false, 1319 bool is_module = false,
1317 bool test_preparser = true) { 1320 bool test_preparser = true) {
1318 i::Isolate* isolate = CcTest::i_isolate(); 1321 i::Isolate* isolate = CcTest::i_isolate();
1319 i::Factory* factory = isolate->factory(); 1322 i::Factory* factory = isolate->factory();
1320 1323
(...skipping 5242 matching lines...) Expand 10 before | Expand all | Expand 10 after
6563 "(a\n=> a)(1)", 6566 "(a\n=> a)(1)",
6564 "(a/*\n*/=> a)(1)", 6567 "(a/*\n*/=> a)(1)",
6565 "((a)\n=> a)(1)", 6568 "((a)\n=> a)(1)",
6566 "((a)/*\n*/=> a)(1)", 6569 "((a)/*\n*/=> a)(1)",
6567 "((a, b)\n=> a + b)(1, 2)", 6570 "((a, b)\n=> a + b)(1, 2)",
6568 "((a, b)/*\n*/=> a + b)(1, 2)", 6571 "((a, b)/*\n*/=> a + b)(1, 2)",
6569 NULL}; 6572 NULL};
6570 RunParserSyncTest(context_data, data, kError); 6573 RunParserSyncTest(context_data, data, kError);
6571 } 6574 }
6572 6575
6576 TEST(ObjectSpreadPositiveTests) {
6577 // clang-format off
6578 const char* context_data[][2] = {
6579 {"x = ", ""},
6580 {"'use strict'; x = ", ""},
6581 {NULL, NULL}};
6582
6583 // clang-format off
6584 const char* data[] = {
6585 "{ ...y }",
6586 "{ a: 1, ...y }",
6587 "{ b: 1, ...y }",
6588 "{ y, ...y}",
6589 "{ ...z = y}",
6590 "{ ...y, y }",
6591 "{ ...y, ...y}",
6592 "{ a: 1, ...y, b: 1}",
6593 "{ ...y, b: 1}",
6594 "{ ...1}",
6595 "{ ...null}",
6596 "{ ...undefined}",
6597 "{ ...1 in {}}",
6598 "{ ...[]}",
6599 "{ ...async function() { }}",
6600 "{ ...async () => { }}",
6601 "{ ...new Foo()}",
6602 NULL};
6603
6604 static const ParserFlag flags[] = {kAllowHarmonyObjectSpread,
6605 kAllowHarmonyAsyncAwait};
6606 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, flags,
6607 arraysize(flags));
6608 }
6609
6610 TEST(ObjectSpreadNegativeTests) {
6611 {
6612 const char* context_data[][2] = {{"x = ", ""},
6613 {"'use strict'; x = ", ""},
6614 {NULL, NULL}};
6615
6616 // clang-format off
6617 const char* data[] = {
6618 "{ ...var z = y}",
6619 "{ ...var}",
6620 "{ ...foo bar}",
6621 NULL};
6622
6623 static const ParserFlag flags[] = {kAllowHarmonyObjectSpread};
6624 RunParserSyncTest(context_data, data, kError, NULL, 0, flags,
6625 arraysize(flags));
6626 }
6627
6628 // Destructuring tests
6629 {
6630 const char* context_data[][2] = {
6631 {"var ", " = {};"},
6632 {"( ", " = {});"},
6633 {"'use strict'; const ", " = {};"},
6634 {"function f(", ") {}"},
6635 {"function f(argument1, ", ") {}"},
6636 {"var f = (", ") => {};"},
6637 {"var f = (argument1,", ") => {};"},
6638 {"try {} catch(", ") {}"},
6639 {NULL, NULL}};
6640
6641 // clang-format off
6642 const char* data[] = {
6643 "{ ...y }",
6644 "{ a: 1, ...y }",
6645 "{ b: 1, ...y }",
6646 "{ y, ...y}",
6647 "{ ...z = y}",
6648 "{ ...y, y }",
6649 "{ ...y, ...y}",
6650 "{ a: 1, ...y, b: 1}",
6651 "{ ...y, b: 1}",
6652 "{ ...1}",
6653 "{ ...null}",
6654 "{ ...undefined}",
6655 "{ ...unknown}",
6656 "{ ...var z = y}",
6657 "({ ...z = {})",
6658 NULL};
6659
6660 static const ParserFlag flags[] = {kAllowHarmonyObjectSpread};
6661 RunParserSyncTest(context_data, data, kError, NULL, 0, flags,
6662 arraysize(flags));
6663 }
6664 }
6573 6665
6574 TEST(DestructuringPositiveTests) { 6666 TEST(DestructuringPositiveTests) {
6575 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, 6667 const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
6576 {"var ", " = {};"}, 6668 {"var ", " = {};"},
6577 {"'use strict'; const ", " = {};"}, 6669 {"'use strict'; const ", " = {};"},
6578 {"function f(", ") {}"}, 6670 {"function f(", ") {}"},
6579 {"function f(argument1, ", ") {}"}, 6671 {"function f(argument1, ", ") {}"},
6580 {"var f = (", ") => {};"}, 6672 {"var f = (", ") => {};"},
6581 {"var f = (argument1,", ") => {};"}, 6673 {"var f = (argument1,", ") => {};"},
6582 {"try {} catch(", ") {}"}, 6674 {"try {} catch(", ") {}"},
(...skipping 2121 matching lines...) Expand 10 before | Expand all | Expand 10 after
8704 DCHECK_NOT_NULL(scope); 8796 DCHECK_NOT_NULL(scope);
8705 DCHECK_NULL(scope->sibling()); 8797 DCHECK_NULL(scope->sibling());
8706 DCHECK(scope->is_function_scope()); 8798 DCHECK(scope->is_function_scope());
8707 const i::AstRawString* var_name = 8799 const i::AstRawString* var_name =
8708 info.ast_value_factory()->GetOneByteString("my_var"); 8800 info.ast_value_factory()->GetOneByteString("my_var");
8709 i::Variable* var = scope->Lookup(var_name); 8801 i::Variable* var = scope->Lookup(var_name);
8710 CHECK_EQ(inners[i].ctxt_allocate, 8802 CHECK_EQ(inners[i].ctxt_allocate,
8711 i::ScopeTestHelper::MustAllocateInContext(var)); 8803 i::ScopeTestHelper::MustAllocateInContext(var));
8712 } 8804 }
8713 } 8805 }
OLDNEW
« no previous file with comments | « src/runtime/runtime-object.cc ('k') | test/mjsunit/harmony/object-spread-basic.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698