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

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

Issue 807173002: ES6 computed property names (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years 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
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 1340 matching lines...) Expand 10 before | Expand all | Expand 10 after
1351 kAllowLazy, 1351 kAllowLazy,
1352 kAllowNatives, 1352 kAllowNatives,
1353 kAllowHarmonyScoping, 1353 kAllowHarmonyScoping,
1354 kAllowHarmonyModules, 1354 kAllowHarmonyModules,
1355 kAllowHarmonyNumericLiterals, 1355 kAllowHarmonyNumericLiterals,
1356 kAllowHarmonyArrowFunctions, 1356 kAllowHarmonyArrowFunctions,
1357 kAllowHarmonyClasses, 1357 kAllowHarmonyClasses,
1358 kAllowHarmonyObjectLiterals, 1358 kAllowHarmonyObjectLiterals,
1359 kAllowHarmonyTemplates, 1359 kAllowHarmonyTemplates,
1360 kAllowHarmonySloppy, 1360 kAllowHarmonySloppy,
1361 kAllowHarmonyUnicode 1361 kAllowHarmonyUnicode,
1362 kAllowHarmonyComputedPropertyNames
1362 }; 1363 };
1363 1364
1364 1365
1365 enum ParserSyncTestResult { 1366 enum ParserSyncTestResult {
1366 kSuccessOrError, 1367 kSuccessOrError,
1367 kSuccess, 1368 kSuccess,
1368 kError 1369 kError
1369 }; 1370 };
1370 1371
1371 template <typename Traits> 1372 template <typename Traits>
1372 void SetParserFlags(i::ParserBase<Traits>* parser, 1373 void SetParserFlags(i::ParserBase<Traits>* parser,
1373 i::EnumSet<ParserFlag> flags) { 1374 i::EnumSet<ParserFlag> flags) {
1374 parser->set_allow_lazy(flags.Contains(kAllowLazy)); 1375 parser->set_allow_lazy(flags.Contains(kAllowLazy));
1375 parser->set_allow_natives(flags.Contains(kAllowNatives)); 1376 parser->set_allow_natives(flags.Contains(kAllowNatives));
1376 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); 1377 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping));
1377 parser->set_allow_harmony_modules(flags.Contains(kAllowHarmonyModules)); 1378 parser->set_allow_harmony_modules(flags.Contains(kAllowHarmonyModules));
1378 parser->set_allow_harmony_numeric_literals( 1379 parser->set_allow_harmony_numeric_literals(
1379 flags.Contains(kAllowHarmonyNumericLiterals)); 1380 flags.Contains(kAllowHarmonyNumericLiterals));
1380 parser->set_allow_harmony_object_literals( 1381 parser->set_allow_harmony_object_literals(
1381 flags.Contains(kAllowHarmonyObjectLiterals)); 1382 flags.Contains(kAllowHarmonyObjectLiterals));
1382 parser->set_allow_harmony_arrow_functions( 1383 parser->set_allow_harmony_arrow_functions(
1383 flags.Contains(kAllowHarmonyArrowFunctions)); 1384 flags.Contains(kAllowHarmonyArrowFunctions));
1384 parser->set_allow_harmony_classes(flags.Contains(kAllowHarmonyClasses)); 1385 parser->set_allow_harmony_classes(flags.Contains(kAllowHarmonyClasses));
1385 parser->set_allow_harmony_templates(flags.Contains(kAllowHarmonyTemplates)); 1386 parser->set_allow_harmony_templates(flags.Contains(kAllowHarmonyTemplates));
1386 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); 1387 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy));
1387 parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode)); 1388 parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode));
1389 parser->set_allow_harmony_computed_property_names(
1390 flags.Contains(kAllowHarmonyComputedPropertyNames));
1388 } 1391 }
1389 1392
1390 1393
1391 void TestParserSyncWithFlags(i::Handle<i::String> source, 1394 void TestParserSyncWithFlags(i::Handle<i::String> source,
1392 i::EnumSet<ParserFlag> flags, 1395 i::EnumSet<ParserFlag> flags,
1393 ParserSyncTestResult result) { 1396 ParserSyncTestResult result) {
1394 i::Isolate* isolate = CcTest::i_isolate(); 1397 i::Isolate* isolate = CcTest::i_isolate();
1395 i::Factory* factory = isolate->factory(); 1398 i::Factory* factory = isolate->factory();
1396 1399
1397 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); 1400 uintptr_t stack_limit = isolate->stack_guard()->real_climit();
(...skipping 3177 matching lines...) Expand 10 before | Expand all | Expand 10 after
4575 always_false_flags, arraysize(always_false_flags)); 4578 always_false_flags, arraysize(always_false_flags));
4576 4579
4577 const char* good_data[] = { 4580 const char* good_data[] = {
4578 "let = 1;", 4581 "let = 1;",
4579 "for(let = 1;;){}", 4582 "for(let = 1;;){}",
4580 NULL}; 4583 NULL};
4581 RunParserSyncTest(context_data, good_data, kSuccess, NULL, 0, 4584 RunParserSyncTest(context_data, good_data, kSuccess, NULL, 0,
4582 always_true_flags, arraysize(always_true_flags), 4585 always_true_flags, arraysize(always_true_flags),
4583 always_false_flags, arraysize(always_false_flags)); 4586 always_false_flags, arraysize(always_false_flags));
4584 } 4587 }
4588
4589
4590 TEST(ComputedPropertyName) {
4591 const char* context_data[][2] = {{"({[", "]: 1});"},
4592 {"({get [", "]() {}});"},
4593 {"({set [", "](_) {}});"},
4594 {"({[", "]() {}});"},
4595 {"({*[", "]() {}});"},
4596 {"(class {get [", "]() {}});"},
4597 {"(class {set [", "](_) {}});"},
4598 {"(class {[", "]() {}});"},
4599 {"(class {*[", "]() {}});"},
4600 {NULL, NULL}};
4601 const char* error_data[] = {
4602 "1, 2",
4603 "var name",
4604 NULL};
4605
4606 static const ParserFlag always_flags[] = {
4607 kAllowHarmonyClasses,
4608 kAllowHarmonyComputedPropertyNames,
4609 kAllowHarmonyObjectLiterals,
4610 kAllowHarmonySloppy,
4611 };
4612 RunParserSyncTest(context_data, error_data, kError, NULL, 0,
4613 always_flags, arraysize(always_flags));
4614
4615 const char* name_data[] = {
4616 "1",
4617 "1 + 2",
4618 "'name'",
4619 "\"name\"",
4620 "[]",
4621 "{}",
4622 NULL};
4623
4624 RunParserSyncTest(context_data, name_data, kSuccess, NULL, 0,
4625 always_flags, arraysize(always_flags));
4626 }
4627
4628
4629 TEST(ComputedPropertyNameShorthandError) {
4630 const char* context_data[][2] = {{"({", "});"},
4631 {NULL, NULL}};
4632 const char* error_data[] = {
4633 "a: 1, [2]",
4634 "[1], a: 1",
4635 NULL};
4636
4637 static const ParserFlag always_flags[] = {
4638 kAllowHarmonyClasses,
4639 kAllowHarmonyComputedPropertyNames,
4640 kAllowHarmonyObjectLiterals,
4641 kAllowHarmonySloppy,
4642 };
4643 RunParserSyncTest(context_data, error_data, kError, NULL, 0,
4644 always_flags, arraysize(always_flags));
4645 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698