OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_PREPARSER_H | 5 #ifndef V8_PREPARSER_H |
6 #define V8_PREPARSER_H | 6 #define V8_PREPARSER_H |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 template <typename Traits> | 63 template <typename Traits> |
64 class ParserBase : public Traits { | 64 class ParserBase : public Traits { |
65 public: | 65 public: |
66 // Shorten type names defined by Traits. | 66 // Shorten type names defined by Traits. |
67 typedef typename Traits::Type::Expression ExpressionT; | 67 typedef typename Traits::Type::Expression ExpressionT; |
68 typedef typename Traits::Type::Identifier IdentifierT; | 68 typedef typename Traits::Type::Identifier IdentifierT; |
69 typedef typename Traits::Type::FormalParameter FormalParameterT; | 69 typedef typename Traits::Type::FormalParameter FormalParameterT; |
70 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; | 70 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; |
71 typedef typename Traits::Type::Literal LiteralT; | 71 typedef typename Traits::Type::Literal LiteralT; |
72 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; | 72 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; |
| 73 typedef typename Traits::Type::FormalParameterParsingState |
| 74 FormalParameterParsingStateT; |
73 | 75 |
74 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit, | 76 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit, |
75 v8::Extension* extension, AstValueFactory* ast_value_factory, | 77 v8::Extension* extension, AstValueFactory* ast_value_factory, |
76 ParserRecorder* log, typename Traits::Type::Parser this_object) | 78 ParserRecorder* log, typename Traits::Type::Parser this_object) |
77 : Traits(this_object), | 79 : Traits(this_object), |
78 parenthesized_function_(false), | 80 parenthesized_function_(false), |
79 scope_(NULL), | 81 scope_(NULL), |
80 function_state_(NULL), | 82 function_state_(NULL), |
81 extension_(extension), | 83 extension_(extension), |
82 fni_(NULL), | 84 fni_(NULL), |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 !classifier->is_valid_strong_mode_formal_parameters()) { | 552 !classifier->is_valid_strong_mode_formal_parameters()) { |
551 ReportClassifierError(classifier->strong_mode_formal_parameter_error()); | 553 ReportClassifierError(classifier->strong_mode_formal_parameter_error()); |
552 *ok = false; | 554 *ok = false; |
553 } | 555 } |
554 } | 556 } |
555 | 557 |
556 void ValidateArrowFormalParameters(const ExpressionClassifier* classifier, | 558 void ValidateArrowFormalParameters(const ExpressionClassifier* classifier, |
557 ExpressionT expr, bool* ok) { | 559 ExpressionT expr, bool* ok) { |
558 if (classifier->is_valid_binding_pattern()) { | 560 if (classifier->is_valid_binding_pattern()) { |
559 // A simple arrow formal parameter: IDENTIFIER => BODY. | 561 // A simple arrow formal parameter: IDENTIFIER => BODY. |
560 if (!allow_harmony_destructuring() && !this->IsIdentifier(expr)) { | 562 if (!this->IsIdentifier(expr)) { |
561 Traits::ReportMessageAt(scanner()->location(), | 563 Traits::ReportMessageAt(scanner()->location(), |
562 MessageTemplate::kUnexpectedToken, | 564 MessageTemplate::kUnexpectedToken, |
563 Token::String(scanner()->current_token())); | 565 Token::String(scanner()->current_token())); |
564 *ok = false; | 566 *ok = false; |
565 } | 567 } |
566 } else if (!classifier->is_valid_arrow_formal_parameters()) { | 568 } else if (!classifier->is_valid_arrow_formal_parameters()) { |
567 ReportClassifierError(classifier->arrow_formal_parameters_error()); | 569 ReportClassifierError(classifier->arrow_formal_parameters_error()); |
568 *ok = false; | 570 *ok = false; |
569 } | 571 } |
570 } | 572 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 ExpressionT ParseUnaryExpression(ExpressionClassifier* classifier, bool* ok); | 641 ExpressionT ParseUnaryExpression(ExpressionClassifier* classifier, bool* ok); |
640 ExpressionT ParsePostfixExpression(ExpressionClassifier* classifier, | 642 ExpressionT ParsePostfixExpression(ExpressionClassifier* classifier, |
641 bool* ok); | 643 bool* ok); |
642 ExpressionT ParseLeftHandSideExpression(ExpressionClassifier* classifier, | 644 ExpressionT ParseLeftHandSideExpression(ExpressionClassifier* classifier, |
643 bool* ok); | 645 bool* ok); |
644 ExpressionT ParseMemberWithNewPrefixesExpression( | 646 ExpressionT ParseMemberWithNewPrefixesExpression( |
645 ExpressionClassifier* classifier, bool* ok); | 647 ExpressionClassifier* classifier, bool* ok); |
646 ExpressionT ParseMemberExpression(ExpressionClassifier* classifier, bool* ok); | 648 ExpressionT ParseMemberExpression(ExpressionClassifier* classifier, bool* ok); |
647 ExpressionT ParseMemberExpressionContinuation( | 649 ExpressionT ParseMemberExpressionContinuation( |
648 ExpressionT expression, ExpressionClassifier* classifier, bool* ok); | 650 ExpressionT expression, ExpressionClassifier* classifier, bool* ok); |
649 ExpressionT ParseArrowFunctionLiteral(Scope* function_scope, bool has_rest, | 651 ExpressionT ParseArrowFunctionLiteral( |
650 const ExpressionClassifier& classifier, | 652 const FormalParameterParsingStateT& parsing_state, |
651 bool* ok); | 653 const ExpressionClassifier& classifier, bool* ok); |
652 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, | 654 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, |
653 ExpressionClassifier* classifier, bool* ok); | 655 ExpressionClassifier* classifier, bool* ok); |
654 void AddTemplateExpression(ExpressionT); | 656 void AddTemplateExpression(ExpressionT); |
655 ExpressionT ParseSuperExpression(bool is_new, | 657 ExpressionT ParseSuperExpression(bool is_new, |
656 ExpressionClassifier* classifier, bool* ok); | 658 ExpressionClassifier* classifier, bool* ok); |
657 ExpressionT ParseNewTargetExpression(bool* ok); | 659 ExpressionT ParseNewTargetExpression(bool* ok); |
658 ExpressionT ParseStrongInitializationExpression( | 660 ExpressionT ParseStrongInitializationExpression( |
659 ExpressionClassifier* classifier, bool* ok); | 661 ExpressionClassifier* classifier, bool* ok); |
660 ExpressionT ParseStrongSuperCallExpression(ExpressionClassifier* classifier, | 662 ExpressionT ParseStrongSuperCallExpression(ExpressionClassifier* classifier, |
661 bool* ok); | 663 bool* ok); |
662 | 664 |
663 void ParseFormalParameter(Scope* scope, bool is_rest, | 665 void ParseFormalParameter(bool is_rest, |
| 666 FormalParameterParsingStateT* parsing_result, |
664 ExpressionClassifier* classifier, bool* ok); | 667 ExpressionClassifier* classifier, bool* ok); |
665 int ParseFormalParameterList(Scope* scope, bool* has_rest, | 668 int ParseFormalParameterList(FormalParameterParsingStateT* parsing_state, |
666 ExpressionClassifier* classifier, bool* ok); | 669 ExpressionClassifier* classifier, bool* ok); |
667 void CheckArityRestrictions( | 670 void CheckArityRestrictions( |
668 int param_count, FunctionLiteral::ArityRestriction arity_restriction, | 671 int param_count, FunctionLiteral::ArityRestriction arity_restriction, |
669 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok); | 672 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok); |
670 | 673 |
671 // Checks if the expression is a valid reference expression (e.g., on the | 674 // Checks if the expression is a valid reference expression (e.g., on the |
672 // left-hand side of assignments). Although ruled out by ECMA as early errors, | 675 // left-hand side of assignments). Although ruled out by ECMA as early errors, |
673 // we allow calls for web compatibility and rewrite them to a runtime throw. | 676 // we allow calls for web compatibility and rewrite them to a runtime throw. |
674 ExpressionT CheckAndRewriteReferenceExpression( | 677 ExpressionT CheckAndRewriteReferenceExpression( |
675 ExpressionT expression, Scanner::Location location, | 678 ExpressionT expression, Scanner::Location location, |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1247 // Return the object itself as AstVisitor and implement the needed | 1250 // Return the object itself as AstVisitor and implement the needed |
1248 // dummy method right in this class. | 1251 // dummy method right in this class. |
1249 PreParserFactory* visitor() { return this; } | 1252 PreParserFactory* visitor() { return this; } |
1250 int* ast_properties() { | 1253 int* ast_properties() { |
1251 static int dummy = 42; | 1254 static int dummy = 42; |
1252 return &dummy; | 1255 return &dummy; |
1253 } | 1256 } |
1254 }; | 1257 }; |
1255 | 1258 |
1256 | 1259 |
| 1260 struct PreParserFormalParameterParsingState { |
| 1261 explicit PreParserFormalParameterParsingState(Scope* scope) |
| 1262 : scope(scope), has_rest(false), is_simple_parameter_list(true) {} |
| 1263 Scope* scope; |
| 1264 bool has_rest; |
| 1265 bool is_simple_parameter_list; |
| 1266 }; |
| 1267 |
| 1268 |
1257 class PreParser; | 1269 class PreParser; |
1258 | 1270 |
1259 class PreParserTraits { | 1271 class PreParserTraits { |
1260 public: | 1272 public: |
1261 struct Type { | 1273 struct Type { |
1262 // TODO(marja): To be removed. The Traits object should contain all the data | 1274 // TODO(marja): To be removed. The Traits object should contain all the data |
1263 // it needs. | 1275 // it needs. |
1264 typedef PreParser* Parser; | 1276 typedef PreParser* Parser; |
1265 | 1277 |
1266 // PreParser doesn't need to store generator variables. | 1278 // PreParser doesn't need to store generator variables. |
1267 typedef void GeneratorVariable; | 1279 typedef void GeneratorVariable; |
1268 | 1280 |
1269 typedef int AstProperties; | 1281 typedef int AstProperties; |
1270 | 1282 |
1271 // Return types for traversing functions. | 1283 // Return types for traversing functions. |
1272 typedef PreParserIdentifier Identifier; | 1284 typedef PreParserIdentifier Identifier; |
1273 typedef PreParserExpression Expression; | 1285 typedef PreParserExpression Expression; |
1274 typedef PreParserExpression YieldExpression; | 1286 typedef PreParserExpression YieldExpression; |
1275 typedef PreParserExpression FunctionLiteral; | 1287 typedef PreParserExpression FunctionLiteral; |
1276 typedef PreParserExpression ClassLiteral; | 1288 typedef PreParserExpression ClassLiteral; |
1277 typedef PreParserExpression ObjectLiteralProperty; | 1289 typedef PreParserExpression ObjectLiteralProperty; |
1278 typedef PreParserExpression Literal; | 1290 typedef PreParserExpression Literal; |
1279 typedef PreParserExpressionList ExpressionList; | 1291 typedef PreParserExpressionList ExpressionList; |
1280 typedef PreParserExpressionList PropertyList; | 1292 typedef PreParserExpressionList PropertyList; |
1281 typedef PreParserIdentifier FormalParameter; | 1293 typedef PreParserIdentifier FormalParameter; |
1282 typedef PreParserStatementList StatementList; | 1294 typedef PreParserStatementList StatementList; |
| 1295 typedef PreParserFormalParameterParsingState FormalParameterParsingState; |
1283 | 1296 |
1284 // For constructing objects returned by the traversing functions. | 1297 // For constructing objects returned by the traversing functions. |
1285 typedef PreParserFactory Factory; | 1298 typedef PreParserFactory Factory; |
1286 }; | 1299 }; |
1287 | 1300 |
1288 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {} | 1301 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {} |
1289 | 1302 |
1290 // Helper functions for recursive descent. | 1303 // Helper functions for recursive descent. |
1291 static bool IsEval(PreParserIdentifier identifier) { | 1304 static bool IsEval(PreParserIdentifier identifier) { |
1292 return identifier.IsEval(); | 1305 return identifier.IsEval(); |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1511 } | 1524 } |
1512 | 1525 |
1513 static PreParserStatementList NewStatementList(int size, Zone* zone) { | 1526 static PreParserStatementList NewStatementList(int size, Zone* zone) { |
1514 return PreParserStatementList(); | 1527 return PreParserStatementList(); |
1515 } | 1528 } |
1516 | 1529 |
1517 static PreParserExpressionList NewPropertyList(int size, Zone* zone) { | 1530 static PreParserExpressionList NewPropertyList(int size, Zone* zone) { |
1518 return PreParserExpressionList(); | 1531 return PreParserExpressionList(); |
1519 } | 1532 } |
1520 | 1533 |
| 1534 static void AddParameterInitializationBlock( |
| 1535 const PreParserFormalParameterParsingState& formal_parameters, |
| 1536 PreParserStatementList list, bool* ok) {} |
| 1537 |
1521 V8_INLINE void SkipLazyFunctionBody(int* materialized_literal_count, | 1538 V8_INLINE void SkipLazyFunctionBody(int* materialized_literal_count, |
1522 int* expected_property_count, bool* ok) { | 1539 int* expected_property_count, bool* ok) { |
1523 UNREACHABLE(); | 1540 UNREACHABLE(); |
1524 } | 1541 } |
1525 | 1542 |
1526 V8_INLINE PreParserStatementList | 1543 V8_INLINE PreParserStatementList ParseEagerFunctionBody( |
1527 ParseEagerFunctionBody(PreParserIdentifier function_name, int pos, | 1544 PreParserIdentifier function_name, int pos, |
1528 Variable* fvar, Token::Value fvar_init_op, | 1545 const PreParserFormalParameterParsingState& formal_parameters, |
1529 FunctionKind kind, bool* ok); | 1546 Variable* fvar, Token::Value fvar_init_op, FunctionKind kind, bool* ok); |
1530 | 1547 |
1531 V8_INLINE void ParseArrowFunctionFormalParameters( | 1548 V8_INLINE void ParseArrowFunctionFormalParameters( |
1532 Scope* scope, PreParserExpression expression, | 1549 PreParserFormalParameterParsingState* parsing_state, |
1533 const Scanner::Location& params_loc, bool* has_rest, | 1550 PreParserExpression expression, const Scanner::Location& params_loc, |
1534 Scanner::Location* duplicate_loc, bool* ok); | 1551 Scanner::Location* duplicate_loc, bool* ok); |
1535 | 1552 |
1536 struct TemplateLiteralState {}; | 1553 struct TemplateLiteralState {}; |
1537 | 1554 |
1538 TemplateLiteralState OpenTemplateLiteral(int pos) { | 1555 TemplateLiteralState OpenTemplateLiteral(int pos) { |
1539 return TemplateLiteralState(); | 1556 return TemplateLiteralState(); |
1540 } | 1557 } |
1541 void AddTemplateSpan(TemplateLiteralState*, bool) {} | 1558 void AddTemplateSpan(TemplateLiteralState*, bool) {} |
1542 void AddTemplateExpression(TemplateLiteralState*, PreParserExpression) {} | 1559 void AddTemplateExpression(TemplateLiteralState*, PreParserExpression) {} |
1543 PreParserExpression CloseTemplateLiteral(TemplateLiteralState*, int, | 1560 PreParserExpression CloseTemplateLiteral(TemplateLiteralState*, int, |
1544 PreParserExpression tag) { | 1561 PreParserExpression tag) { |
1545 if (IsTaggedTemplate(tag)) { | 1562 if (IsTaggedTemplate(tag)) { |
1546 // Emulate generation of array literals for tag callsite | 1563 // Emulate generation of array literals for tag callsite |
1547 // 1st is array of cooked strings, second is array of raw strings | 1564 // 1st is array of cooked strings, second is array of raw strings |
1548 MaterializeTemplateCallsiteLiterals(); | 1565 MaterializeTemplateCallsiteLiterals(); |
1549 } | 1566 } |
1550 return EmptyExpression(); | 1567 return EmptyExpression(); |
1551 } | 1568 } |
1552 inline void MaterializeTemplateCallsiteLiterals(); | 1569 inline void MaterializeTemplateCallsiteLiterals(); |
1553 PreParserExpression NoTemplateTag() { | 1570 PreParserExpression NoTemplateTag() { |
1554 return PreParserExpression::NoTemplateTag(); | 1571 return PreParserExpression::NoTemplateTag(); |
1555 } | 1572 } |
1556 static bool IsTaggedTemplate(const PreParserExpression tag) { | 1573 static bool IsTaggedTemplate(const PreParserExpression tag) { |
1557 return !tag.IsNoTemplateTag(); | 1574 return !tag.IsNoTemplateTag(); |
1558 } | 1575 } |
1559 | 1576 |
1560 void DeclareFormalParameter(Scope* scope, PreParserExpression pattern, | 1577 void DeclareFormalParameter(void* parsing_state, PreParserExpression pattern, |
1561 ExpressionClassifier* classifier, bool is_rest) {} | 1578 ExpressionClassifier* classifier, bool is_rest) {} |
1562 | 1579 |
1563 void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {} | 1580 void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {} |
1564 | 1581 |
1565 // Temporary glue; these functions will move to ParserBase. | 1582 // Temporary glue; these functions will move to ParserBase. |
1566 PreParserExpression ParseV8Intrinsic(bool* ok); | 1583 PreParserExpression ParseV8Intrinsic(bool* ok); |
1567 PreParserExpression ParseFunctionLiteral( | 1584 PreParserExpression ParseFunctionLiteral( |
1568 PreParserIdentifier name, Scanner::Location function_name_location, | 1585 PreParserIdentifier name, Scanner::Location function_name_location, |
1569 bool name_is_strict_reserved, FunctionKind kind, | 1586 bool name_is_strict_reserved, FunctionKind kind, |
1570 int function_token_position, FunctionLiteral::FunctionType type, | 1587 int function_token_position, FunctionLiteral::FunctionType type, |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1701 Statement ParseTryStatement(bool* ok); | 1718 Statement ParseTryStatement(bool* ok); |
1702 Statement ParseDebuggerStatement(bool* ok); | 1719 Statement ParseDebuggerStatement(bool* ok); |
1703 Expression ParseConditionalExpression(bool accept_IN, bool* ok); | 1720 Expression ParseConditionalExpression(bool accept_IN, bool* ok); |
1704 Expression ParseObjectLiteral(bool* ok); | 1721 Expression ParseObjectLiteral(bool* ok); |
1705 Expression ParseV8Intrinsic(bool* ok); | 1722 Expression ParseV8Intrinsic(bool* ok); |
1706 | 1723 |
1707 V8_INLINE void SkipLazyFunctionBody(int* materialized_literal_count, | 1724 V8_INLINE void SkipLazyFunctionBody(int* materialized_literal_count, |
1708 int* expected_property_count, bool* ok); | 1725 int* expected_property_count, bool* ok); |
1709 V8_INLINE PreParserStatementList | 1726 V8_INLINE PreParserStatementList |
1710 ParseEagerFunctionBody(PreParserIdentifier function_name, int pos, | 1727 ParseEagerFunctionBody(PreParserIdentifier function_name, int pos, |
| 1728 const FormalParameterParsingStateT& formal_parameters, |
1711 Variable* fvar, Token::Value fvar_init_op, | 1729 Variable* fvar, Token::Value fvar_init_op, |
1712 FunctionKind kind, bool* ok); | 1730 FunctionKind kind, bool* ok); |
1713 | 1731 |
1714 Expression ParseFunctionLiteral( | 1732 Expression ParseFunctionLiteral( |
1715 Identifier name, Scanner::Location function_name_location, | 1733 Identifier name, Scanner::Location function_name_location, |
1716 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, | 1734 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, |
1717 FunctionLiteral::FunctionType function_type, | 1735 FunctionLiteral::FunctionType function_type, |
1718 FunctionLiteral::ArityRestriction arity_restriction, bool* ok); | 1736 FunctionLiteral::ArityRestriction arity_restriction, bool* ok); |
1719 void ParseLazyFunctionLiteralBody(bool* ok, | 1737 void ParseLazyFunctionLiteralBody(bool* ok, |
1720 Scanner::BookmarkScope* bookmark = nullptr); | 1738 Scanner::BookmarkScope* bookmark = nullptr); |
(...skipping 25 matching lines...) Expand all Loading... |
1746 } | 1764 } |
1747 | 1765 |
1748 PreParserExpression PreParserTraits::SpreadCallNew(PreParserExpression function, | 1766 PreParserExpression PreParserTraits::SpreadCallNew(PreParserExpression function, |
1749 PreParserExpressionList args, | 1767 PreParserExpressionList args, |
1750 int pos) { | 1768 int pos) { |
1751 return pre_parser_->factory()->NewCallNew(function, args, pos); | 1769 return pre_parser_->factory()->NewCallNew(function, args, pos); |
1752 } | 1770 } |
1753 | 1771 |
1754 | 1772 |
1755 void PreParserTraits::ParseArrowFunctionFormalParameters( | 1773 void PreParserTraits::ParseArrowFunctionFormalParameters( |
1756 Scope* scope, PreParserExpression params, | 1774 PreParserFormalParameterParsingState* parsing_state, |
1757 const Scanner::Location& params_loc, bool* has_rest, | 1775 PreParserExpression params, const Scanner::Location& params_loc, |
1758 Scanner::Location* duplicate_loc, bool* ok) { | 1776 Scanner::Location* duplicate_loc, bool* ok) { |
1759 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter | 1777 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter |
1760 // lists that are too long. | 1778 // lists that are too long. |
1761 } | 1779 } |
1762 | 1780 |
1763 | 1781 |
1764 PreParserStatementList PreParser::ParseEagerFunctionBody( | 1782 PreParserStatementList PreParser::ParseEagerFunctionBody( |
1765 PreParserIdentifier function_name, int pos, Variable* fvar, | 1783 PreParserIdentifier function_name, int pos, |
1766 Token::Value fvar_init_op, FunctionKind kind, bool* ok) { | 1784 const PreParserFormalParameterParsingState& formal_parameters, |
| 1785 Variable* fvar, Token::Value fvar_init_op, FunctionKind kind, bool* ok) { |
1767 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 1786 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
1768 | 1787 |
1769 ParseStatementList(Token::RBRACE, ok); | 1788 ParseStatementList(Token::RBRACE, ok); |
1770 if (!*ok) return PreParserStatementList(); | 1789 if (!*ok) return PreParserStatementList(); |
1771 | 1790 |
1772 Expect(Token::RBRACE, ok); | 1791 Expect(Token::RBRACE, ok); |
1773 return PreParserStatementList(); | 1792 return PreParserStatementList(); |
1774 } | 1793 } |
1775 | 1794 |
1776 | 1795 |
1777 PreParserStatementList PreParserTraits::ParseEagerFunctionBody( | 1796 PreParserStatementList PreParserTraits::ParseEagerFunctionBody( |
1778 PreParserIdentifier function_name, int pos, Variable* fvar, | 1797 PreParserIdentifier function_name, int pos, |
1779 Token::Value fvar_init_op, FunctionKind kind, bool* ok) { | 1798 const PreParserFormalParameterParsingState& formal_parameters, |
1780 return pre_parser_->ParseEagerFunctionBody(function_name, pos, fvar, | 1799 Variable* fvar, Token::Value fvar_init_op, FunctionKind kind, bool* ok) { |
1781 fvar_init_op, kind, ok); | 1800 return pre_parser_->ParseEagerFunctionBody( |
| 1801 function_name, pos, formal_parameters, fvar, fvar_init_op, kind, ok); |
1782 } | 1802 } |
1783 | 1803 |
1784 | 1804 |
1785 template <class Traits> | 1805 template <class Traits> |
1786 ParserBase<Traits>::FunctionState::FunctionState( | 1806 ParserBase<Traits>::FunctionState::FunctionState( |
1787 FunctionState** function_state_stack, Scope** scope_stack, Scope* scope, | 1807 FunctionState** function_state_stack, Scope** scope_stack, Scope* scope, |
1788 FunctionKind kind, typename Traits::Type::Factory* factory) | 1808 FunctionKind kind, typename Traits::Type::Factory* factory) |
1789 : next_materialized_literal_index_(0), | 1809 : next_materialized_literal_index_(0), |
1790 expected_property_count_(0), | 1810 expected_property_count_(0), |
1791 this_location_(Scanner::Location::invalid()), | 1811 this_location_(Scanner::Location::invalid()), |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2155 Token::String(Token::RPAREN)); | 2175 Token::String(Token::RPAREN)); |
2156 // Give a good error to the user who might have typed e.g. "return();". | 2176 // Give a good error to the user who might have typed e.g. "return();". |
2157 if (peek() != Token::ARROW) { | 2177 if (peek() != Token::ARROW) { |
2158 ReportUnexpectedTokenAt(scanner_->peek_location(), peek(), | 2178 ReportUnexpectedTokenAt(scanner_->peek_location(), peek(), |
2159 MessageTemplate::kMissingArrow); | 2179 MessageTemplate::kMissingArrow); |
2160 *ok = false; | 2180 *ok = false; |
2161 return this->EmptyExpression(); | 2181 return this->EmptyExpression(); |
2162 } | 2182 } |
2163 Scope* scope = | 2183 Scope* scope = |
2164 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); | 2184 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); |
| 2185 FormalParameterParsingStateT parsing_state(scope); |
2165 scope->set_start_position(beg_pos); | 2186 scope->set_start_position(beg_pos); |
2166 ExpressionClassifier args_classifier; | 2187 ExpressionClassifier args_classifier; |
2167 bool has_rest = false; | 2188 result = this->ParseArrowFunctionLiteral(parsing_state, args_classifier, |
2168 result = this->ParseArrowFunctionLiteral(scope, has_rest, | 2189 CHECK_OK); |
2169 args_classifier, CHECK_OK); | |
2170 } else if (allow_harmony_arrow_functions() && | 2190 } else if (allow_harmony_arrow_functions() && |
2171 allow_harmony_rest_params() && Check(Token::ELLIPSIS)) { | 2191 allow_harmony_rest_params() && Check(Token::ELLIPSIS)) { |
2172 // (...x) => y | 2192 // (...x) => y |
2173 Scope* scope = | 2193 Scope* scope = |
2174 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); | 2194 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); |
| 2195 FormalParameterParsingStateT parsing_state(scope); |
2175 scope->set_start_position(beg_pos); | 2196 scope->set_start_position(beg_pos); |
2176 ExpressionClassifier args_classifier; | 2197 ExpressionClassifier args_classifier; |
2177 const bool has_rest = true; | 2198 const bool is_rest = true; |
2178 this->ParseFormalParameter(scope, has_rest, &args_classifier, CHECK_OK); | 2199 this->ParseFormalParameter(is_rest, &parsing_state, &args_classifier, |
| 2200 CHECK_OK); |
2179 if (peek() == Token::COMMA) { | 2201 if (peek() == Token::COMMA) { |
2180 ReportMessageAt(scanner()->peek_location(), | 2202 ReportMessageAt(scanner()->peek_location(), |
2181 MessageTemplate::kParamAfterRest); | 2203 MessageTemplate::kParamAfterRest); |
2182 *ok = false; | 2204 *ok = false; |
2183 return this->EmptyExpression(); | 2205 return this->EmptyExpression(); |
2184 } | 2206 } |
2185 Expect(Token::RPAREN, CHECK_OK); | 2207 Expect(Token::RPAREN, CHECK_OK); |
2186 result = this->ParseArrowFunctionLiteral(scope, has_rest, | 2208 result = this->ParseArrowFunctionLiteral(parsing_state, args_classifier, |
2187 args_classifier, CHECK_OK); | 2209 CHECK_OK); |
2188 } else { | 2210 } else { |
2189 // Heuristically try to detect immediately called functions before | 2211 // Heuristically try to detect immediately called functions before |
2190 // seeing the call parentheses. | 2212 // seeing the call parentheses. |
2191 parenthesized_function_ = (peek() == Token::FUNCTION); | 2213 parenthesized_function_ = (peek() == Token::FUNCTION); |
2192 result = this->ParseExpression(true, classifier, CHECK_OK); | 2214 result = this->ParseExpression(true, classifier, CHECK_OK); |
2193 Expect(Token::RPAREN, CHECK_OK); | 2215 Expect(Token::RPAREN, CHECK_OK); |
2194 } | 2216 } |
2195 break; | 2217 break; |
2196 | 2218 |
2197 case Token::CLASS: { | 2219 case Token::CLASS: { |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2517 name_expression, value, | 2539 name_expression, value, |
2518 is_get ? ObjectLiteralProperty::GETTER : ObjectLiteralProperty::SETTER, | 2540 is_get ? ObjectLiteralProperty::GETTER : ObjectLiteralProperty::SETTER, |
2519 is_static, *is_computed_name); | 2541 is_static, *is_computed_name); |
2520 | 2542 |
2521 } else if (!in_class && allow_harmony_object_literals_ && | 2543 } else if (!in_class && allow_harmony_object_literals_ && |
2522 Token::IsIdentifier(name_token, language_mode(), | 2544 Token::IsIdentifier(name_token, language_mode(), |
2523 this->is_generator())) { | 2545 this->is_generator())) { |
2524 DCHECK(!*is_computed_name); | 2546 DCHECK(!*is_computed_name); |
2525 DCHECK(!is_static); | 2547 DCHECK(!is_static); |
2526 | 2548 |
| 2549 if (classifier->duplicate_finder() != nullptr && |
| 2550 scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) { |
| 2551 classifier->RecordDuplicateFormalParameterError(scanner()->location()); |
| 2552 } |
| 2553 |
2527 ExpressionT lhs = this->ExpressionFromIdentifier( | 2554 ExpressionT lhs = this->ExpressionFromIdentifier( |
2528 name, next_beg_pos, next_end_pos, scope_, factory()); | 2555 name, next_beg_pos, next_end_pos, scope_, factory()); |
2529 if (peek() == Token::ASSIGN) { | 2556 if (peek() == Token::ASSIGN) { |
2530 this->ExpressionUnexpectedToken(classifier); | 2557 this->ExpressionUnexpectedToken(classifier); |
2531 Consume(Token::ASSIGN); | 2558 Consume(Token::ASSIGN); |
2532 ExpressionClassifier rhs_classifier; | 2559 ExpressionClassifier rhs_classifier; |
2533 ExpressionT rhs = this->ParseAssignmentExpression( | 2560 ExpressionT rhs = this->ParseAssignmentExpression( |
2534 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2561 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
2535 classifier->AccumulateReclassifyingAsPattern(rhs_classifier); | 2562 classifier->AccumulateReclassifyingAsPattern(rhs_classifier); |
2536 value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs, | 2563 value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs, |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2700 // LeftHandSideExpression AssignmentOperator AssignmentExpression | 2727 // LeftHandSideExpression AssignmentOperator AssignmentExpression |
2701 | 2728 |
2702 Scanner::Location lhs_location = scanner()->peek_location(); | 2729 Scanner::Location lhs_location = scanner()->peek_location(); |
2703 | 2730 |
2704 if (peek() == Token::YIELD && is_generator()) { | 2731 if (peek() == Token::YIELD && is_generator()) { |
2705 return this->ParseYieldExpression(classifier, ok); | 2732 return this->ParseYieldExpression(classifier, ok); |
2706 } | 2733 } |
2707 | 2734 |
2708 if (fni_ != NULL) fni_->Enter(); | 2735 if (fni_ != NULL) fni_->Enter(); |
2709 ParserBase<Traits>::Checkpoint checkpoint(this); | 2736 ParserBase<Traits>::Checkpoint checkpoint(this); |
2710 ExpressionClassifier arrow_formals_classifier; | 2737 ExpressionClassifier arrow_formals_classifier(classifier->duplicate_finder()); |
2711 if (peek() != Token::LPAREN) { | 2738 if (peek() != Token::LPAREN) { |
2712 // The expression we are going to read is not a parenthesized arrow function | 2739 // The expression we are going to read is not a parenthesized arrow function |
2713 // formal parameter list. | 2740 // formal parameter list. |
2714 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier); | 2741 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier); |
2715 } | 2742 } |
2716 ExpressionT expression = this->ParseConditionalExpression( | 2743 ExpressionT expression = this->ParseConditionalExpression( |
2717 accept_IN, &arrow_formals_classifier, CHECK_OK); | 2744 accept_IN, &arrow_formals_classifier, CHECK_OK); |
2718 | 2745 |
2719 if (allow_harmony_arrow_functions() && peek() == Token::ARROW) { | 2746 if (allow_harmony_arrow_functions() && peek() == Token::ARROW) { |
2720 checkpoint.Restore(); | 2747 checkpoint.Restore(); |
2721 BindingPatternUnexpectedToken(classifier); | 2748 BindingPatternUnexpectedToken(classifier); |
2722 ValidateArrowFormalParameters(&arrow_formals_classifier, expression, | 2749 ValidateArrowFormalParameters(&arrow_formals_classifier, expression, |
2723 CHECK_OK); | 2750 CHECK_OK); |
2724 Scanner::Location loc(lhs_location.beg_pos, scanner()->location().end_pos); | 2751 Scanner::Location loc(lhs_location.beg_pos, scanner()->location().end_pos); |
2725 Scope* scope = | 2752 Scope* scope = |
2726 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); | 2753 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); |
2727 scope->set_start_position(lhs_location.beg_pos); | 2754 scope->set_start_position(lhs_location.beg_pos); |
2728 Scanner::Location duplicate_loc = Scanner::Location::invalid(); | 2755 Scanner::Location duplicate_loc = Scanner::Location::invalid(); |
2729 bool has_rest = false; | 2756 FormalParameterParsingStateT parsing_state(scope); |
2730 this->ParseArrowFunctionFormalParameters(scope, expression, loc, &has_rest, | 2757 this->ParseArrowFunctionFormalParameters(&parsing_state, expression, loc, |
2731 &duplicate_loc, CHECK_OK); | 2758 &duplicate_loc, CHECK_OK); |
2732 if (duplicate_loc.IsValid()) { | 2759 if (duplicate_loc.IsValid()) { |
2733 arrow_formals_classifier.RecordDuplicateFormalParameterError( | 2760 arrow_formals_classifier.RecordDuplicateFormalParameterError( |
2734 duplicate_loc); | 2761 duplicate_loc); |
2735 } | 2762 } |
2736 expression = this->ParseArrowFunctionLiteral( | 2763 expression = this->ParseArrowFunctionLiteral( |
2737 scope, has_rest, arrow_formals_classifier, CHECK_OK); | 2764 parsing_state, arrow_formals_classifier, CHECK_OK); |
2738 return expression; | 2765 return expression; |
2739 } | 2766 } |
2740 | 2767 |
2741 // "expression" was not itself an arrow function parameter list, but it might | 2768 // "expression" was not itself an arrow function parameter list, but it might |
2742 // form part of one. Propagate speculative formal parameter error locations. | 2769 // form part of one. Propagate speculative formal parameter error locations. |
2743 classifier->Accumulate(arrow_formals_classifier, | 2770 classifier->Accumulate(arrow_formals_classifier, |
2744 ExpressionClassifier::StandardProductions | | 2771 ExpressionClassifier::StandardProductions | |
2745 ExpressionClassifier::FormalParametersProductions); | 2772 ExpressionClassifier::FormalParametersProductions); |
2746 | 2773 |
2747 if (!Token::IsAssignmentOp(peek())) { | 2774 if (!Token::IsAssignmentOp(peek())) { |
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3490 default: | 3517 default: |
3491 return expression; | 3518 return expression; |
3492 } | 3519 } |
3493 } | 3520 } |
3494 DCHECK(false); | 3521 DCHECK(false); |
3495 return this->EmptyExpression(); | 3522 return this->EmptyExpression(); |
3496 } | 3523 } |
3497 | 3524 |
3498 | 3525 |
3499 template <class Traits> | 3526 template <class Traits> |
3500 void ParserBase<Traits>::ParseFormalParameter(Scope* scope, bool is_rest, | 3527 void ParserBase<Traits>::ParseFormalParameter( |
3501 ExpressionClassifier* classifier, | 3528 bool is_rest, FormalParameterParsingStateT* parsing_state, |
3502 bool* ok) { | 3529 ExpressionClassifier* classifier, bool* ok) { |
3503 // FormalParameter[Yield,GeneratorParameter] : | 3530 // FormalParameter[Yield,GeneratorParameter] : |
3504 // BindingElement[?Yield, ?GeneratorParameter] | 3531 // BindingElement[?Yield, ?GeneratorParameter] |
3505 | 3532 |
3506 Token::Value next = peek(); | 3533 Token::Value next = peek(); |
3507 ExpressionT pattern = ParsePrimaryExpression(classifier, ok); | 3534 ExpressionT pattern = ParsePrimaryExpression(classifier, ok); |
3508 if (!*ok) return; | 3535 if (!*ok) return; |
3509 | 3536 |
3510 ValidateBindingPattern(classifier, ok); | 3537 ValidateBindingPattern(classifier, ok); |
3511 if (!*ok) return; | 3538 if (!*ok) return; |
3512 | 3539 |
3513 if (!allow_harmony_destructuring() && !Traits::IsIdentifier(pattern)) { | 3540 if (!allow_harmony_destructuring() && !Traits::IsIdentifier(pattern)) { |
3514 ReportUnexpectedToken(next); | 3541 ReportUnexpectedToken(next); |
3515 *ok = false; | 3542 *ok = false; |
3516 return; | 3543 return; |
3517 } | 3544 } |
3518 | 3545 |
3519 Traits::DeclareFormalParameter(scope, pattern, classifier, is_rest); | 3546 if (parsing_state->is_simple_parameter_list) { |
| 3547 parsing_state->is_simple_parameter_list = |
| 3548 !is_rest && Traits::IsIdentifier(pattern); |
| 3549 } |
| 3550 parsing_state->has_rest = is_rest; |
| 3551 if (is_rest && !Traits::IsIdentifier(pattern)) { |
| 3552 ReportUnexpectedToken(next); |
| 3553 *ok = false; |
| 3554 return; |
| 3555 } |
| 3556 Traits::DeclareFormalParameter(parsing_state, pattern, classifier, is_rest); |
3520 } | 3557 } |
3521 | 3558 |
3522 | 3559 |
3523 template <class Traits> | 3560 template <class Traits> |
3524 int ParserBase<Traits>::ParseFormalParameterList( | 3561 int ParserBase<Traits>::ParseFormalParameterList( |
3525 Scope* scope, bool* is_rest, ExpressionClassifier* classifier, bool* ok) { | 3562 FormalParameterParsingStateT* parsing_state, |
| 3563 ExpressionClassifier* classifier, bool* ok) { |
3526 // FormalParameters[Yield,GeneratorParameter] : | 3564 // FormalParameters[Yield,GeneratorParameter] : |
3527 // [empty] | 3565 // [empty] |
3528 // FormalParameterList[?Yield, ?GeneratorParameter] | 3566 // FormalParameterList[?Yield, ?GeneratorParameter] |
3529 // | 3567 // |
3530 // FormalParameterList[Yield,GeneratorParameter] : | 3568 // FormalParameterList[Yield,GeneratorParameter] : |
3531 // FunctionRestParameter[?Yield] | 3569 // FunctionRestParameter[?Yield] |
3532 // FormalsList[?Yield, ?GeneratorParameter] | 3570 // FormalsList[?Yield, ?GeneratorParameter] |
3533 // FormalsList[?Yield, ?GeneratorParameter] , FunctionRestParameter[?Yield] | 3571 // FormalsList[?Yield, ?GeneratorParameter] , FunctionRestParameter[?Yield] |
3534 // | 3572 // |
3535 // FormalsList[Yield,GeneratorParameter] : | 3573 // FormalsList[Yield,GeneratorParameter] : |
3536 // FormalParameter[?Yield, ?GeneratorParameter] | 3574 // FormalParameter[?Yield, ?GeneratorParameter] |
3537 // FormalsList[?Yield, ?GeneratorParameter] , | 3575 // FormalsList[?Yield, ?GeneratorParameter] , |
3538 // FormalParameter[?Yield,?GeneratorParameter] | 3576 // FormalParameter[?Yield,?GeneratorParameter] |
3539 | 3577 |
3540 int parameter_count = 0; | 3578 int parameter_count = 0; |
3541 | 3579 |
3542 if (peek() != Token::RPAREN) { | 3580 if (peek() != Token::RPAREN) { |
3543 do { | 3581 do { |
3544 if (++parameter_count > Code::kMaxArguments) { | 3582 if (++parameter_count > Code::kMaxArguments) { |
3545 ReportMessage(MessageTemplate::kTooManyParameters); | 3583 ReportMessage(MessageTemplate::kTooManyParameters); |
3546 *ok = false; | 3584 *ok = false; |
3547 return -1; | 3585 return -1; |
3548 } | 3586 } |
3549 *is_rest = allow_harmony_rest_params() && Check(Token::ELLIPSIS); | 3587 bool is_rest = allow_harmony_rest_params() && Check(Token::ELLIPSIS); |
3550 ParseFormalParameter(scope, *is_rest, classifier, ok); | 3588 ParseFormalParameter(is_rest, parsing_state, classifier, ok); |
3551 if (!*ok) return -1; | 3589 if (!*ok) return -1; |
3552 } while (!*is_rest && Check(Token::COMMA)); | 3590 } while (!parsing_state->has_rest && Check(Token::COMMA)); |
3553 | 3591 |
3554 if (*is_rest && peek() == Token::COMMA) { | 3592 if (parsing_state->has_rest && peek() == Token::COMMA) { |
3555 ReportMessageAt(scanner()->peek_location(), | 3593 ReportMessageAt(scanner()->peek_location(), |
3556 MessageTemplate::kParamAfterRest); | 3594 MessageTemplate::kParamAfterRest); |
3557 *ok = false; | 3595 *ok = false; |
3558 return -1; | 3596 return -1; |
3559 } | 3597 } |
3560 } | 3598 } |
3561 | 3599 |
3562 return parameter_count; | 3600 return parameter_count; |
3563 } | 3601 } |
3564 | 3602 |
(...skipping 24 matching lines...) Expand all Loading... |
3589 break; | 3627 break; |
3590 default: | 3628 default: |
3591 break; | 3629 break; |
3592 } | 3630 } |
3593 } | 3631 } |
3594 | 3632 |
3595 | 3633 |
3596 template <class Traits> | 3634 template <class Traits> |
3597 typename ParserBase<Traits>::ExpressionT | 3635 typename ParserBase<Traits>::ExpressionT |
3598 ParserBase<Traits>::ParseArrowFunctionLiteral( | 3636 ParserBase<Traits>::ParseArrowFunctionLiteral( |
3599 Scope* scope, bool has_rest, const ExpressionClassifier& formals_classifier, | 3637 const FormalParameterParsingStateT& formal_parameters, |
3600 bool* ok) { | 3638 const ExpressionClassifier& formals_classifier, bool* ok) { |
3601 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { | 3639 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { |
3602 // ASI inserts `;` after arrow parameters if a line terminator is found. | 3640 // ASI inserts `;` after arrow parameters if a line terminator is found. |
3603 // `=> ...` is never a valid expression, so report as syntax error. | 3641 // `=> ...` is never a valid expression, so report as syntax error. |
3604 // If next token is not `=>`, it's a syntax error anyways. | 3642 // If next token is not `=>`, it's a syntax error anyways. |
3605 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); | 3643 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); |
3606 *ok = false; | 3644 *ok = false; |
3607 return this->EmptyExpression(); | 3645 return this->EmptyExpression(); |
3608 } | 3646 } |
3609 | 3647 |
3610 typename Traits::Type::StatementList body; | 3648 typename Traits::Type::StatementList body; |
3611 int num_parameters = scope->num_parameters(); | 3649 int num_parameters = formal_parameters.scope->num_parameters(); |
3612 int materialized_literal_count = -1; | 3650 int materialized_literal_count = -1; |
3613 int expected_property_count = -1; | 3651 int expected_property_count = -1; |
3614 Scanner::Location super_loc; | 3652 Scanner::Location super_loc; |
3615 | 3653 |
3616 { | 3654 { |
3617 typename Traits::Type::Factory function_factory(ast_value_factory()); | 3655 typename Traits::Type::Factory function_factory(ast_value_factory()); |
3618 FunctionState function_state(&function_state_, &scope_, scope, | 3656 FunctionState function_state(&function_state_, &scope_, |
3619 kArrowFunction, &function_factory); | 3657 formal_parameters.scope, kArrowFunction, |
| 3658 &function_factory); |
3620 | 3659 |
3621 Expect(Token::ARROW, CHECK_OK); | 3660 Expect(Token::ARROW, CHECK_OK); |
3622 | 3661 |
3623 if (peek() == Token::LBRACE) { | 3662 if (peek() == Token::LBRACE) { |
3624 // Multiple statement body | 3663 // Multiple statement body |
3625 Consume(Token::LBRACE); | 3664 Consume(Token::LBRACE); |
3626 bool is_lazily_parsed = | 3665 bool is_lazily_parsed = |
3627 (mode() == PARSE_LAZILY && scope_->AllowsLazyCompilation()); | 3666 (mode() == PARSE_LAZILY && scope_->AllowsLazyCompilation()); |
3628 if (is_lazily_parsed) { | 3667 if (is_lazily_parsed) { |
3629 body = this->NewStatementList(0, zone()); | 3668 body = this->NewStatementList(0, zone()); |
3630 this->SkipLazyFunctionBody(&materialized_literal_count, | 3669 this->SkipLazyFunctionBody(&materialized_literal_count, |
3631 &expected_property_count, CHECK_OK); | 3670 &expected_property_count, CHECK_OK); |
3632 } else { | 3671 } else { |
3633 body = this->ParseEagerFunctionBody( | 3672 body = this->ParseEagerFunctionBody( |
3634 this->EmptyIdentifier(), RelocInfo::kNoPosition, NULL, | 3673 this->EmptyIdentifier(), RelocInfo::kNoPosition, formal_parameters, |
3635 Token::INIT_VAR, kArrowFunction, CHECK_OK); | 3674 NULL, Token::INIT_VAR, kArrowFunction, CHECK_OK); |
3636 materialized_literal_count = | 3675 materialized_literal_count = |
3637 function_state.materialized_literal_count(); | 3676 function_state.materialized_literal_count(); |
3638 expected_property_count = function_state.expected_property_count(); | 3677 expected_property_count = function_state.expected_property_count(); |
3639 } | 3678 } |
3640 } else { | 3679 } else { |
3641 // Single-expression body | 3680 // Single-expression body |
3642 int pos = position(); | 3681 int pos = position(); |
3643 parenthesized_function_ = false; | 3682 parenthesized_function_ = false; |
3644 ExpressionClassifier classifier; | 3683 ExpressionClassifier classifier; |
3645 ExpressionT expression = | 3684 ExpressionT expression = |
3646 ParseAssignmentExpression(true, &classifier, CHECK_OK); | 3685 ParseAssignmentExpression(true, &classifier, CHECK_OK); |
3647 ValidateExpression(&classifier, CHECK_OK); | 3686 ValidateExpression(&classifier, CHECK_OK); |
3648 body = this->NewStatementList(1, zone()); | 3687 body = this->NewStatementList(1, zone()); |
| 3688 this->AddParameterInitializationBlock(formal_parameters, body, CHECK_OK); |
3649 body->Add(factory()->NewReturnStatement(expression, pos), zone()); | 3689 body->Add(factory()->NewReturnStatement(expression, pos), zone()); |
3650 materialized_literal_count = function_state.materialized_literal_count(); | 3690 materialized_literal_count = function_state.materialized_literal_count(); |
3651 expected_property_count = function_state.expected_property_count(); | 3691 expected_property_count = function_state.expected_property_count(); |
3652 } | 3692 } |
3653 super_loc = function_state.super_location(); | 3693 super_loc = function_state.super_location(); |
3654 | 3694 |
3655 scope->set_end_position(scanner()->location().end_pos); | 3695 formal_parameters.scope->set_end_position(scanner()->location().end_pos); |
3656 | 3696 |
3657 // Arrow function formal parameters are parsed as StrictFormalParameterList, | 3697 // Arrow function formal parameters are parsed as StrictFormalParameterList, |
3658 // which is not the same as "parameters of a strict function"; it only means | 3698 // which is not the same as "parameters of a strict function"; it only means |
3659 // that duplicates are not allowed. Of course, the arrow function may | 3699 // that duplicates are not allowed. Of course, the arrow function may |
3660 // itself be strict as well. | 3700 // itself be strict as well. |
3661 const bool allow_duplicate_parameters = false; | 3701 const bool allow_duplicate_parameters = false; |
3662 this->ValidateFormalParameters(&formals_classifier, language_mode(), | 3702 this->ValidateFormalParameters(&formals_classifier, language_mode(), |
3663 allow_duplicate_parameters, CHECK_OK); | 3703 allow_duplicate_parameters, CHECK_OK); |
3664 | 3704 |
3665 // Validate strict mode. | 3705 // Validate strict mode. |
3666 if (is_strict(language_mode())) { | 3706 if (is_strict(language_mode())) { |
3667 CheckStrictOctalLiteral(scope->start_position(), | 3707 CheckStrictOctalLiteral(formal_parameters.scope->start_position(), |
3668 scanner()->location().end_pos, CHECK_OK); | 3708 scanner()->location().end_pos, CHECK_OK); |
3669 this->CheckConflictingVarDeclarations(scope, CHECK_OK); | 3709 this->CheckConflictingVarDeclarations(formal_parameters.scope, CHECK_OK); |
3670 } | 3710 } |
3671 } | 3711 } |
3672 | 3712 |
3673 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( | 3713 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( |
3674 this->EmptyIdentifierString(), ast_value_factory(), scope, body, | 3714 this->EmptyIdentifierString(), ast_value_factory(), |
3675 materialized_literal_count, expected_property_count, num_parameters, | 3715 formal_parameters.scope, body, materialized_literal_count, |
| 3716 expected_property_count, num_parameters, |
3676 FunctionLiteral::kNoDuplicateParameters, | 3717 FunctionLiteral::kNoDuplicateParameters, |
3677 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction, | 3718 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction, |
3678 FunctionLiteral::kShouldLazyCompile, FunctionKind::kArrowFunction, | 3719 FunctionLiteral::kShouldLazyCompile, FunctionKind::kArrowFunction, |
3679 scope->start_position()); | 3720 formal_parameters.scope->start_position()); |
3680 | 3721 |
3681 function_literal->set_function_token_position(scope->start_position()); | 3722 function_literal->set_function_token_position( |
| 3723 formal_parameters.scope->start_position()); |
3682 if (super_loc.IsValid()) function_state_->set_super_location(super_loc); | 3724 if (super_loc.IsValid()) function_state_->set_super_location(super_loc); |
3683 | 3725 |
3684 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); | 3726 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); |
3685 | 3727 |
3686 return function_literal; | 3728 return function_literal; |
3687 } | 3729 } |
3688 | 3730 |
3689 | 3731 |
3690 template <typename Traits> | 3732 template <typename Traits> |
3691 typename ParserBase<Traits>::ExpressionT | 3733 typename ParserBase<Traits>::ExpressionT |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3872 *ok = false; | 3914 *ok = false; |
3873 return; | 3915 return; |
3874 } | 3916 } |
3875 has_seen_constructor_ = true; | 3917 has_seen_constructor_ = true; |
3876 return; | 3918 return; |
3877 } | 3919 } |
3878 } | 3920 } |
3879 } } // v8::internal | 3921 } } // v8::internal |
3880 | 3922 |
3881 #endif // V8_PREPARSER_H | 3923 #endif // V8_PREPARSER_H |
OLD | NEW |