| 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 1411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1422 } | 1422 } |
| 1423 | 1423 |
| 1424 | 1424 |
| 1425 enum ParserFlag { | 1425 enum ParserFlag { |
| 1426 kAllowLazy, | 1426 kAllowLazy, |
| 1427 kAllowNatives, | 1427 kAllowNatives, |
| 1428 kAllowHarmonyArrowFunctions, | 1428 kAllowHarmonyArrowFunctions, |
| 1429 kAllowHarmonyRestParameters, | 1429 kAllowHarmonyRestParameters, |
| 1430 kAllowHarmonySloppy, | 1430 kAllowHarmonySloppy, |
| 1431 kAllowHarmonySloppyLet, | 1431 kAllowHarmonySloppyLet, |
| 1432 kAllowHarmonyUnicode, | |
| 1433 kAllowHarmonyComputedPropertyNames, | 1432 kAllowHarmonyComputedPropertyNames, |
| 1434 kAllowHarmonySpreadCalls, | 1433 kAllowHarmonySpreadCalls, |
| 1435 kAllowHarmonyDestructuring, | 1434 kAllowHarmonyDestructuring, |
| 1436 kAllowHarmonySpreadArrays, | 1435 kAllowHarmonySpreadArrays, |
| 1437 kAllowHarmonyNewTarget, | 1436 kAllowHarmonyNewTarget, |
| 1438 kAllowStrongMode, | 1437 kAllowStrongMode, |
| 1439 kNoLegacyConst | 1438 kNoLegacyConst |
| 1440 }; | 1439 }; |
| 1441 | 1440 |
| 1442 | 1441 |
| 1443 enum ParserSyncTestResult { | 1442 enum ParserSyncTestResult { |
| 1444 kSuccessOrError, | 1443 kSuccessOrError, |
| 1445 kSuccess, | 1444 kSuccess, |
| 1446 kError | 1445 kError |
| 1447 }; | 1446 }; |
| 1448 | 1447 |
| 1449 template <typename Traits> | 1448 template <typename Traits> |
| 1450 void SetParserFlags(i::ParserBase<Traits>* parser, | 1449 void SetParserFlags(i::ParserBase<Traits>* parser, |
| 1451 i::EnumSet<ParserFlag> flags) { | 1450 i::EnumSet<ParserFlag> flags) { |
| 1452 parser->set_allow_lazy(flags.Contains(kAllowLazy)); | 1451 parser->set_allow_lazy(flags.Contains(kAllowLazy)); |
| 1453 parser->set_allow_natives(flags.Contains(kAllowNatives)); | 1452 parser->set_allow_natives(flags.Contains(kAllowNatives)); |
| 1454 parser->set_allow_harmony_arrow_functions( | 1453 parser->set_allow_harmony_arrow_functions( |
| 1455 flags.Contains(kAllowHarmonyArrowFunctions)); | 1454 flags.Contains(kAllowHarmonyArrowFunctions)); |
| 1456 parser->set_allow_harmony_rest_parameters( | 1455 parser->set_allow_harmony_rest_parameters( |
| 1457 flags.Contains(kAllowHarmonyRestParameters)); | 1456 flags.Contains(kAllowHarmonyRestParameters)); |
| 1458 parser->set_allow_harmony_spreadcalls( | 1457 parser->set_allow_harmony_spreadcalls( |
| 1459 flags.Contains(kAllowHarmonySpreadCalls)); | 1458 flags.Contains(kAllowHarmonySpreadCalls)); |
| 1460 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); | 1459 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); |
| 1461 parser->set_allow_harmony_sloppy_let(flags.Contains(kAllowHarmonySloppyLet)); | 1460 parser->set_allow_harmony_sloppy_let(flags.Contains(kAllowHarmonySloppyLet)); |
| 1462 parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode)); | |
| 1463 parser->set_allow_harmony_computed_property_names( | 1461 parser->set_allow_harmony_computed_property_names( |
| 1464 flags.Contains(kAllowHarmonyComputedPropertyNames)); | 1462 flags.Contains(kAllowHarmonyComputedPropertyNames)); |
| 1465 parser->set_allow_harmony_destructuring( | 1463 parser->set_allow_harmony_destructuring( |
| 1466 flags.Contains(kAllowHarmonyDestructuring)); | 1464 flags.Contains(kAllowHarmonyDestructuring)); |
| 1467 parser->set_allow_harmony_spread_arrays( | 1465 parser->set_allow_harmony_spread_arrays( |
| 1468 flags.Contains(kAllowHarmonySpreadArrays)); | 1466 flags.Contains(kAllowHarmonySpreadArrays)); |
| 1469 parser->set_allow_harmony_new_target(flags.Contains(kAllowHarmonyNewTarget)); | 1467 parser->set_allow_harmony_new_target(flags.Contains(kAllowHarmonyNewTarget)); |
| 1470 parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode)); | 1468 parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode)); |
| 1471 parser->set_allow_legacy_const(!flags.Contains(kNoLegacyConst)); | 1469 parser->set_allow_legacy_const(!flags.Contains(kNoLegacyConst)); |
| 1472 } | 1470 } |
| (...skipping 3381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4854 "\"foob\\u{c481r\"", | 4852 "\"foob\\u{c481r\"", |
| 4855 "var foob\\u{}ar = 0;", | 4853 "var foob\\u{}ar = 0;", |
| 4856 // Too high value for the unicode escape | 4854 // Too high value for the unicode escape |
| 4857 "\"\\u{110000}\"", | 4855 "\"\\u{110000}\"", |
| 4858 // Not an unicode escape | 4856 // Not an unicode escape |
| 4859 "var foob\\v1234r = 0;", | 4857 "var foob\\v1234r = 0;", |
| 4860 "var foob\\U1234r = 0;", | 4858 "var foob\\U1234r = 0;", |
| 4861 "var foob\\v{1234}r = 0;", | 4859 "var foob\\v{1234}r = 0;", |
| 4862 "var foob\\U{1234}r = 0;", | 4860 "var foob\\U{1234}r = 0;", |
| 4863 NULL}; | 4861 NULL}; |
| 4864 static const ParserFlag always_flags[] = {kAllowHarmonyUnicode}; | 4862 RunParserSyncTest(context_data, data, kError); |
| 4865 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | |
| 4866 arraysize(always_flags)); | |
| 4867 } | 4863 } |
| 4868 | 4864 |
| 4869 | 4865 |
| 4870 TEST(UnicodeEscapes) { | 4866 TEST(UnicodeEscapes) { |
| 4871 const char* context_data[][2] = {{"", ""}, | 4867 const char* context_data[][2] = {{"", ""}, |
| 4872 {"'use strict';", ""}, | 4868 {"'use strict';", ""}, |
| 4873 {NULL, NULL}}; | 4869 {NULL, NULL}}; |
| 4874 const char* data[] = { | 4870 const char* data[] = { |
| 4875 // Identifier starting with escape | 4871 // Identifier starting with escape |
| 4876 "var \\u0052oo = 0;", | 4872 "var \\u0052oo = 0;", |
| 4877 "var \\u{0052}oo = 0;", | 4873 "var \\u{0052}oo = 0;", |
| 4878 "var \\u{52}oo = 0;", | 4874 "var \\u{52}oo = 0;", |
| 4879 "var \\u{00000000052}oo = 0;", | 4875 "var \\u{00000000052}oo = 0;", |
| 4880 // Identifier with an escape but not starting with an escape | 4876 // Identifier with an escape but not starting with an escape |
| 4881 "var foob\\uc481r = 0;", | 4877 "var foob\\uc481r = 0;", |
| 4882 "var foob\\u{c481}r = 0;", | 4878 "var foob\\u{c481}r = 0;", |
| 4883 // String with an escape | 4879 // String with an escape |
| 4884 "\"foob\\uc481r\"", | 4880 "\"foob\\uc481r\"", |
| 4885 "\"foob\\{uc481}r\"", | 4881 "\"foob\\{uc481}r\"", |
| 4886 // This character is a valid unicode character, representable as a surrogate | 4882 // This character is a valid unicode character, representable as a surrogate |
| 4887 // pair, not representable as 4 hex digits. | 4883 // pair, not representable as 4 hex digits. |
| 4888 "\"foo\\u{10e6d}\"", | 4884 "\"foo\\u{10e6d}\"", |
| 4889 // Max value for the unicode escape | 4885 // Max value for the unicode escape |
| 4890 "\"\\u{10ffff}\"", | 4886 "\"\\u{10ffff}\"", |
| 4891 NULL}; | 4887 NULL}; |
| 4892 static const ParserFlag always_flags[] = {kAllowHarmonyUnicode}; | 4888 RunParserSyncTest(context_data, data, kSuccess); |
| 4893 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, | |
| 4894 arraysize(always_flags)); | |
| 4895 } | 4889 } |
| 4896 | 4890 |
| 4897 | 4891 |
| 4898 TEST(ScanTemplateLiterals) { | 4892 TEST(ScanTemplateLiterals) { |
| 4899 const char* context_data[][2] = {{"'use strict';", ""}, | 4893 const char* context_data[][2] = {{"'use strict';", ""}, |
| 4900 {"function foo(){ 'use strict';" | 4894 {"function foo(){ 'use strict';" |
| 4901 " var a, b, c; return ", "}"}, | 4895 " var a, b, c; return ", "}"}, |
| 4902 {NULL, NULL}}; | 4896 {NULL, NULL}}; |
| 4903 | 4897 |
| 4904 const char* data[] = { | 4898 const char* data[] = { |
| (...skipping 1932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6837 "for (let x of []) {}", | 6831 "for (let x of []) {}", |
| 6838 NULL | 6832 NULL |
| 6839 }; | 6833 }; |
| 6840 // clang-format on | 6834 // clang-format on |
| 6841 | 6835 |
| 6842 static const ParserFlag always_flags[] = {kAllowHarmonySloppy, | 6836 static const ParserFlag always_flags[] = {kAllowHarmonySloppy, |
| 6843 kAllowHarmonySloppyLet}; | 6837 kAllowHarmonySloppyLet}; |
| 6844 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, | 6838 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, |
| 6845 arraysize(always_flags)); | 6839 arraysize(always_flags)); |
| 6846 } | 6840 } |
| OLD | NEW |