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

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

Issue 2665513002: [parser] Lift template literal invalid escape restriction (Closed)
Patch Set: rebase harder Created 3 years, 10 months 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 1268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 1279
1280 enum ParserFlag { 1280 enum ParserFlag {
1281 kAllowLazy, 1281 kAllowLazy,
1282 kAllowNatives, 1282 kAllowNatives,
1283 kAllowHarmonyFunctionSent, 1283 kAllowHarmonyFunctionSent,
1284 kAllowHarmonyRestrictiveGenerators, 1284 kAllowHarmonyRestrictiveGenerators,
1285 kAllowHarmonyTrailingCommas, 1285 kAllowHarmonyTrailingCommas,
1286 kAllowHarmonyClassFields, 1286 kAllowHarmonyClassFields,
1287 kAllowHarmonyObjectRestSpread, 1287 kAllowHarmonyObjectRestSpread,
1288 kAllowHarmonyDynamicImport, 1288 kAllowHarmonyDynamicImport,
1289 kAllowHarmonyTemplateEscapes,
1289 }; 1290 };
1290 1291
1291 enum ParserSyncTestResult { 1292 enum ParserSyncTestResult {
1292 kSuccessOrError, 1293 kSuccessOrError,
1293 kSuccess, 1294 kSuccess,
1294 kError 1295 kError
1295 }; 1296 };
1296 1297
1297 void SetGlobalFlags(i::EnumSet<ParserFlag> flags) { 1298 void SetGlobalFlags(i::EnumSet<ParserFlag> flags) {
1298 i::FLAG_allow_natives_syntax = flags.Contains(kAllowNatives); 1299 i::FLAG_allow_natives_syntax = flags.Contains(kAllowNatives);
1299 i::FLAG_harmony_function_sent = flags.Contains(kAllowHarmonyFunctionSent); 1300 i::FLAG_harmony_function_sent = flags.Contains(kAllowHarmonyFunctionSent);
1300 i::FLAG_harmony_restrictive_generators = 1301 i::FLAG_harmony_restrictive_generators =
1301 flags.Contains(kAllowHarmonyRestrictiveGenerators); 1302 flags.Contains(kAllowHarmonyRestrictiveGenerators);
1302 i::FLAG_harmony_trailing_commas = flags.Contains(kAllowHarmonyTrailingCommas); 1303 i::FLAG_harmony_trailing_commas = flags.Contains(kAllowHarmonyTrailingCommas);
1303 i::FLAG_harmony_class_fields = flags.Contains(kAllowHarmonyClassFields); 1304 i::FLAG_harmony_class_fields = flags.Contains(kAllowHarmonyClassFields);
1304 i::FLAG_harmony_object_rest_spread = 1305 i::FLAG_harmony_object_rest_spread =
1305 flags.Contains(kAllowHarmonyObjectRestSpread); 1306 flags.Contains(kAllowHarmonyObjectRestSpread);
1306 i::FLAG_harmony_dynamic_import = flags.Contains(kAllowHarmonyDynamicImport); 1307 i::FLAG_harmony_dynamic_import = flags.Contains(kAllowHarmonyDynamicImport);
1308 i::FLAG_harmony_template_escapes =
1309 flags.Contains(kAllowHarmonyTemplateEscapes);
1307 } 1310 }
1308 1311
1309 void SetParserFlags(i::PreParser* parser, i::EnumSet<ParserFlag> flags) { 1312 void SetParserFlags(i::PreParser* parser, i::EnumSet<ParserFlag> flags) {
1310 parser->set_allow_natives(flags.Contains(kAllowNatives)); 1313 parser->set_allow_natives(flags.Contains(kAllowNatives));
1311 parser->set_allow_harmony_function_sent( 1314 parser->set_allow_harmony_function_sent(
1312 flags.Contains(kAllowHarmonyFunctionSent)); 1315 flags.Contains(kAllowHarmonyFunctionSent));
1313 parser->set_allow_harmony_restrictive_generators( 1316 parser->set_allow_harmony_restrictive_generators(
1314 flags.Contains(kAllowHarmonyRestrictiveGenerators)); 1317 flags.Contains(kAllowHarmonyRestrictiveGenerators));
1315 parser->set_allow_harmony_trailing_commas( 1318 parser->set_allow_harmony_trailing_commas(
1316 flags.Contains(kAllowHarmonyTrailingCommas)); 1319 flags.Contains(kAllowHarmonyTrailingCommas));
1317 parser->set_allow_harmony_class_fields( 1320 parser->set_allow_harmony_class_fields(
1318 flags.Contains(kAllowHarmonyClassFields)); 1321 flags.Contains(kAllowHarmonyClassFields));
1319 parser->set_allow_harmony_object_rest_spread( 1322 parser->set_allow_harmony_object_rest_spread(
1320 flags.Contains(kAllowHarmonyObjectRestSpread)); 1323 flags.Contains(kAllowHarmonyObjectRestSpread));
1321 parser->set_allow_harmony_dynamic_import( 1324 parser->set_allow_harmony_dynamic_import(
1322 flags.Contains(kAllowHarmonyDynamicImport)); 1325 flags.Contains(kAllowHarmonyDynamicImport));
1326 parser->set_allow_harmony_template_escapes(
1327 flags.Contains(kAllowHarmonyTemplateEscapes));
1323 } 1328 }
1324 1329
1325 void TestParserSyncWithFlags(i::Handle<i::String> source, 1330 void TestParserSyncWithFlags(i::Handle<i::String> source,
1326 i::EnumSet<ParserFlag> flags, 1331 i::EnumSet<ParserFlag> flags,
1327 ParserSyncTestResult result, 1332 ParserSyncTestResult result,
1328 bool is_module = false, bool test_preparser = true, 1333 bool is_module = false, bool test_preparser = true,
1329 bool ignore_error_msg = false) { 1334 bool ignore_error_msg = false) {
1330 i::Isolate* isolate = CcTest::i_isolate(); 1335 i::Isolate* isolate = CcTest::i_isolate();
1331 i::Factory* factory = isolate->factory(); 1336 i::Factory* factory = isolate->factory();
1332 1337
(...skipping 5407 matching lines...) Expand 10 before | Expand all | Expand 10 after
6740 "{ ...y, b: 1}", 6745 "{ ...y, b: 1}",
6741 "{ ...1}", 6746 "{ ...1}",
6742 "{ ...null}", 6747 "{ ...null}",
6743 "{ ...undefined}", 6748 "{ ...undefined}",
6744 "{ ...1 in {}}", 6749 "{ ...1 in {}}",
6745 "{ ...[]}", 6750 "{ ...[]}",
6746 "{ ...async function() { }}", 6751 "{ ...async function() { }}",
6747 "{ ...async () => { }}", 6752 "{ ...async () => { }}",
6748 "{ ...new Foo()}", 6753 "{ ...new Foo()}",
6749 NULL}; 6754 NULL};
6755 // clang-format on
6750 6756
6751 static const ParserFlag flags[] = {kAllowHarmonyObjectRestSpread}; 6757 static const ParserFlag flags[] = {kAllowHarmonyObjectRestSpread};
6752 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, flags, 6758 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, flags,
6753 arraysize(flags)); 6759 arraysize(flags));
6754 } 6760 }
6755 6761
6756 TEST(ObjectSpreadNegativeTests) { 6762 TEST(ObjectSpreadNegativeTests) {
6757 const char* context_data[][2] = {{"x = ", ""}, 6763 const char* context_data[][2] = {{"x = ", ""},
6758 {"'use strict'; x = ", ""}, 6764 {"'use strict'; x = ", ""},
6759 {NULL, NULL}}; 6765 {NULL, NULL}};
6760 6766
6761 // clang-format off 6767 // clang-format off
6762 const char* data[] = { 6768 const char* data[] = {
6763 "{ ...var z = y}", 6769 "{ ...var z = y}",
6764 "{ ...var}", 6770 "{ ...var}",
6765 "{ ...foo bar}", 6771 "{ ...foo bar}",
6766 NULL}; 6772 NULL};
6767 6773
6768 static const ParserFlag flags[] = {kAllowHarmonyObjectRestSpread}; 6774 static const ParserFlag flags[] = {kAllowHarmonyObjectRestSpread};
6769 RunParserSyncTest(context_data, data, kError, NULL, 0, flags, 6775 RunParserSyncTest(context_data, data, kError, NULL, 0, flags,
6770 arraysize(flags)); 6776 arraysize(flags));
6771 } 6777 }
6772 6778
6779 TEST(TemplateEscapesPositiveTests) {
6780 // clang-format off
6781 const char* context_data[][2] = {
6782 {"", ""},
6783 {"'use strict';", ""},
6784 {NULL, NULL}};
6785
6786 // clang-format off
6787 const char* data[] = {
6788 "tag`\\01`",
6789 "tag`\\01${0}right`",
6790 "tag`left${0}\\01`",
6791 "tag`left${0}\\01${1}right`",
6792 "tag`\\1`",
6793 "tag`\\1${0}right`",
6794 "tag`left${0}\\1`",
6795 "tag`left${0}\\1${1}right`",
6796 "tag`\\xg`",
6797 "tag`\\xg${0}right`",
6798 "tag`left${0}\\xg`",
6799 "tag`left${0}\\xg${1}right`",
6800 "tag`\\xAg`",
6801 "tag`\\xAg${0}right`",
6802 "tag`left${0}\\xAg`",
6803 "tag`left${0}\\xAg${1}right`",
6804 "tag`\\u0`",
6805 "tag`\\u0${0}right`",
6806 "tag`left${0}\\u0`",
6807 "tag`left${0}\\u0${1}right`",
6808 "tag`\\u0g`",
6809 "tag`\\u0g${0}right`",
6810 "tag`left${0}\\u0g`",
6811 "tag`left${0}\\u0g${1}right`",
6812 "tag`\\u00g`",
6813 "tag`\\u00g${0}right`",
6814 "tag`left${0}\\u00g`",
6815 "tag`left${0}\\u00g${1}right`",
6816 "tag`\\u000g`",
6817 "tag`\\u000g${0}right`",
6818 "tag`left${0}\\u000g`",
6819 "tag`left${0}\\u000g${1}right`",
6820 "tag`\\u{}`",
6821 "tag`\\u{}${0}right`",
6822 "tag`left${0}\\u{}`",
6823 "tag`left${0}\\u{}${1}right`",
6824 "tag`\\u{-0}`",
6825 "tag`\\u{-0}${0}right`",
6826 "tag`left${0}\\u{-0}`",
6827 "tag`left${0}\\u{-0}${1}right`",
6828 "tag`\\u{g}`",
6829 "tag`\\u{g}${0}right`",
6830 "tag`left${0}\\u{g}`",
6831 "tag`left${0}\\u{g}${1}right`",
6832 "tag`\\u{0`",
6833 "tag`\\u{0${0}right`",
6834 "tag`left${0}\\u{0`",
6835 "tag`left${0}\\u{0${1}right`",
6836 "tag`\\u{\\u{0}`",
6837 "tag`\\u{\\u{0}${0}right`",
6838 "tag`left${0}\\u{\\u{0}`",
6839 "tag`left${0}\\u{\\u{0}${1}right`",
6840 "tag`\\u{110000}`",
6841 "tag`\\u{110000}${0}right`",
6842 "tag`left${0}\\u{110000}`",
6843 "tag`left${0}\\u{110000}${1}right`",
6844 NULL};
6845 // clang-format on
6846
6847 static const ParserFlag flags[] = {kAllowHarmonyTemplateEscapes};
6848 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, flags,
vogelheim 2017/02/13 17:36:06 If I read this correctly, this tests the behaviour
bakkot1 2017/02/13 20:22:24 I was figuring the existing tests would suffice fo
vogelheim 2017/02/17 16:33:53 Well, I was thinking more about also running the n
bakkot1 2017/02/17 20:42:18 Done.
6849 arraysize(flags));
6850 }
6851
6852 TEST(TemplateEscapesNegativeTests) {
6853 // clang-format off
6854 const char* context_data[][2] = {
6855 {"", ""},
6856 {"'use strict';", ""},
6857 {NULL, NULL}};
6858
6859 // clang-format off
6860 const char* data[] = {
6861 "`\\01`",
6862 "`\\01${0}right`",
6863 "`left${0}\\01`",
6864 "`left${0}\\01${1}right`",
6865 "`\\1`",
6866 "`\\1${0}right`",
6867 "`left${0}\\1`",
6868 "`left${0}\\1${1}right`",
6869 "`\\xg`",
6870 "`\\xg${0}right`",
6871 "`left${0}\\xg`",
6872 "`left${0}\\xg${1}right`",
6873 "`\\xAg`",
6874 "`\\xAg${0}right`",
6875 "`left${0}\\xAg`",
6876 "`left${0}\\xAg${1}right`",
6877 "`\\u0`",
6878 "`\\u0${0}right`",
6879 "`left${0}\\u0`",
6880 "`left${0}\\u0${1}right`",
6881 "`\\u0g`",
6882 "`\\u0g${0}right`",
6883 "`left${0}\\u0g`",
6884 "`left${0}\\u0g${1}right`",
6885 "`\\u00g`",
6886 "`\\u00g${0}right`",
6887 "`left${0}\\u00g`",
6888 "`left${0}\\u00g${1}right`",
6889 "`\\u000g`",
6890 "`\\u000g${0}right`",
6891 "`left${0}\\u000g`",
6892 "`left${0}\\u000g${1}right`",
6893 "`\\u{}`",
6894 "`\\u{}${0}right`",
6895 "`left${0}\\u{}`",
6896 "`left${0}\\u{}${1}right`",
6897 "`\\u{-0}`",
6898 "`\\u{-0}${0}right`",
6899 "`left${0}\\u{-0}`",
6900 "`left${0}\\u{-0}${1}right`",
6901 "`\\u{g}`",
6902 "`\\u{g}${0}right`",
6903 "`left${0}\\u{g}`",
6904 "`left${0}\\u{g}${1}right`",
6905 "`\\u{0`",
6906 "`\\u{0${0}right`",
6907 "`left${0}\\u{0`",
6908 "`left${0}\\u{0${1}right`",
6909 "`\\u{\\u{0}`",
6910 "`\\u{\\u{0}${0}right`",
6911 "`left${0}\\u{\\u{0}`",
6912 "`left${0}\\u{\\u{0}${1}right`",
6913 "`\\u{110000}`",
6914 "`\\u{110000}${0}right`",
6915 "`left${0}\\u{110000}`",
6916 "`left${0}\\u{110000}${1}right`",
6917 NULL};
6918 // clang-format on
6919
6920 static const ParserFlag flags[] = {kAllowHarmonyTemplateEscapes};
6921 RunParserSyncTest(context_data, data, kError, NULL, 0, flags,
6922 arraysize(flags));
6923 }
6924
6773 TEST(DestructuringPositiveTests) { 6925 TEST(DestructuringPositiveTests) {
6774 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, 6926 const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
6775 {"var ", " = {};"}, 6927 {"var ", " = {};"},
6776 {"'use strict'; const ", " = {};"}, 6928 {"'use strict'; const ", " = {};"},
6777 {"function f(", ") {}"}, 6929 {"function f(", ") {}"},
6778 {"function f(argument1, ", ") {}"}, 6930 {"function f(argument1, ", ") {}"},
6779 {"var f = (", ") => {};"}, 6931 {"var f = (", ") => {};"},
6780 {"var f = (argument1,", ") => {};"}, 6932 {"var f = (argument1,", ") => {};"},
6781 {"try {} catch(", ") {}"}, 6933 {"try {} catch(", ") {}"},
6782 {NULL, NULL}}; 6934 {NULL, NULL}};
(...skipping 2745 matching lines...) Expand 10 before | Expand all | Expand 10 after
9528 eager_info.literal()->scope()->inner_scope()->inner_scope(); 9680 eager_info.literal()->scope()->inner_scope()->inner_scope();
9529 DCHECK_NOT_NULL(scope); 9681 DCHECK_NOT_NULL(scope);
9530 DCHECK_NULL(scope->sibling()); 9682 DCHECK_NULL(scope->sibling());
9531 DCHECK(scope->is_function_scope()); 9683 DCHECK(scope->is_function_scope());
9532 9684
9533 size_t index = 0; 9685 size_t index = 0;
9534 i::ScopeTestHelper::CompareScopeToData( 9686 i::ScopeTestHelper::CompareScopeToData(
9535 scope, lazy_info.preparsed_scope_data(), index); 9687 scope, lazy_info.preparsed_scope_data(), index);
9536 } 9688 }
9537 } 9689 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698