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 2630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4299 {"'use strict';", ""}, | 4302 {"'use strict';", ""}, |
4300 {NULL, NULL}}; | 4303 {NULL, NULL}}; |
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 "/regex/g\\u123r", | 4308 "/regex/g\\u123r", |
4306 NULL}; | 4309 NULL}; |
4307 RunParserSyncTest(context_data, data, kError); | 4310 RunParserSyncTest(context_data, data, kError); |
4308 } | 4311 } |
4312 | |
4313 | |
4314 TEST(ScanTemplateLiterals) { | |
4315 const char* context_data[][2] = {{"'use strict';", ""}, | |
4316 {"function foo(){ 'use strict';" | |
4317 " var a, b, c; return ", "}"}, | |
4318 {NULL, NULL}}; | |
4319 | |
4320 const char* data[] = { | |
4321 "`no-subst-template`", | |
arv (Not doing code reviews)
2014/11/07 16:55:50
Also include an empty one
``
caitp (gmail)
2014/11/07 17:13:08
Done.
| |
4322 "`template-head${a}`", | |
4323 "`${a}template-tail`", | |
arv (Not doing code reviews)
2014/11/07 16:55:50
How about one with only a place holder
`${a}`
caitp (gmail)
2014/11/07 17:13:08
Done.
| |
4324 "`template-head${a}template-tail`", | |
4325 "`${a}${b}${c}`", | |
4326 "`a${a}b${b}c${c}`", | |
4327 "`${a}a${b}b${c}c`", | |
4328 "`foo\n\nbar\r\nbaz`", | |
4329 "`foo\n\n${ bar }\r\nbaz`", | |
4330 NULL}; | |
4331 static const ParserFlag always_flags[] = {kAllowHarmonyTemplates}; | |
4332 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, | |
4333 arraysize(always_flags)); | |
4334 } | |
4335 | |
4336 | |
4337 TEST(ScanTaggedTemplateLiterals) { | |
4338 const char* context_data[][2] = {{"'use strict';", ""}, | |
4339 {"function foo(){ 'use strict';" | |
4340 " function tag() {}" | |
4341 " var a, b, c; return ", "}"}, | |
4342 {NULL, NULL}}; | |
4343 | |
4344 const char* data[] = { | |
4345 "tag `no-subst-template`", | |
4346 "tag`template-head${a}`", | |
4347 "tag `${a}template-tail`", | |
4348 "tag `template-head${a}template-tail`", | |
4349 "tag\n`${a}${b}${c}`", | |
4350 "tag\r\n`a${a}b${b}c${c}`", | |
4351 "tag `${a}a${b}b${c}c`", | |
4352 "tag\t`foo\n\nbar\r\nbaz`", | |
4353 "tag\r`foo\n\n${ bar }\r\nbaz`", | |
4354 NULL}; | |
4355 static const ParserFlag always_flags[] = {kAllowHarmonyTemplates}; | |
4356 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, | |
4357 arraysize(always_flags)); | |
4358 } | |
4359 | |
4360 | |
4361 TEST(ScanUnterminatedTemplateLiterals) { | |
4362 const char* context_data[][2] = {{"'use strict';", ""}, | |
4363 {"function foo(){ 'use strict';" | |
4364 " var a, b, c; return ", "}"}, | |
4365 {NULL, NULL}}; | |
4366 | |
4367 const char* data[] = { | |
4368 "`no-subst-template", | |
4369 "`template-head${a}", | |
4370 "`${a}template-tail", | |
4371 "`template-head${a}template-tail", | |
4372 "`${a}${b}${c}", | |
4373 "`a${a}b${b}c${c}", | |
4374 "`${a}a${b}b${c}c", | |
4375 "`foo\n\nbar\r\nbaz", | |
4376 "`foo\n\n${ bar }\r\nbaz", | |
4377 NULL}; | |
4378 static const ParserFlag always_flags[] = {kAllowHarmonyTemplates}; | |
4379 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | |
4380 arraysize(always_flags)); | |
4381 } | |
OLD | NEW |