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 1338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1349 | 1349 |
1350 enum ParserFlag { | 1350 enum ParserFlag { |
1351 kAllowLazy, | 1351 kAllowLazy, |
1352 kAllowNatives, | 1352 kAllowNatives, |
1353 kAllowHarmonyScoping, | 1353 kAllowHarmonyScoping, |
1354 kAllowHarmonyModules, | 1354 kAllowHarmonyModules, |
1355 kAllowHarmonyNumericLiterals, | 1355 kAllowHarmonyNumericLiterals, |
1356 kAllowHarmonyArrowFunctions, | 1356 kAllowHarmonyArrowFunctions, |
1357 kAllowHarmonyClasses, | 1357 kAllowHarmonyClasses, |
1358 kAllowHarmonyObjectLiterals, | 1358 kAllowHarmonyObjectLiterals, |
| 1359 kAllowHarmonyRestParameters, |
1359 kAllowHarmonyTemplates, | 1360 kAllowHarmonyTemplates, |
1360 kAllowHarmonySloppy, | 1361 kAllowHarmonySloppy, |
1361 kAllowHarmonyUnicode, | 1362 kAllowHarmonyUnicode, |
1362 kAllowHarmonyComputedPropertyNames | 1363 kAllowHarmonyComputedPropertyNames |
1363 }; | 1364 }; |
1364 | 1365 |
1365 | 1366 |
1366 enum ParserSyncTestResult { | 1367 enum ParserSyncTestResult { |
1367 kSuccessOrError, | 1368 kSuccessOrError, |
1368 kSuccess, | 1369 kSuccess, |
1369 kError | 1370 kError |
1370 }; | 1371 }; |
1371 | 1372 |
1372 template <typename Traits> | 1373 template <typename Traits> |
1373 void SetParserFlags(i::ParserBase<Traits>* parser, | 1374 void SetParserFlags(i::ParserBase<Traits>* parser, |
1374 i::EnumSet<ParserFlag> flags) { | 1375 i::EnumSet<ParserFlag> flags) { |
1375 parser->set_allow_lazy(flags.Contains(kAllowLazy)); | 1376 parser->set_allow_lazy(flags.Contains(kAllowLazy)); |
1376 parser->set_allow_natives(flags.Contains(kAllowNatives)); | 1377 parser->set_allow_natives(flags.Contains(kAllowNatives)); |
1377 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); | 1378 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); |
1378 parser->set_allow_harmony_modules(flags.Contains(kAllowHarmonyModules)); | 1379 parser->set_allow_harmony_modules(flags.Contains(kAllowHarmonyModules)); |
1379 parser->set_allow_harmony_numeric_literals( | 1380 parser->set_allow_harmony_numeric_literals( |
1380 flags.Contains(kAllowHarmonyNumericLiterals)); | 1381 flags.Contains(kAllowHarmonyNumericLiterals)); |
1381 parser->set_allow_harmony_object_literals( | 1382 parser->set_allow_harmony_object_literals( |
1382 flags.Contains(kAllowHarmonyObjectLiterals)); | 1383 flags.Contains(kAllowHarmonyObjectLiterals)); |
1383 parser->set_allow_harmony_arrow_functions( | 1384 parser->set_allow_harmony_arrow_functions( |
1384 flags.Contains(kAllowHarmonyArrowFunctions)); | 1385 flags.Contains(kAllowHarmonyArrowFunctions)); |
1385 parser->set_allow_harmony_classes(flags.Contains(kAllowHarmonyClasses)); | 1386 parser->set_allow_harmony_classes(flags.Contains(kAllowHarmonyClasses)); |
1386 parser->set_allow_harmony_templates(flags.Contains(kAllowHarmonyTemplates)); | 1387 parser->set_allow_harmony_templates(flags.Contains(kAllowHarmonyTemplates)); |
| 1388 parser->set_allow_harmony_rest_params( |
| 1389 flags.Contains(kAllowHarmonyRestParameters)); |
1387 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); | 1390 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); |
1388 parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode)); | 1391 parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode)); |
1389 parser->set_allow_harmony_computed_property_names( | 1392 parser->set_allow_harmony_computed_property_names( |
1390 flags.Contains(kAllowHarmonyComputedPropertyNames)); | 1393 flags.Contains(kAllowHarmonyComputedPropertyNames)); |
1391 } | 1394 } |
1392 | 1395 |
1393 | 1396 |
1394 void TestParserSyncWithFlags(i::Handle<i::String> source, | 1397 void TestParserSyncWithFlags(i::Handle<i::String> source, |
1395 i::EnumSet<ParserFlag> flags, | 1398 i::EnumSet<ParserFlag> flags, |
1396 ParserSyncTestResult result) { | 1399 ParserSyncTestResult result) { |
(...skipping 3164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4561 "`hello${1}\\x\n`", | 4564 "`hello${1}\\x\n`", |
4562 "`hello${1}\\x\n${2}`", | 4565 "`hello${1}\\x\n${2}`", |
4563 NULL}; | 4566 NULL}; |
4564 | 4567 |
4565 static const ParserFlag always_flags[] = {kAllowHarmonyTemplates}; | 4568 static const ParserFlag always_flags[] = {kAllowHarmonyTemplates}; |
4566 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | 4569 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
4567 arraysize(always_flags)); | 4570 arraysize(always_flags)); |
4568 } | 4571 } |
4569 | 4572 |
4570 | 4573 |
| 4574 TEST(ParseRestParameters) { |
| 4575 const char* context_data[][2] = {{"'use strict';(function(", |
| 4576 "){ return args;})(1, [], /regexp/, 'str'," |
| 4577 "function(){});"}, |
| 4578 {"(function(", "){ return args;})(1, []," |
| 4579 "/regexp/, 'str', function(){});"}, |
| 4580 {NULL, NULL}}; |
| 4581 |
| 4582 const char* data[] = { |
| 4583 "...args", |
| 4584 "a, ...args", |
| 4585 "... args", |
| 4586 "a, ... args", |
| 4587 "...\targs", |
| 4588 "a, ...\targs", |
| 4589 "...\r\nargs", |
| 4590 "a, ...\r\nargs", |
| 4591 "...\rargs", |
| 4592 "a, ...\rargs", |
| 4593 "...\t\n\t\t\n args", |
| 4594 "a, ... \n \n args", |
| 4595 NULL}; |
| 4596 static const ParserFlag always_flags[] = {kAllowHarmonyRestParameters}; |
| 4597 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, |
| 4598 arraysize(always_flags)); |
| 4599 } |
| 4600 |
| 4601 |
| 4602 TEST(ParseRestParametersErrors) { |
| 4603 const char* context_data[][2] = {{"'use strict';(function(", |
| 4604 "){ return args;}(1, [], /regexp/, 'str'," |
| 4605 "function(){});"}, |
| 4606 {"(function(", "){ return args;}(1, []," |
| 4607 "/regexp/, 'str', function(){});"}, |
| 4608 {NULL, NULL}}; |
| 4609 |
| 4610 const char* data[] = { |
| 4611 "...args, b", |
| 4612 "a, ...args, b", |
| 4613 "...args, b", |
| 4614 "a, ...args, b", |
| 4615 "...args,\tb", |
| 4616 "a,...args\t,b", |
| 4617 "...args\r\n, b", |
| 4618 "a, ... args,\r\nb", |
| 4619 "...args\r,b", |
| 4620 "a, ... args,\rb", |
| 4621 "...args\t\n\t\t\n, b", |
| 4622 "a, ... args, \n \n b", |
| 4623 "a, a, ...args", |
| 4624 "a,\ta, ...args", |
| 4625 "a,\ra, ...args", |
| 4626 "a,\na, ...args", |
| 4627 NULL}; |
| 4628 static const ParserFlag always_flags[] = {kAllowHarmonyRestParameters}; |
| 4629 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
| 4630 arraysize(always_flags)); |
| 4631 } |
| 4632 |
| 4633 |
4571 TEST(LexicalScopingSloppyMode) { | 4634 TEST(LexicalScopingSloppyMode) { |
4572 const char* context_data[][2] = { | 4635 const char* context_data[][2] = { |
4573 {"", ""}, | 4636 {"", ""}, |
4574 {"function f() {", "}"}, | 4637 {"function f() {", "}"}, |
4575 {"{", "}"}, | 4638 {"{", "}"}, |
4576 {NULL, NULL}}; | 4639 {NULL, NULL}}; |
4577 const char* bad_data[] = { | 4640 const char* bad_data[] = { |
4578 "let x = 1;", | 4641 "let x = 1;", |
4579 "for(let x = 1;;){}", | 4642 "for(let x = 1;;){}", |
4580 "for(let x of []){}", | 4643 "for(let x of []){}", |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4913 "const x = 1;", | 4976 "const x = 1;", |
4914 "class C {}", | 4977 "class C {}", |
4915 NULL}; | 4978 NULL}; |
4916 | 4979 |
4917 static const ParserFlag always_flags[] = { | 4980 static const ParserFlag always_flags[] = { |
4918 kAllowHarmonyClasses, kAllowHarmonyScoping | 4981 kAllowHarmonyClasses, kAllowHarmonyScoping |
4919 }; | 4982 }; |
4920 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, | 4983 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, |
4921 always_flags, arraysize(always_flags)); | 4984 always_flags, arraysize(always_flags)); |
4922 } | 4985 } |
OLD | NEW |