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 1244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1255 | 1255 |
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 kAllowHarmonyTemplateEscapes, |
1265 }; | 1266 }; |
1266 | 1267 |
1267 enum ParserSyncTestResult { | 1268 enum ParserSyncTestResult { |
1268 kSuccessOrError, | 1269 kSuccessOrError, |
1269 kSuccess, | 1270 kSuccess, |
1270 kError | 1271 kError |
1271 }; | 1272 }; |
1272 | 1273 |
1273 void SetGlobalFlags(i::EnumSet<ParserFlag> flags) { | 1274 void SetGlobalFlags(i::EnumSet<ParserFlag> flags) { |
1274 i::FLAG_allow_natives_syntax = flags.Contains(kAllowNatives); | 1275 i::FLAG_allow_natives_syntax = flags.Contains(kAllowNatives); |
1275 i::FLAG_harmony_function_sent = flags.Contains(kAllowHarmonyFunctionSent); | 1276 i::FLAG_harmony_function_sent = flags.Contains(kAllowHarmonyFunctionSent); |
1276 i::FLAG_harmony_restrictive_generators = | 1277 i::FLAG_harmony_restrictive_generators = |
1277 flags.Contains(kAllowHarmonyRestrictiveGenerators); | 1278 flags.Contains(kAllowHarmonyRestrictiveGenerators); |
1278 i::FLAG_harmony_trailing_commas = flags.Contains(kAllowHarmonyTrailingCommas); | 1279 i::FLAG_harmony_trailing_commas = flags.Contains(kAllowHarmonyTrailingCommas); |
1279 i::FLAG_harmony_class_fields = flags.Contains(kAllowHarmonyClassFields); | 1280 i::FLAG_harmony_class_fields = flags.Contains(kAllowHarmonyClassFields); |
1280 i::FLAG_harmony_object_rest_spread = | 1281 i::FLAG_harmony_object_rest_spread = |
1281 flags.Contains(kAllowHarmonyObjectRestSpread); | 1282 flags.Contains(kAllowHarmonyObjectRestSpread); |
1282 i::FLAG_harmony_dynamic_import = flags.Contains(kAllowHarmonyDynamicImport); | 1283 i::FLAG_harmony_dynamic_import = flags.Contains(kAllowHarmonyDynamicImport); |
| 1284 i::FLAG_harmony_template_escapes = |
| 1285 flags.Contains(kAllowHarmonyTemplateEscapes); |
1283 } | 1286 } |
1284 | 1287 |
1285 void SetParserFlags(i::PreParser* parser, i::EnumSet<ParserFlag> flags) { | 1288 void SetParserFlags(i::PreParser* parser, i::EnumSet<ParserFlag> flags) { |
1286 parser->set_allow_natives(flags.Contains(kAllowNatives)); | 1289 parser->set_allow_natives(flags.Contains(kAllowNatives)); |
1287 parser->set_allow_harmony_function_sent( | 1290 parser->set_allow_harmony_function_sent( |
1288 flags.Contains(kAllowHarmonyFunctionSent)); | 1291 flags.Contains(kAllowHarmonyFunctionSent)); |
1289 parser->set_allow_harmony_restrictive_generators( | 1292 parser->set_allow_harmony_restrictive_generators( |
1290 flags.Contains(kAllowHarmonyRestrictiveGenerators)); | 1293 flags.Contains(kAllowHarmonyRestrictiveGenerators)); |
1291 parser->set_allow_harmony_trailing_commas( | 1294 parser->set_allow_harmony_trailing_commas( |
1292 flags.Contains(kAllowHarmonyTrailingCommas)); | 1295 flags.Contains(kAllowHarmonyTrailingCommas)); |
1293 parser->set_allow_harmony_class_fields( | 1296 parser->set_allow_harmony_class_fields( |
1294 flags.Contains(kAllowHarmonyClassFields)); | 1297 flags.Contains(kAllowHarmonyClassFields)); |
1295 parser->set_allow_harmony_object_rest_spread( | 1298 parser->set_allow_harmony_object_rest_spread( |
1296 flags.Contains(kAllowHarmonyObjectRestSpread)); | 1299 flags.Contains(kAllowHarmonyObjectRestSpread)); |
1297 parser->set_allow_harmony_dynamic_import( | 1300 parser->set_allow_harmony_dynamic_import( |
1298 flags.Contains(kAllowHarmonyDynamicImport)); | 1301 flags.Contains(kAllowHarmonyDynamicImport)); |
| 1302 parser->set_allow_harmony_template_escapes( |
| 1303 flags.Contains(kAllowHarmonyTemplateEscapes)); |
1299 } | 1304 } |
1300 | 1305 |
1301 void TestParserSyncWithFlags(i::Handle<i::String> source, | 1306 void TestParserSyncWithFlags(i::Handle<i::String> source, |
1302 i::EnumSet<ParserFlag> flags, | 1307 i::EnumSet<ParserFlag> flags, |
1303 ParserSyncTestResult result, | 1308 ParserSyncTestResult result, |
1304 bool is_module = false, bool test_preparser = true, | 1309 bool is_module = false, bool test_preparser = true, |
1305 bool ignore_error_msg = false) { | 1310 bool ignore_error_msg = false) { |
1306 i::Isolate* isolate = CcTest::i_isolate(); | 1311 i::Isolate* isolate = CcTest::i_isolate(); |
1307 i::Factory* factory = isolate->factory(); | 1312 i::Factory* factory = isolate->factory(); |
1308 | 1313 |
(...skipping 5763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7072 "{ ...y, b: 1}", | 7077 "{ ...y, b: 1}", |
7073 "{ ...1}", | 7078 "{ ...1}", |
7074 "{ ...null}", | 7079 "{ ...null}", |
7075 "{ ...undefined}", | 7080 "{ ...undefined}", |
7076 "{ ...1 in {}}", | 7081 "{ ...1 in {}}", |
7077 "{ ...[]}", | 7082 "{ ...[]}", |
7078 "{ ...async function() { }}", | 7083 "{ ...async function() { }}", |
7079 "{ ...async () => { }}", | 7084 "{ ...async () => { }}", |
7080 "{ ...new Foo()}", | 7085 "{ ...new Foo()}", |
7081 NULL}; | 7086 NULL}; |
| 7087 // clang-format on |
7082 | 7088 |
7083 static const ParserFlag flags[] = {kAllowHarmonyObjectRestSpread}; | 7089 static const ParserFlag flags[] = {kAllowHarmonyObjectRestSpread}; |
7084 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, flags, | 7090 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, flags, |
7085 arraysize(flags)); | 7091 arraysize(flags)); |
7086 } | 7092 } |
7087 | 7093 |
7088 TEST(ObjectSpreadNegativeTests) { | 7094 TEST(ObjectSpreadNegativeTests) { |
7089 const char* context_data[][2] = {{"x = ", ""}, | 7095 const char* context_data[][2] = {{"x = ", ""}, |
7090 {"'use strict'; x = ", ""}, | 7096 {"'use strict'; x = ", ""}, |
7091 {NULL, NULL}}; | 7097 {NULL, NULL}}; |
7092 | 7098 |
7093 // clang-format off | 7099 // clang-format off |
7094 const char* data[] = { | 7100 const char* data[] = { |
7095 "{ ...var z = y}", | 7101 "{ ...var z = y}", |
7096 "{ ...var}", | 7102 "{ ...var}", |
7097 "{ ...foo bar}", | 7103 "{ ...foo bar}", |
7098 NULL}; | 7104 NULL}; |
7099 | 7105 |
7100 static const ParserFlag flags[] = {kAllowHarmonyObjectRestSpread}; | 7106 static const ParserFlag flags[] = {kAllowHarmonyObjectRestSpread}; |
7101 RunParserSyncTest(context_data, data, kError, NULL, 0, flags, | 7107 RunParserSyncTest(context_data, data, kError, NULL, 0, flags, |
7102 arraysize(flags)); | 7108 arraysize(flags)); |
7103 } | 7109 } |
7104 | 7110 |
| 7111 TEST(TemplateEscapesPositiveTests) { |
| 7112 // clang-format off |
| 7113 const char* context_data[][2] = { |
| 7114 {"", ""}, |
| 7115 {"'use strict';", ""}, |
| 7116 {NULL, NULL}}; |
| 7117 |
| 7118 // clang-format off |
| 7119 const char* data[] = { |
| 7120 "tag`\\01`", |
| 7121 "tag`\\01${0}right`", |
| 7122 "tag`left${0}\\01`", |
| 7123 "tag`left${0}\\01${1}right`", |
| 7124 "tag`\\1`", |
| 7125 "tag`\\1${0}right`", |
| 7126 "tag`left${0}\\1`", |
| 7127 "tag`left${0}\\1${1}right`", |
| 7128 "tag`\\xg`", |
| 7129 "tag`\\xg${0}right`", |
| 7130 "tag`left${0}\\xg`", |
| 7131 "tag`left${0}\\xg${1}right`", |
| 7132 "tag`\\xAg`", |
| 7133 "tag`\\xAg${0}right`", |
| 7134 "tag`left${0}\\xAg`", |
| 7135 "tag`left${0}\\xAg${1}right`", |
| 7136 "tag`\\u0`", |
| 7137 "tag`\\u0${0}right`", |
| 7138 "tag`left${0}\\u0`", |
| 7139 "tag`left${0}\\u0${1}right`", |
| 7140 "tag`\\u0g`", |
| 7141 "tag`\\u0g${0}right`", |
| 7142 "tag`left${0}\\u0g`", |
| 7143 "tag`left${0}\\u0g${1}right`", |
| 7144 "tag`\\u00g`", |
| 7145 "tag`\\u00g${0}right`", |
| 7146 "tag`left${0}\\u00g`", |
| 7147 "tag`left${0}\\u00g${1}right`", |
| 7148 "tag`\\u000g`", |
| 7149 "tag`\\u000g${0}right`", |
| 7150 "tag`left${0}\\u000g`", |
| 7151 "tag`left${0}\\u000g${1}right`", |
| 7152 "tag`\\u{}`", |
| 7153 "tag`\\u{}${0}right`", |
| 7154 "tag`left${0}\\u{}`", |
| 7155 "tag`left${0}\\u{}${1}right`", |
| 7156 "tag`\\u{-0}`", |
| 7157 "tag`\\u{-0}${0}right`", |
| 7158 "tag`left${0}\\u{-0}`", |
| 7159 "tag`left${0}\\u{-0}${1}right`", |
| 7160 "tag`\\u{g}`", |
| 7161 "tag`\\u{g}${0}right`", |
| 7162 "tag`left${0}\\u{g}`", |
| 7163 "tag`left${0}\\u{g}${1}right`", |
| 7164 "tag`\\u{0`", |
| 7165 "tag`\\u{0${0}right`", |
| 7166 "tag`left${0}\\u{0`", |
| 7167 "tag`left${0}\\u{0${1}right`", |
| 7168 "tag`\\u{\\u{0}`", |
| 7169 "tag`\\u{\\u{0}${0}right`", |
| 7170 "tag`left${0}\\u{\\u{0}`", |
| 7171 "tag`left${0}\\u{\\u{0}${1}right`", |
| 7172 "tag`\\u{110000}`", |
| 7173 "tag`\\u{110000}${0}right`", |
| 7174 "tag`left${0}\\u{110000}`", |
| 7175 "tag`left${0}\\u{110000}${1}right`", |
| 7176 NULL}; |
| 7177 // clang-format on |
| 7178 |
| 7179 static const ParserFlag flags[] = {kAllowHarmonyTemplateEscapes}; |
| 7180 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, flags, |
| 7181 arraysize(flags)); |
| 7182 } |
| 7183 |
| 7184 TEST(TemplateEscapesNegativeTests) { |
| 7185 // clang-format off |
| 7186 const char* context_data[][2] = { |
| 7187 {"", ""}, |
| 7188 {"'use strict';", ""}, |
| 7189 {NULL, NULL}}; |
| 7190 |
| 7191 // clang-format off |
| 7192 const char* data[] = { |
| 7193 "`\\01`", |
| 7194 "`\\01${0}right`", |
| 7195 "`left${0}\\01`", |
| 7196 "`left${0}\\01${1}right`", |
| 7197 "`\\1`", |
| 7198 "`\\1${0}right`", |
| 7199 "`left${0}\\1`", |
| 7200 "`left${0}\\1${1}right`", |
| 7201 "`\\xg`", |
| 7202 "`\\xg${0}right`", |
| 7203 "`left${0}\\xg`", |
| 7204 "`left${0}\\xg${1}right`", |
| 7205 "`\\xAg`", |
| 7206 "`\\xAg${0}right`", |
| 7207 "`left${0}\\xAg`", |
| 7208 "`left${0}\\xAg${1}right`", |
| 7209 "`\\u0`", |
| 7210 "`\\u0${0}right`", |
| 7211 "`left${0}\\u0`", |
| 7212 "`left${0}\\u0${1}right`", |
| 7213 "`\\u0g`", |
| 7214 "`\\u0g${0}right`", |
| 7215 "`left${0}\\u0g`", |
| 7216 "`left${0}\\u0g${1}right`", |
| 7217 "`\\u00g`", |
| 7218 "`\\u00g${0}right`", |
| 7219 "`left${0}\\u00g`", |
| 7220 "`left${0}\\u00g${1}right`", |
| 7221 "`\\u000g`", |
| 7222 "`\\u000g${0}right`", |
| 7223 "`left${0}\\u000g`", |
| 7224 "`left${0}\\u000g${1}right`", |
| 7225 "`\\u{}`", |
| 7226 "`\\u{}${0}right`", |
| 7227 "`left${0}\\u{}`", |
| 7228 "`left${0}\\u{}${1}right`", |
| 7229 "`\\u{-0}`", |
| 7230 "`\\u{-0}${0}right`", |
| 7231 "`left${0}\\u{-0}`", |
| 7232 "`left${0}\\u{-0}${1}right`", |
| 7233 "`\\u{g}`", |
| 7234 "`\\u{g}${0}right`", |
| 7235 "`left${0}\\u{g}`", |
| 7236 "`left${0}\\u{g}${1}right`", |
| 7237 "`\\u{0`", |
| 7238 "`\\u{0${0}right`", |
| 7239 "`left${0}\\u{0`", |
| 7240 "`left${0}\\u{0${1}right`", |
| 7241 "`\\u{\\u{0}`", |
| 7242 "`\\u{\\u{0}${0}right`", |
| 7243 "`left${0}\\u{\\u{0}`", |
| 7244 "`left${0}\\u{\\u{0}${1}right`", |
| 7245 "`\\u{110000}`", |
| 7246 "`\\u{110000}${0}right`", |
| 7247 "`left${0}\\u{110000}`", |
| 7248 "`left${0}\\u{110000}${1}right`", |
| 7249 NULL}; |
| 7250 // clang-format on |
| 7251 |
| 7252 static const ParserFlag flags[] = {kAllowHarmonyTemplateEscapes}; |
| 7253 RunParserSyncTest(context_data, data, kError, NULL, 0, flags, |
| 7254 arraysize(flags)); |
| 7255 } |
| 7256 |
7105 TEST(DestructuringPositiveTests) { | 7257 TEST(DestructuringPositiveTests) { |
7106 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, | 7258 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, |
7107 {"var ", " = {};"}, | 7259 {"var ", " = {};"}, |
7108 {"'use strict'; const ", " = {};"}, | 7260 {"'use strict'; const ", " = {};"}, |
7109 {"function f(", ") {}"}, | 7261 {"function f(", ") {}"}, |
7110 {"function f(argument1, ", ") {}"}, | 7262 {"function f(argument1, ", ") {}"}, |
7111 {"var f = (", ") => {};"}, | 7263 {"var f = (", ") => {};"}, |
7112 {"var f = (argument1,", ") => {};"}, | 7264 {"var f = (argument1,", ") => {};"}, |
7113 {"try {} catch(", ") {}"}, | 7265 {"try {} catch(", ") {}"}, |
7114 {NULL, NULL}}; | 7266 {NULL, NULL}}; |
(...skipping 2327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9442 DCHECK_NULL(scope->sibling()); | 9594 DCHECK_NULL(scope->sibling()); |
9443 DCHECK(scope->is_function_scope()); | 9595 DCHECK(scope->is_function_scope()); |
9444 const i::AstRawString* var_name = | 9596 const i::AstRawString* var_name = |
9445 info.ast_value_factory()->GetOneByteString("my_var"); | 9597 info.ast_value_factory()->GetOneByteString("my_var"); |
9446 i::Variable* var = scope->Lookup(var_name); | 9598 i::Variable* var = scope->Lookup(var_name); |
9447 CHECK_EQ(inners[i].ctxt_allocate, | 9599 CHECK_EQ(inners[i].ctxt_allocate, |
9448 i::ScopeTestHelper::MustAllocateInContext(var)); | 9600 i::ScopeTestHelper::MustAllocateInContext(var)); |
9449 } | 9601 } |
9450 } | 9602 } |
9451 } | 9603 } |
OLD | NEW |