OLD | NEW |
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 Loading... |
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 | |
1363 }; | 1362 }; |
1364 | 1363 |
1365 | 1364 |
1366 enum ParserSyncTestResult { | 1365 enum ParserSyncTestResult { |
1367 kSuccessOrError, | 1366 kSuccessOrError, |
1368 kSuccess, | 1367 kSuccess, |
1369 kError | 1368 kError |
1370 }; | 1369 }; |
1371 | 1370 |
1372 template <typename Traits> | 1371 template <typename Traits> |
1373 void SetParserFlags(i::ParserBase<Traits>* parser, | 1372 void SetParserFlags(i::ParserBase<Traits>* parser, |
1374 i::EnumSet<ParserFlag> flags) { | 1373 i::EnumSet<ParserFlag> flags) { |
1375 parser->set_allow_lazy(flags.Contains(kAllowLazy)); | 1374 parser->set_allow_lazy(flags.Contains(kAllowLazy)); |
1376 parser->set_allow_natives(flags.Contains(kAllowNatives)); | 1375 parser->set_allow_natives(flags.Contains(kAllowNatives)); |
1377 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); | 1376 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); |
1378 parser->set_allow_harmony_modules(flags.Contains(kAllowHarmonyModules)); | 1377 parser->set_allow_harmony_modules(flags.Contains(kAllowHarmonyModules)); |
1379 parser->set_allow_harmony_numeric_literals( | 1378 parser->set_allow_harmony_numeric_literals( |
1380 flags.Contains(kAllowHarmonyNumericLiterals)); | 1379 flags.Contains(kAllowHarmonyNumericLiterals)); |
1381 parser->set_allow_harmony_object_literals( | 1380 parser->set_allow_harmony_object_literals( |
1382 flags.Contains(kAllowHarmonyObjectLiterals)); | 1381 flags.Contains(kAllowHarmonyObjectLiterals)); |
1383 parser->set_allow_harmony_arrow_functions( | 1382 parser->set_allow_harmony_arrow_functions( |
1384 flags.Contains(kAllowHarmonyArrowFunctions)); | 1383 flags.Contains(kAllowHarmonyArrowFunctions)); |
1385 parser->set_allow_harmony_classes(flags.Contains(kAllowHarmonyClasses)); | 1384 parser->set_allow_harmony_classes(flags.Contains(kAllowHarmonyClasses)); |
1386 parser->set_allow_harmony_templates(flags.Contains(kAllowHarmonyTemplates)); | 1385 parser->set_allow_harmony_templates(flags.Contains(kAllowHarmonyTemplates)); |
1387 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); | 1386 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); |
1388 parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode)); | 1387 parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode)); |
1389 parser->set_allow_harmony_computed_property_names( | |
1390 flags.Contains(kAllowHarmonyComputedPropertyNames)); | |
1391 } | 1388 } |
1392 | 1389 |
1393 | 1390 |
1394 void TestParserSyncWithFlags(i::Handle<i::String> source, | 1391 void TestParserSyncWithFlags(i::Handle<i::String> source, |
1395 i::EnumSet<ParserFlag> flags, | 1392 i::EnumSet<ParserFlag> flags, |
1396 ParserSyncTestResult result) { | 1393 ParserSyncTestResult result) { |
1397 i::Isolate* isolate = CcTest::i_isolate(); | 1394 i::Isolate* isolate = CcTest::i_isolate(); |
1398 i::Factory* factory = isolate->factory(); | 1395 i::Factory* factory = isolate->factory(); |
1399 | 1396 |
1400 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); | 1397 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); |
(...skipping 3177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4578 always_false_flags, arraysize(always_false_flags)); | 4575 always_false_flags, arraysize(always_false_flags)); |
4579 | 4576 |
4580 const char* good_data[] = { | 4577 const char* good_data[] = { |
4581 "let = 1;", | 4578 "let = 1;", |
4582 "for(let = 1;;){}", | 4579 "for(let = 1;;){}", |
4583 NULL}; | 4580 NULL}; |
4584 RunParserSyncTest(context_data, good_data, kSuccess, NULL, 0, | 4581 RunParserSyncTest(context_data, good_data, kSuccess, NULL, 0, |
4585 always_true_flags, arraysize(always_true_flags), | 4582 always_true_flags, arraysize(always_true_flags), |
4586 always_false_flags, arraysize(always_false_flags)); | 4583 always_false_flags, arraysize(always_false_flags)); |
4587 } | 4584 } |
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 } | |
OLD | NEW |