Chromium Code Reviews| 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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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}", | 286 "{label: 42}", |
| 287 "var x = 42;", | 287 "var x = 42;", |
| 288 "function foo(x, y) { return x + y; }", | 288 "function foo(x, y) { return x + y; }", |
| 289 "%ArgleBargle(glop);", | 289 "%ArgleBargle(glop);", |
| 290 "var x = new new Function('this.x = 42');", | 290 "var x = new new Function('this.x = 42');", |
| 291 "var f = (x, y) => x + y;", | |
| 291 NULL | 292 NULL |
| 292 }; | 293 }; |
| 293 | 294 |
| 294 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); | 295 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); |
| 295 for (int i = 0; programs[i]; i++) { | 296 for (int i = 0; programs[i]; i++) { |
| 296 const char* program = programs[i]; | 297 const char* program = programs[i]; |
| 297 i::Utf8ToUtf16CharacterStream stream( | 298 i::Utf8ToUtf16CharacterStream stream( |
| 298 reinterpret_cast<const i::byte*>(program), | 299 reinterpret_cast<const i::byte*>(program), |
| 299 static_cast<unsigned>(strlen(program))); | 300 static_cast<unsigned>(strlen(program))); |
| 300 i::CompleteParserRecorder log; | 301 i::CompleteParserRecorder log; |
| 301 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 302 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 302 scanner.Initialize(&stream); | 303 scanner.Initialize(&stream); |
| 303 | 304 |
| 304 i::PreParser preparser(&scanner, &log, stack_limit); | 305 i::PreParser preparser(&scanner, &log, stack_limit); |
| 305 preparser.set_allow_lazy(true); | 306 preparser.set_allow_lazy(true); |
| 306 preparser.set_allow_natives_syntax(true); | 307 preparser.set_allow_natives_syntax(true); |
| 308 preparser.set_allow_arrow_functions(true); | |
| 307 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 309 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 308 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 310 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 309 i::ScriptData data(log.ExtractData()); | 311 i::ScriptData data(log.ExtractData()); |
| 310 CHECK(!data.has_error()); | 312 CHECK(!data.has_error()); |
| 311 } | 313 } |
| 312 } | 314 } |
| 313 | 315 |
| 314 | 316 |
| 315 TEST(StandAlonePreParserNoNatives) { | 317 TEST(StandAlonePreParserNoNatives) { |
| 316 v8::V8::Initialize(); | 318 v8::V8::Initialize(); |
| (...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1161 } | 1163 } |
| 1162 | 1164 |
| 1163 | 1165 |
| 1164 enum ParserFlag { | 1166 enum ParserFlag { |
| 1165 kAllowLazy, | 1167 kAllowLazy, |
| 1166 kAllowNativesSyntax, | 1168 kAllowNativesSyntax, |
| 1167 kAllowHarmonyScoping, | 1169 kAllowHarmonyScoping, |
| 1168 kAllowModules, | 1170 kAllowModules, |
| 1169 kAllowGenerators, | 1171 kAllowGenerators, |
| 1170 kAllowForOf, | 1172 kAllowForOf, |
| 1171 kAllowHarmonyNumericLiterals | 1173 kAllowHarmonyNumericLiterals, |
| 1174 kAllowArrowFunctions | |
| 1172 }; | 1175 }; |
| 1173 | 1176 |
| 1174 | 1177 |
| 1175 enum ParserSyncTestResult { | 1178 enum ParserSyncTestResult { |
| 1176 kSuccessOrError, | 1179 kSuccessOrError, |
| 1177 kSuccess, | 1180 kSuccess, |
| 1178 kError | 1181 kError |
| 1179 }; | 1182 }; |
| 1180 | 1183 |
| 1181 template <typename Traits> | 1184 template <typename Traits> |
| 1182 void SetParserFlags(i::ParserBase<Traits>* parser, | 1185 void SetParserFlags(i::ParserBase<Traits>* parser, |
| 1183 i::EnumSet<ParserFlag> flags) { | 1186 i::EnumSet<ParserFlag> flags) { |
| 1184 parser->set_allow_lazy(flags.Contains(kAllowLazy)); | 1187 parser->set_allow_lazy(flags.Contains(kAllowLazy)); |
| 1185 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax)); | 1188 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax)); |
| 1186 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); | 1189 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); |
| 1187 parser->set_allow_modules(flags.Contains(kAllowModules)); | 1190 parser->set_allow_modules(flags.Contains(kAllowModules)); |
| 1188 parser->set_allow_generators(flags.Contains(kAllowGenerators)); | 1191 parser->set_allow_generators(flags.Contains(kAllowGenerators)); |
| 1189 parser->set_allow_for_of(flags.Contains(kAllowForOf)); | 1192 parser->set_allow_for_of(flags.Contains(kAllowForOf)); |
| 1190 parser->set_allow_harmony_numeric_literals( | 1193 parser->set_allow_harmony_numeric_literals( |
| 1191 flags.Contains(kAllowHarmonyNumericLiterals)); | 1194 flags.Contains(kAllowHarmonyNumericLiterals)); |
| 1195 parser->set_allow_arrow_functions(flags.Contains(kAllowArrowFunctions)); | |
| 1192 } | 1196 } |
| 1193 | 1197 |
| 1194 | 1198 |
| 1195 void TestParserSyncWithFlags(i::Handle<i::String> source, | 1199 void TestParserSyncWithFlags(i::Handle<i::String> source, |
| 1196 i::EnumSet<ParserFlag> flags, | 1200 i::EnumSet<ParserFlag> flags, |
| 1197 ParserSyncTestResult result) { | 1201 ParserSyncTestResult result) { |
| 1198 i::Isolate* isolate = CcTest::i_isolate(); | 1202 i::Isolate* isolate = CcTest::i_isolate(); |
| 1199 i::Factory* factory = isolate->factory(); | 1203 i::Factory* factory = isolate->factory(); |
| 1200 | 1204 |
| 1201 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); | 1205 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1385 | 1389 |
| 1386 v8::HandleScope handles(CcTest::isolate()); | 1390 v8::HandleScope handles(CcTest::isolate()); |
| 1387 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 1391 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 1388 v8::Context::Scope context_scope(context); | 1392 v8::Context::Scope context_scope(context); |
| 1389 | 1393 |
| 1390 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - | 1394 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - |
| 1391 128 * 1024); | 1395 128 * 1024); |
| 1392 | 1396 |
| 1393 static const ParserFlag flags1[] = { | 1397 static const ParserFlag flags1[] = { |
| 1394 kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators, | 1398 kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators, |
| 1395 kAllowForOf | 1399 kAllowForOf, kAllowArrowFunctions |
| 1396 }; | 1400 }; |
| 1397 for (int i = 0; context_data[i][0] != NULL; ++i) { | 1401 for (int i = 0; context_data[i][0] != NULL; ++i) { |
| 1398 for (int j = 0; statement_data[j] != NULL; ++j) { | 1402 for (int j = 0; statement_data[j] != NULL; ++j) { |
| 1399 for (int k = 0; termination_data[k] != NULL; ++k) { | 1403 for (int k = 0; termination_data[k] != NULL; ++k) { |
| 1400 int kPrefixLen = i::StrLength(context_data[i][0]); | 1404 int kPrefixLen = i::StrLength(context_data[i][0]); |
| 1401 int kStatementLen = i::StrLength(statement_data[j]); | 1405 int kStatementLen = i::StrLength(statement_data[j]); |
| 1402 int kTerminationLen = i::StrLength(termination_data[k]); | 1406 int kTerminationLen = i::StrLength(termination_data[k]); |
| 1403 int kSuffixLen = i::StrLength(context_data[i][1]); | 1407 int kSuffixLen = i::StrLength(context_data[i][1]); |
| 1404 int kProgramSize = kPrefixLen + kStatementLen + kTerminationLen | 1408 int kProgramSize = kPrefixLen + kStatementLen + kTerminationLen |
| 1405 + kSuffixLen + i::StrLength("label: for (;;) { }"); | 1409 + kSuffixLen + i::StrLength("label: for (;;) { }"); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 1427 | 1431 |
| 1428 static const ParserFlag flags3[] = { kAllowNativesSyntax }; | 1432 static const ParserFlag flags3[] = { kAllowNativesSyntax }; |
| 1429 TestParserSync("%DebugPrint(123)", flags3, ARRAY_SIZE(flags3)); | 1433 TestParserSync("%DebugPrint(123)", flags3, ARRAY_SIZE(flags3)); |
| 1430 } | 1434 } |
| 1431 | 1435 |
| 1432 | 1436 |
| 1433 TEST(StrictOctal) { | 1437 TEST(StrictOctal) { |
| 1434 // Test that syntax error caused by octal literal is reported correctly as | 1438 // Test that syntax error caused by octal literal is reported correctly as |
| 1435 // such (issue 2220). | 1439 // such (issue 2220). |
| 1436 v8::V8::Initialize(); | 1440 v8::V8::Initialize(); |
| 1441 | |
|
marja
2014/07/04 08:21:13
Hey, no adding whitespaces :)
| |
| 1437 v8::HandleScope scope(CcTest::isolate()); | 1442 v8::HandleScope scope(CcTest::isolate()); |
| 1438 v8::Context::Scope context_scope( | 1443 v8::Context::Scope context_scope( |
| 1439 v8::Context::New(CcTest::isolate())); | 1444 v8::Context::New(CcTest::isolate())); |
| 1440 v8::TryCatch try_catch; | 1445 v8::TryCatch try_catch; |
| 1441 const char* script = | 1446 const char* script = |
| 1442 "\"use strict\"; \n" | 1447 "\"use strict\"; \n" |
| 1443 "a = function() { \n" | 1448 "a = function() { \n" |
| 1444 " b = function() { \n" | 1449 " b = function() { \n" |
| 1445 " 01; \n" | 1450 " 01; \n" |
| 1446 " }; \n" | 1451 " }; \n" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1462 int always_true_flags_len = 0) { | 1467 int always_true_flags_len = 0) { |
| 1463 v8::HandleScope handles(CcTest::isolate()); | 1468 v8::HandleScope handles(CcTest::isolate()); |
| 1464 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 1469 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 1465 v8::Context::Scope context_scope(context); | 1470 v8::Context::Scope context_scope(context); |
| 1466 | 1471 |
| 1467 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - | 1472 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - |
| 1468 128 * 1024); | 1473 128 * 1024); |
| 1469 | 1474 |
| 1470 static const ParserFlag default_flags[] = { | 1475 static const ParserFlag default_flags[] = { |
| 1471 kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators, | 1476 kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators, |
| 1472 kAllowForOf, kAllowNativesSyntax | 1477 kAllowForOf, kAllowNativesSyntax, kAllowArrowFunctions |
| 1473 }; | 1478 }; |
| 1474 ParserFlag* generated_flags = NULL; | 1479 ParserFlag* generated_flags = NULL; |
| 1475 if (flags == NULL) { | 1480 if (flags == NULL) { |
| 1476 flags = default_flags; | 1481 flags = default_flags; |
| 1477 flags_len = ARRAY_SIZE(default_flags); | 1482 flags_len = ARRAY_SIZE(default_flags); |
| 1478 if (always_true_flags != NULL) { | 1483 if (always_true_flags != NULL) { |
| 1479 // Remove always_true_flags from default_flags. | 1484 // Remove always_true_flags from default_flags. |
| 1480 CHECK(always_true_flags_len < flags_len); | 1485 CHECK(always_true_flags_len < flags_len); |
| 1481 generated_flags = new ParserFlag[flags_len - always_true_flags_len]; | 1486 generated_flags = new ParserFlag[flags_len - always_true_flags_len]; |
| 1482 int flag_index = 0; | 1487 int flag_index = 0; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1539 "var foo, eval;", | 1544 "var foo, eval;", |
| 1540 "var foo, arguments;", | 1545 "var foo, arguments;", |
| 1541 "try { } catch (eval) { }", | 1546 "try { } catch (eval) { }", |
| 1542 "try { } catch (arguments) { }", | 1547 "try { } catch (arguments) { }", |
| 1543 "function eval() { }", | 1548 "function eval() { }", |
| 1544 "function arguments() { }", | 1549 "function arguments() { }", |
| 1545 "function foo(eval) { }", | 1550 "function foo(eval) { }", |
| 1546 "function foo(arguments) { }", | 1551 "function foo(arguments) { }", |
| 1547 "function foo(bar, eval) { }", | 1552 "function foo(bar, eval) { }", |
| 1548 "function foo(bar, arguments) { }", | 1553 "function foo(bar, arguments) { }", |
| 1554 "(eval) => { }", | |
| 1555 "(arguments) => { }", | |
| 1556 "(foo, eval) => { }", | |
| 1557 "(foo, arguments) => { }", | |
| 1549 "eval = 1;", | 1558 "eval = 1;", |
| 1550 "arguments = 1;", | 1559 "arguments = 1;", |
| 1551 "var foo = eval = 1;", | 1560 "var foo = eval = 1;", |
| 1552 "var foo = arguments = 1;", | 1561 "var foo = arguments = 1;", |
| 1553 "++eval;", | 1562 "++eval;", |
| 1554 "++arguments;", | 1563 "++arguments;", |
| 1555 "eval++;", | 1564 "eval++;", |
| 1556 "arguments++;", | 1565 "arguments++;", |
| 1557 NULL | 1566 NULL |
| 1558 }; | 1567 }; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1595 }; | 1604 }; |
| 1596 | 1605 |
| 1597 RunParserSyncTest(context_data, statement_data, kSuccess); | 1606 RunParserSyncTest(context_data, statement_data, kSuccess); |
| 1598 } | 1607 } |
| 1599 | 1608 |
| 1600 | 1609 |
| 1601 TEST(NoErrorsEvalAndArgumentsStrict) { | 1610 TEST(NoErrorsEvalAndArgumentsStrict) { |
| 1602 const char* context_data[][2] = { | 1611 const char* context_data[][2] = { |
| 1603 { "\"use strict\";", "" }, | 1612 { "\"use strict\";", "" }, |
| 1604 { "function test_func() { \"use strict\";", "}" }, | 1613 { "function test_func() { \"use strict\";", "}" }, |
| 1614 { "() => { \"use strict\"; ", "}" }, | |
| 1605 { NULL, NULL } | 1615 { NULL, NULL } |
| 1606 }; | 1616 }; |
| 1607 | 1617 |
| 1608 const char* statement_data[] = { | 1618 const char* statement_data[] = { |
| 1609 "eval;", | 1619 "eval;", |
| 1610 "arguments;", | 1620 "arguments;", |
| 1611 "var foo = eval;", | 1621 "var foo = eval;", |
| 1612 "var foo = arguments;", | 1622 "var foo = arguments;", |
| 1613 "var foo = { eval: 1 };", | 1623 "var foo = { eval: 1 };", |
| 1614 "var foo = { arguments: 1 };", | 1624 "var foo = { arguments: 1 };", |
| 1615 "var foo = { }; foo.eval = {};", | 1625 "var foo = { }; foo.eval = {};", |
| 1616 "var foo = { }; foo.arguments = {};", | 1626 "var foo = { }; foo.arguments = {};", |
| 1617 NULL | 1627 NULL |
| 1618 }; | 1628 }; |
| 1619 | 1629 |
| 1620 RunParserSyncTest(context_data, statement_data, kSuccess); | 1630 static const ParserFlag always_flags[] = { kAllowArrowFunctions }; |
| 1631 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | |
| 1632 always_flags, ARRAY_SIZE(always_flags)); | |
| 1621 } | 1633 } |
| 1622 | 1634 |
| 1623 | 1635 |
| 1624 TEST(ErrorsFutureStrictReservedWords) { | 1636 TEST(ErrorsFutureStrictReservedWords) { |
| 1625 // Tests that both preparsing and parsing produce the right kind of errors for | 1637 // Tests that both preparsing and parsing produce the right kind of errors for |
| 1626 // using future strict reserved words as identifiers. Without the strict mode, | 1638 // using future strict reserved words as identifiers. Without the strict mode, |
| 1627 // it's ok to use future strict reserved words as identifiers. With the strict | 1639 // it's ok to use future strict reserved words as identifiers. With the strict |
| 1628 // mode, it isn't. | 1640 // mode, it isn't. |
| 1629 const char* context_data[][2] = { | 1641 const char* context_data[][2] = { |
| 1630 { "\"use strict\";", "" }, | 1642 { "\"use strict\";", "" }, |
| 1631 { "function test_func() {\"use strict\"; ", "}"}, | 1643 { "function test_func() {\"use strict\"; ", "}"}, |
| 1644 { "() => { \"use strict\"; ", "}" }, | |
| 1632 { NULL, NULL } | 1645 { NULL, NULL } |
| 1633 }; | 1646 }; |
| 1634 | 1647 |
| 1635 const char* statement_data[] = { | 1648 const char* statement_data[] = { |
| 1636 "var interface;", | 1649 "var interface;", |
| 1637 "var foo, interface;", | 1650 "var foo, interface;", |
| 1638 "try { } catch (interface) { }", | 1651 "try { } catch (interface) { }", |
| 1639 "function interface() { }", | 1652 "function interface() { }", |
| 1640 "function foo(interface) { }", | 1653 "function foo(interface) { }", |
| 1641 "function foo(bar, interface) { }", | 1654 "function foo(bar, interface) { }", |
| 1642 "interface = 1;", | 1655 "interface = 1;", |
| 1643 "var foo = interface = 1;", | 1656 "var foo = interface = 1;", |
| 1644 "++interface;", | 1657 "++interface;", |
| 1645 "interface++;", | 1658 "interface++;", |
| 1646 "var yield = 13;", | 1659 "var yield = 13;", |
| 1647 NULL | 1660 NULL |
| 1648 }; | 1661 }; |
| 1649 | 1662 |
| 1650 RunParserSyncTest(context_data, statement_data, kError); | 1663 static const ParserFlag always_flags[] = { kAllowArrowFunctions }; |
| 1664 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, | |
| 1665 always_flags, ARRAY_SIZE(always_flags)); | |
| 1651 } | 1666 } |
| 1652 | 1667 |
| 1653 | 1668 |
| 1654 TEST(NoErrorsFutureStrictReservedWords) { | 1669 TEST(NoErrorsFutureStrictReservedWords) { |
| 1655 const char* context_data[][2] = { | 1670 const char* context_data[][2] = { |
| 1656 { "", "" }, | 1671 { "", "" }, |
| 1657 { "function test_func() {", "}"}, | 1672 { "function test_func() {", "}"}, |
| 1673 { "() => {", "}" }, | |
| 1658 { NULL, NULL } | 1674 { NULL, NULL } |
| 1659 }; | 1675 }; |
| 1660 | 1676 |
| 1661 const char* statement_data[] = { | 1677 const char* statement_data[] = { |
| 1662 "var interface;", | 1678 "var interface;", |
| 1663 "var foo, interface;", | 1679 "var foo, interface;", |
| 1664 "try { } catch (interface) { }", | 1680 "try { } catch (interface) { }", |
| 1665 "function interface() { }", | 1681 "function interface() { }", |
| 1666 "function foo(interface) { }", | 1682 "function foo(interface) { }", |
| 1667 "function foo(bar, interface) { }", | 1683 "function foo(bar, interface) { }", |
| 1668 "interface = 1;", | 1684 "interface = 1;", |
| 1669 "var foo = interface = 1;", | 1685 "var foo = interface = 1;", |
| 1670 "++interface;", | 1686 "++interface;", |
| 1671 "interface++;", | 1687 "interface++;", |
| 1672 "var yield = 13;", | 1688 "var yield = 13;", |
| 1673 NULL | 1689 NULL |
| 1674 }; | 1690 }; |
| 1675 | 1691 |
| 1676 RunParserSyncTest(context_data, statement_data, kSuccess); | 1692 static const ParserFlag always_flags[] = { kAllowArrowFunctions }; |
| 1693 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | |
| 1694 always_flags, ARRAY_SIZE(always_flags)); | |
| 1695 | |
| 1677 } | 1696 } |
| 1678 | 1697 |
| 1679 | 1698 |
| 1680 TEST(ErrorsReservedWords) { | 1699 TEST(ErrorsReservedWords) { |
| 1681 // Tests that both preparsing and parsing produce the right kind of errors for | 1700 // Tests that both preparsing and parsing produce the right kind of errors for |
| 1682 // using future reserved words as identifiers. These tests don't depend on the | 1701 // using future reserved words as identifiers. These tests don't depend on the |
| 1683 // strict mode. | 1702 // strict mode. |
| 1684 const char* context_data[][2] = { | 1703 const char* context_data[][2] = { |
| 1685 { "", "" }, | 1704 { "", "" }, |
| 1686 { "\"use strict\";", "" }, | 1705 { "\"use strict\";", "" }, |
| 1687 { "var eval; function test_func() {", "}"}, | 1706 { "var eval; function test_func() {", "}"}, |
| 1688 { "var eval; function test_func() {\"use strict\"; ", "}"}, | 1707 { "var eval; function test_func() {\"use strict\"; ", "}"}, |
| 1708 { "var eval; () => {", "}" }, | |
| 1709 { "var eval; () => {\"use strict\"; ", "}" }, | |
| 1689 { NULL, NULL } | 1710 { NULL, NULL } |
| 1690 }; | 1711 }; |
| 1691 | 1712 |
| 1692 const char* statement_data[] = { | 1713 const char* statement_data[] = { |
| 1693 "var super;", | 1714 "var super;", |
| 1694 "var foo, super;", | 1715 "var foo, super;", |
| 1695 "try { } catch (super) { }", | 1716 "try { } catch (super) { }", |
| 1696 "function super() { }", | 1717 "function super() { }", |
| 1697 "function foo(super) { }", | 1718 "function foo(super) { }", |
| 1698 "function foo(bar, super) { }", | 1719 "function foo(bar, super) { }", |
| 1720 "(super) => { }", | |
| 1721 "(bar, super) => { }", | |
| 1699 "super = 1;", | 1722 "super = 1;", |
| 1700 "var foo = super = 1;", | 1723 "var foo = super = 1;", |
| 1701 "++super;", | 1724 "++super;", |
| 1702 "super++;", | 1725 "super++;", |
| 1703 "function foo super", | 1726 "function foo super", |
| 1704 NULL | 1727 NULL |
| 1705 }; | 1728 }; |
| 1706 | 1729 |
| 1707 RunParserSyncTest(context_data, statement_data, kError); | 1730 RunParserSyncTest(context_data, statement_data, kError); |
| 1708 } | 1731 } |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 1731 "++yield;", | 1754 "++yield;", |
| 1732 "yield++;", | 1755 "yield++;", |
| 1733 "yield: 34", | 1756 "yield: 34", |
| 1734 "function yield(yield) { yield: yield (yield + yield (0)); }", | 1757 "function yield(yield) { yield: yield (yield + yield (0)); }", |
| 1735 "({ yield: 1 })", | 1758 "({ yield: 1 })", |
| 1736 "({ get yield() { 1 } })", | 1759 "({ get yield() { 1 } })", |
| 1737 "yield (100)", | 1760 "yield (100)", |
| 1738 NULL | 1761 NULL |
| 1739 }; | 1762 }; |
| 1740 | 1763 |
| 1741 RunParserSyncTest(context_data, statement_data, kSuccess); | 1764 static const ParserFlag always_flags[] = { kAllowArrowFunctions }; |
| 1765 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | |
| 1766 always_flags, ARRAY_SIZE(always_flags)); | |
| 1742 } | 1767 } |
| 1743 | 1768 |
| 1744 | 1769 |
| 1745 TEST(NoErrorsYieldSloppyGeneratorsEnabled) { | 1770 TEST(NoErrorsYieldSloppyGeneratorsEnabled) { |
| 1746 // In sloppy mode, it's okay to use "yield" as identifier, *except* inside a | 1771 // In sloppy mode, it's okay to use "yield" as identifier, *except* inside a |
| 1747 // generator (see next test). | 1772 // generator (see next test). |
| 1748 const char* context_data[][2] = { | 1773 const char* context_data[][2] = { |
| 1749 { "", "" }, | 1774 { "", "" }, |
| 1750 { "function not_gen() {", "}" }, | 1775 { "function not_gen() {", "}" }, |
| 1751 { "function * gen() { function not_gen() {", "} }" }, | 1776 { "function * gen() { function not_gen() {", "} }" }, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1786 | 1811 |
| 1787 | 1812 |
| 1788 TEST(ErrorsYieldStrict) { | 1813 TEST(ErrorsYieldStrict) { |
| 1789 const char* context_data[][2] = { | 1814 const char* context_data[][2] = { |
| 1790 { "\"use strict\";", "" }, | 1815 { "\"use strict\";", "" }, |
| 1791 { "\"use strict\"; function not_gen() {", "}" }, | 1816 { "\"use strict\"; function not_gen() {", "}" }, |
| 1792 { "function test_func() {\"use strict\"; ", "}"}, | 1817 { "function test_func() {\"use strict\"; ", "}"}, |
| 1793 { "\"use strict\"; function * gen() { function not_gen() {", "} }" }, | 1818 { "\"use strict\"; function * gen() { function not_gen() {", "} }" }, |
| 1794 { "\"use strict\"; (function not_gen() {", "})" }, | 1819 { "\"use strict\"; (function not_gen() {", "})" }, |
| 1795 { "\"use strict\"; (function * gen() { (function not_gen() {", "}) })" }, | 1820 { "\"use strict\"; (function * gen() { (function not_gen() {", "}) })" }, |
| 1821 { "() => {\"use strict\"; ", "}" }, | |
| 1796 { NULL, NULL } | 1822 { NULL, NULL } |
| 1797 }; | 1823 }; |
| 1798 | 1824 |
| 1799 const char* statement_data[] = { | 1825 const char* statement_data[] = { |
| 1800 "var yield;", | 1826 "var yield;", |
| 1801 "var foo, yield;", | 1827 "var foo, yield;", |
| 1802 "try { } catch (yield) { }", | 1828 "try { } catch (yield) { }", |
| 1803 "function yield() { }", | 1829 "function yield() { }", |
| 1804 "(function yield() { })", | 1830 "(function yield() { })", |
| 1805 "function foo(yield) { }", | 1831 "function foo(yield) { }", |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1868 "yield; yield", | 1894 "yield; yield", |
| 1869 "(yield) ? yield : yield", | 1895 "(yield) ? yield : yield", |
| 1870 "(yield) \n ? yield : yield", | 1896 "(yield) \n ? yield : yield", |
| 1871 // If there is a newline before the next token, we don't look for RHS. | 1897 // If there is a newline before the next token, we don't look for RHS. |
| 1872 "yield\nfor (;;) {}", | 1898 "yield\nfor (;;) {}", |
| 1873 NULL | 1899 NULL |
| 1874 }; | 1900 }; |
| 1875 | 1901 |
| 1876 // This test requires kAllowGenerators to succeed. | 1902 // This test requires kAllowGenerators to succeed. |
| 1877 static const ParserFlag always_true_flags[] = { | 1903 static const ParserFlag always_true_flags[] = { |
| 1878 kAllowGenerators | 1904 kAllowGenerators, |
| 1879 }; | 1905 }; |
| 1880 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | 1906 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, |
| 1881 always_true_flags, 1); | 1907 always_true_flags, 1); |
| 1882 } | 1908 } |
| 1883 | 1909 |
| 1884 | 1910 |
| 1885 TEST(ErrorsYieldGenerator) { | 1911 TEST(ErrorsYieldGenerator) { |
| 1886 const char* context_data[][2] = { | 1912 const char* context_data[][2] = { |
| 1887 { "function * gen() {", "}" }, | 1913 { "function * gen() {", "}" }, |
| 1888 { "\"use strict\"; function * gen() {", "}" }, | 1914 { "\"use strict\"; function * gen() {", "}" }, |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1996 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | 2022 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, |
| 1997 always_true_flags, 1); | 2023 always_true_flags, 1); |
| 1998 } | 2024 } |
| 1999 | 2025 |
| 2000 | 2026 |
| 2001 TEST(ErrorsIllegalWordsAsLabelsSloppy) { | 2027 TEST(ErrorsIllegalWordsAsLabelsSloppy) { |
| 2002 // Using future reserved words as labels is always an error. | 2028 // Using future reserved words as labels is always an error. |
| 2003 const char* context_data[][2] = { | 2029 const char* context_data[][2] = { |
| 2004 { "", ""}, | 2030 { "", ""}, |
| 2005 { "function test_func() {", "}" }, | 2031 { "function test_func() {", "}" }, |
| 2032 { "() => {", "}" }, | |
| 2006 { NULL, NULL } | 2033 { NULL, NULL } |
| 2007 }; | 2034 }; |
| 2008 | 2035 |
| 2009 const char* statement_data[] = { | 2036 const char* statement_data[] = { |
| 2010 "super: while(true) { break super; }", | 2037 "super: while(true) { break super; }", |
| 2011 NULL | 2038 NULL |
| 2012 }; | 2039 }; |
| 2013 | 2040 |
| 2014 RunParserSyncTest(context_data, statement_data, kError); | 2041 RunParserSyncTest(context_data, statement_data, kError); |
| 2015 } | 2042 } |
| 2016 | 2043 |
| 2017 | 2044 |
| 2018 TEST(ErrorsIllegalWordsAsLabelsStrict) { | 2045 TEST(ErrorsIllegalWordsAsLabelsStrict) { |
| 2019 // Tests that illegal tokens as labels produce the correct errors. | 2046 // Tests that illegal tokens as labels produce the correct errors. |
| 2020 const char* context_data[][2] = { | 2047 const char* context_data[][2] = { |
| 2021 { "\"use strict\";", "" }, | 2048 { "\"use strict\";", "" }, |
| 2022 { "function test_func() {\"use strict\"; ", "}"}, | 2049 { "function test_func() {\"use strict\"; ", "}"}, |
| 2050 { "() => {\"use strict\"; ", "}" }, | |
| 2023 { NULL, NULL } | 2051 { NULL, NULL } |
| 2024 }; | 2052 }; |
| 2025 | 2053 |
| 2026 const char* statement_data[] = { | 2054 const char* statement_data[] = { |
| 2027 "super: while(true) { break super; }", | 2055 "super: while(true) { break super; }", |
| 2028 "interface: while(true) { break interface; }", | 2056 "interface: while(true) { break interface; }", |
| 2029 "yield: while(true) { break yield; }", | 2057 "yield: while(true) { break yield; }", |
| 2030 NULL | 2058 NULL |
| 2031 }; | 2059 }; |
| 2032 | 2060 |
| 2033 RunParserSyncTest(context_data, statement_data, kError); | 2061 RunParserSyncTest(context_data, statement_data, kError); |
| 2034 } | 2062 } |
| 2035 | 2063 |
| 2036 | 2064 |
| 2037 TEST(NoErrorsIllegalWordsAsLabels) { | 2065 TEST(NoErrorsIllegalWordsAsLabels) { |
| 2038 // Using eval and arguments as labels is legal even in strict mode. | 2066 // Using eval and arguments as labels is legal even in strict mode. |
| 2039 const char* context_data[][2] = { | 2067 const char* context_data[][2] = { |
| 2040 { "", ""}, | 2068 { "", ""}, |
| 2041 { "function test_func() {", "}" }, | 2069 { "function test_func() {", "}" }, |
| 2070 { "() => {", "}" }, | |
| 2042 { "\"use strict\";", "" }, | 2071 { "\"use strict\";", "" }, |
| 2043 { "\"use strict\"; function test_func() {", "}" }, | 2072 { "\"use strict\"; function test_func() {", "}" }, |
| 2073 { "\"use strict\"; () => {", "}" }, | |
| 2044 { NULL, NULL } | 2074 { NULL, NULL } |
| 2045 }; | 2075 }; |
| 2046 | 2076 |
| 2047 const char* statement_data[] = { | 2077 const char* statement_data[] = { |
| 2048 "mylabel: while(true) { break mylabel; }", | 2078 "mylabel: while(true) { break mylabel; }", |
| 2049 "eval: while(true) { break eval; }", | 2079 "eval: while(true) { break eval; }", |
| 2050 "arguments: while(true) { break arguments; }", | 2080 "arguments: while(true) { break arguments; }", |
| 2051 NULL | 2081 NULL |
| 2052 }; | 2082 }; |
| 2053 | 2083 |
| 2054 RunParserSyncTest(context_data, statement_data, kSuccess); | 2084 static const ParserFlag always_flags[] = { kAllowArrowFunctions }; |
| 2085 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | |
| 2086 always_flags, ARRAY_SIZE(always_flags)); | |
| 2055 } | 2087 } |
| 2056 | 2088 |
| 2057 | 2089 |
| 2058 TEST(ErrorsParenthesizedLabels) { | 2090 TEST(ErrorsParenthesizedLabels) { |
| 2059 // Parenthesized identifiers shouldn't be recognized as labels. | 2091 // Parenthesized identifiers shouldn't be recognized as labels. |
| 2060 const char* context_data[][2] = { | 2092 const char* context_data[][2] = { |
| 2061 { "", ""}, | 2093 { "", ""}, |
| 2062 { "function test_func() {", "}" }, | 2094 { "function test_func() {", "}" }, |
| 2095 { "() => {", "}" }, | |
| 2063 { NULL, NULL } | 2096 { NULL, NULL } |
| 2064 }; | 2097 }; |
| 2065 | 2098 |
| 2066 const char* statement_data[] = { | 2099 const char* statement_data[] = { |
| 2067 "(mylabel): while(true) { break mylabel; }", | 2100 "(mylabel): while(true) { break mylabel; }", |
| 2068 NULL | 2101 NULL |
| 2069 }; | 2102 }; |
| 2070 | 2103 |
| 2071 RunParserSyncTest(context_data, statement_data, kError); | 2104 RunParserSyncTest(context_data, statement_data, kError); |
| 2072 } | 2105 } |
| (...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2895 LocalContext env; | 2928 LocalContext env; |
| 2896 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {}; | 2929 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {}; |
| 2897 global_use_counts = use_counts; | 2930 global_use_counts = use_counts; |
| 2898 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback); | 2931 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback); |
| 2899 CompileRun("\"use asm\";\n" | 2932 CompileRun("\"use asm\";\n" |
| 2900 "var foo = 1;\n" | 2933 "var foo = 1;\n" |
| 2901 "\"use asm\";\n" // Only the first one counts. | 2934 "\"use asm\";\n" // Only the first one counts. |
| 2902 "function bar() { \"use asm\"; var baz = 1; }"); | 2935 "function bar() { \"use asm\"; var baz = 1; }"); |
| 2903 CHECK_EQ(2, use_counts[v8::Isolate::kUseAsm]); | 2936 CHECK_EQ(2, use_counts[v8::Isolate::kUseAsm]); |
| 2904 } | 2937 } |
| 2938 | |
| 2939 | |
| 2940 TEST(ErrorsArrowFunctions) { | |
| 2941 // Tests that parser and preparser generate the same kind of errors | |
| 2942 // on invalid arrow function syntax. | |
| 2943 const char* context_data[][2] = { | |
| 2944 {"", ";"}, | |
| 2945 {"v = ", ";"}, | |
| 2946 {"bar ? (", ") : baz;"}, | |
| 2947 {"bar ? baz : (", ");"}, | |
| 2948 {"bar[", "];"}, | |
| 2949 {"bar, ", ";"}, | |
| 2950 {"", ", bar;"}, | |
| 2951 { NULL, NULL } | |
| 2952 }; | |
| 2953 | |
| 2954 const char* statement_data[] = { | |
| 2955 "=> 0", | |
| 2956 "=>", | |
| 2957 "() =>", | |
| 2958 "=> {}", | |
| 2959 ") => {}", | |
| 2960 ", => {}", | |
| 2961 "(,) => {}", | |
| 2962 "return => {}", | |
| 2963 "() => {'value': 42}", | |
| 2964 | |
| 2965 // Check that the early return introduced in ParsePrimaryExpression | |
| 2966 // does not accept stray closing parentheses. | |
| 2967 ")", | |
| 2968 ") => 0", | |
| 2969 "foo[()]", | |
| 2970 "()", | |
| 2971 | |
| 2972 // Parameter lists with extra parens should be recognized as errors. | |
| 2973 "(()) => 0", | |
| 2974 "((x)) => 0", | |
| 2975 "((x, y)) => 0", | |
| 2976 "(x, (y)) => 0", | |
| 2977 "((x, y, z)) => 0", | |
| 2978 "(x, (y, z)) => 0", | |
| 2979 "((x, y), z) => 0", | |
| 2980 | |
| 2981 // Parameter lists are always validated as strict, so those are errors. | |
| 2982 "eval => {}", | |
| 2983 "arguments => {}", | |
| 2984 "yield => {}", | |
| 2985 "interface => {}", | |
| 2986 "(eval) => {}", | |
| 2987 "(arguments) => {}", | |
| 2988 "(yield) => {}", | |
| 2989 "(interface) => {}", | |
| 2990 "(eval, bar) => {}", | |
| 2991 "(bar, eval) => {}", | |
| 2992 "(bar, arguments) => {}", | |
| 2993 "(bar, yield) => {}", | |
| 2994 "(bar, interface) => {}", | |
| 2995 // TODO(aperez): Detecting duplicates does not work in PreParser. | |
| 2996 //"(bar, bar) => {}", | |
| 2997 | |
| 2998 // The parameter list is parsed as an expression, but only | |
| 2999 // a comma-separated list of identifier is valid. | |
| 3000 "32 => {}", | |
| 3001 "(32) => {}", | |
| 3002 "(a, 32) => {}", | |
| 3003 "if => {}", | |
| 3004 "(if) => {}", | |
| 3005 "(a, if) => {}", | |
| 3006 "a + b => {}", | |
| 3007 "(a + b) => {}", | |
| 3008 "(a + b, c) => {}", | |
| 3009 "(a, b - c) => {}", | |
| 3010 "\"a\" => {}", | |
| 3011 "(\"a\") => {}", | |
| 3012 "(\"a\", b) => {}", | |
| 3013 "(a, \"b\") => {}", | |
| 3014 "-a => {}", | |
| 3015 "(-a) => {}", | |
| 3016 "(-a, b) => {}", | |
| 3017 "(a, -b) => {}", | |
| 3018 "{} => {}", | |
| 3019 "({}) => {}", | |
| 3020 "(a, {}) => {}", | |
| 3021 "({}, a) => {}", | |
| 3022 "a++ => {}", | |
| 3023 "(a++) => {}", | |
| 3024 "(a++, b) => {}", | |
| 3025 "(a, b++) => {}", | |
| 3026 "[] => {}", | |
| 3027 "([]) => {}", | |
| 3028 "(a, []) => {}", | |
| 3029 "([], a) => {}", | |
| 3030 "(a = b) => {}", | |
| 3031 "(a = b, c) => {}", | |
| 3032 "(a, b = c) => {}", | |
| 3033 "(foo ? bar : baz) => {}", | |
| 3034 "(a, foo ? bar : baz) => {}", | |
| 3035 "(foo ? bar : baz, a) => {}", | |
| 3036 | |
| 3037 NULL | |
| 3038 }; | |
| 3039 | |
| 3040 RunParserSyncTest(context_data, statement_data, kError); | |
| 3041 } | |
| 3042 | |
| 3043 | |
| 3044 TEST(NoErrorsArrowFunctions) { | |
| 3045 // Tests that parser and preparser accept valid arrow functions syntax. | |
| 3046 const char* context_data[][2] = { | |
| 3047 {"", ";"}, | |
| 3048 {"bar ? (", ") : baz;"}, | |
| 3049 {"bar ? baz : (", ");"}, | |
| 3050 {"bar, ", ";"}, | |
| 3051 {"", ", bar;"}, | |
| 3052 { NULL, NULL } | |
| 3053 }; | |
| 3054 | |
| 3055 const char* statement_data[] = { | |
| 3056 "() => {}", | |
| 3057 "() => { return 42 }", | |
| 3058 "x => { return x; }", | |
| 3059 "(x) => { return x; }", | |
| 3060 "(x, y) => { return x + y; }", | |
| 3061 "(x, y, z) => { return x + y + z; }", | |
| 3062 "(x, y) => { x.a = y; }", | |
| 3063 "() => 42", | |
| 3064 "x => x", | |
| 3065 "x => x * x", | |
| 3066 "(x) => x", | |
| 3067 "(x) => x * x", | |
| 3068 "(x, y) => x + y", | |
| 3069 "(x, y, z) => x, y, z", | |
| 3070 "(x, y) => x.a = y", | |
| 3071 "() => ({'value': 42})", | |
| 3072 "x => y => x + y", | |
| 3073 "(x, y) => (u, v) => x*u + y*v", | |
| 3074 "(x, y) => z => z * (x + y)", | |
| 3075 "x => (y, z) => z * (x + y)", | |
| 3076 | |
| 3077 // Those are comma-separated expressions, with arrow functions as items. | |
| 3078 // They stress the code for validating arrow function parameter lists. | |
| 3079 "a, b => 0", | |
| 3080 "a, b, (c, d) => 0", | |
| 3081 "(a, b, (c, d) => 0)", | |
| 3082 "(a, b) => 0, (c, d) => 1", | |
| 3083 "(a, b => {}, a => a + 1)", | |
| 3084 "((a, b) => {}, (a => a + 1))", | |
| 3085 "(a, (a, (b, c) => 0))", | |
| 3086 | |
| 3087 // Arrow has more precedence, this is the same as: foo ? bar : (baz = {}) | |
| 3088 "foo ? bar : baz => {}", | |
| 3089 | |
| 3090 NULL | |
| 3091 }; | |
| 3092 | |
| 3093 static const ParserFlag always_flags[] = { kAllowArrowFunctions }; | |
| 3094 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | |
| 3095 always_flags, ARRAY_SIZE(always_flags)); | |
| 3096 } | |
| OLD | NEW |