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 NULL}; | |
4345 static const ParserFlag always_flags[] = {kAllowHarmonyTemplates}; | |
4346 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, | |
4347 arraysize(always_flags)); | |
4348 } | |
rossberg
2014/11/14 12:28:07
Add tests for some of the different InputElementTe
| |
4349 | |
4350 | |
4351 TEST(ScanTaggedTemplateLiterals) { | |
4352 const char* context_data[][2] = {{"'use strict';", ""}, | |
4353 {"function foo(){ 'use strict';" | |
4354 " function tag() {}" | |
4355 " var a, b, c; return ", "}"}, | |
4356 {NULL, NULL}}; | |
4357 | |
4358 const char* data[] = { | |
4359 "tag ``", | |
4360 "tag `no-subst-template`", | |
4361 "tag`template-head${a}`", | |
4362 "tag `${a}`", | |
4363 "tag `${a}template-tail`", | |
4364 "tag `template-head${a}template-tail`", | |
4365 "tag\n`${a}${b}${c}`", | |
4366 "tag\r\n`a${a}b${b}c${c}`", | |
4367 "tag `${a}a${b}b${c}c`", | |
4368 "tag\t`foo\n\nbar\r\nbaz`", | |
4369 "tag\r`foo\n\n${ bar }\r\nbaz`", | |
4370 NULL}; | |
4371 static const ParserFlag always_flags[] = {kAllowHarmonyTemplates}; | |
4372 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, | |
4373 arraysize(always_flags)); | |
4374 } | |
4375 | |
4376 | |
4377 TEST(ScanUnterminatedTemplateLiterals) { | |
4378 const char* context_data[][2] = {{"'use strict';", ""}, | |
4379 {"function foo(){ 'use strict';" | |
4380 " var a, b, c; return ", "}"}, | |
4381 {NULL, NULL}}; | |
4382 | |
4383 const char* data[] = { | |
4384 "`no-subst-template", | |
4385 "`template-head${a}", | |
4386 "`${a}template-tail", | |
4387 "`template-head${a}template-tail", | |
4388 "`${a}${b}${c}", | |
4389 "`a${a}b${b}c${c}", | |
4390 "`${a}a${b}b${c}c", | |
4391 "`foo\n\nbar\r\nbaz", | |
4392 "`foo\n\n${ bar }\r\nbaz", | |
4393 NULL}; | |
4394 static const ParserFlag always_flags[] = {kAllowHarmonyTemplates}; | |
4395 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | |
4396 arraysize(always_flags)); | |
4397 } | |
rossberg
2014/11/14 12:28:07
We should also have sync test cases where the scri
| |
OLD | NEW |