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

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

Issue 2606833002: [ESnext] Implement Object spread (Closed)
Patch Set: revert is_dynamic_name change 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] = {
6572 {"'use strict'; let y = { a: 1}; let x = ", ""},
adamk 2016/12/29 00:48:45 Generally the context data is about different sort
gsathya 2016/12/29 06:40:56 Done.
adamk 2016/12/29 18:32:45 Sorry if I wasn't clear, but I don't think you nee
gsathya 2017/01/05 22:18:35 Done.
6573 {"var y = { a: 1}, x = ", ""},
6574 {"var y = { a: 1}; var x = ", ""},
6575 {"'use strict'; const y = { a: 1}; const x = ", ""},
6576 {"function f(y = { a: 1}, x = ", ") {}"},
6577 {"var y = { a: 1 }; function f(x = ", ") {}"},
6578 {"var y = { a: 1 }; var f = (x = ", ") => {};"},
6579 {"var f = (y = { a: 1 }, x = ", ") => {};"},
6580 {NULL, NULL}};
6581
6582 // clang-format off
6583 const char* data[] = {
6584 "{ ...y }",
6585 "{ a: 1, ...y }",
6586 "{ b: 1, ...y }",
6587 "{ y, ...y}",
6588 "{ ...z = y}",
6589 "{ ...y, y }",
6590 "{ ...y, ...y}",
6591 "{ a: 1, ...y, b: 1}",
6592 "{ ...y, b: 1}",
6593 "{ ...1}",
6594 "{ ...null}",
6595 "{ ...undefined}",
6596 "{ ...unknown}",
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 y = { a: 1}; let x = ", ""},
adamk 2016/12/29 00:48:45 Same comment on context data here.
gsathya 2016/12/29 06:40:56 Done.
adamk 2016/12/29 18:32:45 Same here
gsathya 2017/01/05 22:18:35 Done.
6608 {"var y = { a: 1}, x = ", ""},
6609 {"var y = { a: 1}; var x = ", ""},
6610 {"'use strict'; const y = { a: 1}; const x = ", ""},
6611 {"function f(y = { a: 1}, x = ", ") {}"},
6612 {"var y = { a: 1 }; function f(x = ", ") {}"},
6613 {"var y = { a: 1 }; var f = (x = ", ") => {};"},
6614 {"var f = (y = { a: 1 }, x = ", ") => {};"},
6615 {NULL, NULL}};
6616
6617 // clang-format off
6618 const char* data[] = {
6619 "{ ...var z = y}",
adamk 2016/12/29 00:48:45 I agree that negative tests are kinda tricky for t
gsathya 2016/12/29 06:40:56 Done.
adamk 2016/12/29 18:32:45 ? I don't see any additional tests here.
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(", ") {}"},
adamk 2016/12/29 00:48:45 Need to add an assignment context.
6637 {NULL, NULL}};
6638
6639 // clang-format off
6640 const char* data[] = {
6641 "{ ...y }",
6642 "{ a: 1, ...y }",
6643 "{ b: 1, ...y }",
6644 "{ y, ...y}",
6645 "{ ...z = y}",
6646 "{ ...y, y }",
6647 "{ ...y, ...y}",
6648 "{ a: 1, ...y, b: 1}",
6649 "{ ...y, b: 1}",
6650 "{ ...1}",
6651 "{ ...null}",
6652 "{ ...undefined}",
6653 "{ ...unknown}",
6654 "{ ...var z = y}",
6655 NULL};
6656
6657 static const ParserFlag flags[] = {kAllowHarmonyObjectSpread};
6658 RunParserSyncTest(context_data, data, kError, NULL, 0, flags,
6659 arraysize(flags));
6660 }
6661 }
6567 6662
6568 TEST(DestructuringPositiveTests) { 6663 TEST(DestructuringPositiveTests) {
6569 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, 6664 const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
6570 {"var ", " = {};"}, 6665 {"var ", " = {};"},
6571 {"'use strict'; const ", " = {};"}, 6666 {"'use strict'; const ", " = {};"},
6572 {"function f(", ") {}"}, 6667 {"function f(", ") {}"},
6573 {"function f(argument1, ", ") {}"}, 6668 {"function f(argument1, ", ") {}"},
6574 {"var f = (", ") => {};"}, 6669 {"var f = (", ") => {};"},
6575 {"var f = (argument1,", ") => {};"}, 6670 {"var f = (argument1,", ") => {};"},
6576 {"try {} catch(", ") {}"}, 6671 {"try {} catch(", ") {}"},
(...skipping 2118 matching lines...) Expand 10 before | Expand all | Expand 10 after
8695 DCHECK_NOT_NULL(scope); 8790 DCHECK_NOT_NULL(scope);
8696 DCHECK_NULL(scope->sibling()); 8791 DCHECK_NULL(scope->sibling());
8697 DCHECK(scope->is_function_scope()); 8792 DCHECK(scope->is_function_scope());
8698 const i::AstRawString* var_name = 8793 const i::AstRawString* var_name =
8699 info.ast_value_factory()->GetOneByteString("my_var"); 8794 info.ast_value_factory()->GetOneByteString("my_var");
8700 i::Variable* var = scope->Lookup(var_name); 8795 i::Variable* var = scope->Lookup(var_name);
8701 CHECK_EQ(inners[i].ctxt_allocate, 8796 CHECK_EQ(inners[i].ctxt_allocate,
8702 i::ScopeTestHelper::MustAllocateInContext(var)); 8797 i::ScopeTestHelper::MustAllocateInContext(var));
8703 } 8798 }
8704 } 8799 }
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