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 1368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1379 kAllowHarmonyArrowFunctions, | 1379 kAllowHarmonyArrowFunctions, |
1380 kAllowHarmonyClasses, | 1380 kAllowHarmonyClasses, |
1381 kAllowHarmonyObjectLiterals, | 1381 kAllowHarmonyObjectLiterals, |
1382 kAllowHarmonyRestParameters, | 1382 kAllowHarmonyRestParameters, |
1383 kAllowHarmonySloppy, | 1383 kAllowHarmonySloppy, |
1384 kAllowHarmonyUnicode, | 1384 kAllowHarmonyUnicode, |
1385 kAllowHarmonyComputedPropertyNames, | 1385 kAllowHarmonyComputedPropertyNames, |
1386 kAllowHarmonySpreadCalls, | 1386 kAllowHarmonySpreadCalls, |
1387 kAllowHarmonyDestructuring, | 1387 kAllowHarmonyDestructuring, |
1388 kAllowHarmonySpreadArrays, | 1388 kAllowHarmonySpreadArrays, |
| 1389 kAllowHarmonyNewTarget, |
1389 kAllowStrongMode | 1390 kAllowStrongMode |
1390 }; | 1391 }; |
1391 | 1392 |
1392 | 1393 |
1393 enum ParserSyncTestResult { | 1394 enum ParserSyncTestResult { |
1394 kSuccessOrError, | 1395 kSuccessOrError, |
1395 kSuccess, | 1396 kSuccess, |
1396 kError | 1397 kError |
1397 }; | 1398 }; |
1398 | 1399 |
(...skipping 13 matching lines...) Expand all Loading... |
1412 parser->set_allow_harmony_spreadcalls( | 1413 parser->set_allow_harmony_spreadcalls( |
1413 flags.Contains(kAllowHarmonySpreadCalls)); | 1414 flags.Contains(kAllowHarmonySpreadCalls)); |
1414 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); | 1415 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); |
1415 parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode)); | 1416 parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode)); |
1416 parser->set_allow_harmony_computed_property_names( | 1417 parser->set_allow_harmony_computed_property_names( |
1417 flags.Contains(kAllowHarmonyComputedPropertyNames)); | 1418 flags.Contains(kAllowHarmonyComputedPropertyNames)); |
1418 parser->set_allow_harmony_destructuring( | 1419 parser->set_allow_harmony_destructuring( |
1419 flags.Contains(kAllowHarmonyDestructuring)); | 1420 flags.Contains(kAllowHarmonyDestructuring)); |
1420 parser->set_allow_harmony_spread_arrays( | 1421 parser->set_allow_harmony_spread_arrays( |
1421 flags.Contains(kAllowHarmonySpreadArrays)); | 1422 flags.Contains(kAllowHarmonySpreadArrays)); |
| 1423 parser->set_allow_harmony_new_target(flags.Contains(kAllowHarmonyNewTarget)); |
1422 parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode)); | 1424 parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode)); |
1423 } | 1425 } |
1424 | 1426 |
1425 | 1427 |
1426 void TestParserSyncWithFlags(i::Handle<i::String> source, | 1428 void TestParserSyncWithFlags(i::Handle<i::String> source, |
1427 i::EnumSet<ParserFlag> flags, | 1429 i::EnumSet<ParserFlag> flags, |
1428 ParserSyncTestResult result) { | 1430 ParserSyncTestResult result) { |
1429 i::Isolate* isolate = CcTest::i_isolate(); | 1431 i::Isolate* isolate = CcTest::i_isolate(); |
1430 i::Factory* factory = isolate->factory(); | 1432 i::Factory* factory = isolate->factory(); |
1431 | 1433 |
(...skipping 5176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6608 "[a, ...]", | 6610 "[a, ...]", |
6609 "[..., ]", | 6611 "[..., ]", |
6610 "[..., ...]", | 6612 "[..., ...]", |
6611 "[ (...a)]", | 6613 "[ (...a)]", |
6612 NULL}; | 6614 NULL}; |
6613 // clang-format on | 6615 // clang-format on |
6614 static const ParserFlag always_flags[] = {kAllowHarmonySpreadArrays}; | 6616 static const ParserFlag always_flags[] = {kAllowHarmonySpreadArrays}; |
6615 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | 6617 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
6616 arraysize(always_flags)); | 6618 arraysize(always_flags)); |
6617 } | 6619 } |
| 6620 |
| 6621 |
| 6622 TEST(NewTarget) { |
| 6623 // clang-format off |
| 6624 const char* good_context_data[][2] = { |
| 6625 {"function f() {", "}"}, |
| 6626 {"'use strict'; function f() {", "}"}, |
| 6627 {"var f = function() {", "}"}, |
| 6628 {"'use strict'; var f = function() {", "}"}, |
| 6629 {"({m: function() {", "}})"}, |
| 6630 {"'use strict'; ({m: function() {", "}})"}, |
| 6631 {"({m() {", "}})"}, |
| 6632 {"'use strict'; ({m() {", "}})"}, |
| 6633 {"({get x() {", "}})"}, |
| 6634 {"'use strict'; ({get x() {", "}})"}, |
| 6635 {"({set x(_) {", "}})"}, |
| 6636 {"'use strict'; ({set x(_) {", "}})"}, |
| 6637 {"class C {m() {", "}}"}, |
| 6638 {"class C {get x() {", "}}"}, |
| 6639 {"class C {set x(_) {", "}}"}, |
| 6640 {NULL} |
| 6641 }; |
| 6642 |
| 6643 const char* bad_context_data[][2] = { |
| 6644 {"", ""}, |
| 6645 {"'use strict';", ""}, |
| 6646 {NULL} |
| 6647 }; |
| 6648 |
| 6649 const char* data[] = { |
| 6650 "new.target", |
| 6651 "{ new.target }", |
| 6652 "() => { new.target }", |
| 6653 "() => new.target", |
| 6654 "if (1) { new.target }", |
| 6655 "if (1) {} else { new.target }", |
| 6656 "while (0) { new.target }", |
| 6657 "do { new.target } while (0)", |
| 6658 NULL |
| 6659 }; |
| 6660 |
| 6661 static const ParserFlag always_flags[] = { |
| 6662 kAllowHarmonyArrowFunctions, |
| 6663 kAllowHarmonyClasses, |
| 6664 kAllowHarmonyNewTarget, |
| 6665 kAllowHarmonyObjectLiterals, |
| 6666 kAllowHarmonySloppy, |
| 6667 }; |
| 6668 // clang-format on |
| 6669 |
| 6670 RunParserSyncTest(good_context_data, data, kSuccess, NULL, 0, always_flags, |
| 6671 arraysize(always_flags)); |
| 6672 RunParserSyncTest(bad_context_data, data, kError, NULL, 0, always_flags, |
| 6673 arraysize(always_flags)); |
| 6674 } |
OLD | NEW |