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 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
548 !classifier->is_valid_strong_mode_formal_parameters()) { | 550 !classifier->is_valid_strong_mode_formal_parameters()) { |
549 ReportClassifierError(classifier->strong_mode_formal_parameter_error()); | 551 ReportClassifierError(classifier->strong_mode_formal_parameter_error()); |
550 *ok = false; | 552 *ok = false; |
551 } | 553 } |
552 } | 554 } |
553 | 555 |
554 void ValidateArrowFormalParameters(const ExpressionClassifier* classifier, | 556 void ValidateArrowFormalParameters(const ExpressionClassifier* classifier, |
555 ExpressionT expr, bool* ok) { | 557 ExpressionT expr, bool* ok) { |
556 if (classifier->is_valid_binding_pattern()) { | 558 if (classifier->is_valid_binding_pattern()) { |
557 // A simple arrow formal parameter: IDENTIFIER => BODY. | 559 // A simple arrow formal parameter: IDENTIFIER => BODY. |
558 if (!allow_harmony_destructuring() && !this->IsIdentifier(expr)) { | 560 if (!this->IsIdentifier(expr)) { |
559 Traits::ReportMessageAt(scanner()->location(), | 561 Traits::ReportMessageAt(scanner()->location(), |
560 MessageTemplate::kUnexpectedToken, | 562 MessageTemplate::kUnexpectedToken, |
561 Token::String(scanner()->current_token())); | 563 Token::String(scanner()->current_token())); |
562 *ok = false; | 564 *ok = false; |
563 } | 565 } |
564 } else if (!classifier->is_valid_arrow_formal_parameters()) { | 566 } else if (!classifier->is_valid_arrow_formal_parameters()) { |
565 ReportClassifierError(classifier->arrow_formal_parameters_error()); | 567 ReportClassifierError(classifier->arrow_formal_parameters_error()); |
566 *ok = false; | 568 *ok = false; |
567 } | 569 } |
568 } | 570 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
637 ExpressionT ParseUnaryExpression(ExpressionClassifier* classifier, bool* ok); | 639 ExpressionT ParseUnaryExpression(ExpressionClassifier* classifier, bool* ok); |
638 ExpressionT ParsePostfixExpression(ExpressionClassifier* classifier, | 640 ExpressionT ParsePostfixExpression(ExpressionClassifier* classifier, |
639 bool* ok); | 641 bool* ok); |
640 ExpressionT ParseLeftHandSideExpression(ExpressionClassifier* classifier, | 642 ExpressionT ParseLeftHandSideExpression(ExpressionClassifier* classifier, |
641 bool* ok); | 643 bool* ok); |
642 ExpressionT ParseMemberWithNewPrefixesExpression( | 644 ExpressionT ParseMemberWithNewPrefixesExpression( |
643 ExpressionClassifier* classifier, bool* ok); | 645 ExpressionClassifier* classifier, bool* ok); |
644 ExpressionT ParseMemberExpression(ExpressionClassifier* classifier, bool* ok); | 646 ExpressionT ParseMemberExpression(ExpressionClassifier* classifier, bool* ok); |
645 ExpressionT ParseMemberExpressionContinuation( | 647 ExpressionT ParseMemberExpressionContinuation( |
646 ExpressionT expression, ExpressionClassifier* classifier, bool* ok); | 648 ExpressionT expression, ExpressionClassifier* classifier, bool* ok); |
647 ExpressionT ParseArrowFunctionLiteral(Scope* function_scope, bool has_rest, | 649 ExpressionT ParseArrowFunctionLiteral( |
648 const ExpressionClassifier& classifier, | 650 const FormalParameterParsingStateT& parsing_state, |
649 bool* ok); | 651 const ExpressionClassifier& classifier, bool* ok); |
650 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, | 652 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, |
651 ExpressionClassifier* classifier, bool* ok); | 653 ExpressionClassifier* classifier, bool* ok); |
652 void AddTemplateExpression(ExpressionT); | 654 void AddTemplateExpression(ExpressionT); |
653 ExpressionT ParseSuperExpression(bool is_new, | 655 ExpressionT ParseSuperExpression(bool is_new, |
654 ExpressionClassifier* classifier, bool* ok); | 656 ExpressionClassifier* classifier, bool* ok); |
655 ExpressionT ParseNewTargetExpression(bool* ok); | 657 ExpressionT ParseNewTargetExpression(bool* ok); |
656 ExpressionT ParseStrongInitializationExpression( | 658 ExpressionT ParseStrongInitializationExpression( |
657 ExpressionClassifier* classifier, bool* ok); | 659 ExpressionClassifier* classifier, bool* ok); |
658 ExpressionT ParseStrongSuperCallExpression(ExpressionClassifier* classifier, | 660 ExpressionT ParseStrongSuperCallExpression(ExpressionClassifier* classifier, |
659 bool* ok); | 661 bool* ok); |
660 | 662 |
661 void ParseFormalParameter(Scope* scope, bool is_rest, | 663 void ParseFormalParameter(bool is_rest, |
664 FormalParameterParsingStateT* parsing_result, | |
662 ExpressionClassifier* classifier, bool* ok); | 665 ExpressionClassifier* classifier, bool* ok); |
663 int ParseFormalParameterList(Scope* scope, bool* has_rest, | 666 int ParseFormalParameterList(FormalParameterParsingStateT* parsing_state, |
664 ExpressionClassifier* classifier, bool* ok); | 667 ExpressionClassifier* classifier, bool* ok); |
665 void CheckArityRestrictions( | 668 void CheckArityRestrictions( |
666 int param_count, FunctionLiteral::ArityRestriction arity_restriction, | 669 int param_count, FunctionLiteral::ArityRestriction arity_restriction, |
667 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok); | 670 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok); |
668 | 671 |
669 // Checks if the expression is a valid reference expression (e.g., on the | 672 // Checks if the expression is a valid reference expression (e.g., on the |
670 // left-hand side of assignments). Although ruled out by ECMA as early errors, | 673 // left-hand side of assignments). Although ruled out by ECMA as early errors, |
671 // we allow calls for web compatibility and rewrite them to a runtime throw. | 674 // we allow calls for web compatibility and rewrite them to a runtime throw. |
672 ExpressionT CheckAndRewriteReferenceExpression( | 675 ExpressionT CheckAndRewriteReferenceExpression( |
673 ExpressionT expression, Scanner::Location location, | 676 ExpressionT expression, Scanner::Location location, |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1245 // Return the object itself as AstVisitor and implement the needed | 1248 // Return the object itself as AstVisitor and implement the needed |
1246 // dummy method right in this class. | 1249 // dummy method right in this class. |
1247 PreParserFactory* visitor() { return this; } | 1250 PreParserFactory* visitor() { return this; } |
1248 int* ast_properties() { | 1251 int* ast_properties() { |
1249 static int dummy = 42; | 1252 static int dummy = 42; |
1250 return &dummy; | 1253 return &dummy; |
1251 } | 1254 } |
1252 }; | 1255 }; |
1253 | 1256 |
1254 | 1257 |
1258 struct PreParserFormalParameterParsingState { | |
1259 explicit PreParserFormalParameterParsingState(Scope* scope) | |
1260 : scope(scope), has_rest(false), is_simple_parameter_list(true) {} | |
1261 Scope* scope; | |
1262 bool has_rest; | |
1263 bool is_simple_parameter_list; | |
1264 }; | |
1265 | |
1266 | |
1255 class PreParser; | 1267 class PreParser; |
1256 | 1268 |
1257 class PreParserTraits { | 1269 class PreParserTraits { |
1258 public: | 1270 public: |
1259 struct Type { | 1271 struct Type { |
1260 // TODO(marja): To be removed. The Traits object should contain all the data | 1272 // TODO(marja): To be removed. The Traits object should contain all the data |
1261 // it needs. | 1273 // it needs. |
1262 typedef PreParser* Parser; | 1274 typedef PreParser* Parser; |
1263 | 1275 |
1264 // PreParser doesn't need to store generator variables. | 1276 // PreParser doesn't need to store generator variables. |
1265 typedef void GeneratorVariable; | 1277 typedef void GeneratorVariable; |
1266 | 1278 |
1267 typedef int AstProperties; | 1279 typedef int AstProperties; |
1268 | 1280 |
1269 // Return types for traversing functions. | 1281 // Return types for traversing functions. |
1270 typedef PreParserIdentifier Identifier; | 1282 typedef PreParserIdentifier Identifier; |
1271 typedef PreParserExpression Expression; | 1283 typedef PreParserExpression Expression; |
1272 typedef PreParserExpression YieldExpression; | 1284 typedef PreParserExpression YieldExpression; |
1273 typedef PreParserExpression FunctionLiteral; | 1285 typedef PreParserExpression FunctionLiteral; |
1274 typedef PreParserExpression ClassLiteral; | 1286 typedef PreParserExpression ClassLiteral; |
1275 typedef PreParserExpression ObjectLiteralProperty; | 1287 typedef PreParserExpression ObjectLiteralProperty; |
1276 typedef PreParserExpression Literal; | 1288 typedef PreParserExpression Literal; |
1277 typedef PreParserExpressionList ExpressionList; | 1289 typedef PreParserExpressionList ExpressionList; |
1278 typedef PreParserExpressionList PropertyList; | 1290 typedef PreParserExpressionList PropertyList; |
1279 typedef PreParserIdentifier FormalParameter; | 1291 typedef PreParserIdentifier FormalParameter; |
1280 typedef PreParserStatementList StatementList; | 1292 typedef PreParserStatementList StatementList; |
1293 typedef PreParserFormalParameterParsingState FormalParameterParsingState; | |
1281 | 1294 |
1282 // For constructing objects returned by the traversing functions. | 1295 // For constructing objects returned by the traversing functions. |
1283 typedef PreParserFactory Factory; | 1296 typedef PreParserFactory Factory; |
1284 }; | 1297 }; |
1285 | 1298 |
1286 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {} | 1299 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {} |
1287 | 1300 |
1288 // Helper functions for recursive descent. | 1301 // Helper functions for recursive descent. |
1289 static bool IsEval(PreParserIdentifier identifier) { | 1302 static bool IsEval(PreParserIdentifier identifier) { |
1290 return identifier.IsEval(); | 1303 return identifier.IsEval(); |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1509 } | 1522 } |
1510 | 1523 |
1511 static PreParserStatementList NewStatementList(int size, Zone* zone) { | 1524 static PreParserStatementList NewStatementList(int size, Zone* zone) { |
1512 return PreParserStatementList(); | 1525 return PreParserStatementList(); |
1513 } | 1526 } |
1514 | 1527 |
1515 static PreParserExpressionList NewPropertyList(int size, Zone* zone) { | 1528 static PreParserExpressionList NewPropertyList(int size, Zone* zone) { |
1516 return PreParserExpressionList(); | 1529 return PreParserExpressionList(); |
1517 } | 1530 } |
1518 | 1531 |
1532 static void AddParameterInitializationBlock( | |
1533 const PreParserFormalParameterParsingState& formal_parameters, | |
1534 PreParserStatementList list, bool* ok) {} | |
1535 | |
1519 V8_INLINE void SkipLazyFunctionBody(int* materialized_literal_count, | 1536 V8_INLINE void SkipLazyFunctionBody(int* materialized_literal_count, |
1520 int* expected_property_count, bool* ok) { | 1537 int* expected_property_count, bool* ok) { |
1521 UNREACHABLE(); | 1538 UNREACHABLE(); |
1522 } | 1539 } |
1523 | 1540 |
1524 V8_INLINE PreParserStatementList | 1541 V8_INLINE PreParserStatementList ParseEagerFunctionBody( |
1525 ParseEagerFunctionBody(PreParserIdentifier function_name, int pos, | 1542 PreParserIdentifier function_name, int pos, |
1526 Variable* fvar, Token::Value fvar_init_op, | 1543 const PreParserFormalParameterParsingState& formal_parameters, |
1527 FunctionKind kind, bool* ok); | 1544 Variable* fvar, Token::Value fvar_init_op, FunctionKind kind, bool* ok); |
1528 | 1545 |
1529 V8_INLINE void ParseArrowFunctionFormalParameters( | 1546 V8_INLINE void ParseArrowFunctionFormalParameters( |
1530 Scope* scope, PreParserExpression expression, | 1547 PreParserFormalParameterParsingState* parsing_state, |
1531 const Scanner::Location& params_loc, bool* has_rest, | 1548 PreParserExpression expression, const Scanner::Location& params_loc, |
1532 Scanner::Location* duplicate_loc, bool* ok); | 1549 Scanner::Location* duplicate_loc, bool* ok); |
1533 | 1550 |
1534 struct TemplateLiteralState {}; | 1551 struct TemplateLiteralState {}; |
1535 | 1552 |
1536 TemplateLiteralState OpenTemplateLiteral(int pos) { | 1553 TemplateLiteralState OpenTemplateLiteral(int pos) { |
1537 return TemplateLiteralState(); | 1554 return TemplateLiteralState(); |
1538 } | 1555 } |
1539 void AddTemplateSpan(TemplateLiteralState*, bool) {} | 1556 void AddTemplateSpan(TemplateLiteralState*, bool) {} |
1540 void AddTemplateExpression(TemplateLiteralState*, PreParserExpression) {} | 1557 void AddTemplateExpression(TemplateLiteralState*, PreParserExpression) {} |
1541 PreParserExpression CloseTemplateLiteral(TemplateLiteralState*, int, | 1558 PreParserExpression CloseTemplateLiteral(TemplateLiteralState*, int, |
1542 PreParserExpression tag) { | 1559 PreParserExpression tag) { |
1543 if (IsTaggedTemplate(tag)) { | 1560 if (IsTaggedTemplate(tag)) { |
1544 // Emulate generation of array literals for tag callsite | 1561 // Emulate generation of array literals for tag callsite |
1545 // 1st is array of cooked strings, second is array of raw strings | 1562 // 1st is array of cooked strings, second is array of raw strings |
1546 MaterializeTemplateCallsiteLiterals(); | 1563 MaterializeTemplateCallsiteLiterals(); |
1547 } | 1564 } |
1548 return EmptyExpression(); | 1565 return EmptyExpression(); |
1549 } | 1566 } |
1550 inline void MaterializeTemplateCallsiteLiterals(); | 1567 inline void MaterializeTemplateCallsiteLiterals(); |
1551 PreParserExpression NoTemplateTag() { | 1568 PreParserExpression NoTemplateTag() { |
1552 return PreParserExpression::NoTemplateTag(); | 1569 return PreParserExpression::NoTemplateTag(); |
1553 } | 1570 } |
1554 static bool IsTaggedTemplate(const PreParserExpression tag) { | 1571 static bool IsTaggedTemplate(const PreParserExpression tag) { |
1555 return !tag.IsNoTemplateTag(); | 1572 return !tag.IsNoTemplateTag(); |
1556 } | 1573 } |
1557 | 1574 |
1558 void DeclareFormalParameter(Scope* scope, PreParserExpression pattern, | 1575 void DeclareFormalParameter(void* parsing_state, PreParserExpression pattern, |
1559 ExpressionClassifier* classifier, bool is_rest) {} | 1576 ExpressionClassifier* classifier, bool is_rest) {} |
1560 | 1577 |
1561 void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {} | 1578 void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {} |
1562 | 1579 |
1563 // Temporary glue; these functions will move to ParserBase. | 1580 // Temporary glue; these functions will move to ParserBase. |
1564 PreParserExpression ParseV8Intrinsic(bool* ok); | 1581 PreParserExpression ParseV8Intrinsic(bool* ok); |
1565 PreParserExpression ParseFunctionLiteral( | 1582 PreParserExpression ParseFunctionLiteral( |
1566 PreParserIdentifier name, Scanner::Location function_name_location, | 1583 PreParserIdentifier name, Scanner::Location function_name_location, |
1567 bool name_is_strict_reserved, FunctionKind kind, | 1584 bool name_is_strict_reserved, FunctionKind kind, |
1568 int function_token_position, FunctionLiteral::FunctionType type, | 1585 int function_token_position, FunctionLiteral::FunctionType type, |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1699 Statement ParseTryStatement(bool* ok); | 1716 Statement ParseTryStatement(bool* ok); |
1700 Statement ParseDebuggerStatement(bool* ok); | 1717 Statement ParseDebuggerStatement(bool* ok); |
1701 Expression ParseConditionalExpression(bool accept_IN, bool* ok); | 1718 Expression ParseConditionalExpression(bool accept_IN, bool* ok); |
1702 Expression ParseObjectLiteral(bool* ok); | 1719 Expression ParseObjectLiteral(bool* ok); |
1703 Expression ParseV8Intrinsic(bool* ok); | 1720 Expression ParseV8Intrinsic(bool* ok); |
1704 | 1721 |
1705 V8_INLINE void SkipLazyFunctionBody(int* materialized_literal_count, | 1722 V8_INLINE void SkipLazyFunctionBody(int* materialized_literal_count, |
1706 int* expected_property_count, bool* ok); | 1723 int* expected_property_count, bool* ok); |
1707 V8_INLINE PreParserStatementList | 1724 V8_INLINE PreParserStatementList |
1708 ParseEagerFunctionBody(PreParserIdentifier function_name, int pos, | 1725 ParseEagerFunctionBody(PreParserIdentifier function_name, int pos, |
1726 const FormalParameterParsingStateT& formal_parameters, | |
1709 Variable* fvar, Token::Value fvar_init_op, | 1727 Variable* fvar, Token::Value fvar_init_op, |
1710 FunctionKind kind, bool* ok); | 1728 FunctionKind kind, bool* ok); |
1711 | 1729 |
1712 Expression ParseFunctionLiteral( | 1730 Expression ParseFunctionLiteral( |
1713 Identifier name, Scanner::Location function_name_location, | 1731 Identifier name, Scanner::Location function_name_location, |
1714 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, | 1732 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, |
1715 FunctionLiteral::FunctionType function_type, | 1733 FunctionLiteral::FunctionType function_type, |
1716 FunctionLiteral::ArityRestriction arity_restriction, bool* ok); | 1734 FunctionLiteral::ArityRestriction arity_restriction, bool* ok); |
1717 void ParseLazyFunctionLiteralBody(bool* ok, | 1735 void ParseLazyFunctionLiteralBody(bool* ok, |
1718 Scanner::BookmarkScope* bookmark = nullptr); | 1736 Scanner::BookmarkScope* bookmark = nullptr); |
(...skipping 25 matching lines...) Expand all Loading... | |
1744 } | 1762 } |
1745 | 1763 |
1746 PreParserExpression PreParserTraits::SpreadCallNew(PreParserExpression function, | 1764 PreParserExpression PreParserTraits::SpreadCallNew(PreParserExpression function, |
1747 PreParserExpressionList args, | 1765 PreParserExpressionList args, |
1748 int pos) { | 1766 int pos) { |
1749 return pre_parser_->factory()->NewCallNew(function, args, pos); | 1767 return pre_parser_->factory()->NewCallNew(function, args, pos); |
1750 } | 1768 } |
1751 | 1769 |
1752 | 1770 |
1753 void PreParserTraits::ParseArrowFunctionFormalParameters( | 1771 void PreParserTraits::ParseArrowFunctionFormalParameters( |
1754 Scope* scope, PreParserExpression params, | 1772 PreParserFormalParameterParsingState* parsing_state, |
1755 const Scanner::Location& params_loc, bool* has_rest, | 1773 PreParserExpression params, const Scanner::Location& params_loc, |
1756 Scanner::Location* duplicate_loc, bool* ok) { | 1774 Scanner::Location* duplicate_loc, bool* ok) { |
1757 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter | 1775 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter |
1758 // lists that are too long. | 1776 // lists that are too long. |
1759 } | 1777 } |
1760 | 1778 |
1761 | 1779 |
1762 PreParserStatementList PreParser::ParseEagerFunctionBody( | 1780 PreParserStatementList PreParser::ParseEagerFunctionBody( |
1763 PreParserIdentifier function_name, int pos, Variable* fvar, | 1781 PreParserIdentifier function_name, int pos, |
1764 Token::Value fvar_init_op, FunctionKind kind, bool* ok) { | 1782 const PreParserFormalParameterParsingState& formal_parameters, |
1783 Variable* fvar, Token::Value fvar_init_op, FunctionKind kind, bool* ok) { | |
1765 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 1784 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
1766 | 1785 |
1767 ParseStatementList(Token::RBRACE, ok); | 1786 ParseStatementList(Token::RBRACE, ok); |
1768 if (!*ok) return PreParserStatementList(); | 1787 if (!*ok) return PreParserStatementList(); |
1769 | 1788 |
1770 Expect(Token::RBRACE, ok); | 1789 Expect(Token::RBRACE, ok); |
1771 return PreParserStatementList(); | 1790 return PreParserStatementList(); |
1772 } | 1791 } |
1773 | 1792 |
1774 | 1793 |
1775 PreParserStatementList PreParserTraits::ParseEagerFunctionBody( | 1794 PreParserStatementList PreParserTraits::ParseEagerFunctionBody( |
1776 PreParserIdentifier function_name, int pos, Variable* fvar, | 1795 PreParserIdentifier function_name, int pos, |
1777 Token::Value fvar_init_op, FunctionKind kind, bool* ok) { | 1796 const PreParserFormalParameterParsingState& formal_parameters, |
1778 return pre_parser_->ParseEagerFunctionBody(function_name, pos, fvar, | 1797 Variable* fvar, Token::Value fvar_init_op, FunctionKind kind, bool* ok) { |
1779 fvar_init_op, kind, ok); | 1798 return pre_parser_->ParseEagerFunctionBody( |
1799 function_name, pos, formal_parameters, fvar, fvar_init_op, kind, ok); | |
1780 } | 1800 } |
1781 | 1801 |
1782 | 1802 |
1783 template <class Traits> | 1803 template <class Traits> |
1784 ParserBase<Traits>::FunctionState::FunctionState( | 1804 ParserBase<Traits>::FunctionState::FunctionState( |
1785 FunctionState** function_state_stack, Scope** scope_stack, Scope* scope, | 1805 FunctionState** function_state_stack, Scope** scope_stack, Scope* scope, |
1786 FunctionKind kind, typename Traits::Type::Factory* factory) | 1806 FunctionKind kind, typename Traits::Type::Factory* factory) |
1787 : next_materialized_literal_index_(0), | 1807 : next_materialized_literal_index_(0), |
1788 expected_property_count_(0), | 1808 expected_property_count_(0), |
1789 this_location_(Scanner::Location::invalid()), | 1809 this_location_(Scanner::Location::invalid()), |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2147 } | 2167 } |
2148 BindingPatternUnexpectedToken(classifier); | 2168 BindingPatternUnexpectedToken(classifier); |
2149 Consume(Token::LPAREN); | 2169 Consume(Token::LPAREN); |
2150 if (allow_harmony_arrow_functions() && Check(Token::RPAREN)) { | 2170 if (allow_harmony_arrow_functions() && Check(Token::RPAREN)) { |
2151 // As a primary expression, the only thing that can follow "()" is "=>". | 2171 // As a primary expression, the only thing that can follow "()" is "=>". |
2152 classifier->RecordBindingPatternError(scanner()->location(), | 2172 classifier->RecordBindingPatternError(scanner()->location(), |
2153 MessageTemplate::kUnexpectedToken, | 2173 MessageTemplate::kUnexpectedToken, |
2154 Token::String(Token::RPAREN)); | 2174 Token::String(Token::RPAREN)); |
2155 Scope* scope = | 2175 Scope* scope = |
2156 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); | 2176 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); |
2177 FormalParameterParsingStateT parsing_state(scope); | |
2157 scope->set_start_position(beg_pos); | 2178 scope->set_start_position(beg_pos); |
2158 ExpressionClassifier args_classifier; | 2179 ExpressionClassifier args_classifier; |
2159 bool has_rest = false; | 2180 result = this->ParseArrowFunctionLiteral(parsing_state, args_classifier, |
2160 result = this->ParseArrowFunctionLiteral(scope, has_rest, | 2181 CHECK_OK); |
2161 args_classifier, CHECK_OK); | |
2162 } else if (allow_harmony_arrow_functions() && | 2182 } else if (allow_harmony_arrow_functions() && |
2163 allow_harmony_rest_params() && Check(Token::ELLIPSIS)) { | 2183 allow_harmony_rest_params() && Check(Token::ELLIPSIS)) { |
2164 // (...x) => y | 2184 // (...x) => y |
2165 Scope* scope = | 2185 Scope* scope = |
2166 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); | 2186 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); |
2187 FormalParameterParsingStateT parsing_state(scope); | |
2167 scope->set_start_position(beg_pos); | 2188 scope->set_start_position(beg_pos); |
2168 ExpressionClassifier args_classifier; | 2189 ExpressionClassifier args_classifier; |
2169 const bool has_rest = true; | 2190 const bool is_rest = true; |
2170 this->ParseFormalParameter(scope, has_rest, &args_classifier, CHECK_OK); | 2191 this->ParseFormalParameter(is_rest, &parsing_state, &args_classifier, |
2192 CHECK_OK); | |
2171 if (peek() == Token::COMMA) { | 2193 if (peek() == Token::COMMA) { |
2172 ReportMessageAt(scanner()->peek_location(), | 2194 ReportMessageAt(scanner()->peek_location(), |
2173 MessageTemplate::kParamAfterRest); | 2195 MessageTemplate::kParamAfterRest); |
2174 *ok = false; | 2196 *ok = false; |
2175 return this->EmptyExpression(); | 2197 return this->EmptyExpression(); |
2176 } | 2198 } |
2177 Expect(Token::RPAREN, CHECK_OK); | 2199 Expect(Token::RPAREN, CHECK_OK); |
2178 result = this->ParseArrowFunctionLiteral(scope, has_rest, | 2200 result = this->ParseArrowFunctionLiteral(parsing_state, args_classifier, |
2179 args_classifier, CHECK_OK); | 2201 CHECK_OK); |
2180 } else { | 2202 } else { |
2181 // Heuristically try to detect immediately called functions before | 2203 // Heuristically try to detect immediately called functions before |
2182 // seeing the call parentheses. | 2204 // seeing the call parentheses. |
2183 parenthesized_function_ = (peek() == Token::FUNCTION); | 2205 parenthesized_function_ = (peek() == Token::FUNCTION); |
2184 result = this->ParseExpression(true, classifier, CHECK_OK); | 2206 result = this->ParseExpression(true, classifier, CHECK_OK); |
2185 Expect(Token::RPAREN, CHECK_OK); | 2207 Expect(Token::RPAREN, CHECK_OK); |
2186 } | 2208 } |
2187 break; | 2209 break; |
2188 | 2210 |
2189 case Token::CLASS: { | 2211 case Token::CLASS: { |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2384 return expression; | 2406 return expression; |
2385 } | 2407 } |
2386 | 2408 |
2387 // Fall through. | 2409 // Fall through. |
2388 case Token::STATIC: | 2410 case Token::STATIC: |
2389 *is_static = true; | 2411 *is_static = true; |
2390 | 2412 |
2391 // Fall through. | 2413 // Fall through. |
2392 default: | 2414 default: |
2393 *name = ParseIdentifierNameOrGetOrSet(is_get, is_set, CHECK_OK); | 2415 *name = ParseIdentifierNameOrGetOrSet(is_get, is_set, CHECK_OK); |
2416 if (classifier->duplicate_finder() != nullptr && !*is_get && !*is_set && | |
2417 scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) { | |
2418 classifier->RecordDuplicateFormalParameterError(scanner()->location()); | |
arv (Not doing code reviews)
2015/06/19 19:25:26
The following is not supposed to be an error.
f
Dmitry Lomov (no reviews)
2015/06/22 10:14:10
Done.
| |
2419 } | |
2394 break; | 2420 break; |
2395 } | 2421 } |
2396 | 2422 |
2397 uint32_t index; | 2423 uint32_t index; |
2398 return this->IsArrayIndex(*name, &index) | 2424 return this->IsArrayIndex(*name, &index) |
2399 ? factory()->NewNumberLiteral(index, pos) | 2425 ? factory()->NewNumberLiteral(index, pos) |
2400 : factory()->NewStringLiteral(*name, pos); | 2426 : factory()->NewStringLiteral(*name, pos); |
2401 } | 2427 } |
2402 | 2428 |
2403 | 2429 |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2711 if (allow_harmony_arrow_functions() && peek() == Token::ARROW) { | 2737 if (allow_harmony_arrow_functions() && peek() == Token::ARROW) { |
2712 checkpoint.Restore(); | 2738 checkpoint.Restore(); |
2713 BindingPatternUnexpectedToken(classifier); | 2739 BindingPatternUnexpectedToken(classifier); |
2714 ValidateArrowFormalParameters(&arrow_formals_classifier, expression, | 2740 ValidateArrowFormalParameters(&arrow_formals_classifier, expression, |
2715 CHECK_OK); | 2741 CHECK_OK); |
2716 Scanner::Location loc(lhs_location.beg_pos, scanner()->location().end_pos); | 2742 Scanner::Location loc(lhs_location.beg_pos, scanner()->location().end_pos); |
2717 Scope* scope = | 2743 Scope* scope = |
2718 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); | 2744 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); |
2719 scope->set_start_position(lhs_location.beg_pos); | 2745 scope->set_start_position(lhs_location.beg_pos); |
2720 Scanner::Location duplicate_loc = Scanner::Location::invalid(); | 2746 Scanner::Location duplicate_loc = Scanner::Location::invalid(); |
2721 bool has_rest = false; | 2747 FormalParameterParsingStateT parsing_state(scope); |
2722 this->ParseArrowFunctionFormalParameters(scope, expression, loc, &has_rest, | 2748 this->ParseArrowFunctionFormalParameters(&parsing_state, expression, loc, |
2723 &duplicate_loc, CHECK_OK); | 2749 &duplicate_loc, CHECK_OK); |
2724 if (duplicate_loc.IsValid()) { | 2750 if (duplicate_loc.IsValid()) { |
2725 arrow_formals_classifier.RecordDuplicateFormalParameterError( | 2751 arrow_formals_classifier.RecordDuplicateFormalParameterError( |
2726 duplicate_loc); | 2752 duplicate_loc); |
2727 } | 2753 } |
2728 expression = this->ParseArrowFunctionLiteral( | 2754 expression = this->ParseArrowFunctionLiteral( |
2729 scope, has_rest, arrow_formals_classifier, CHECK_OK); | 2755 parsing_state, arrow_formals_classifier, CHECK_OK); |
2730 return expression; | 2756 return expression; |
2731 } | 2757 } |
2732 | 2758 |
2733 // "expression" was not itself an arrow function parameter list, but it might | 2759 // "expression" was not itself an arrow function parameter list, but it might |
2734 // form part of one. Propagate speculative formal parameter error locations. | 2760 // form part of one. Propagate speculative formal parameter error locations. |
2735 classifier->Accumulate(arrow_formals_classifier, | 2761 classifier->Accumulate(arrow_formals_classifier, |
2736 ExpressionClassifier::StandardProductions | | 2762 ExpressionClassifier::StandardProductions | |
2737 ExpressionClassifier::FormalParametersProductions); | 2763 ExpressionClassifier::FormalParametersProductions); |
2738 | 2764 |
2739 if (!Token::IsAssignmentOp(peek())) { | 2765 if (!Token::IsAssignmentOp(peek())) { |
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3482 default: | 3508 default: |
3483 return expression; | 3509 return expression; |
3484 } | 3510 } |
3485 } | 3511 } |
3486 DCHECK(false); | 3512 DCHECK(false); |
3487 return this->EmptyExpression(); | 3513 return this->EmptyExpression(); |
3488 } | 3514 } |
3489 | 3515 |
3490 | 3516 |
3491 template <class Traits> | 3517 template <class Traits> |
3492 void ParserBase<Traits>::ParseFormalParameter(Scope* scope, bool is_rest, | 3518 void ParserBase<Traits>::ParseFormalParameter( |
3493 ExpressionClassifier* classifier, | 3519 bool is_rest, FormalParameterParsingStateT* parsing_state, |
3494 bool* ok) { | 3520 ExpressionClassifier* classifier, bool* ok) { |
3495 // FormalParameter[Yield,GeneratorParameter] : | 3521 // FormalParameter[Yield,GeneratorParameter] : |
3496 // BindingElement[?Yield, ?GeneratorParameter] | 3522 // BindingElement[?Yield, ?GeneratorParameter] |
wingo
2015/06/22 10:22:14
if is_rest is true then we are parsing BindingRest
| |
3497 | 3523 |
3498 Token::Value next = peek(); | 3524 Token::Value next = peek(); |
3499 ExpressionT pattern = ParsePrimaryExpression(classifier, ok); | 3525 ExpressionT pattern = ParsePrimaryExpression(classifier, ok); |
3500 if (!*ok) return; | 3526 if (!*ok) return; |
3501 | 3527 |
3502 ValidateBindingPattern(classifier, ok); | 3528 ValidateBindingPattern(classifier, ok); |
3503 if (!*ok) return; | 3529 if (!*ok) return; |
3504 | 3530 |
3505 if (!allow_harmony_destructuring() && !Traits::IsIdentifier(pattern)) { | 3531 if (!allow_harmony_destructuring() && !Traits::IsIdentifier(pattern)) { |
3506 ReportUnexpectedToken(next); | 3532 ReportUnexpectedToken(next); |
3507 *ok = false; | 3533 *ok = false; |
3508 return; | 3534 return; |
3509 } | 3535 } |
3510 | 3536 |
3511 Traits::DeclareFormalParameter(scope, pattern, classifier, is_rest); | 3537 if (parsing_state->is_simple_parameter_list) { |
3538 parsing_state->is_simple_parameter_list = | |
3539 !is_rest && Traits::IsIdentifier(pattern); | |
3540 } | |
3541 parsing_state->has_rest = is_rest; | |
3542 Traits::DeclareFormalParameter(parsing_state, pattern, classifier, is_rest); | |
3512 } | 3543 } |
3513 | 3544 |
3514 | 3545 |
3515 template <class Traits> | 3546 template <class Traits> |
3516 int ParserBase<Traits>::ParseFormalParameterList( | 3547 int ParserBase<Traits>::ParseFormalParameterList( |
3517 Scope* scope, bool* is_rest, ExpressionClassifier* classifier, bool* ok) { | 3548 FormalParameterParsingStateT* parsing_state, |
3549 ExpressionClassifier* classifier, bool* ok) { | |
3518 // FormalParameters[Yield,GeneratorParameter] : | 3550 // FormalParameters[Yield,GeneratorParameter] : |
3519 // [empty] | 3551 // [empty] |
3520 // FormalParameterList[?Yield, ?GeneratorParameter] | 3552 // FormalParameterList[?Yield, ?GeneratorParameter] |
3521 // | 3553 // |
3522 // FormalParameterList[Yield,GeneratorParameter] : | 3554 // FormalParameterList[Yield,GeneratorParameter] : |
3523 // FunctionRestParameter[?Yield] | 3555 // FunctionRestParameter[?Yield] |
3524 // FormalsList[?Yield, ?GeneratorParameter] | 3556 // FormalsList[?Yield, ?GeneratorParameter] |
3525 // FormalsList[?Yield, ?GeneratorParameter] , FunctionRestParameter[?Yield] | 3557 // FormalsList[?Yield, ?GeneratorParameter] , FunctionRestParameter[?Yield] |
3526 // | 3558 // |
3527 // FormalsList[Yield,GeneratorParameter] : | 3559 // FormalsList[Yield,GeneratorParameter] : |
3528 // FormalParameter[?Yield, ?GeneratorParameter] | 3560 // FormalParameter[?Yield, ?GeneratorParameter] |
3529 // FormalsList[?Yield, ?GeneratorParameter] , | 3561 // FormalsList[?Yield, ?GeneratorParameter] , |
3530 // FormalParameter[?Yield,?GeneratorParameter] | 3562 // FormalParameter[?Yield,?GeneratorParameter] |
3531 | 3563 |
3532 int parameter_count = 0; | 3564 int parameter_count = 0; |
3533 | 3565 |
3534 if (peek() != Token::RPAREN) { | 3566 if (peek() != Token::RPAREN) { |
3535 do { | 3567 do { |
3536 if (++parameter_count > Code::kMaxArguments) { | 3568 if (++parameter_count > Code::kMaxArguments) { |
3537 ReportMessage(MessageTemplate::kTooManyParameters); | 3569 ReportMessage(MessageTemplate::kTooManyParameters); |
3538 *ok = false; | 3570 *ok = false; |
3539 return -1; | 3571 return -1; |
3540 } | 3572 } |
3541 *is_rest = allow_harmony_rest_params() && Check(Token::ELLIPSIS); | 3573 bool is_rest = allow_harmony_rest_params() && Check(Token::ELLIPSIS); |
3542 ParseFormalParameter(scope, *is_rest, classifier, ok); | 3574 ParseFormalParameter(is_rest, parsing_state, classifier, ok); |
3543 if (!*ok) return -1; | 3575 if (!*ok) return -1; |
3544 } while (!*is_rest && Check(Token::COMMA)); | 3576 } while (!parsing_state->has_rest && Check(Token::COMMA)); |
3545 | 3577 |
3546 if (*is_rest && peek() == Token::COMMA) { | 3578 if (parsing_state->has_rest && peek() == Token::COMMA) { |
3547 ReportMessageAt(scanner()->peek_location(), | 3579 ReportMessageAt(scanner()->peek_location(), |
3548 MessageTemplate::kParamAfterRest); | 3580 MessageTemplate::kParamAfterRest); |
3549 *ok = false; | 3581 *ok = false; |
3550 return -1; | 3582 return -1; |
3551 } | 3583 } |
3552 } | 3584 } |
3553 | 3585 |
3554 return parameter_count; | 3586 return parameter_count; |
3555 } | 3587 } |
3556 | 3588 |
(...skipping 24 matching lines...) Expand all Loading... | |
3581 break; | 3613 break; |
3582 default: | 3614 default: |
3583 break; | 3615 break; |
3584 } | 3616 } |
3585 } | 3617 } |
3586 | 3618 |
3587 | 3619 |
3588 template <class Traits> | 3620 template <class Traits> |
3589 typename ParserBase<Traits>::ExpressionT | 3621 typename ParserBase<Traits>::ExpressionT |
3590 ParserBase<Traits>::ParseArrowFunctionLiteral( | 3622 ParserBase<Traits>::ParseArrowFunctionLiteral( |
3591 Scope* scope, bool has_rest, const ExpressionClassifier& formals_classifier, | 3623 const FormalParameterParsingStateT& formal_parameters, |
3592 bool* ok) { | 3624 const ExpressionClassifier& formals_classifier, bool* ok) { |
3593 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { | 3625 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { |
3594 // ASI inserts `;` after arrow parameters if a line terminator is found. | 3626 // ASI inserts `;` after arrow parameters if a line terminator is found. |
3595 // `=> ...` is never a valid expression, so report as syntax error. | 3627 // `=> ...` is never a valid expression, so report as syntax error. |
3596 // If next token is not `=>`, it's a syntax error anyways. | 3628 // If next token is not `=>`, it's a syntax error anyways. |
3597 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); | 3629 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); |
3598 *ok = false; | 3630 *ok = false; |
3599 return this->EmptyExpression(); | 3631 return this->EmptyExpression(); |
3600 } | 3632 } |
3601 | 3633 |
3602 typename Traits::Type::StatementList body; | 3634 typename Traits::Type::StatementList body; |
3603 int num_parameters = scope->num_parameters(); | 3635 int num_parameters = formal_parameters.scope->num_parameters(); |
3604 int materialized_literal_count = -1; | 3636 int materialized_literal_count = -1; |
3605 int expected_property_count = -1; | 3637 int expected_property_count = -1; |
3606 Scanner::Location super_loc; | 3638 Scanner::Location super_loc; |
3607 | 3639 |
3608 { | 3640 { |
3609 typename Traits::Type::Factory function_factory(ast_value_factory()); | 3641 typename Traits::Type::Factory function_factory(ast_value_factory()); |
3610 FunctionState function_state(&function_state_, &scope_, scope, | 3642 FunctionState function_state(&function_state_, &scope_, |
3611 kArrowFunction, &function_factory); | 3643 formal_parameters.scope, kArrowFunction, |
3644 &function_factory); | |
3612 | 3645 |
3613 Expect(Token::ARROW, CHECK_OK); | 3646 Expect(Token::ARROW, CHECK_OK); |
3614 | 3647 |
3615 if (peek() == Token::LBRACE) { | 3648 if (peek() == Token::LBRACE) { |
3616 // Multiple statement body | 3649 // Multiple statement body |
3617 Consume(Token::LBRACE); | 3650 Consume(Token::LBRACE); |
3618 bool is_lazily_parsed = | 3651 bool is_lazily_parsed = |
3619 (mode() == PARSE_LAZILY && scope_->AllowsLazyCompilation()); | 3652 (mode() == PARSE_LAZILY && scope_->AllowsLazyCompilation()); |
3620 if (is_lazily_parsed) { | 3653 if (is_lazily_parsed) { |
3621 body = this->NewStatementList(0, zone()); | 3654 body = this->NewStatementList(0, zone()); |
3622 this->SkipLazyFunctionBody(&materialized_literal_count, | 3655 this->SkipLazyFunctionBody(&materialized_literal_count, |
3623 &expected_property_count, CHECK_OK); | 3656 &expected_property_count, CHECK_OK); |
3624 } else { | 3657 } else { |
3625 body = this->ParseEagerFunctionBody( | 3658 body = this->ParseEagerFunctionBody( |
3626 this->EmptyIdentifier(), RelocInfo::kNoPosition, NULL, | 3659 this->EmptyIdentifier(), RelocInfo::kNoPosition, formal_parameters, |
3627 Token::INIT_VAR, kArrowFunction, CHECK_OK); | 3660 NULL, Token::INIT_VAR, kArrowFunction, CHECK_OK); |
wingo
2015/06/22 10:22:14
Nit: const Variable *name = nullptr, pass by name?
| |
3628 materialized_literal_count = | 3661 materialized_literal_count = |
3629 function_state.materialized_literal_count(); | 3662 function_state.materialized_literal_count(); |
3630 expected_property_count = function_state.expected_property_count(); | 3663 expected_property_count = function_state.expected_property_count(); |
3631 } | 3664 } |
3632 } else { | 3665 } else { |
3633 // Single-expression body | 3666 // Single-expression body |
3634 int pos = position(); | 3667 int pos = position(); |
3635 parenthesized_function_ = false; | 3668 parenthesized_function_ = false; |
3636 ExpressionClassifier classifier; | 3669 ExpressionClassifier classifier; |
3637 ExpressionT expression = | 3670 ExpressionT expression = |
3638 ParseAssignmentExpression(true, &classifier, CHECK_OK); | 3671 ParseAssignmentExpression(true, &classifier, CHECK_OK); |
3639 ValidateExpression(&classifier, CHECK_OK); | 3672 ValidateExpression(&classifier, CHECK_OK); |
3640 body = this->NewStatementList(1, zone()); | 3673 body = this->NewStatementList(1, zone()); |
3674 this->AddParameterInitializationBlock(formal_parameters, body, CHECK_OK); | |
3641 body->Add(factory()->NewReturnStatement(expression, pos), zone()); | 3675 body->Add(factory()->NewReturnStatement(expression, pos), zone()); |
3642 materialized_literal_count = function_state.materialized_literal_count(); | 3676 materialized_literal_count = function_state.materialized_literal_count(); |
3643 expected_property_count = function_state.expected_property_count(); | 3677 expected_property_count = function_state.expected_property_count(); |
3644 } | 3678 } |
3645 super_loc = function_state.super_location(); | 3679 super_loc = function_state.super_location(); |
3646 | 3680 |
3647 scope->set_end_position(scanner()->location().end_pos); | 3681 formal_parameters.scope->set_end_position(scanner()->location().end_pos); |
3648 | 3682 |
3649 // Arrow function formal parameters are parsed as StrictFormalParameterList, | 3683 // Arrow function formal parameters are parsed as StrictFormalParameterList, |
3650 // which is not the same as "parameters of a strict function"; it only means | 3684 // which is not the same as "parameters of a strict function"; it only means |
3651 // that duplicates are not allowed. Of course, the arrow function may | 3685 // that duplicates are not allowed. Of course, the arrow function may |
3652 // itself be strict as well. | 3686 // itself be strict as well. |
3653 const bool allow_duplicate_parameters = false; | 3687 const bool allow_duplicate_parameters = false; |
3654 this->ValidateFormalParameters(&formals_classifier, language_mode(), | 3688 this->ValidateFormalParameters(&formals_classifier, language_mode(), |
3655 allow_duplicate_parameters, CHECK_OK); | 3689 allow_duplicate_parameters, CHECK_OK); |
3656 | 3690 |
3657 // Validate strict mode. | 3691 // Validate strict mode. |
3658 if (is_strict(language_mode())) { | 3692 if (is_strict(language_mode())) { |
3659 CheckStrictOctalLiteral(scope->start_position(), | 3693 CheckStrictOctalLiteral(formal_parameters.scope->start_position(), |
3660 scanner()->location().end_pos, CHECK_OK); | 3694 scanner()->location().end_pos, CHECK_OK); |
3661 this->CheckConflictingVarDeclarations(scope, CHECK_OK); | 3695 this->CheckConflictingVarDeclarations(formal_parameters.scope, CHECK_OK); |
3662 } | 3696 } |
3663 } | 3697 } |
3664 | 3698 |
3665 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( | 3699 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( |
3666 this->EmptyIdentifierString(), ast_value_factory(), scope, body, | 3700 this->EmptyIdentifierString(), ast_value_factory(), |
3667 materialized_literal_count, expected_property_count, num_parameters, | 3701 formal_parameters.scope, body, materialized_literal_count, |
3702 expected_property_count, num_parameters, | |
3668 FunctionLiteral::kNoDuplicateParameters, | 3703 FunctionLiteral::kNoDuplicateParameters, |
3669 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction, | 3704 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction, |
3670 FunctionLiteral::kShouldLazyCompile, FunctionKind::kArrowFunction, | 3705 FunctionLiteral::kShouldLazyCompile, FunctionKind::kArrowFunction, |
3671 scope->start_position()); | 3706 formal_parameters.scope->start_position()); |
3672 | 3707 |
3673 function_literal->set_function_token_position(scope->start_position()); | 3708 function_literal->set_function_token_position( |
3709 formal_parameters.scope->start_position()); | |
3674 if (super_loc.IsValid()) function_state_->set_super_location(super_loc); | 3710 if (super_loc.IsValid()) function_state_->set_super_location(super_loc); |
3675 | 3711 |
3676 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); | 3712 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); |
3677 | 3713 |
3678 return function_literal; | 3714 return function_literal; |
3679 } | 3715 } |
3680 | 3716 |
3681 | 3717 |
3682 template <typename Traits> | 3718 template <typename Traits> |
3683 typename ParserBase<Traits>::ExpressionT | 3719 typename ParserBase<Traits>::ExpressionT |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3864 *ok = false; | 3900 *ok = false; |
3865 return; | 3901 return; |
3866 } | 3902 } |
3867 has_seen_constructor_ = true; | 3903 has_seen_constructor_ = true; |
3868 return; | 3904 return; |
3869 } | 3905 } |
3870 } | 3906 } |
3871 } } // v8::internal | 3907 } } // v8::internal |
3872 | 3908 |
3873 #endif // V8_PREPARSER_H | 3909 #endif // V8_PREPARSER_H |
OLD | NEW |