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

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

Issue 2665513002: [parser] Lift template literal invalid escape restriction (Closed)
Patch Set: reintroduce DCHECK_EQ 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
« no previous file with comments | « src/parsing/scanner.cc ('k') | test/mjsunit/compiler/literals.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 enum ParserFlag { 1256 enum ParserFlag {
1257 kAllowLazy, 1257 kAllowLazy,
1258 kAllowNatives, 1258 kAllowNatives,
1259 kAllowHarmonyFunctionSent, 1259 kAllowHarmonyFunctionSent,
1260 kAllowHarmonyRestrictiveGenerators, 1260 kAllowHarmonyRestrictiveGenerators,
1261 kAllowHarmonyTrailingCommas, 1261 kAllowHarmonyTrailingCommas,
1262 kAllowHarmonyClassFields, 1262 kAllowHarmonyClassFields,
1263 kAllowHarmonyObjectRestSpread, 1263 kAllowHarmonyObjectRestSpread,
1264 kAllowHarmonyDynamicImport, 1264 kAllowHarmonyDynamicImport,
1265 kAllowHarmonyAsyncIteration, 1265 kAllowHarmonyAsyncIteration,
1266 kAllowHarmonyTemplateEscapes,
1266 }; 1267 };
1267 1268
1268 enum ParserSyncTestResult { 1269 enum ParserSyncTestResult {
1269 kSuccessOrError, 1270 kSuccessOrError,
1270 kSuccess, 1271 kSuccess,
1271 kError 1272 kError
1272 }; 1273 };
1273 1274
1274 void SetGlobalFlags(i::EnumSet<ParserFlag> flags) { 1275 void SetGlobalFlags(i::EnumSet<ParserFlag> flags) {
1275 i::FLAG_allow_natives_syntax = flags.Contains(kAllowNatives); 1276 i::FLAG_allow_natives_syntax = flags.Contains(kAllowNatives);
1276 i::FLAG_harmony_function_sent = flags.Contains(kAllowHarmonyFunctionSent); 1277 i::FLAG_harmony_function_sent = flags.Contains(kAllowHarmonyFunctionSent);
1277 i::FLAG_harmony_restrictive_generators = 1278 i::FLAG_harmony_restrictive_generators =
1278 flags.Contains(kAllowHarmonyRestrictiveGenerators); 1279 flags.Contains(kAllowHarmonyRestrictiveGenerators);
1279 i::FLAG_harmony_trailing_commas = flags.Contains(kAllowHarmonyTrailingCommas); 1280 i::FLAG_harmony_trailing_commas = flags.Contains(kAllowHarmonyTrailingCommas);
1280 i::FLAG_harmony_class_fields = flags.Contains(kAllowHarmonyClassFields); 1281 i::FLAG_harmony_class_fields = flags.Contains(kAllowHarmonyClassFields);
1281 i::FLAG_harmony_object_rest_spread = 1282 i::FLAG_harmony_object_rest_spread =
1282 flags.Contains(kAllowHarmonyObjectRestSpread); 1283 flags.Contains(kAllowHarmonyObjectRestSpread);
1283 i::FLAG_harmony_dynamic_import = flags.Contains(kAllowHarmonyDynamicImport); 1284 i::FLAG_harmony_dynamic_import = flags.Contains(kAllowHarmonyDynamicImport);
1284 i::FLAG_harmony_async_iteration = flags.Contains(kAllowHarmonyAsyncIteration); 1285 i::FLAG_harmony_async_iteration = flags.Contains(kAllowHarmonyAsyncIteration);
1286 i::FLAG_harmony_template_escapes =
1287 flags.Contains(kAllowHarmonyTemplateEscapes);
1285 } 1288 }
1286 1289
1287 void SetParserFlags(i::PreParser* parser, i::EnumSet<ParserFlag> flags) { 1290 void SetParserFlags(i::PreParser* parser, i::EnumSet<ParserFlag> flags) {
1288 parser->set_allow_natives(flags.Contains(kAllowNatives)); 1291 parser->set_allow_natives(flags.Contains(kAllowNatives));
1289 parser->set_allow_harmony_function_sent( 1292 parser->set_allow_harmony_function_sent(
1290 flags.Contains(kAllowHarmonyFunctionSent)); 1293 flags.Contains(kAllowHarmonyFunctionSent));
1291 parser->set_allow_harmony_restrictive_generators( 1294 parser->set_allow_harmony_restrictive_generators(
1292 flags.Contains(kAllowHarmonyRestrictiveGenerators)); 1295 flags.Contains(kAllowHarmonyRestrictiveGenerators));
1293 parser->set_allow_harmony_trailing_commas( 1296 parser->set_allow_harmony_trailing_commas(
1294 flags.Contains(kAllowHarmonyTrailingCommas)); 1297 flags.Contains(kAllowHarmonyTrailingCommas));
1295 parser->set_allow_harmony_class_fields( 1298 parser->set_allow_harmony_class_fields(
1296 flags.Contains(kAllowHarmonyClassFields)); 1299 flags.Contains(kAllowHarmonyClassFields));
1297 parser->set_allow_harmony_object_rest_spread( 1300 parser->set_allow_harmony_object_rest_spread(
1298 flags.Contains(kAllowHarmonyObjectRestSpread)); 1301 flags.Contains(kAllowHarmonyObjectRestSpread));
1299 parser->set_allow_harmony_dynamic_import( 1302 parser->set_allow_harmony_dynamic_import(
1300 flags.Contains(kAllowHarmonyDynamicImport)); 1303 flags.Contains(kAllowHarmonyDynamicImport));
1301 parser->set_allow_harmony_async_iteration( 1304 parser->set_allow_harmony_async_iteration(
1302 flags.Contains(kAllowHarmonyAsyncIteration)); 1305 flags.Contains(kAllowHarmonyAsyncIteration));
1306 parser->set_allow_harmony_template_escapes(
1307 flags.Contains(kAllowHarmonyTemplateEscapes));
1303 } 1308 }
1304 1309
1305 void TestParserSyncWithFlags(i::Handle<i::String> source, 1310 void TestParserSyncWithFlags(i::Handle<i::String> source,
1306 i::EnumSet<ParserFlag> flags, 1311 i::EnumSet<ParserFlag> flags,
1307 ParserSyncTestResult result, 1312 ParserSyncTestResult result,
1308 bool is_module = false, bool test_preparser = true, 1313 bool is_module = false, bool test_preparser = true,
1309 bool ignore_error_msg = false) { 1314 bool ignore_error_msg = false) {
1310 i::Isolate* isolate = CcTest::i_isolate(); 1315 i::Isolate* isolate = CcTest::i_isolate();
1311 i::Factory* factory = isolate->factory(); 1316 i::Factory* factory = isolate->factory();
1312 1317
(...skipping 5747 matching lines...) Expand 10 before | Expand all | Expand 10 after
7060 "{ ...y, b: 1}", 7065 "{ ...y, b: 1}",
7061 "{ ...1}", 7066 "{ ...1}",
7062 "{ ...null}", 7067 "{ ...null}",
7063 "{ ...undefined}", 7068 "{ ...undefined}",
7064 "{ ...1 in {}}", 7069 "{ ...1 in {}}",
7065 "{ ...[]}", 7070 "{ ...[]}",
7066 "{ ...async function() { }}", 7071 "{ ...async function() { }}",
7067 "{ ...async () => { }}", 7072 "{ ...async () => { }}",
7068 "{ ...new Foo()}", 7073 "{ ...new Foo()}",
7069 NULL}; 7074 NULL};
7075 // clang-format on
7070 7076
7071 static const ParserFlag flags[] = {kAllowHarmonyObjectRestSpread}; 7077 static const ParserFlag flags[] = {kAllowHarmonyObjectRestSpread};
7072 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, flags, 7078 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, flags,
7073 arraysize(flags)); 7079 arraysize(flags));
7074 } 7080 }
7075 7081
7076 TEST(ObjectSpreadNegativeTests) { 7082 TEST(ObjectSpreadNegativeTests) {
7077 const char* context_data[][2] = {{"x = ", ""}, 7083 const char* context_data[][2] = {{"x = ", ""},
7078 {"'use strict'; x = ", ""}, 7084 {"'use strict'; x = ", ""},
7079 {NULL, NULL}}; 7085 {NULL, NULL}};
7080 7086
7081 // clang-format off 7087 // clang-format off
7082 const char* data[] = { 7088 const char* data[] = {
7083 "{ ...var z = y}", 7089 "{ ...var z = y}",
7084 "{ ...var}", 7090 "{ ...var}",
7085 "{ ...foo bar}", 7091 "{ ...foo bar}",
7086 NULL}; 7092 NULL};
7087 7093
7088 static const ParserFlag flags[] = {kAllowHarmonyObjectRestSpread}; 7094 static const ParserFlag flags[] = {kAllowHarmonyObjectRestSpread};
7089 RunParserSyncTest(context_data, data, kError, NULL, 0, flags, 7095 RunParserSyncTest(context_data, data, kError, NULL, 0, flags,
7090 arraysize(flags)); 7096 arraysize(flags));
7091 } 7097 }
7092 7098
7099 TEST(TemplateEscapesPositiveTests) {
7100 // clang-format off
7101 const char* context_data[][2] = {
7102 {"", ""},
7103 {"'use strict';", ""},
7104 {NULL, NULL}};
7105
7106 // clang-format off
7107 const char* data[] = {
7108 "tag`\\01`",
7109 "tag`\\01${0}right`",
7110 "tag`left${0}\\01`",
7111 "tag`left${0}\\01${1}right`",
7112 "tag`\\1`",
7113 "tag`\\1${0}right`",
7114 "tag`left${0}\\1`",
7115 "tag`left${0}\\1${1}right`",
7116 "tag`\\xg`",
7117 "tag`\\xg${0}right`",
7118 "tag`left${0}\\xg`",
7119 "tag`left${0}\\xg${1}right`",
7120 "tag`\\xAg`",
7121 "tag`\\xAg${0}right`",
7122 "tag`left${0}\\xAg`",
7123 "tag`left${0}\\xAg${1}right`",
7124 "tag`\\u0`",
7125 "tag`\\u0${0}right`",
7126 "tag`left${0}\\u0`",
7127 "tag`left${0}\\u0${1}right`",
7128 "tag`\\u0g`",
7129 "tag`\\u0g${0}right`",
7130 "tag`left${0}\\u0g`",
7131 "tag`left${0}\\u0g${1}right`",
7132 "tag`\\u00g`",
7133 "tag`\\u00g${0}right`",
7134 "tag`left${0}\\u00g`",
7135 "tag`left${0}\\u00g${1}right`",
7136 "tag`\\u000g`",
7137 "tag`\\u000g${0}right`",
7138 "tag`left${0}\\u000g`",
7139 "tag`left${0}\\u000g${1}right`",
7140 "tag`\\u{}`",
7141 "tag`\\u{}${0}right`",
7142 "tag`left${0}\\u{}`",
7143 "tag`left${0}\\u{}${1}right`",
7144 "tag`\\u{-0}`",
7145 "tag`\\u{-0}${0}right`",
7146 "tag`left${0}\\u{-0}`",
7147 "tag`left${0}\\u{-0}${1}right`",
7148 "tag`\\u{g}`",
7149 "tag`\\u{g}${0}right`",
7150 "tag`left${0}\\u{g}`",
7151 "tag`left${0}\\u{g}${1}right`",
7152 "tag`\\u{0`",
7153 "tag`\\u{0${0}right`",
7154 "tag`left${0}\\u{0`",
7155 "tag`left${0}\\u{0${1}right`",
7156 "tag`\\u{\\u{0}`",
7157 "tag`\\u{\\u{0}${0}right`",
7158 "tag`left${0}\\u{\\u{0}`",
7159 "tag`left${0}\\u{\\u{0}${1}right`",
7160 "tag`\\u{110000}`",
7161 "tag`\\u{110000}${0}right`",
7162 "tag`left${0}\\u{110000}`",
7163 "tag`left${0}\\u{110000}${1}right`",
7164 NULL};
7165 // clang-format on
7166
7167 // No error with flag
7168 static const ParserFlag flags[] = {kAllowHarmonyTemplateEscapes};
7169 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, flags,
7170 arraysize(flags));
7171
7172 // Still an error without flag
7173 RunParserSyncTest(context_data, data, kError);
7174 }
7175
7176 TEST(TemplateEscapesNegativeTests) {
7177 // clang-format off
7178 const char* context_data[][2] = {
7179 {"", ""},
7180 {"'use strict';", ""},
7181 {NULL, NULL}};
7182
7183 // clang-format off
7184 const char* data[] = {
7185 "`\\01`",
7186 "`\\01${0}right`",
7187 "`left${0}\\01`",
7188 "`left${0}\\01${1}right`",
7189 "`\\1`",
7190 "`\\1${0}right`",
7191 "`left${0}\\1`",
7192 "`left${0}\\1${1}right`",
7193 "`\\xg`",
7194 "`\\xg${0}right`",
7195 "`left${0}\\xg`",
7196 "`left${0}\\xg${1}right`",
7197 "`\\xAg`",
7198 "`\\xAg${0}right`",
7199 "`left${0}\\xAg`",
7200 "`left${0}\\xAg${1}right`",
7201 "`\\u0`",
7202 "`\\u0${0}right`",
7203 "`left${0}\\u0`",
7204 "`left${0}\\u0${1}right`",
7205 "`\\u0g`",
7206 "`\\u0g${0}right`",
7207 "`left${0}\\u0g`",
7208 "`left${0}\\u0g${1}right`",
7209 "`\\u00g`",
7210 "`\\u00g${0}right`",
7211 "`left${0}\\u00g`",
7212 "`left${0}\\u00g${1}right`",
7213 "`\\u000g`",
7214 "`\\u000g${0}right`",
7215 "`left${0}\\u000g`",
7216 "`left${0}\\u000g${1}right`",
7217 "`\\u{}`",
7218 "`\\u{}${0}right`",
7219 "`left${0}\\u{}`",
7220 "`left${0}\\u{}${1}right`",
7221 "`\\u{-0}`",
7222 "`\\u{-0}${0}right`",
7223 "`left${0}\\u{-0}`",
7224 "`left${0}\\u{-0}${1}right`",
7225 "`\\u{g}`",
7226 "`\\u{g}${0}right`",
7227 "`left${0}\\u{g}`",
7228 "`left${0}\\u{g}${1}right`",
7229 "`\\u{0`",
7230 "`\\u{0${0}right`",
7231 "`left${0}\\u{0`",
7232 "`left${0}\\u{0${1}right`",
7233 "`\\u{\\u{0}`",
7234 "`\\u{\\u{0}${0}right`",
7235 "`left${0}\\u{\\u{0}`",
7236 "`left${0}\\u{\\u{0}${1}right`",
7237 "`\\u{110000}`",
7238 "`\\u{110000}${0}right`",
7239 "`left${0}\\u{110000}`",
7240 "`left${0}\\u{110000}${1}right`",
7241 "`\\1``\\2`",
7242 NULL};
7243 // clang-format on
7244
7245 // Error with flag
7246 static const ParserFlag flags[] = {kAllowHarmonyTemplateEscapes};
7247 RunParserSyncTest(context_data, data, kError, NULL, 0, flags,
7248 arraysize(flags));
7249
7250 // Still an error without flag
7251 RunParserSyncTest(context_data, data, kError);
7252 }
7253
7093 TEST(DestructuringPositiveTests) { 7254 TEST(DestructuringPositiveTests) {
7094 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, 7255 const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
7095 {"var ", " = {};"}, 7256 {"var ", " = {};"},
7096 {"'use strict'; const ", " = {};"}, 7257 {"'use strict'; const ", " = {};"},
7097 {"function f(", ") {}"}, 7258 {"function f(", ") {}"},
7098 {"function f(argument1, ", ") {}"}, 7259 {"function f(argument1, ", ") {}"},
7099 {"var f = (", ") => {};"}, 7260 {"var f = (", ") => {};"},
7100 {"var f = (argument1,", ") => {};"}, 7261 {"var f = (argument1,", ") => {};"},
7101 {"try {} catch(", ") {}"}, 7262 {"try {} catch(", ") {}"},
7102 {NULL, NULL}}; 7263 {NULL, NULL}};
(...skipping 2664 matching lines...) Expand 10 before | Expand all | Expand 10 after
9767 // "for await (x of []) async function a() {};", 9928 // "for await (x of []) async function a() {};",
9768 // "for await (x of []) async function a() {}; return a;", 9929 // "for await (x of []) async function a() {}; return a;",
9769 NULL 9930 NULL
9770 }; 9931 };
9771 9932
9772 // clang-format on 9933 // clang-format on
9773 static const ParserFlag always_flags[] = {kAllowHarmonyAsyncIteration}; 9934 static const ParserFlag always_flags[] = {kAllowHarmonyAsyncIteration};
9774 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 9935 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
9775 arraysize(always_flags)); 9936 arraysize(always_flags));
9776 } 9937 }
OLDNEW
« no previous file with comments | « src/parsing/scanner.cc ('k') | test/mjsunit/compiler/literals.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698