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