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 1316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1327 | 1327 |
1328 | 1328 |
1329 enum ParserFlag { | 1329 enum ParserFlag { |
1330 kAllowLazy, | 1330 kAllowLazy, |
1331 kAllowNativesSyntax, | 1331 kAllowNativesSyntax, |
1332 kAllowHarmonyScoping, | 1332 kAllowHarmonyScoping, |
1333 kAllowModules, | 1333 kAllowModules, |
1334 kAllowHarmonyNumericLiterals, | 1334 kAllowHarmonyNumericLiterals, |
1335 kAllowArrowFunctions, | 1335 kAllowArrowFunctions, |
1336 kAllowClasses, | 1336 kAllowClasses, |
1337 kAllowHarmonyObjectLiterals | 1337 kAllowHarmonyObjectLiterals, |
| 1338 kAllowHarmonyTemplates |
1338 }; | 1339 }; |
1339 | 1340 |
1340 | 1341 |
1341 enum ParserSyncTestResult { | 1342 enum ParserSyncTestResult { |
1342 kSuccessOrError, | 1343 kSuccessOrError, |
1343 kSuccess, | 1344 kSuccess, |
1344 kError | 1345 kError |
1345 }; | 1346 }; |
1346 | 1347 |
1347 template <typename Traits> | 1348 template <typename Traits> |
1348 void SetParserFlags(i::ParserBase<Traits>* parser, | 1349 void SetParserFlags(i::ParserBase<Traits>* parser, |
1349 i::EnumSet<ParserFlag> flags) { | 1350 i::EnumSet<ParserFlag> flags) { |
1350 parser->set_allow_lazy(flags.Contains(kAllowLazy)); | 1351 parser->set_allow_lazy(flags.Contains(kAllowLazy)); |
1351 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax)); | 1352 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax)); |
1352 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); | 1353 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); |
1353 parser->set_allow_modules(flags.Contains(kAllowModules)); | 1354 parser->set_allow_modules(flags.Contains(kAllowModules)); |
1354 parser->set_allow_harmony_numeric_literals( | 1355 parser->set_allow_harmony_numeric_literals( |
1355 flags.Contains(kAllowHarmonyNumericLiterals)); | 1356 flags.Contains(kAllowHarmonyNumericLiterals)); |
1356 parser->set_allow_harmony_object_literals( | 1357 parser->set_allow_harmony_object_literals( |
1357 flags.Contains(kAllowHarmonyObjectLiterals)); | 1358 flags.Contains(kAllowHarmonyObjectLiterals)); |
1358 parser->set_allow_arrow_functions(flags.Contains(kAllowArrowFunctions)); | 1359 parser->set_allow_arrow_functions(flags.Contains(kAllowArrowFunctions)); |
1359 parser->set_allow_classes(flags.Contains(kAllowClasses)); | 1360 parser->set_allow_classes(flags.Contains(kAllowClasses)); |
| 1361 parser->set_allow_harmony_templates(flags.Contains(kAllowHarmonyTemplates)); |
1360 } | 1362 } |
1361 | 1363 |
1362 | 1364 |
1363 void TestParserSyncWithFlags(i::Handle<i::String> source, | 1365 void TestParserSyncWithFlags(i::Handle<i::String> source, |
1364 i::EnumSet<ParserFlag> flags, | 1366 i::EnumSet<ParserFlag> flags, |
1365 ParserSyncTestResult result) { | 1367 ParserSyncTestResult result) { |
1366 i::Isolate* isolate = CcTest::i_isolate(); | 1368 i::Isolate* isolate = CcTest::i_isolate(); |
1367 i::Factory* factory = isolate->factory(); | 1369 i::Factory* factory = isolate->factory(); |
1368 | 1370 |
1369 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); | 1371 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1649 | 1651 |
1650 static const ParserFlag default_flags[] = { | 1652 static const ParserFlag default_flags[] = { |
1651 kAllowArrowFunctions, | 1653 kAllowArrowFunctions, |
1652 kAllowClasses, | 1654 kAllowClasses, |
1653 kAllowHarmonyNumericLiterals, | 1655 kAllowHarmonyNumericLiterals, |
1654 kAllowHarmonyObjectLiterals, | 1656 kAllowHarmonyObjectLiterals, |
1655 kAllowHarmonyScoping, | 1657 kAllowHarmonyScoping, |
1656 kAllowLazy, | 1658 kAllowLazy, |
1657 kAllowModules, | 1659 kAllowModules, |
1658 kAllowNativesSyntax, | 1660 kAllowNativesSyntax, |
| 1661 kAllowHarmonyTemplates |
1659 }; | 1662 }; |
1660 ParserFlag* generated_flags = NULL; | 1663 ParserFlag* generated_flags = NULL; |
1661 if (flags == NULL) { | 1664 if (flags == NULL) { |
1662 flags = default_flags; | 1665 flags = default_flags; |
1663 flags_len = arraysize(default_flags); | 1666 flags_len = arraysize(default_flags); |
1664 if (always_true_flags != NULL) { | 1667 if (always_true_flags != NULL) { |
1665 // Remove always_true_flags from default_flags. | 1668 // Remove always_true_flags from default_flags. |
1666 CHECK(always_true_flags_len < flags_len); | 1669 CHECK(always_true_flags_len < flags_len); |
1667 generated_flags = new ParserFlag[flags_len - always_true_flags_len]; | 1670 generated_flags = new ParserFlag[flags_len - always_true_flags_len]; |
1668 int flag_index = 0; | 1671 int flag_index = 0; |
(...skipping 2582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4251 "for(const x = 4, y of [1,2,3]) {}", | 4254 "for(const x = 4, y of [1,2,3]) {}", |
4252 "for(const x = 1, y = 2 in []) {}", | 4255 "for(const x = 1, y = 2 in []) {}", |
4253 "for(const x,y in []) {}", | 4256 "for(const x,y in []) {}", |
4254 "for(const x = 1, y = 2 of []) {}", | 4257 "for(const x = 1, y = 2 of []) {}", |
4255 "for(const x,y of []) {}", | 4258 "for(const x,y of []) {}", |
4256 NULL}; | 4259 NULL}; |
4257 static const ParserFlag always_flags[] = {kAllowHarmonyScoping}; | 4260 static const ParserFlag always_flags[] = {kAllowHarmonyScoping}; |
4258 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | 4261 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
4259 arraysize(always_flags)); | 4262 arraysize(always_flags)); |
4260 } | 4263 } |
| 4264 |
| 4265 |
| 4266 TEST(ScanTemplateLiterals) { |
| 4267 const char* context_data[][2] = {{"'use strict';", ""}, |
| 4268 {"function foo(){ 'use strict';" |
| 4269 " var a, b, c; return ", "}"}, |
| 4270 {NULL, NULL}}; |
| 4271 |
| 4272 const char* data[] = { |
| 4273 "`no-subst-template`", |
| 4274 "`template-head${a}`", |
| 4275 "`${a}template-tail`", |
| 4276 "`template-head${a}template-tail`", |
| 4277 "`${a}${b}${c}`", |
| 4278 "`a${a}b${b}c${c}`", |
| 4279 "`${a}a${b}b${c}c`", |
| 4280 "`foo\n\nbar\r\nbaz`", |
| 4281 "`foo\n\n${ bar }\r\nbaz`", |
| 4282 NULL}; |
| 4283 static const ParserFlag always_flags[] = {kAllowHarmonyTemplates}; |
| 4284 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, |
| 4285 arraysize(always_flags)); |
| 4286 } |
| 4287 |
| 4288 |
| 4289 TEST(ScanTaggedTemplateLiterals) { |
| 4290 const char* context_data[][2] = {{"'use strict';", ""}, |
| 4291 {"function foo(){ 'use strict';" |
| 4292 " function tag() {}" |
| 4293 " var a, b, c; return ", "}"}, |
| 4294 {NULL, NULL}}; |
| 4295 |
| 4296 const char* data[] = { |
| 4297 "tag `no-subst-template`", |
| 4298 "tag`template-head${a}`", |
| 4299 "tag `${a}template-tail`", |
| 4300 "tag `template-head${a}template-tail`", |
| 4301 "tag\n`${a}${b}${c}`", |
| 4302 "tag\r\n`a${a}b${b}c${c}`", |
| 4303 "tag `${a}a${b}b${c}c`", |
| 4304 "tag\t`foo\n\nbar\r\nbaz`", |
| 4305 "tag\r`foo\n\n${ bar }\r\nbaz`", |
| 4306 NULL}; |
| 4307 static const ParserFlag always_flags[] = {kAllowHarmonyTemplates}; |
| 4308 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, |
| 4309 arraysize(always_flags)); |
| 4310 } |
| 4311 |
| 4312 |
| 4313 TEST(ScanUnterminatedTemplateLiterals) { |
| 4314 const char* context_data[][2] = {{"'use strict';", ""}, |
| 4315 {"function foo(){ 'use strict';" |
| 4316 " var a, b, c; return ", "}"}, |
| 4317 {NULL, NULL}}; |
| 4318 |
| 4319 const char* data[] = { |
| 4320 "`no-subst-template", |
| 4321 "`template-head${a}", |
| 4322 "`${a}template-tail", |
| 4323 "`template-head${a}template-tail", |
| 4324 "`${a}${b}${c}", |
| 4325 "`a${a}b${b}c${c}", |
| 4326 "`${a}a${b}b${c}c", |
| 4327 "`foo\n\nbar\r\nbaz", |
| 4328 "`foo\n\n${ bar }\r\nbaz", |
| 4329 NULL}; |
| 4330 static const ParserFlag always_flags[] = {kAllowHarmonyTemplates}; |
| 4331 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
| 4332 arraysize(always_flags)); |
| 4333 } |
OLD | NEW |