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 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1337 | 1337 |
1338 | 1338 |
1339 enum ParserFlag { | 1339 enum ParserFlag { |
1340 kAllowLazy, | 1340 kAllowLazy, |
1341 kAllowNativesSyntax, | 1341 kAllowNativesSyntax, |
1342 kAllowHarmonyScoping, | 1342 kAllowHarmonyScoping, |
1343 kAllowModules, | 1343 kAllowModules, |
1344 kAllowHarmonyNumericLiterals, | 1344 kAllowHarmonyNumericLiterals, |
1345 kAllowArrowFunctions, | 1345 kAllowArrowFunctions, |
1346 kAllowClasses, | 1346 kAllowClasses, |
1347 kAllowHarmonyObjectLiterals | 1347 kAllowHarmonyObjectLiterals, |
| 1348 kAllowHarmonyTemplates |
1348 }; | 1349 }; |
1349 | 1350 |
1350 | 1351 |
1351 enum ParserSyncTestResult { | 1352 enum ParserSyncTestResult { |
1352 kSuccessOrError, | 1353 kSuccessOrError, |
1353 kSuccess, | 1354 kSuccess, |
1354 kError | 1355 kError |
1355 }; | 1356 }; |
1356 | 1357 |
1357 template <typename Traits> | 1358 template <typename Traits> |
1358 void SetParserFlags(i::ParserBase<Traits>* parser, | 1359 void SetParserFlags(i::ParserBase<Traits>* parser, |
1359 i::EnumSet<ParserFlag> flags) { | 1360 i::EnumSet<ParserFlag> flags) { |
1360 parser->set_allow_lazy(flags.Contains(kAllowLazy)); | 1361 parser->set_allow_lazy(flags.Contains(kAllowLazy)); |
1361 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax)); | 1362 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax)); |
1362 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); | 1363 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); |
1363 parser->set_allow_modules(flags.Contains(kAllowModules)); | 1364 parser->set_allow_modules(flags.Contains(kAllowModules)); |
1364 parser->set_allow_harmony_numeric_literals( | 1365 parser->set_allow_harmony_numeric_literals( |
1365 flags.Contains(kAllowHarmonyNumericLiterals)); | 1366 flags.Contains(kAllowHarmonyNumericLiterals)); |
1366 parser->set_allow_harmony_object_literals( | 1367 parser->set_allow_harmony_object_literals( |
1367 flags.Contains(kAllowHarmonyObjectLiterals)); | 1368 flags.Contains(kAllowHarmonyObjectLiterals)); |
1368 parser->set_allow_arrow_functions(flags.Contains(kAllowArrowFunctions)); | 1369 parser->set_allow_arrow_functions(flags.Contains(kAllowArrowFunctions)); |
1369 parser->set_allow_classes(flags.Contains(kAllowClasses)); | 1370 parser->set_allow_classes(flags.Contains(kAllowClasses)); |
| 1371 parser->set_allow_harmony_templates(flags.Contains(kAllowHarmonyTemplates)); |
1370 } | 1372 } |
1371 | 1373 |
1372 | 1374 |
1373 void TestParserSyncWithFlags(i::Handle<i::String> source, | 1375 void TestParserSyncWithFlags(i::Handle<i::String> source, |
1374 i::EnumSet<ParserFlag> flags, | 1376 i::EnumSet<ParserFlag> flags, |
1375 ParserSyncTestResult result) { | 1377 ParserSyncTestResult result) { |
1376 i::Isolate* isolate = CcTest::i_isolate(); | 1378 i::Isolate* isolate = CcTest::i_isolate(); |
1377 i::Factory* factory = isolate->factory(); | 1379 i::Factory* factory = isolate->factory(); |
1378 | 1380 |
1379 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); | 1381 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1659 | 1661 |
1660 static const ParserFlag default_flags[] = { | 1662 static const ParserFlag default_flags[] = { |
1661 kAllowArrowFunctions, | 1663 kAllowArrowFunctions, |
1662 kAllowClasses, | 1664 kAllowClasses, |
1663 kAllowHarmonyNumericLiterals, | 1665 kAllowHarmonyNumericLiterals, |
1664 kAllowHarmonyObjectLiterals, | 1666 kAllowHarmonyObjectLiterals, |
1665 kAllowHarmonyScoping, | 1667 kAllowHarmonyScoping, |
1666 kAllowLazy, | 1668 kAllowLazy, |
1667 kAllowModules, | 1669 kAllowModules, |
1668 kAllowNativesSyntax, | 1670 kAllowNativesSyntax, |
| 1671 kAllowHarmonyTemplates |
1669 }; | 1672 }; |
1670 ParserFlag* generated_flags = NULL; | 1673 ParserFlag* generated_flags = NULL; |
1671 if (flags == NULL) { | 1674 if (flags == NULL) { |
1672 flags = default_flags; | 1675 flags = default_flags; |
1673 flags_len = arraysize(default_flags); | 1676 flags_len = arraysize(default_flags); |
1674 if (always_true_flags != NULL) { | 1677 if (always_true_flags != NULL) { |
1675 // Remove always_true_flags from default_flags. | 1678 // Remove always_true_flags from default_flags. |
1676 CHECK(always_true_flags_len < flags_len); | 1679 CHECK(always_true_flags_len < flags_len); |
1677 generated_flags = new ParserFlag[flags_len - always_true_flags_len]; | 1680 generated_flags = new ParserFlag[flags_len - always_true_flags_len]; |
1678 int flag_index = 0; | 1681 int flag_index = 0; |
(...skipping 2632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4311 const char* data[] = { | 4314 const char* data[] = { |
4312 "var foob\\u123r = 0;", | 4315 "var foob\\u123r = 0;", |
4313 "var \\u123roo = 0;", | 4316 "var \\u123roo = 0;", |
4314 "\"foob\\u123rr\"", | 4317 "\"foob\\u123rr\"", |
4315 // No escapes allowed in regexp flags | 4318 // No escapes allowed in regexp flags |
4316 "/regex/\\u0069g", | 4319 "/regex/\\u0069g", |
4317 "/regex/\\u006g", | 4320 "/regex/\\u006g", |
4318 NULL}; | 4321 NULL}; |
4319 RunParserSyncTest(context_data, data, kError); | 4322 RunParserSyncTest(context_data, data, kError); |
4320 } | 4323 } |
| 4324 |
| 4325 |
| 4326 TEST(ScanTemplateLiterals) { |
| 4327 const char* context_data[][2] = {{"'use strict';", ""}, |
| 4328 {"function foo(){ 'use strict';" |
| 4329 " var a, b, c; return ", "}"}, |
| 4330 {NULL, NULL}}; |
| 4331 |
| 4332 const char* data[] = { |
| 4333 "``", |
| 4334 "`no-subst-template`", |
| 4335 "`template-head${a}`", |
| 4336 "`${a}`", |
| 4337 "`${a}template-tail`", |
| 4338 "`template-head${a}template-tail`", |
| 4339 "`${a}${b}${c}`", |
| 4340 "`a${a}b${b}c${c}`", |
| 4341 "`${a}a${b}b${c}c`", |
| 4342 "`foo\n\nbar\r\nbaz`", |
| 4343 "`foo\n\n${ bar }\r\nbaz`", |
| 4344 "`foo${a /* comment */}`", |
| 4345 "`foo${a // comment\n}`", |
| 4346 "`foo${a \n}`", |
| 4347 "`foo${a \r\n}`", |
| 4348 "`foo${a \r}`", |
| 4349 "`foo${/* comment */ a}`", |
| 4350 "`foo${// comment\na}`", |
| 4351 "`foo${\n a}`", |
| 4352 "`foo${\r\n a}`", |
| 4353 "`foo${\r a}`", |
| 4354 "`foo${'a' in a}`", |
| 4355 NULL}; |
| 4356 static const ParserFlag always_flags[] = {kAllowHarmonyTemplates}; |
| 4357 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, |
| 4358 arraysize(always_flags)); |
| 4359 } |
| 4360 |
| 4361 |
| 4362 TEST(ScanTaggedTemplateLiterals) { |
| 4363 const char* context_data[][2] = {{"'use strict';", ""}, |
| 4364 {"function foo(){ 'use strict';" |
| 4365 " function tag() {}" |
| 4366 " var a, b, c; return ", "}"}, |
| 4367 {NULL, NULL}}; |
| 4368 |
| 4369 const char* data[] = { |
| 4370 "tag ``", |
| 4371 "tag `no-subst-template`", |
| 4372 "tag`template-head${a}`", |
| 4373 "tag `${a}`", |
| 4374 "tag `${a}template-tail`", |
| 4375 "tag `template-head${a}template-tail`", |
| 4376 "tag\n`${a}${b}${c}`", |
| 4377 "tag\r\n`a${a}b${b}c${c}`", |
| 4378 "tag `${a}a${b}b${c}c`", |
| 4379 "tag\t`foo\n\nbar\r\nbaz`", |
| 4380 "tag\r`foo\n\n${ bar }\r\nbaz`", |
| 4381 "tag`foo${a /* comment */}`", |
| 4382 "tag`foo${a // comment\n}`", |
| 4383 "tag`foo${a \n}`", |
| 4384 "tag`foo${a \r\n}`", |
| 4385 "tag`foo${a \r}`", |
| 4386 "tag`foo${/* comment */ a}`", |
| 4387 "tag`foo${// comment\na}`", |
| 4388 "tag`foo${\n a}`", |
| 4389 "tag`foo${\r\n a}`", |
| 4390 "tag`foo${\r a}`", |
| 4391 "tag`foo${'a' in a}`", |
| 4392 NULL}; |
| 4393 static const ParserFlag always_flags[] = {kAllowHarmonyTemplates}; |
| 4394 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, |
| 4395 arraysize(always_flags)); |
| 4396 } |
| 4397 |
| 4398 |
| 4399 TEST(ScanUnterminatedTemplateLiterals) { |
| 4400 const char* context_data[][2] = {{"'use strict';", ""}, |
| 4401 {"function foo(){ 'use strict';" |
| 4402 " var a, b, c; return ", "}"}, |
| 4403 {NULL, NULL}}; |
| 4404 |
| 4405 const char* data[] = { |
| 4406 "`no-subst-template", |
| 4407 "`template-head${a}", |
| 4408 "`${a}template-tail", |
| 4409 "`template-head${a}template-tail", |
| 4410 "`${a}${b}${c}", |
| 4411 "`a${a}b${b}c${c}", |
| 4412 "`${a}a${b}b${c}c", |
| 4413 "`foo\n\nbar\r\nbaz", |
| 4414 "`foo\n\n${ bar }\r\nbaz", |
| 4415 "`foo${a /* comment } */`", |
| 4416 "`foo${a /* comment } `*/", |
| 4417 "`foo${a // comment}`", |
| 4418 "`foo${a \n`", |
| 4419 "`foo${a \r\n`", |
| 4420 "`foo${a \r`", |
| 4421 "`foo${/* comment */ a`", |
| 4422 "`foo${// commenta}`", |
| 4423 "`foo${\n a`", |
| 4424 "`foo${\r\n a`", |
| 4425 "`foo${\r a`", |
| 4426 "`foo${fn(}`", |
| 4427 "`foo${1 if}`", |
| 4428 NULL}; |
| 4429 static const ParserFlag always_flags[] = {kAllowHarmonyTemplates}; |
| 4430 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
| 4431 arraysize(always_flags)); |
| 4432 } |
OLD | NEW |