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

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

Issue 795573005: ES6 computed property names (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: moar cleanup 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 3133 matching lines...) Expand 10 before | Expand all | Expand 10 after
4531 always_false_flags, arraysize(always_false_flags)); 4534 always_false_flags, arraysize(always_false_flags));
4532 4535
4533 const char* good_data[] = { 4536 const char* good_data[] = {
4534 "let = 1;", 4537 "let = 1;",
4535 "for(let = 1;;){}", 4538 "for(let = 1;;){}",
4536 NULL}; 4539 NULL};
4537 RunParserSyncTest(context_data, good_data, kSuccess, NULL, 0, 4540 RunParserSyncTest(context_data, good_data, kSuccess, NULL, 0,
4538 always_true_flags, arraysize(always_true_flags), 4541 always_true_flags, arraysize(always_true_flags),
4539 always_false_flags, arraysize(always_false_flags)); 4542 always_false_flags, arraysize(always_false_flags));
4540 } 4543 }
4544
4545
4546 TEST(ComputedPropertyName) {
4547 const char* context_data[][2] = {{"({[", "]: 1});"},
4548 {"({get [", "]() {}});"},
4549 {"({set [", "](_) {}});"},
4550 {"({[", "]() {}});"},
4551 {"({*[", "]() {}});"},
4552 {"(class {get [", "]() {}});"},
4553 {"(class {set [", "](_) {}});"},
4554 {"(class {[", "]() {}});"},
4555 {"(class {*[", "]() {}});"},
4556 {NULL, NULL}};
4557 const char* error_data[] = {
4558 "1, 2",
4559 "var name",
4560 NULL};
4561
4562 static const ParserFlag always_flags[] = {
4563 kAllowHarmonyClasses,
4564 kAllowHarmonyComputedPropertyNames,
4565 kAllowHarmonyObjectLiterals,
4566 kAllowHarmonySloppy,
4567 };
4568 RunParserSyncTest(context_data, error_data, kError, NULL, 0,
4569 always_flags, arraysize(always_flags));
4570
4571 const char* name_data[] = {
4572 "1",
4573 "1 + 2",
4574 "'name'",
4575 "\"name\"",
4576 "[]",
4577 "{}",
4578 NULL};
4579
4580 RunParserSyncTest(context_data, name_data, kSuccess, NULL, 0,
4581 always_flags, arraysize(always_flags));
4582 }
4583
4584
4585 TEST(ComputedPropertyNameShorthandError) {
4586 const char* context_data[][2] = {{"({", "});"},
4587 {NULL, NULL}};
4588 const char* error_data[] = {
4589 "a: 1, [2]",
4590 "[1], a: 1",
4591 NULL};
4592
4593 static const ParserFlag always_flags[] = {
4594 kAllowHarmonyClasses,
4595 kAllowHarmonyComputedPropertyNames,
4596 kAllowHarmonyObjectLiterals,
4597 kAllowHarmonySloppy,
4598 };
4599 RunParserSyncTest(context_data, error_data, kError, NULL, 0,
4600 always_flags, arraysize(always_flags));
4601 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698