Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: test/cctest/test-parsing.cc

Issue 389503002: Revert "Implement handling of arrow functions in the parser" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/token.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 279
280 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - 280 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() -
281 128 * 1024); 281 128 * 1024);
282 282
283 const char* programs[] = { 283 const char* programs[] = {
284 "{label: 42}", 284 "{label: 42}",
285 "var x = 42;", 285 "var x = 42;",
286 "function foo(x, y) { return x + y; }", 286 "function foo(x, y) { return x + y; }",
287 "%ArgleBargle(glop);", 287 "%ArgleBargle(glop);",
288 "var x = new new Function('this.x = 42');", 288 "var x = new new Function('this.x = 42');",
289 "var f = (x, y) => x + y;",
290 NULL 289 NULL
291 }; 290 };
292 291
293 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); 292 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
294 for (int i = 0; programs[i]; i++) { 293 for (int i = 0; programs[i]; i++) {
295 const char* program = programs[i]; 294 const char* program = programs[i];
296 i::Utf8ToUtf16CharacterStream stream( 295 i::Utf8ToUtf16CharacterStream stream(
297 reinterpret_cast<const i::byte*>(program), 296 reinterpret_cast<const i::byte*>(program),
298 static_cast<unsigned>(strlen(program))); 297 static_cast<unsigned>(strlen(program)));
299 i::CompleteParserRecorder log; 298 i::CompleteParserRecorder log;
300 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 299 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
301 scanner.Initialize(&stream); 300 scanner.Initialize(&stream);
302 301
303 i::PreParser preparser(&scanner, &log, stack_limit); 302 i::PreParser preparser(&scanner, &log, stack_limit);
304 preparser.set_allow_lazy(true); 303 preparser.set_allow_lazy(true);
305 preparser.set_allow_natives_syntax(true); 304 preparser.set_allow_natives_syntax(true);
306 preparser.set_allow_arrow_functions(true);
307 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 305 i::PreParser::PreParseResult result = preparser.PreParseProgram();
308 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 306 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
309 CHECK(!log.HasError()); 307 CHECK(!log.HasError());
310 } 308 }
311 } 309 }
312 310
313 311
314 TEST(StandAlonePreParserNoNatives) { 312 TEST(StandAlonePreParserNoNatives) {
315 v8::V8::Initialize(); 313 v8::V8::Initialize();
316 314
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 } 1178 }
1181 1179
1182 1180
1183 enum ParserFlag { 1181 enum ParserFlag {
1184 kAllowLazy, 1182 kAllowLazy,
1185 kAllowNativesSyntax, 1183 kAllowNativesSyntax,
1186 kAllowHarmonyScoping, 1184 kAllowHarmonyScoping,
1187 kAllowModules, 1185 kAllowModules,
1188 kAllowGenerators, 1186 kAllowGenerators,
1189 kAllowForOf, 1187 kAllowForOf,
1190 kAllowHarmonyNumericLiterals, 1188 kAllowHarmonyNumericLiterals
1191 kAllowArrowFunctions
1192 }; 1189 };
1193 1190
1194 1191
1195 enum ParserSyncTestResult { 1192 enum ParserSyncTestResult {
1196 kSuccessOrError, 1193 kSuccessOrError,
1197 kSuccess, 1194 kSuccess,
1198 kError 1195 kError
1199 }; 1196 };
1200 1197
1201 template <typename Traits> 1198 template <typename Traits>
1202 void SetParserFlags(i::ParserBase<Traits>* parser, 1199 void SetParserFlags(i::ParserBase<Traits>* parser,
1203 i::EnumSet<ParserFlag> flags) { 1200 i::EnumSet<ParserFlag> flags) {
1204 parser->set_allow_lazy(flags.Contains(kAllowLazy)); 1201 parser->set_allow_lazy(flags.Contains(kAllowLazy));
1205 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax)); 1202 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax));
1206 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); 1203 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping));
1207 parser->set_allow_modules(flags.Contains(kAllowModules)); 1204 parser->set_allow_modules(flags.Contains(kAllowModules));
1208 parser->set_allow_generators(flags.Contains(kAllowGenerators)); 1205 parser->set_allow_generators(flags.Contains(kAllowGenerators));
1209 parser->set_allow_for_of(flags.Contains(kAllowForOf)); 1206 parser->set_allow_for_of(flags.Contains(kAllowForOf));
1210 parser->set_allow_harmony_numeric_literals( 1207 parser->set_allow_harmony_numeric_literals(
1211 flags.Contains(kAllowHarmonyNumericLiterals)); 1208 flags.Contains(kAllowHarmonyNumericLiterals));
1212 parser->set_allow_arrow_functions(flags.Contains(kAllowArrowFunctions));
1213 } 1209 }
1214 1210
1215 1211
1216 void TestParserSyncWithFlags(i::Handle<i::String> source, 1212 void TestParserSyncWithFlags(i::Handle<i::String> source,
1217 i::EnumSet<ParserFlag> flags, 1213 i::EnumSet<ParserFlag> flags,
1218 ParserSyncTestResult result) { 1214 ParserSyncTestResult result) {
1219 i::Isolate* isolate = CcTest::i_isolate(); 1215 i::Isolate* isolate = CcTest::i_isolate();
1220 i::Factory* factory = isolate->factory(); 1216 i::Factory* factory = isolate->factory();
1221 1217
1222 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); 1218 uintptr_t stack_limit = isolate->stack_guard()->real_climit();
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 1405
1410 v8::HandleScope handles(CcTest::isolate()); 1406 v8::HandleScope handles(CcTest::isolate());
1411 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 1407 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
1412 v8::Context::Scope context_scope(context); 1408 v8::Context::Scope context_scope(context);
1413 1409
1414 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - 1410 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() -
1415 128 * 1024); 1411 128 * 1024);
1416 1412
1417 static const ParserFlag flags1[] = { 1413 static const ParserFlag flags1[] = {
1418 kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators, 1414 kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators,
1419 kAllowForOf, kAllowArrowFunctions 1415 kAllowForOf
1420 }; 1416 };
1421 for (int i = 0; context_data[i][0] != NULL; ++i) { 1417 for (int i = 0; context_data[i][0] != NULL; ++i) {
1422 for (int j = 0; statement_data[j] != NULL; ++j) { 1418 for (int j = 0; statement_data[j] != NULL; ++j) {
1423 for (int k = 0; termination_data[k] != NULL; ++k) { 1419 for (int k = 0; termination_data[k] != NULL; ++k) {
1424 int kPrefixLen = i::StrLength(context_data[i][0]); 1420 int kPrefixLen = i::StrLength(context_data[i][0]);
1425 int kStatementLen = i::StrLength(statement_data[j]); 1421 int kStatementLen = i::StrLength(statement_data[j]);
1426 int kTerminationLen = i::StrLength(termination_data[k]); 1422 int kTerminationLen = i::StrLength(termination_data[k]);
1427 int kSuffixLen = i::StrLength(context_data[i][1]); 1423 int kSuffixLen = i::StrLength(context_data[i][1]);
1428 int kProgramSize = kPrefixLen + kStatementLen + kTerminationLen 1424 int kProgramSize = kPrefixLen + kStatementLen + kTerminationLen
1429 + kSuffixLen + i::StrLength("label: for (;;) { }"); 1425 + kSuffixLen + i::StrLength("label: for (;;) { }");
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1486 int always_true_flags_len = 0) { 1482 int always_true_flags_len = 0) {
1487 v8::HandleScope handles(CcTest::isolate()); 1483 v8::HandleScope handles(CcTest::isolate());
1488 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 1484 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
1489 v8::Context::Scope context_scope(context); 1485 v8::Context::Scope context_scope(context);
1490 1486
1491 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - 1487 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() -
1492 128 * 1024); 1488 128 * 1024);
1493 1489
1494 static const ParserFlag default_flags[] = { 1490 static const ParserFlag default_flags[] = {
1495 kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators, 1491 kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators,
1496 kAllowForOf, kAllowNativesSyntax, kAllowArrowFunctions 1492 kAllowForOf, kAllowNativesSyntax
1497 }; 1493 };
1498 ParserFlag* generated_flags = NULL; 1494 ParserFlag* generated_flags = NULL;
1499 if (flags == NULL) { 1495 if (flags == NULL) {
1500 flags = default_flags; 1496 flags = default_flags;
1501 flags_len = ARRAY_SIZE(default_flags); 1497 flags_len = ARRAY_SIZE(default_flags);
1502 if (always_true_flags != NULL) { 1498 if (always_true_flags != NULL) {
1503 // Remove always_true_flags from default_flags. 1499 // Remove always_true_flags from default_flags.
1504 CHECK(always_true_flags_len < flags_len); 1500 CHECK(always_true_flags_len < flags_len);
1505 generated_flags = new ParserFlag[flags_len - always_true_flags_len]; 1501 generated_flags = new ParserFlag[flags_len - always_true_flags_len];
1506 int flag_index = 0; 1502 int flag_index = 0;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 "var foo, eval;", 1559 "var foo, eval;",
1564 "var foo, arguments;", 1560 "var foo, arguments;",
1565 "try { } catch (eval) { }", 1561 "try { } catch (eval) { }",
1566 "try { } catch (arguments) { }", 1562 "try { } catch (arguments) { }",
1567 "function eval() { }", 1563 "function eval() { }",
1568 "function arguments() { }", 1564 "function arguments() { }",
1569 "function foo(eval) { }", 1565 "function foo(eval) { }",
1570 "function foo(arguments) { }", 1566 "function foo(arguments) { }",
1571 "function foo(bar, eval) { }", 1567 "function foo(bar, eval) { }",
1572 "function foo(bar, arguments) { }", 1568 "function foo(bar, arguments) { }",
1573 "(eval) => { }",
1574 "(arguments) => { }",
1575 "(foo, eval) => { }",
1576 "(foo, arguments) => { }",
1577 "eval = 1;", 1569 "eval = 1;",
1578 "arguments = 1;", 1570 "arguments = 1;",
1579 "var foo = eval = 1;", 1571 "var foo = eval = 1;",
1580 "var foo = arguments = 1;", 1572 "var foo = arguments = 1;",
1581 "++eval;", 1573 "++eval;",
1582 "++arguments;", 1574 "++arguments;",
1583 "eval++;", 1575 "eval++;",
1584 "arguments++;", 1576 "arguments++;",
1585 NULL 1577 NULL
1586 }; 1578 };
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1623 }; 1615 };
1624 1616
1625 RunParserSyncTest(context_data, statement_data, kSuccess); 1617 RunParserSyncTest(context_data, statement_data, kSuccess);
1626 } 1618 }
1627 1619
1628 1620
1629 TEST(NoErrorsEvalAndArgumentsStrict) { 1621 TEST(NoErrorsEvalAndArgumentsStrict) {
1630 const char* context_data[][2] = { 1622 const char* context_data[][2] = {
1631 { "\"use strict\";", "" }, 1623 { "\"use strict\";", "" },
1632 { "function test_func() { \"use strict\";", "}" }, 1624 { "function test_func() { \"use strict\";", "}" },
1633 { "() => { \"use strict\"; ", "}" },
1634 { NULL, NULL } 1625 { NULL, NULL }
1635 }; 1626 };
1636 1627
1637 const char* statement_data[] = { 1628 const char* statement_data[] = {
1638 "eval;", 1629 "eval;",
1639 "arguments;", 1630 "arguments;",
1640 "var foo = eval;", 1631 "var foo = eval;",
1641 "var foo = arguments;", 1632 "var foo = arguments;",
1642 "var foo = { eval: 1 };", 1633 "var foo = { eval: 1 };",
1643 "var foo = { arguments: 1 };", 1634 "var foo = { arguments: 1 };",
1644 "var foo = { }; foo.eval = {};", 1635 "var foo = { }; foo.eval = {};",
1645 "var foo = { }; foo.arguments = {};", 1636 "var foo = { }; foo.arguments = {};",
1646 NULL 1637 NULL
1647 }; 1638 };
1648 1639
1649 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; 1640 RunParserSyncTest(context_data, statement_data, kSuccess);
1650 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
1651 always_flags, ARRAY_SIZE(always_flags));
1652 } 1641 }
1653 1642
1654 1643
1655 TEST(ErrorsFutureStrictReservedWords) { 1644 TEST(ErrorsFutureStrictReservedWords) {
1656 // Tests that both preparsing and parsing produce the right kind of errors for 1645 // Tests that both preparsing and parsing produce the right kind of errors for
1657 // using future strict reserved words as identifiers. Without the strict mode, 1646 // using future strict reserved words as identifiers. Without the strict mode,
1658 // it's ok to use future strict reserved words as identifiers. With the strict 1647 // it's ok to use future strict reserved words as identifiers. With the strict
1659 // mode, it isn't. 1648 // mode, it isn't.
1660 const char* context_data[][2] = { 1649 const char* context_data[][2] = {
1661 { "\"use strict\";", "" }, 1650 { "\"use strict\";", "" },
1662 { "function test_func() {\"use strict\"; ", "}"}, 1651 { "function test_func() {\"use strict\"; ", "}"},
1663 { "() => { \"use strict\"; ", "}" },
1664 { NULL, NULL } 1652 { NULL, NULL }
1665 }; 1653 };
1666 1654
1667 const char* statement_data[] = { 1655 const char* statement_data[] = {
1668 "var interface;", 1656 "var interface;",
1669 "var foo, interface;", 1657 "var foo, interface;",
1670 "try { } catch (interface) { }", 1658 "try { } catch (interface) { }",
1671 "function interface() { }", 1659 "function interface() { }",
1672 "function foo(interface) { }", 1660 "function foo(interface) { }",
1673 "function foo(bar, interface) { }", 1661 "function foo(bar, interface) { }",
1674 "interface = 1;", 1662 "interface = 1;",
1675 "var foo = interface = 1;", 1663 "var foo = interface = 1;",
1676 "++interface;", 1664 "++interface;",
1677 "interface++;", 1665 "interface++;",
1678 "var yield = 13;", 1666 "var yield = 13;",
1679 NULL 1667 NULL
1680 }; 1668 };
1681 1669
1682 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; 1670 RunParserSyncTest(context_data, statement_data, kError);
1683 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, always_flags,
1684 ARRAY_SIZE(always_flags));
1685 } 1671 }
1686 1672
1687 1673
1688 TEST(NoErrorsFutureStrictReservedWords) { 1674 TEST(NoErrorsFutureStrictReservedWords) {
1689 const char* context_data[][2] = { 1675 const char* context_data[][2] = {
1690 { "", "" }, 1676 { "", "" },
1691 { "function test_func() {", "}"}, 1677 { "function test_func() {", "}"},
1692 { "() => {", "}" },
1693 { NULL, NULL } 1678 { NULL, NULL }
1694 }; 1679 };
1695 1680
1696 const char* statement_data[] = { 1681 const char* statement_data[] = {
1697 "var interface;", 1682 "var interface;",
1698 "var foo, interface;", 1683 "var foo, interface;",
1699 "try { } catch (interface) { }", 1684 "try { } catch (interface) { }",
1700 "function interface() { }", 1685 "function interface() { }",
1701 "function foo(interface) { }", 1686 "function foo(interface) { }",
1702 "function foo(bar, interface) { }", 1687 "function foo(bar, interface) { }",
1703 "interface = 1;", 1688 "interface = 1;",
1704 "var foo = interface = 1;", 1689 "var foo = interface = 1;",
1705 "++interface;", 1690 "++interface;",
1706 "interface++;", 1691 "interface++;",
1707 "var yield = 13;", 1692 "var yield = 13;",
1708 NULL 1693 NULL
1709 }; 1694 };
1710 1695
1711 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; 1696 RunParserSyncTest(context_data, statement_data, kSuccess);
1712 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
1713 always_flags, ARRAY_SIZE(always_flags));
1714 } 1697 }
1715 1698
1716 1699
1717 TEST(ErrorsReservedWords) { 1700 TEST(ErrorsReservedWords) {
1718 // Tests that both preparsing and parsing produce the right kind of errors for 1701 // Tests that both preparsing and parsing produce the right kind of errors for
1719 // using future reserved words as identifiers. These tests don't depend on the 1702 // using future reserved words as identifiers. These tests don't depend on the
1720 // strict mode. 1703 // strict mode.
1721 const char* context_data[][2] = { 1704 const char* context_data[][2] = {
1722 { "", "" }, 1705 { "", "" },
1723 { "\"use strict\";", "" }, 1706 { "\"use strict\";", "" },
1724 { "var eval; function test_func() {", "}"}, 1707 { "var eval; function test_func() {", "}"},
1725 { "var eval; function test_func() {\"use strict\"; ", "}"}, 1708 { "var eval; function test_func() {\"use strict\"; ", "}"},
1726 { "var eval; () => {", "}"},
1727 { "var eval; () => {\"use strict\"; ", "}"},
1728 { NULL, NULL } 1709 { NULL, NULL }
1729 }; 1710 };
1730 1711
1731 const char* statement_data[] = { 1712 const char* statement_data[] = {
1732 "var super;", 1713 "var super;",
1733 "var foo, super;", 1714 "var foo, super;",
1734 "try { } catch (super) { }", 1715 "try { } catch (super) { }",
1735 "function super() { }", 1716 "function super() { }",
1736 "function foo(super) { }", 1717 "function foo(super) { }",
1737 "function foo(bar, super) { }", 1718 "function foo(bar, super) { }",
1738 "(super) => { }",
1739 "(bar, super) => { }",
1740 "super = 1;", 1719 "super = 1;",
1741 "var foo = super = 1;", 1720 "var foo = super = 1;",
1742 "++super;", 1721 "++super;",
1743 "super++;", 1722 "super++;",
1744 "function foo super", 1723 "function foo super",
1745 NULL 1724 NULL
1746 }; 1725 };
1747 1726
1748 RunParserSyncTest(context_data, statement_data, kError); 1727 RunParserSyncTest(context_data, statement_data, kError);
1749 } 1728 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1863 1842
1864 1843
1865 TEST(ErrorsYieldStrict) { 1844 TEST(ErrorsYieldStrict) {
1866 const char* context_data[][2] = { 1845 const char* context_data[][2] = {
1867 { "\"use strict\";", "" }, 1846 { "\"use strict\";", "" },
1868 { "\"use strict\"; function not_gen() {", "}" }, 1847 { "\"use strict\"; function not_gen() {", "}" },
1869 { "function test_func() {\"use strict\"; ", "}"}, 1848 { "function test_func() {\"use strict\"; ", "}"},
1870 { "\"use strict\"; function * gen() { function not_gen() {", "} }" }, 1849 { "\"use strict\"; function * gen() { function not_gen() {", "} }" },
1871 { "\"use strict\"; (function not_gen() {", "})" }, 1850 { "\"use strict\"; (function not_gen() {", "})" },
1872 { "\"use strict\"; (function * gen() { (function not_gen() {", "}) })" }, 1851 { "\"use strict\"; (function * gen() { (function not_gen() {", "}) })" },
1873 { "() => {\"use strict\"; ", "}" },
1874 { NULL, NULL } 1852 { NULL, NULL }
1875 }; 1853 };
1876 1854
1877 const char* statement_data[] = { 1855 const char* statement_data[] = {
1878 "var yield;", 1856 "var yield;",
1879 "var foo, yield;", 1857 "var foo, yield;",
1880 "try { } catch (yield) { }", 1858 "try { } catch (yield) { }",
1881 "function yield() { }", 1859 "function yield() { }",
1882 "(function yield() { })", 1860 "(function yield() { })",
1883 "function foo(yield) { }", 1861 "function foo(yield) { }",
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
2074 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, 2052 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
2075 always_true_flags, 1); 2053 always_true_flags, 1);
2076 } 2054 }
2077 2055
2078 2056
2079 TEST(ErrorsIllegalWordsAsLabelsSloppy) { 2057 TEST(ErrorsIllegalWordsAsLabelsSloppy) {
2080 // Using future reserved words as labels is always an error. 2058 // Using future reserved words as labels is always an error.
2081 const char* context_data[][2] = { 2059 const char* context_data[][2] = {
2082 { "", ""}, 2060 { "", ""},
2083 { "function test_func() {", "}" }, 2061 { "function test_func() {", "}" },
2084 { "() => {", "}" },
2085 { NULL, NULL } 2062 { NULL, NULL }
2086 }; 2063 };
2087 2064
2088 const char* statement_data[] = { 2065 const char* statement_data[] = {
2089 "super: while(true) { break super; }", 2066 "super: while(true) { break super; }",
2090 NULL 2067 NULL
2091 }; 2068 };
2092 2069
2093 RunParserSyncTest(context_data, statement_data, kError); 2070 RunParserSyncTest(context_data, statement_data, kError);
2094 } 2071 }
2095 2072
2096 2073
2097 TEST(ErrorsIllegalWordsAsLabelsStrict) { 2074 TEST(ErrorsIllegalWordsAsLabelsStrict) {
2098 // Tests that illegal tokens as labels produce the correct errors. 2075 // Tests that illegal tokens as labels produce the correct errors.
2099 const char* context_data[][2] = { 2076 const char* context_data[][2] = {
2100 { "\"use strict\";", "" }, 2077 { "\"use strict\";", "" },
2101 { "function test_func() {\"use strict\"; ", "}"}, 2078 { "function test_func() {\"use strict\"; ", "}"},
2102 { "() => {\"use strict\"; ", "}" },
2103 { NULL, NULL } 2079 { NULL, NULL }
2104 }; 2080 };
2105 2081
2106 const char* statement_data[] = { 2082 const char* statement_data[] = {
2107 "super: while(true) { break super; }", 2083 "super: while(true) { break super; }",
2108 "interface: while(true) { break interface; }", 2084 "interface: while(true) { break interface; }",
2109 "yield: while(true) { break yield; }", 2085 "yield: while(true) { break yield; }",
2110 NULL 2086 NULL
2111 }; 2087 };
2112 2088
2113 RunParserSyncTest(context_data, statement_data, kError); 2089 RunParserSyncTest(context_data, statement_data, kError);
2114 } 2090 }
2115 2091
2116 2092
2117 TEST(NoErrorsIllegalWordsAsLabels) { 2093 TEST(NoErrorsIllegalWordsAsLabels) {
2118 // Using eval and arguments as labels is legal even in strict mode. 2094 // Using eval and arguments as labels is legal even in strict mode.
2119 const char* context_data[][2] = { 2095 const char* context_data[][2] = {
2120 { "", ""}, 2096 { "", ""},
2121 { "function test_func() {", "}" }, 2097 { "function test_func() {", "}" },
2122 { "() => {", "}" },
2123 { "\"use strict\";", "" }, 2098 { "\"use strict\";", "" },
2124 { "\"use strict\"; function test_func() {", "}" }, 2099 { "\"use strict\"; function test_func() {", "}" },
2125 { "\"use strict\"; () => {", "}" },
2126 { NULL, NULL } 2100 { NULL, NULL }
2127 }; 2101 };
2128 2102
2129 const char* statement_data[] = { 2103 const char* statement_data[] = {
2130 "mylabel: while(true) { break mylabel; }", 2104 "mylabel: while(true) { break mylabel; }",
2131 "eval: while(true) { break eval; }", 2105 "eval: while(true) { break eval; }",
2132 "arguments: while(true) { break arguments; }", 2106 "arguments: while(true) { break arguments; }",
2133 NULL 2107 NULL
2134 }; 2108 };
2135 2109
2136 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; 2110 RunParserSyncTest(context_data, statement_data, kSuccess);
2137 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
2138 always_flags, ARRAY_SIZE(always_flags));
2139 } 2111 }
2140 2112
2141 2113
2142 TEST(ErrorsParenthesizedLabels) { 2114 TEST(ErrorsParenthesizedLabels) {
2143 // Parenthesized identifiers shouldn't be recognized as labels. 2115 // Parenthesized identifiers shouldn't be recognized as labels.
2144 const char* context_data[][2] = { 2116 const char* context_data[][2] = {
2145 { "", ""}, 2117 { "", ""},
2146 { "function test_func() {", "}" }, 2118 { "function test_func() {", "}" },
2147 { "() => {", "}" },
2148 { NULL, NULL } 2119 { NULL, NULL }
2149 }; 2120 };
2150 2121
2151 const char* statement_data[] = { 2122 const char* statement_data[] = {
2152 "(mylabel): while(true) { break mylabel; }", 2123 "(mylabel): while(true) { break mylabel; }",
2153 NULL 2124 NULL
2154 }; 2125 };
2155 2126
2156 RunParserSyncTest(context_data, statement_data, kError); 2127 RunParserSyncTest(context_data, statement_data, kError);
2157 } 2128 }
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after
2978 LocalContext env; 2949 LocalContext env;
2979 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {}; 2950 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {};
2980 global_use_counts = use_counts; 2951 global_use_counts = use_counts;
2981 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback); 2952 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback);
2982 CompileRun("\"use asm\";\n" 2953 CompileRun("\"use asm\";\n"
2983 "var foo = 1;\n" 2954 "var foo = 1;\n"
2984 "\"use asm\";\n" // Only the first one counts. 2955 "\"use asm\";\n" // Only the first one counts.
2985 "function bar() { \"use asm\"; var baz = 1; }"); 2956 "function bar() { \"use asm\"; var baz = 1; }");
2986 CHECK_EQ(2, use_counts[v8::Isolate::kUseAsm]); 2957 CHECK_EQ(2, use_counts[v8::Isolate::kUseAsm]);
2987 } 2958 }
2988
2989
2990 TEST(ErrorsArrowFunctions) {
2991 // Tests that parser and preparser generate the same kind of errors
2992 // on invalid arrow function syntax.
2993 const char* context_data[][2] = {
2994 {"", ";"},
2995 {"v = ", ";"},
2996 {"bar ? (", ") : baz;"},
2997 {"bar ? baz : (", ");"},
2998 {"bar[", "];"},
2999 {"bar, ", ";"},
3000 {"", ", bar;"},
3001 {NULL, NULL}
3002 };
3003
3004 const char* statement_data[] = {
3005 "=> 0",
3006 "=>",
3007 "() =>",
3008 "=> {}",
3009 ") => {}",
3010 ", => {}",
3011 "(,) => {}",
3012 "return => {}",
3013 "() => {'value': 42}",
3014
3015 // Check that the early return introduced in ParsePrimaryExpression
3016 // does not accept stray closing parentheses.
3017 ")",
3018 ") => 0",
3019 "foo[()]",
3020 "()",
3021
3022 // Parameter lists with extra parens should be recognized as errors.
3023 "(()) => 0",
3024 "((x)) => 0",
3025 "((x, y)) => 0",
3026 "(x, (y)) => 0",
3027 "((x, y, z)) => 0",
3028 "(x, (y, z)) => 0",
3029 "((x, y), z) => 0",
3030
3031 // Parameter lists are always validated as strict, so those are errors.
3032 "eval => {}",
3033 "arguments => {}",
3034 "yield => {}",
3035 "interface => {}",
3036 "(eval) => {}",
3037 "(arguments) => {}",
3038 "(yield) => {}",
3039 "(interface) => {}",
3040 "(eval, bar) => {}",
3041 "(bar, eval) => {}",
3042 "(bar, arguments) => {}",
3043 "(bar, yield) => {}",
3044 "(bar, interface) => {}",
3045 // TODO(aperez): Detecting duplicates does not work in PreParser.
3046 // "(bar, bar) => {}",
3047
3048 // The parameter list is parsed as an expression, but only
3049 // a comma-separated list of identifier is valid.
3050 "32 => {}",
3051 "(32) => {}",
3052 "(a, 32) => {}",
3053 "if => {}",
3054 "(if) => {}",
3055 "(a, if) => {}",
3056 "a + b => {}",
3057 "(a + b) => {}",
3058 "(a + b, c) => {}",
3059 "(a, b - c) => {}",
3060 "\"a\" => {}",
3061 "(\"a\") => {}",
3062 "(\"a\", b) => {}",
3063 "(a, \"b\") => {}",
3064 "-a => {}",
3065 "(-a) => {}",
3066 "(-a, b) => {}",
3067 "(a, -b) => {}",
3068 "{} => {}",
3069 "({}) => {}",
3070 "(a, {}) => {}",
3071 "({}, a) => {}",
3072 "a++ => {}",
3073 "(a++) => {}",
3074 "(a++, b) => {}",
3075 "(a, b++) => {}",
3076 "[] => {}",
3077 "([]) => {}",
3078 "(a, []) => {}",
3079 "([], a) => {}",
3080 "(a = b) => {}",
3081 "(a = b, c) => {}",
3082 "(a, b = c) => {}",
3083 "(foo ? bar : baz) => {}",
3084 "(a, foo ? bar : baz) => {}",
3085 "(foo ? bar : baz, a) => {}",
3086 NULL
3087 };
3088
3089 RunParserSyncTest(context_data, statement_data, kError);
3090 }
3091
3092
3093 TEST(NoErrorsArrowFunctions) {
3094 // Tests that parser and preparser accept valid arrow functions syntax.
3095 const char* context_data[][2] = {
3096 {"", ";"},
3097 {"bar ? (", ") : baz;"},
3098 {"bar ? baz : (", ");"},
3099 {"bar, ", ";"},
3100 {"", ", bar;"},
3101 {NULL, NULL}
3102 };
3103
3104 const char* statement_data[] = {
3105 "() => {}",
3106 "() => { return 42 }",
3107 "x => { return x; }",
3108 "(x) => { return x; }",
3109 "(x, y) => { return x + y; }",
3110 "(x, y, z) => { return x + y + z; }",
3111 "(x, y) => { x.a = y; }",
3112 "() => 42",
3113 "x => x",
3114 "x => x * x",
3115 "(x) => x",
3116 "(x) => x * x",
3117 "(x, y) => x + y",
3118 "(x, y, z) => x, y, z",
3119 "(x, y) => x.a = y",
3120 "() => ({'value': 42})",
3121 "x => y => x + y",
3122 "(x, y) => (u, v) => x*u + y*v",
3123 "(x, y) => z => z * (x + y)",
3124 "x => (y, z) => z * (x + y)",
3125
3126 // Those are comma-separated expressions, with arrow functions as items.
3127 // They stress the code for validating arrow function parameter lists.
3128 "a, b => 0",
3129 "a, b, (c, d) => 0",
3130 "(a, b, (c, d) => 0)",
3131 "(a, b) => 0, (c, d) => 1",
3132 "(a, b => {}, a => a + 1)",
3133 "((a, b) => {}, (a => a + 1))",
3134 "(a, (a, (b, c) => 0))",
3135
3136 // Arrow has more precedence, this is the same as: foo ? bar : (baz = {})
3137 "foo ? bar : baz => {}",
3138 NULL
3139 };
3140
3141 static const ParserFlag always_flags[] = {kAllowArrowFunctions};
3142 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
3143 always_flags, ARRAY_SIZE(always_flags));
3144 }
OLDNEW
« no previous file with comments | « src/token.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698