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 2632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4301 const char* data[] = { | 4304 const char* data[] = { |
4302 "var foob\\u123r = 0;", | 4305 "var foob\\u123r = 0;", |
4303 "var \\u123roo = 0;", | 4306 "var \\u123roo = 0;", |
4304 "\"foob\\u123rr\"", | 4307 "\"foob\\u123rr\"", |
4305 // No escapes allowed in regexp flags | 4308 // No escapes allowed in regexp flags |
4306 "/regex/\\u0069g", | 4309 "/regex/\\u0069g", |
4307 "/regex/\\u006g", | 4310 "/regex/\\u006g", |
4308 NULL}; | 4311 NULL}; |
4309 RunParserSyncTest(context_data, data, kError); | 4312 RunParserSyncTest(context_data, data, kError); |
4310 } | 4313 } |
| 4314 |
| 4315 |
| 4316 TEST(ScanTemplateLiterals) { |
| 4317 const char* context_data[][2] = {{"'use strict';", ""}, |
| 4318 {"function foo(){ 'use strict';" |
| 4319 " var a, b, c; return ", "}"}, |
| 4320 {NULL, NULL}}; |
| 4321 |
| 4322 const char* data[] = { |
| 4323 "``", |
| 4324 "`no-subst-template`", |
| 4325 "`template-head${a}`", |
| 4326 "`${a}`", |
| 4327 "`${a}template-tail`", |
| 4328 "`template-head${a}template-tail`", |
| 4329 "`${a}${b}${c}`", |
| 4330 "`a${a}b${b}c${c}`", |
| 4331 "`${a}a${b}b${c}c`", |
| 4332 "`foo\n\nbar\r\nbaz`", |
| 4333 "`foo\n\n${ bar }\r\nbaz`", |
| 4334 NULL}; |
| 4335 static const ParserFlag always_flags[] = {kAllowHarmonyTemplates}; |
| 4336 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, |
| 4337 arraysize(always_flags)); |
| 4338 } |
| 4339 |
| 4340 |
| 4341 TEST(ScanTaggedTemplateLiterals) { |
| 4342 const char* context_data[][2] = {{"'use strict';", ""}, |
| 4343 {"function foo(){ 'use strict';" |
| 4344 " function tag() {}" |
| 4345 " var a, b, c; return ", "}"}, |
| 4346 {NULL, NULL}}; |
| 4347 |
| 4348 const char* data[] = { |
| 4349 "tag ``", |
| 4350 "tag `no-subst-template`", |
| 4351 "tag`template-head${a}`", |
| 4352 "tag `${a}`", |
| 4353 "tag `${a}template-tail`", |
| 4354 "tag `template-head${a}template-tail`", |
| 4355 "tag\n`${a}${b}${c}`", |
| 4356 "tag\r\n`a${a}b${b}c${c}`", |
| 4357 "tag `${a}a${b}b${c}c`", |
| 4358 "tag\t`foo\n\nbar\r\nbaz`", |
| 4359 "tag\r`foo\n\n${ bar }\r\nbaz`", |
| 4360 NULL}; |
| 4361 static const ParserFlag always_flags[] = {kAllowHarmonyTemplates}; |
| 4362 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, |
| 4363 arraysize(always_flags)); |
| 4364 } |
| 4365 |
| 4366 |
| 4367 TEST(ScanUnterminatedTemplateLiterals) { |
| 4368 const char* context_data[][2] = {{"'use strict';", ""}, |
| 4369 {"function foo(){ 'use strict';" |
| 4370 " var a, b, c; return ", "}"}, |
| 4371 {NULL, NULL}}; |
| 4372 |
| 4373 const char* data[] = { |
| 4374 "`no-subst-template", |
| 4375 "`template-head${a}", |
| 4376 "`${a}template-tail", |
| 4377 "`template-head${a}template-tail", |
| 4378 "`${a}${b}${c}", |
| 4379 "`a${a}b${b}c${c}", |
| 4380 "`${a}a${b}b${c}c", |
| 4381 "`foo\n\nbar\r\nbaz", |
| 4382 "`foo\n\n${ bar }\r\nbaz", |
| 4383 NULL}; |
| 4384 static const ParserFlag always_flags[] = {kAllowHarmonyTemplates}; |
| 4385 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
| 4386 arraysize(always_flags)); |
| 4387 } |
OLD | NEW |