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

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

Issue 372983003: 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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 } 276 }
277 277
278 278
279 TEST(StandAlonePreParser) { 279 TEST(StandAlonePreParser) {
280 v8::V8::Initialize(); 280 v8::V8::Initialize();
281 281
282 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - 282 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() -
283 128 * 1024); 283 128 * 1024);
284 284
285 const char* programs[] = { 285 const char* programs[] = {
286 "{label: 42}", "var x = 42;", 286 "{label: 42}",
287 "function foo(x, y) { return x + y; }", "%ArgleBargle(glop);", 287 "var x = 42;",
288 "var x = new new Function('this.x = 42');", "var f = (x, y) => x + y;", 288 "function foo(x, y) { return x + y; }",
289 NULL}; 289 "%ArgleBargle(glop);",
290 "var x = new new Function('this.x = 42');",
291 NULL
292 };
290 293
291 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); 294 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
292 for (int i = 0; programs[i]; i++) { 295 for (int i = 0; programs[i]; i++) {
293 const char* program = programs[i]; 296 const char* program = programs[i];
294 i::Utf8ToUtf16CharacterStream stream( 297 i::Utf8ToUtf16CharacterStream stream(
295 reinterpret_cast<const i::byte*>(program), 298 reinterpret_cast<const i::byte*>(program),
296 static_cast<unsigned>(strlen(program))); 299 static_cast<unsigned>(strlen(program)));
297 i::CompleteParserRecorder log; 300 i::CompleteParserRecorder log;
298 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 301 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
299 scanner.Initialize(&stream); 302 scanner.Initialize(&stream);
300 303
301 i::PreParser preparser(&scanner, &log, stack_limit); 304 i::PreParser preparser(&scanner, &log, stack_limit);
302 preparser.set_allow_lazy(true); 305 preparser.set_allow_lazy(true);
303 preparser.set_allow_natives_syntax(true); 306 preparser.set_allow_natives_syntax(true);
304 preparser.set_allow_arrow_functions(true);
305 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 307 i::PreParser::PreParseResult result = preparser.PreParseProgram();
306 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 308 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
307 i::ScriptData data(log.ExtractData()); 309 i::ScriptData data(log.ExtractData());
308 CHECK(!data.has_error()); 310 CHECK(!data.has_error());
309 } 311 }
310 } 312 }
311 313
312 314
313 TEST(StandAlonePreParserNoNatives) { 315 TEST(StandAlonePreParserNoNatives) {
314 v8::V8::Initialize(); 316 v8::V8::Initialize();
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 } 1161 }
1160 1162
1161 1163
1162 enum ParserFlag { 1164 enum ParserFlag {
1163 kAllowLazy, 1165 kAllowLazy,
1164 kAllowNativesSyntax, 1166 kAllowNativesSyntax,
1165 kAllowHarmonyScoping, 1167 kAllowHarmonyScoping,
1166 kAllowModules, 1168 kAllowModules,
1167 kAllowGenerators, 1169 kAllowGenerators,
1168 kAllowForOf, 1170 kAllowForOf,
1169 kAllowHarmonyNumericLiterals, 1171 kAllowHarmonyNumericLiterals
1170 kAllowArrowFunctions
1171 }; 1172 };
1172 1173
1173 1174
1174 enum ParserSyncTestResult { 1175 enum ParserSyncTestResult {
1175 kSuccessOrError, 1176 kSuccessOrError,
1176 kSuccess, 1177 kSuccess,
1177 kError 1178 kError
1178 }; 1179 };
1179 1180
1180 template <typename Traits> 1181 template <typename Traits>
1181 void SetParserFlags(i::ParserBase<Traits>* parser, 1182 void SetParserFlags(i::ParserBase<Traits>* parser,
1182 i::EnumSet<ParserFlag> flags) { 1183 i::EnumSet<ParserFlag> flags) {
1183 parser->set_allow_lazy(flags.Contains(kAllowLazy)); 1184 parser->set_allow_lazy(flags.Contains(kAllowLazy));
1184 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax)); 1185 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax));
1185 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); 1186 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping));
1186 parser->set_allow_modules(flags.Contains(kAllowModules)); 1187 parser->set_allow_modules(flags.Contains(kAllowModules));
1187 parser->set_allow_generators(flags.Contains(kAllowGenerators)); 1188 parser->set_allow_generators(flags.Contains(kAllowGenerators));
1188 parser->set_allow_for_of(flags.Contains(kAllowForOf)); 1189 parser->set_allow_for_of(flags.Contains(kAllowForOf));
1189 parser->set_allow_harmony_numeric_literals( 1190 parser->set_allow_harmony_numeric_literals(
1190 flags.Contains(kAllowHarmonyNumericLiterals)); 1191 flags.Contains(kAllowHarmonyNumericLiterals));
1191 parser->set_allow_arrow_functions(flags.Contains(kAllowArrowFunctions));
1192 } 1192 }
1193 1193
1194 1194
1195 void TestParserSyncWithFlags(i::Handle<i::String> source, 1195 void TestParserSyncWithFlags(i::Handle<i::String> source,
1196 i::EnumSet<ParserFlag> flags, 1196 i::EnumSet<ParserFlag> flags,
1197 ParserSyncTestResult result) { 1197 ParserSyncTestResult result) {
1198 i::Isolate* isolate = CcTest::i_isolate(); 1198 i::Isolate* isolate = CcTest::i_isolate();
1199 i::Factory* factory = isolate->factory(); 1199 i::Factory* factory = isolate->factory();
1200 1200
1201 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); 1201 uintptr_t stack_limit = isolate->stack_guard()->real_climit();
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 NULL 1383 NULL
1384 }; 1384 };
1385 1385
1386 v8::HandleScope handles(CcTest::isolate()); 1386 v8::HandleScope handles(CcTest::isolate());
1387 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 1387 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
1388 v8::Context::Scope context_scope(context); 1388 v8::Context::Scope context_scope(context);
1389 1389
1390 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - 1390 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() -
1391 128 * 1024); 1391 128 * 1024);
1392 1392
1393 static const ParserFlag flags1[] = {kAllowLazy, kAllowHarmonyScoping, 1393 static const ParserFlag flags1[] = {
1394 kAllowModules, kAllowGenerators, 1394 kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators,
1395 kAllowForOf, kAllowArrowFunctions}; 1395 kAllowForOf
1396 };
1396 for (int i = 0; context_data[i][0] != NULL; ++i) { 1397 for (int i = 0; context_data[i][0] != NULL; ++i) {
1397 for (int j = 0; statement_data[j] != NULL; ++j) { 1398 for (int j = 0; statement_data[j] != NULL; ++j) {
1398 for (int k = 0; termination_data[k] != NULL; ++k) { 1399 for (int k = 0; termination_data[k] != NULL; ++k) {
1399 int kPrefixLen = i::StrLength(context_data[i][0]); 1400 int kPrefixLen = i::StrLength(context_data[i][0]);
1400 int kStatementLen = i::StrLength(statement_data[j]); 1401 int kStatementLen = i::StrLength(statement_data[j]);
1401 int kTerminationLen = i::StrLength(termination_data[k]); 1402 int kTerminationLen = i::StrLength(termination_data[k]);
1402 int kSuffixLen = i::StrLength(context_data[i][1]); 1403 int kSuffixLen = i::StrLength(context_data[i][1]);
1403 int kProgramSize = kPrefixLen + kStatementLen + kTerminationLen 1404 int kProgramSize = kPrefixLen + kStatementLen + kTerminationLen
1404 + kSuffixLen + i::StrLength("label: for (;;) { }"); 1405 + kSuffixLen + i::StrLength("label: for (;;) { }");
1405 1406
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1460 const ParserFlag* always_true_flags = NULL, 1461 const ParserFlag* always_true_flags = NULL,
1461 int always_true_flags_len = 0) { 1462 int always_true_flags_len = 0) {
1462 v8::HandleScope handles(CcTest::isolate()); 1463 v8::HandleScope handles(CcTest::isolate());
1463 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 1464 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
1464 v8::Context::Scope context_scope(context); 1465 v8::Context::Scope context_scope(context);
1465 1466
1466 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - 1467 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() -
1467 128 * 1024); 1468 128 * 1024);
1468 1469
1469 static const ParserFlag default_flags[] = { 1470 static const ParserFlag default_flags[] = {
1470 kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators, 1471 kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators,
1471 kAllowForOf, kAllowNativesSyntax, kAllowArrowFunctions}; 1472 kAllowForOf, kAllowNativesSyntax
1473 };
1472 ParserFlag* generated_flags = NULL; 1474 ParserFlag* generated_flags = NULL;
1473 if (flags == NULL) { 1475 if (flags == NULL) {
1474 flags = default_flags; 1476 flags = default_flags;
1475 flags_len = ARRAY_SIZE(default_flags); 1477 flags_len = ARRAY_SIZE(default_flags);
1476 if (always_true_flags != NULL) { 1478 if (always_true_flags != NULL) {
1477 // Remove always_true_flags from default_flags. 1479 // Remove always_true_flags from default_flags.
1478 CHECK(always_true_flags_len < flags_len); 1480 CHECK(always_true_flags_len < flags_len);
1479 generated_flags = new ParserFlag[flags_len - always_true_flags_len]; 1481 generated_flags = new ParserFlag[flags_len - always_true_flags_len];
1480 int flag_index = 0; 1482 int flag_index = 0;
1481 for (int i = 0; i < flags_len; ++i) { 1483 for (int i = 0; i < flags_len; ++i) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1525 // using "eval" and "arguments" as identifiers. Without the strict mode, it's 1527 // using "eval" and "arguments" as identifiers. Without the strict mode, it's
1526 // ok to use "eval" or "arguments" as identifiers. With the strict mode, it 1528 // ok to use "eval" or "arguments" as identifiers. With the strict mode, it
1527 // isn't. 1529 // isn't.
1528 const char* context_data[][2] = { 1530 const char* context_data[][2] = {
1529 { "\"use strict\";", "" }, 1531 { "\"use strict\";", "" },
1530 { "var eval; function test_func() {\"use strict\"; ", "}"}, 1532 { "var eval; function test_func() {\"use strict\"; ", "}"},
1531 { NULL, NULL } 1533 { NULL, NULL }
1532 }; 1534 };
1533 1535
1534 const char* statement_data[] = { 1536 const char* statement_data[] = {
1535 "var eval;", "var arguments", 1537 "var eval;",
1536 "var foo, eval;", "var foo, arguments;", 1538 "var arguments",
1537 "try { } catch (eval) { }", "try { } catch (arguments) { }", 1539 "var foo, eval;",
1538 "function eval() { }", "function arguments() { }", 1540 "var foo, arguments;",
1539 "function foo(eval) { }", "function foo(arguments) { }", 1541 "try { } catch (eval) { }",
1540 "function foo(bar, eval) { }", "function foo(bar, arguments) { }", 1542 "try { } catch (arguments) { }",
1541 "(eval) => { }", "(arguments) => { }", 1543 "function eval() { }",
1542 "(foo, eval) => { }", "(foo, arguments) => { }", 1544 "function arguments() { }",
1543 "eval = 1;", "arguments = 1;", 1545 "function foo(eval) { }",
1544 "var foo = eval = 1;", "var foo = arguments = 1;", 1546 "function foo(arguments) { }",
1545 "++eval;", "++arguments;", 1547 "function foo(bar, eval) { }",
1546 "eval++;", "arguments++;", 1548 "function foo(bar, arguments) { }",
1547 NULL}; 1549 "eval = 1;",
1550 "arguments = 1;",
1551 "var foo = eval = 1;",
1552 "var foo = arguments = 1;",
1553 "++eval;",
1554 "++arguments;",
1555 "eval++;",
1556 "arguments++;",
1557 NULL
1558 };
1548 1559
1549 RunParserSyncTest(context_data, statement_data, kError); 1560 RunParserSyncTest(context_data, statement_data, kError);
1550 } 1561 }
1551 1562
1552 1563
1553 TEST(NoErrorsEvalAndArgumentsSloppy) { 1564 TEST(NoErrorsEvalAndArgumentsSloppy) {
1554 // Tests that both preparsing and parsing accept "eval" and "arguments" as 1565 // Tests that both preparsing and parsing accept "eval" and "arguments" as
1555 // identifiers when needed. 1566 // identifiers when needed.
1556 const char* context_data[][2] = { 1567 const char* context_data[][2] = {
1557 { "", "" }, 1568 { "", "" },
(...skipping 24 matching lines...) Expand all
1582 "arguments++;", 1593 "arguments++;",
1583 NULL 1594 NULL
1584 }; 1595 };
1585 1596
1586 RunParserSyncTest(context_data, statement_data, kSuccess); 1597 RunParserSyncTest(context_data, statement_data, kSuccess);
1587 } 1598 }
1588 1599
1589 1600
1590 TEST(NoErrorsEvalAndArgumentsStrict) { 1601 TEST(NoErrorsEvalAndArgumentsStrict) {
1591 const char* context_data[][2] = { 1602 const char* context_data[][2] = {
1592 {"\"use strict\";", ""}, 1603 { "\"use strict\";", "" },
1593 {"function test_func() { \"use strict\";", "}"}, 1604 { "function test_func() { \"use strict\";", "}" },
1594 {"() => { \"use strict\"; ", "}"}, 1605 { NULL, NULL }
1595 {NULL, NULL}}; 1606 };
1596 1607
1597 const char* statement_data[] = { 1608 const char* statement_data[] = {
1598 "eval;", 1609 "eval;",
1599 "arguments;", 1610 "arguments;",
1600 "var foo = eval;", 1611 "var foo = eval;",
1601 "var foo = arguments;", 1612 "var foo = arguments;",
1602 "var foo = { eval: 1 };", 1613 "var foo = { eval: 1 };",
1603 "var foo = { arguments: 1 };", 1614 "var foo = { arguments: 1 };",
1604 "var foo = { }; foo.eval = {};", 1615 "var foo = { }; foo.eval = {};",
1605 "var foo = { }; foo.arguments = {};", 1616 "var foo = { }; foo.arguments = {};",
1606 NULL 1617 NULL
1607 }; 1618 };
1608 1619
1609 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; 1620 RunParserSyncTest(context_data, statement_data, kSuccess);
1610 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
1611 always_flags, ARRAY_SIZE(always_flags));
1612 } 1621 }
1613 1622
1614 1623
1615 TEST(ErrorsFutureStrictReservedWords) { 1624 TEST(ErrorsFutureStrictReservedWords) {
1616 // Tests that both preparsing and parsing produce the right kind of errors for 1625 // Tests that both preparsing and parsing produce the right kind of errors for
1617 // using future strict reserved words as identifiers. Without the strict mode, 1626 // using future strict reserved words as identifiers. Without the strict mode,
1618 // it's ok to use future strict reserved words as identifiers. With the strict 1627 // it's ok to use future strict reserved words as identifiers. With the strict
1619 // mode, it isn't. 1628 // mode, it isn't.
1620 const char* context_data[][2] = { 1629 const char* context_data[][2] = {
1621 {"\"use strict\";", ""}, 1630 { "\"use strict\";", "" },
1622 {"function test_func() {\"use strict\"; ", "}"}, 1631 { "function test_func() {\"use strict\"; ", "}"},
1623 {"() => { \"use strict\"; ", "}"}, 1632 { NULL, NULL }
1624 {NULL, NULL}}; 1633 };
1625 1634
1626 const char* statement_data[] = { 1635 const char* statement_data[] = {
1627 "var interface;", 1636 "var interface;",
1628 "var foo, interface;", 1637 "var foo, interface;",
1629 "try { } catch (interface) { }", 1638 "try { } catch (interface) { }",
1630 "function interface() { }", 1639 "function interface() { }",
1631 "function foo(interface) { }", 1640 "function foo(interface) { }",
1632 "function foo(bar, interface) { }", 1641 "function foo(bar, interface) { }",
1633 "interface = 1;", 1642 "interface = 1;",
1634 "var foo = interface = 1;", 1643 "var foo = interface = 1;",
1635 "++interface;", 1644 "++interface;",
1636 "interface++;", 1645 "interface++;",
1637 "var yield = 13;", 1646 "var yield = 13;",
1638 NULL 1647 NULL
1639 }; 1648 };
1640 1649
1641 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; 1650 RunParserSyncTest(context_data, statement_data, kError);
1642 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, always_flags,
1643 ARRAY_SIZE(always_flags));
1644 } 1651 }
1645 1652
1646 1653
1647 TEST(NoErrorsFutureStrictReservedWords) { 1654 TEST(NoErrorsFutureStrictReservedWords) {
1648 const char* context_data[][2] = {{"", ""}, 1655 const char* context_data[][2] = {
1649 {"function test_func() {", "}"}, 1656 { "", "" },
1650 {"() => {", "}"}, 1657 { "function test_func() {", "}"},
1651 {NULL, NULL}}; 1658 { NULL, NULL }
1659 };
1652 1660
1653 const char* statement_data[] = { 1661 const char* statement_data[] = {
1654 "var interface;", 1662 "var interface;",
1655 "var foo, interface;", 1663 "var foo, interface;",
1656 "try { } catch (interface) { }", 1664 "try { } catch (interface) { }",
1657 "function interface() { }", 1665 "function interface() { }",
1658 "function foo(interface) { }", 1666 "function foo(interface) { }",
1659 "function foo(bar, interface) { }", 1667 "function foo(bar, interface) { }",
1660 "interface = 1;", 1668 "interface = 1;",
1661 "var foo = interface = 1;", 1669 "var foo = interface = 1;",
1662 "++interface;", 1670 "++interface;",
1663 "interface++;", 1671 "interface++;",
1664 "var yield = 13;", 1672 "var yield = 13;",
1665 NULL 1673 NULL
1666 }; 1674 };
1667 1675
1668 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; 1676 RunParserSyncTest(context_data, statement_data, kSuccess);
1669 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
1670 always_flags, ARRAY_SIZE(always_flags));
1671 } 1677 }
1672 1678
1673 1679
1674 TEST(ErrorsReservedWords) { 1680 TEST(ErrorsReservedWords) {
1675 // Tests that both preparsing and parsing produce the right kind of errors for 1681 // Tests that both preparsing and parsing produce the right kind of errors for
1676 // using future reserved words as identifiers. These tests don't depend on the 1682 // using future reserved words as identifiers. These tests don't depend on the
1677 // strict mode. 1683 // strict mode.
1678 const char* context_data[][2] = { 1684 const char* context_data[][2] = {
1679 {"", ""}, 1685 { "", "" },
1680 {"\"use strict\";", ""}, 1686 { "\"use strict\";", "" },
1681 {"var eval; function test_func() {", "}"}, 1687 { "var eval; function test_func() {", "}"},
1682 {"var eval; function test_func() {\"use strict\"; ", "}"}, 1688 { "var eval; function test_func() {\"use strict\"; ", "}"},
1683 {"var eval; () => {", "}"}, 1689 { NULL, NULL }
1684 {"var eval; () => {\"use strict\"; ", "}"}, 1690 };
1685 {NULL, NULL}};
1686 1691
1687 const char* statement_data[] = { 1692 const char* statement_data[] = {
1688 "var super;", "var foo, super;", 1693 "var super;",
1689 "try { } catch (super) { }", "function super() { }", 1694 "var foo, super;",
1690 "function foo(super) { }", "function foo(bar, super) { }", 1695 "try { } catch (super) { }",
1691 "(super) => { }", "(bar, super) => { }", 1696 "function super() { }",
1692 "super = 1;", "var foo = super = 1;", 1697 "function foo(super) { }",
1693 "++super;", "super++;", 1698 "function foo(bar, super) { }",
1694 "function foo super", NULL}; 1699 "super = 1;",
1700 "var foo = super = 1;",
1701 "++super;",
1702 "super++;",
1703 "function foo super",
1704 NULL
1705 };
1695 1706
1696 RunParserSyncTest(context_data, statement_data, kError); 1707 RunParserSyncTest(context_data, statement_data, kError);
1697 } 1708 }
1698 1709
1699 1710
1700 TEST(NoErrorsYieldSloppyAllModes) { 1711 TEST(NoErrorsYieldSloppyAllModes) {
1701 // In sloppy mode, it's okay to use "yield" as identifier, *except* inside a 1712 // In sloppy mode, it's okay to use "yield" as identifier, *except* inside a
1702 // generator (see next test). 1713 // generator (see next test).
1703 const char* context_data[][2] = { 1714 const char* context_data[][2] = {
1704 { "", "" }, 1715 { "", "" },
(...skipping 15 matching lines...) Expand all
1720 "++yield;", 1731 "++yield;",
1721 "yield++;", 1732 "yield++;",
1722 "yield: 34", 1733 "yield: 34",
1723 "function yield(yield) { yield: yield (yield + yield (0)); }", 1734 "function yield(yield) { yield: yield (yield + yield (0)); }",
1724 "({ yield: 1 })", 1735 "({ yield: 1 })",
1725 "({ get yield() { 1 } })", 1736 "({ get yield() { 1 } })",
1726 "yield (100)", 1737 "yield (100)",
1727 NULL 1738 NULL
1728 }; 1739 };
1729 1740
1730 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; 1741 RunParserSyncTest(context_data, statement_data, kSuccess);
1731 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
1732 always_flags, ARRAY_SIZE(always_flags));
1733 } 1742 }
1734 1743
1735 1744
1736 TEST(NoErrorsYieldSloppyGeneratorsEnabled) { 1745 TEST(NoErrorsYieldSloppyGeneratorsEnabled) {
1737 // In sloppy mode, it's okay to use "yield" as identifier, *except* inside a 1746 // In sloppy mode, it's okay to use "yield" as identifier, *except* inside a
1738 // generator (see next test). 1747 // generator (see next test).
1739 const char* context_data[][2] = { 1748 const char* context_data[][2] = {
1740 { "", "" }, 1749 { "", "" },
1741 { "function not_gen() {", "}" }, 1750 { "function not_gen() {", "}" },
1742 { "function * gen() { function not_gen() {", "} }" }, 1751 { "function * gen() { function not_gen() {", "} }" },
(...skipping 28 matching lines...) Expand all
1771 static const ParserFlag always_true_flags[] = { 1780 static const ParserFlag always_true_flags[] = {
1772 kAllowGenerators 1781 kAllowGenerators
1773 }; 1782 };
1774 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, 1783 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
1775 always_true_flags, 1); 1784 always_true_flags, 1);
1776 } 1785 }
1777 1786
1778 1787
1779 TEST(ErrorsYieldStrict) { 1788 TEST(ErrorsYieldStrict) {
1780 const char* context_data[][2] = { 1789 const char* context_data[][2] = {
1781 {"\"use strict\";", ""}, 1790 { "\"use strict\";", "" },
1782 {"\"use strict\"; function not_gen() {", "}"}, 1791 { "\"use strict\"; function not_gen() {", "}" },
1783 {"function test_func() {\"use strict\"; ", "}"}, 1792 { "function test_func() {\"use strict\"; ", "}"},
1784 {"\"use strict\"; function * gen() { function not_gen() {", "} }"}, 1793 { "\"use strict\"; function * gen() { function not_gen() {", "} }" },
1785 {"\"use strict\"; (function not_gen() {", "})"}, 1794 { "\"use strict\"; (function not_gen() {", "})" },
1786 {"\"use strict\"; (function * gen() { (function not_gen() {", "}) })"}, 1795 { "\"use strict\"; (function * gen() { (function not_gen() {", "}) })" },
1787 {"() => {\"use strict\"; ", "}"}, 1796 { NULL, NULL }
1788 {NULL, NULL}}; 1797 };
1789 1798
1790 const char* statement_data[] = { 1799 const char* statement_data[] = {
1791 "var yield;", 1800 "var yield;",
1792 "var foo, yield;", 1801 "var foo, yield;",
1793 "try { } catch (yield) { }", 1802 "try { } catch (yield) { }",
1794 "function yield() { }", 1803 "function yield() { }",
1795 "(function yield() { })", 1804 "(function yield() { })",
1796 "function foo(yield) { }", 1805 "function foo(yield) { }",
1797 "function foo(bar, yield) { }", 1806 "function foo(bar, yield) { }",
1798 "function * yield() { }", 1807 "function * yield() { }",
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1984 static const ParserFlag always_true_flags[] = { 1993 static const ParserFlag always_true_flags[] = {
1985 kAllowGenerators 1994 kAllowGenerators
1986 }; 1995 };
1987 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, 1996 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
1988 always_true_flags, 1); 1997 always_true_flags, 1);
1989 } 1998 }
1990 1999
1991 2000
1992 TEST(ErrorsIllegalWordsAsLabelsSloppy) { 2001 TEST(ErrorsIllegalWordsAsLabelsSloppy) {
1993 // Using future reserved words as labels is always an error. 2002 // Using future reserved words as labels is always an error.
1994 const char* context_data[][2] = {{"", ""}, 2003 const char* context_data[][2] = {
1995 {"function test_func() {", "}"}, 2004 { "", ""},
1996 {"() => {", "}"}, 2005 { "function test_func() {", "}" },
1997 {NULL, NULL}}; 2006 { NULL, NULL }
2007 };
1998 2008
1999 const char* statement_data[] = { 2009 const char* statement_data[] = {
2000 "super: while(true) { break super; }", 2010 "super: while(true) { break super; }",
2001 NULL 2011 NULL
2002 }; 2012 };
2003 2013
2004 RunParserSyncTest(context_data, statement_data, kError); 2014 RunParserSyncTest(context_data, statement_data, kError);
2005 } 2015 }
2006 2016
2007 2017
2008 TEST(ErrorsIllegalWordsAsLabelsStrict) { 2018 TEST(ErrorsIllegalWordsAsLabelsStrict) {
2009 // Tests that illegal tokens as labels produce the correct errors. 2019 // Tests that illegal tokens as labels produce the correct errors.
2010 const char* context_data[][2] = { 2020 const char* context_data[][2] = {
2011 {"\"use strict\";", ""}, 2021 { "\"use strict\";", "" },
2012 {"function test_func() {\"use strict\"; ", "}"}, 2022 { "function test_func() {\"use strict\"; ", "}"},
2013 {"() => {\"use strict\"; ", "}"}, 2023 { NULL, NULL }
2014 {NULL, NULL}}; 2024 };
2015 2025
2016 const char* statement_data[] = { 2026 const char* statement_data[] = {
2017 "super: while(true) { break super; }", 2027 "super: while(true) { break super; }",
2018 "interface: while(true) { break interface; }", 2028 "interface: while(true) { break interface; }",
2019 "yield: while(true) { break yield; }", 2029 "yield: while(true) { break yield; }",
2020 NULL 2030 NULL
2021 }; 2031 };
2022 2032
2023 RunParserSyncTest(context_data, statement_data, kError); 2033 RunParserSyncTest(context_data, statement_data, kError);
2024 } 2034 }
2025 2035
2026 2036
2027 TEST(NoErrorsIllegalWordsAsLabels) { 2037 TEST(NoErrorsIllegalWordsAsLabels) {
2028 // Using eval and arguments as labels is legal even in strict mode. 2038 // Using eval and arguments as labels is legal even in strict mode.
2029 const char* context_data[][2] = { 2039 const char* context_data[][2] = {
2030 {"", ""}, 2040 { "", ""},
2031 {"function test_func() {", "}"}, 2041 { "function test_func() {", "}" },
2032 {"() => {", "}"}, 2042 { "\"use strict\";", "" },
2033 {"\"use strict\";", ""}, 2043 { "\"use strict\"; function test_func() {", "}" },
2034 {"\"use strict\"; function test_func() {", "}"}, 2044 { NULL, NULL }
2035 {"\"use strict\"; () => {", "}"}, 2045 };
2036 {NULL, NULL}};
2037 2046
2038 const char* statement_data[] = { 2047 const char* statement_data[] = {
2039 "mylabel: while(true) { break mylabel; }", 2048 "mylabel: while(true) { break mylabel; }",
2040 "eval: while(true) { break eval; }", 2049 "eval: while(true) { break eval; }",
2041 "arguments: while(true) { break arguments; }", 2050 "arguments: while(true) { break arguments; }",
2042 NULL 2051 NULL
2043 }; 2052 };
2044 2053
2045 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; 2054 RunParserSyncTest(context_data, statement_data, kSuccess);
2046 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
2047 always_flags, ARRAY_SIZE(always_flags));
2048 } 2055 }
2049 2056
2050 2057
2051 TEST(ErrorsParenthesizedLabels) { 2058 TEST(ErrorsParenthesizedLabels) {
2052 // Parenthesized identifiers shouldn't be recognized as labels. 2059 // Parenthesized identifiers shouldn't be recognized as labels.
2053 const char* context_data[][2] = {{"", ""}, 2060 const char* context_data[][2] = {
2054 {"function test_func() {", "}"}, 2061 { "", ""},
2055 {"() => {", "}"}, 2062 { "function test_func() {", "}" },
2056 {NULL, NULL}}; 2063 { NULL, NULL }
2064 };
2057 2065
2058 const char* statement_data[] = { 2066 const char* statement_data[] = {
2059 "(mylabel): while(true) { break mylabel; }", 2067 "(mylabel): while(true) { break mylabel; }",
2060 NULL 2068 NULL
2061 }; 2069 };
2062 2070
2063 RunParserSyncTest(context_data, statement_data, kError); 2071 RunParserSyncTest(context_data, statement_data, kError);
2064 } 2072 }
2065 2073
2066 2074
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after
2887 LocalContext env; 2895 LocalContext env;
2888 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {}; 2896 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {};
2889 global_use_counts = use_counts; 2897 global_use_counts = use_counts;
2890 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback); 2898 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback);
2891 CompileRun("\"use asm\";\n" 2899 CompileRun("\"use asm\";\n"
2892 "var foo = 1;\n" 2900 "var foo = 1;\n"
2893 "\"use asm\";\n" // Only the first one counts. 2901 "\"use asm\";\n" // Only the first one counts.
2894 "function bar() { \"use asm\"; var baz = 1; }"); 2902 "function bar() { \"use asm\"; var baz = 1; }");
2895 CHECK_EQ(2, use_counts[v8::Isolate::kUseAsm]); 2903 CHECK_EQ(2, use_counts[v8::Isolate::kUseAsm]);
2896 } 2904 }
2897
2898
2899 TEST(ErrorsArrowFunctions) {
2900 // Tests that parser and preparser generate the same kind of errors
2901 // on invalid arrow function syntax.
2902 const char* context_data[][2] = {{"", ";"},
2903 {"v = ", ";"},
2904 {"bar ? (", ") : baz;"},
2905 {"bar ? baz : (", ");"},
2906 {"bar[", "];"},
2907 {"bar, ", ";"},
2908 {"", ", bar;"},
2909 {NULL, NULL}};
2910
2911 const char* statement_data[] = {
2912 "=> 0", "=>",
2913 "() =>", "=> {}",
2914 ") => {}", ", => {}",
2915 "(,) => {}", "return => {}",
2916 "() => {'value': 42}",
2917
2918 // Check that the early return introduced in ParsePrimaryExpression
2919 // does not accept stray closing parentheses.
2920 ")", ") => 0",
2921 "foo[()]", "()",
2922
2923 // Parameter lists with extra parens should be recognized as errors.
2924 "(()) => 0", "((x)) => 0",
2925 "((x, y)) => 0", "(x, (y)) => 0",
2926 "((x, y, z)) => 0", "(x, (y, z)) => 0",
2927 "((x, y), z) => 0",
2928
2929 // Parameter lists are always validated as strict, so those are errors.
2930 "eval => {}", "arguments => {}",
2931 "yield => {}", "interface => {}",
2932 "(eval) => {}", "(arguments) => {}",
2933 "(yield) => {}", "(interface) => {}",
2934 "(eval, bar) => {}", "(bar, eval) => {}",
2935 "(bar, arguments) => {}", "(bar, yield) => {}",
2936 "(bar, interface) => {}",
2937 // TODO(aperez): Detecting duplicates does not work in PreParser.
2938 // "(bar, bar) => {}",
2939
2940 // The parameter list is parsed as an expression, but only
2941 // a comma-separated list of identifier is valid.
2942 "32 => {}", "(32) => {}",
2943 "(a, 32) => {}", "if => {}",
2944 "(if) => {}", "(a, if) => {}",
2945 "a + b => {}", "(a + b) => {}",
2946 "(a + b, c) => {}", "(a, b - c) => {}",
2947 "\"a\" => {}", "(\"a\") => {}",
2948 "(\"a\", b) => {}", "(a, \"b\") => {}",
2949 "-a => {}", "(-a) => {}",
2950 "(-a, b) => {}", "(a, -b) => {}",
2951 "{} => {}", "({}) => {}",
2952 "(a, {}) => {}", "({}, a) => {}",
2953 "a++ => {}", "(a++) => {}",
2954 "(a++, b) => {}", "(a, b++) => {}",
2955 "[] => {}", "([]) => {}",
2956 "(a, []) => {}", "([], a) => {}",
2957 "(a = b) => {}", "(a = b, c) => {}",
2958 "(a, b = c) => {}", "(foo ? bar : baz) => {}",
2959 "(a, foo ? bar : baz) => {}", "(foo ? bar : baz, a) => {}",
2960 NULL};
2961
2962 RunParserSyncTest(context_data, statement_data, kError);
2963 }
2964
2965
2966 TEST(NoErrorsArrowFunctions) {
2967 // Tests that parser and preparser accept valid arrow functions syntax.
2968 const char* context_data[][2] = {{"", ";"},
2969 {"bar ? (", ") : baz;"},
2970 {"bar ? baz : (", ");"},
2971 {"bar, ", ";"},
2972 {"", ", bar;"},
2973 {NULL, NULL}};
2974
2975 const char* statement_data[] = {
2976 "() => {}", "() => { return 42 }",
2977 "x => { return x; }", "(x) => { return x; }",
2978 "(x, y) => { return x + y; }", "(x, y, z) => { return x + y + z; }",
2979 "(x, y) => { x.a = y; }", "() => 42",
2980 "x => x", "x => x * x",
2981 "(x) => x", "(x) => x * x",
2982 "(x, y) => x + y", "(x, y, z) => x, y, z",
2983 "(x, y) => x.a = y", "() => ({'value': 42})",
2984 "x => y => x + y", "(x, y) => (u, v) => x*u + y*v",
2985 "(x, y) => z => z * (x + y)", "x => (y, z) => z * (x + y)",
2986
2987 // Those are comma-separated expressions, with arrow functions as items.
2988 // They stress the code for validating arrow function parameter lists.
2989 "a, b => 0", "a, b, (c, d) => 0",
2990 "(a, b, (c, d) => 0)", "(a, b) => 0, (c, d) => 1",
2991 "(a, b => {}, a => a + 1)", "((a, b) => {}, (a => a + 1))",
2992 "(a, (a, (b, c) => 0))",
2993
2994 // Arrow has more precedence, this is the same as: foo ? bar : (baz = {})
2995 "foo ? bar : baz => {}", NULL};
2996
2997 static const ParserFlag always_flags[] = {kAllowArrowFunctions};
2998 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
2999 always_flags, ARRAY_SIZE(always_flags));
3000 }
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