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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 // typedef Factory; | 77 // typedef Factory; |
78 // }; | 78 // }; |
79 // // ... | 79 // // ... |
80 // }; | 80 // }; |
81 | 81 |
82 template <typename Traits> | 82 template <typename Traits> |
83 class ParserBase : public Traits { | 83 class ParserBase : public Traits { |
84 public: | 84 public: |
85 // Shorten type names defined by Traits. | 85 // Shorten type names defined by Traits. |
86 typedef typename Traits::Type::Expression ExpressionT; | 86 typedef typename Traits::Type::Expression ExpressionT; |
87 typedef typename Traits::Type::ExpressionList ExpressionListT; | |
87 typedef typename Traits::Type::Identifier IdentifierT; | 88 typedef typename Traits::Type::Identifier IdentifierT; |
88 typedef typename Traits::Type::FormalParameter FormalParameterT; | 89 typedef typename Traits::Type::FormalParameter FormalParameterT; |
89 typedef typename Traits::Type::FormalParameterScope FormalParameterScopeT; | 90 typedef typename Traits::Type::FormalParameterScope FormalParameterScopeT; |
90 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; | 91 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; |
91 typedef typename Traits::Type::Literal LiteralT; | 92 typedef typename Traits::Type::Literal LiteralT; |
92 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; | 93 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; |
93 | 94 |
94 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit, | 95 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit, |
95 v8::Extension* extension, AstValueFactory* ast_value_factory, | 96 v8::Extension* extension, AstValueFactory* ast_value_factory, |
96 ParserRecorder* log, typename Traits::Type::Parser this_object) | 97 ParserRecorder* log, typename Traits::Type::Parser this_object) |
(...skipping 11 matching lines...) Expand all Loading... | |
108 scanner_(scanner), | 109 scanner_(scanner), |
109 stack_overflow_(false), | 110 stack_overflow_(false), |
110 allow_lazy_(false), | 111 allow_lazy_(false), |
111 allow_natives_(false), | 112 allow_natives_(false), |
112 allow_harmony_arrow_functions_(false), | 113 allow_harmony_arrow_functions_(false), |
113 allow_harmony_object_literals_(false), | 114 allow_harmony_object_literals_(false), |
114 allow_harmony_sloppy_(false), | 115 allow_harmony_sloppy_(false), |
115 allow_harmony_computed_property_names_(false), | 116 allow_harmony_computed_property_names_(false), |
116 allow_harmony_rest_params_(false), | 117 allow_harmony_rest_params_(false), |
117 allow_harmony_spreadcalls_(false), | 118 allow_harmony_spreadcalls_(false), |
119 allow_harmony_optional_params_(false), | |
118 allow_strong_mode_(false) {} | 120 allow_strong_mode_(false) {} |
119 | 121 |
120 // Getters that indicate whether certain syntactical constructs are | 122 // Getters that indicate whether certain syntactical constructs are |
121 // allowed to be parsed by this instance of the parser. | 123 // allowed to be parsed by this instance of the parser. |
122 bool allow_lazy() const { return allow_lazy_; } | 124 bool allow_lazy() const { return allow_lazy_; } |
123 bool allow_natives() const { return allow_natives_; } | 125 bool allow_natives() const { return allow_natives_; } |
124 bool allow_harmony_arrow_functions() const { | 126 bool allow_harmony_arrow_functions() const { |
125 return allow_harmony_arrow_functions_; | 127 return allow_harmony_arrow_functions_; |
126 } | 128 } |
127 bool allow_harmony_modules() const { return scanner()->HarmonyModules(); } | 129 bool allow_harmony_modules() const { return scanner()->HarmonyModules(); } |
128 bool allow_harmony_classes() const { return scanner()->HarmonyClasses(); } | 130 bool allow_harmony_classes() const { return scanner()->HarmonyClasses(); } |
129 bool allow_harmony_object_literals() const { | 131 bool allow_harmony_object_literals() const { |
130 return allow_harmony_object_literals_; | 132 return allow_harmony_object_literals_; |
131 } | 133 } |
132 bool allow_harmony_sloppy() const { return allow_harmony_sloppy_; } | 134 bool allow_harmony_sloppy() const { return allow_harmony_sloppy_; } |
133 bool allow_harmony_unicode() const { return scanner()->HarmonyUnicode(); } | 135 bool allow_harmony_unicode() const { return scanner()->HarmonyUnicode(); } |
134 bool allow_harmony_computed_property_names() const { | 136 bool allow_harmony_computed_property_names() const { |
135 return allow_harmony_computed_property_names_; | 137 return allow_harmony_computed_property_names_; |
136 } | 138 } |
137 bool allow_harmony_rest_params() const { | 139 bool allow_harmony_rest_params() const { |
138 return allow_harmony_rest_params_; | 140 return allow_harmony_rest_params_; |
139 } | 141 } |
140 bool allow_harmony_spreadcalls() const { return allow_harmony_spreadcalls_; } | 142 bool allow_harmony_spreadcalls() const { return allow_harmony_spreadcalls_; } |
141 bool allow_harmony_destructuring() const { | 143 bool allow_harmony_destructuring() const { |
142 return allow_harmony_destructuring_; | 144 return allow_harmony_destructuring_; |
143 } | 145 } |
146 bool allow_harmony_optional_params() const { | |
147 return allow_harmony_optional_params_; | |
148 } | |
144 | 149 |
145 bool allow_strong_mode() const { return allow_strong_mode_; } | 150 bool allow_strong_mode() const { return allow_strong_mode_; } |
146 | 151 |
147 // Setters that determine whether certain syntactical constructs are | 152 // Setters that determine whether certain syntactical constructs are |
148 // allowed to be parsed by this instance of the parser. | 153 // allowed to be parsed by this instance of the parser. |
149 void set_allow_lazy(bool allow) { allow_lazy_ = allow; } | 154 void set_allow_lazy(bool allow) { allow_lazy_ = allow; } |
150 void set_allow_natives(bool allow) { allow_natives_ = allow; } | 155 void set_allow_natives(bool allow) { allow_natives_ = allow; } |
151 void set_allow_harmony_arrow_functions(bool allow) { | 156 void set_allow_harmony_arrow_functions(bool allow) { |
152 allow_harmony_arrow_functions_ = allow; | 157 allow_harmony_arrow_functions_ = allow; |
153 } | 158 } |
(...skipping 18 matching lines...) Expand all Loading... | |
172 void set_allow_harmony_rest_params(bool allow) { | 177 void set_allow_harmony_rest_params(bool allow) { |
173 allow_harmony_rest_params_ = allow; | 178 allow_harmony_rest_params_ = allow; |
174 } | 179 } |
175 void set_allow_harmony_spreadcalls(bool allow) { | 180 void set_allow_harmony_spreadcalls(bool allow) { |
176 allow_harmony_spreadcalls_ = allow; | 181 allow_harmony_spreadcalls_ = allow; |
177 } | 182 } |
178 void set_allow_strong_mode(bool allow) { allow_strong_mode_ = allow; } | 183 void set_allow_strong_mode(bool allow) { allow_strong_mode_ = allow; } |
179 void set_allow_harmony_destructuring(bool allow) { | 184 void set_allow_harmony_destructuring(bool allow) { |
180 allow_harmony_destructuring_ = allow; | 185 allow_harmony_destructuring_ = allow; |
181 } | 186 } |
187 void set_allow_harmony_optional_params(bool allow) { | |
188 allow_harmony_optional_params_ = allow; | |
189 } | |
182 | 190 |
183 | 191 |
184 protected: | 192 protected: |
185 enum AllowRestrictedIdentifiers { | 193 enum AllowRestrictedIdentifiers { |
186 kAllowRestrictedIdentifiers, | 194 kAllowRestrictedIdentifiers, |
187 kDontAllowRestrictedIdentifiers | 195 kDontAllowRestrictedIdentifiers |
188 }; | 196 }; |
189 | 197 |
190 enum Mode { | 198 enum Mode { |
191 PARSE_LAZILY, | 199 PARSE_LAZILY, |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
757 ExpressionClassifier* classifier, bool* ok); | 765 ExpressionClassifier* classifier, bool* ok); |
758 void AddTemplateExpression(ExpressionT); | 766 void AddTemplateExpression(ExpressionT); |
759 ExpressionT ParseSuperExpression(bool is_new, | 767 ExpressionT ParseSuperExpression(bool is_new, |
760 ExpressionClassifier* classifier, bool* ok); | 768 ExpressionClassifier* classifier, bool* ok); |
761 ExpressionT ParseStrongInitializationExpression( | 769 ExpressionT ParseStrongInitializationExpression( |
762 ExpressionClassifier* classifier, bool* ok); | 770 ExpressionClassifier* classifier, bool* ok); |
763 ExpressionT ParseStrongSuperCallExpression(ExpressionClassifier* classifier, | 771 ExpressionT ParseStrongSuperCallExpression(ExpressionClassifier* classifier, |
764 bool* ok); | 772 bool* ok); |
765 | 773 |
766 void ParseFormalParameter(FormalParameterScopeT* scope, | 774 void ParseFormalParameter(FormalParameterScopeT* scope, |
767 FormalParameterErrorLocations* locs, bool is_rest, | 775 FormalParameterErrorLocations* locs, |
768 bool* ok); | 776 ExpressionT* initializer, bool* has_initializer, |
777 bool is_rest, bool* ok); | |
769 int ParseFormalParameterList(FormalParameterScopeT* scope, | 778 int ParseFormalParameterList(FormalParameterScopeT* scope, |
770 FormalParameterErrorLocations* locs, | 779 FormalParameterErrorLocations* locs, |
771 bool* has_rest, bool* ok); | 780 ExpressionListT initializers, |
781 bool* has_initializers, bool* has_rest, | |
782 bool* ok); | |
772 void CheckArityRestrictions( | 783 void CheckArityRestrictions( |
773 int param_count, FunctionLiteral::ArityRestriction arity_restriction, | 784 int param_count, FunctionLiteral::ArityRestriction arity_restriction, |
774 int formals_start_pos, int formals_end_pos, bool* ok); | 785 int formals_start_pos, int formals_end_pos, bool* ok); |
775 | 786 |
776 // Checks if the expression is a valid reference expression (e.g., on the | 787 // Checks if the expression is a valid reference expression (e.g., on the |
777 // left-hand side of assignments). Although ruled out by ECMA as early errors, | 788 // left-hand side of assignments). Although ruled out by ECMA as early errors, |
778 // we allow calls for web compatibility and rewrite them to a runtime throw. | 789 // we allow calls for web compatibility and rewrite them to a runtime throw. |
779 ExpressionT CheckAndRewriteReferenceExpression( | 790 ExpressionT CheckAndRewriteReferenceExpression( |
780 ExpressionT expression, | 791 ExpressionT expression, |
781 Scanner::Location location, const char* message, bool* ok); | 792 Scanner::Location location, const char* message, bool* ok); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
862 | 873 |
863 bool allow_lazy_; | 874 bool allow_lazy_; |
864 bool allow_natives_; | 875 bool allow_natives_; |
865 bool allow_harmony_arrow_functions_; | 876 bool allow_harmony_arrow_functions_; |
866 bool allow_harmony_object_literals_; | 877 bool allow_harmony_object_literals_; |
867 bool allow_harmony_sloppy_; | 878 bool allow_harmony_sloppy_; |
868 bool allow_harmony_computed_property_names_; | 879 bool allow_harmony_computed_property_names_; |
869 bool allow_harmony_rest_params_; | 880 bool allow_harmony_rest_params_; |
870 bool allow_harmony_spreadcalls_; | 881 bool allow_harmony_spreadcalls_; |
871 bool allow_harmony_destructuring_; | 882 bool allow_harmony_destructuring_; |
883 bool allow_harmony_optional_params_; | |
872 bool allow_strong_mode_; | 884 bool allow_strong_mode_; |
873 }; | 885 }; |
874 | 886 |
875 | 887 |
876 class PreParserIdentifier { | 888 class PreParserIdentifier { |
877 public: | 889 public: |
878 PreParserIdentifier() : type_(kUnknownIdentifier) {} | 890 PreParserIdentifier() : type_(kUnknownIdentifier) {} |
879 static PreParserIdentifier Default() { | 891 static PreParserIdentifier Default() { |
880 return PreParserIdentifier(kUnknownIdentifier); | 892 return PreParserIdentifier(kUnknownIdentifier); |
881 } | 893 } |
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1717 } | 1729 } |
1718 inline void MaterializeTemplateCallsiteLiterals(); | 1730 inline void MaterializeTemplateCallsiteLiterals(); |
1719 PreParserExpression NoTemplateTag() { | 1731 PreParserExpression NoTemplateTag() { |
1720 return PreParserExpression::NoTemplateTag(); | 1732 return PreParserExpression::NoTemplateTag(); |
1721 } | 1733 } |
1722 static bool IsTaggedTemplate(const PreParserExpression tag) { | 1734 static bool IsTaggedTemplate(const PreParserExpression tag) { |
1723 return !tag.IsNoTemplateTag(); | 1735 return !tag.IsNoTemplateTag(); |
1724 } | 1736 } |
1725 | 1737 |
1726 V8_INLINE bool DeclareFormalParameter(DuplicateFinder* scope, | 1738 V8_INLINE bool DeclareFormalParameter(DuplicateFinder* scope, |
1727 PreParserIdentifier param, | 1739 PreParserIdentifier param, bool is_rest, |
1728 bool is_rest); | 1740 int pos); |
1729 | 1741 |
1730 void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {} | 1742 void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {} |
1731 | 1743 |
1732 // Temporary glue; these functions will move to ParserBase. | 1744 // Temporary glue; these functions will move to ParserBase. |
1733 PreParserExpression ParseV8Intrinsic(bool* ok); | 1745 PreParserExpression ParseV8Intrinsic(bool* ok); |
1734 PreParserExpression ParseFunctionLiteral( | 1746 PreParserExpression ParseFunctionLiteral( |
1735 PreParserIdentifier name, Scanner::Location function_name_location, | 1747 PreParserIdentifier name, Scanner::Location function_name_location, |
1736 bool name_is_strict_reserved, FunctionKind kind, | 1748 bool name_is_strict_reserved, FunctionKind kind, |
1737 int function_token_position, FunctionLiteral::FunctionType type, | 1749 int function_token_position, FunctionLiteral::FunctionType type, |
1738 FunctionLiteral::ArityRestriction arity_restriction, bool* ok); | 1750 FunctionLiteral::ArityRestriction arity_restriction, bool* ok); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1914 | 1926 |
1915 PreParserExpression PreParserTraits::SpreadCallNew(PreParserExpression function, | 1927 PreParserExpression PreParserTraits::SpreadCallNew(PreParserExpression function, |
1916 PreParserExpressionList args, | 1928 PreParserExpressionList args, |
1917 int pos) { | 1929 int pos) { |
1918 return pre_parser_->factory()->NewCallNew(function, args, pos); | 1930 return pre_parser_->factory()->NewCallNew(function, args, pos); |
1919 } | 1931 } |
1920 | 1932 |
1921 | 1933 |
1922 bool PreParserTraits::DeclareFormalParameter( | 1934 bool PreParserTraits::DeclareFormalParameter( |
1923 DuplicateFinder* duplicate_finder, PreParserIdentifier current_identifier, | 1935 DuplicateFinder* duplicate_finder, PreParserIdentifier current_identifier, |
1924 bool is_rest) { | 1936 bool is_rest, int pos) { |
1925 return pre_parser_->scanner()->FindSymbol(duplicate_finder, 1) != 0; | 1937 return pre_parser_->scanner()->FindSymbol(duplicate_finder, 1) != 0; |
1926 } | 1938 } |
1927 | 1939 |
1928 | 1940 |
1929 void PreParserTraits::ParseArrowFunctionFormalParameters( | 1941 void PreParserTraits::ParseArrowFunctionFormalParameters( |
1930 Scope* scope, PreParserExpression params, | 1942 Scope* scope, PreParserExpression params, |
1931 const Scanner::Location& params_loc, | 1943 const Scanner::Location& params_loc, |
1932 FormalParameterErrorLocations* error_locs, bool* is_rest, bool* ok) { | 1944 FormalParameterErrorLocations* error_locs, bool* is_rest, bool* ok) { |
1933 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter | 1945 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter |
1934 // lists that are too long. | 1946 // lists that are too long. |
(...skipping 1526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3461 } | 3473 } |
3462 } | 3474 } |
3463 DCHECK(false); | 3475 DCHECK(false); |
3464 return this->EmptyExpression(); | 3476 return this->EmptyExpression(); |
3465 } | 3477 } |
3466 | 3478 |
3467 | 3479 |
3468 template <class Traits> | 3480 template <class Traits> |
3469 void ParserBase<Traits>::ParseFormalParameter( | 3481 void ParserBase<Traits>::ParseFormalParameter( |
3470 FormalParameterScopeT* scope, FormalParameterErrorLocations* locs, | 3482 FormalParameterScopeT* scope, FormalParameterErrorLocations* locs, |
3471 bool is_rest, bool* ok) { | 3483 ExpressionT* initializer, bool* has_initializer, bool is_rest, bool* ok) { |
3472 // FormalParameter[Yield,GeneratorParameter] : | 3484 // FormalParameter[Yield,GeneratorParameter] : |
3473 // BindingElement[?Yield, ?GeneratorParameter] | 3485 // BindingElement[?Yield, ?GeneratorParameter] |
3474 bool is_strict_reserved; | 3486 bool is_strict_reserved; |
3487 int pos = peek_position(); | |
3475 IdentifierT name = | 3488 IdentifierT name = |
3476 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, ok); | 3489 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, ok); |
3477 if (!*ok) return; | 3490 if (!*ok) return; |
3478 | 3491 |
3492 if (initializer && allow_harmony_optional_params() && Check(Token::ASSIGN)) { | |
arv (Not doing code reviews)
2015/05/11 14:10:54
This looks strange. Why are we checking initialize
caitp (gmail)
2015/05/11 14:34:57
below, *initializer is assigned, and we probably d
arv (Not doing code reviews)
2015/05/11 14:38:01
What initializer are you passing in before the ini
| |
3493 // Optional parameter initializer | |
3494 // let formalName = IS_UNDEFINED(arguments[i]) ? initializer : arguments[i]; | |
3495 static const bool accept_IN = true; | |
3496 ExpressionClassifier classifier; | |
3497 *initializer = ParseAssignmentExpression(accept_IN, &classifier, ok); | |
3498 if (!*ok) return; | |
3499 *has_initializer = true; | |
3500 } | |
3501 | |
3479 // Store locations for possible future error reports. | 3502 // Store locations for possible future error reports. |
3480 if (!locs->eval_or_arguments.IsValid() && this->IsEvalOrArguments(name)) { | 3503 if (!locs->eval_or_arguments.IsValid() && this->IsEvalOrArguments(name)) { |
3481 locs->eval_or_arguments = scanner()->location(); | 3504 locs->eval_or_arguments = scanner()->location(); |
3482 } | 3505 } |
3483 if (!locs->undefined.IsValid() && this->IsUndefined(name)) { | 3506 if (!locs->undefined.IsValid() && this->IsUndefined(name)) { |
3484 locs->undefined = scanner()->location(); | 3507 locs->undefined = scanner()->location(); |
3485 } | 3508 } |
3486 if (!locs->reserved.IsValid() && is_strict_reserved) { | 3509 if (!locs->reserved.IsValid() && is_strict_reserved) { |
3487 locs->reserved = scanner()->location(); | 3510 locs->reserved = scanner()->location(); |
3488 } | 3511 } |
3489 bool was_declared = Traits::DeclareFormalParameter(scope, name, is_rest); | 3512 bool was_declared = Traits::DeclareFormalParameter(scope, name, is_rest, pos); |
3490 if (!locs->duplicate.IsValid() && was_declared) { | 3513 if (!locs->duplicate.IsValid() && was_declared) { |
3491 locs->duplicate = scanner()->location(); | 3514 locs->duplicate = scanner()->location(); |
3492 } | 3515 } |
3493 } | 3516 } |
3494 | 3517 |
3495 | 3518 |
3496 template <class Traits> | 3519 template <class Traits> |
3497 int ParserBase<Traits>::ParseFormalParameterList( | 3520 int ParserBase<Traits>::ParseFormalParameterList( |
3498 FormalParameterScopeT* scope, FormalParameterErrorLocations* locs, | 3521 FormalParameterScopeT* scope, FormalParameterErrorLocations* locs, |
3499 bool* is_rest, bool* ok) { | 3522 ExpressionListT initializers, bool* has_initializers, bool* is_rest, |
3523 bool* ok) { | |
3500 // FormalParameters[Yield,GeneratorParameter] : | 3524 // FormalParameters[Yield,GeneratorParameter] : |
3501 // [empty] | 3525 // [empty] |
3502 // FormalParameterList[?Yield, ?GeneratorParameter] | 3526 // FormalParameterList[?Yield, ?GeneratorParameter] |
3503 // | 3527 // |
3504 // FormalParameterList[Yield,GeneratorParameter] : | 3528 // FormalParameterList[Yield,GeneratorParameter] : |
3505 // FunctionRestParameter[?Yield] | 3529 // FunctionRestParameter[?Yield] |
3506 // FormalsList[?Yield, ?GeneratorParameter] | 3530 // FormalsList[?Yield, ?GeneratorParameter] |
3507 // FormalsList[?Yield, ?GeneratorParameter] , FunctionRestParameter[?Yield] | 3531 // FormalsList[?Yield, ?GeneratorParameter] , FunctionRestParameter[?Yield] |
3508 // | 3532 // |
3509 // FormalsList[Yield,GeneratorParameter] : | 3533 // FormalsList[Yield,GeneratorParameter] : |
3510 // FormalParameter[?Yield, ?GeneratorParameter] | 3534 // FormalParameter[?Yield, ?GeneratorParameter] |
3511 // FormalsList[?Yield, ?GeneratorParameter] , | 3535 // FormalsList[?Yield, ?GeneratorParameter] , |
3512 // FormalParameter[?Yield,?GeneratorParameter] | 3536 // FormalParameter[?Yield,?GeneratorParameter] |
3513 | 3537 |
3514 int parameter_count = 0; | 3538 int parameter_count = 0; |
3515 | 3539 |
3516 if (peek() != Token::RPAREN) { | 3540 if (peek() != Token::RPAREN) { |
3541 DCHECK(scope_->is_function_scope()); | |
caitp (gmail)
2015/05/09 20:57:22
Apparently this is a problem for lazy-parsed arrow
arv (Not doing code reviews)
2015/05/11 14:10:54
Andy, could you take a look too?
wingo
2015/05/11 15:00:48
So only lazy-parsed arrow functions will have a ch
caitp (gmail)
2015/05/11 15:34:24
The issue with lazy-parsing is that the scope does
| |
3517 do { | 3542 do { |
3543 Scope* param_scope = NewScope(scope_, BLOCK_SCOPE); | |
3544 param_scope->set_start_position(scanner()->peek_location().beg_pos); | |
3545 BlockState param_state(&scope_, param_scope); | |
3546 | |
3518 if (++parameter_count > Code::kMaxArguments) { | 3547 if (++parameter_count > Code::kMaxArguments) { |
3519 ReportMessage("too_many_parameters"); | 3548 ReportMessage("too_many_parameters"); |
3520 *ok = false; | 3549 *ok = false; |
3521 return -1; | 3550 return -1; |
3522 } | 3551 } |
3523 *is_rest = allow_harmony_rest_params() && Check(Token::ELLIPSIS); | 3552 *is_rest = allow_harmony_rest_params() && Check(Token::ELLIPSIS); |
3524 ParseFormalParameter(scope, locs, *is_rest, ok); | 3553 |
3554 bool has_initializer = false; | |
3555 ExpressionT initializer = this->EmptyExpression(); | |
3556 ParseFormalParameter(scope, locs, &initializer, &has_initializer, | |
3557 *is_rest, ok); | |
3525 if (!*ok) return -1; | 3558 if (!*ok) return -1; |
3559 param_scope->set_end_position(scanner()->location().end_pos); | |
3560 initializers->Add(initializer, zone()); | |
3561 if (has_initializer) *has_initializers = true; | |
3526 } while (!*is_rest && Check(Token::COMMA)); | 3562 } while (!*is_rest && Check(Token::COMMA)); |
3527 | 3563 |
3528 if (*is_rest && peek() == Token::COMMA) { | 3564 if (*is_rest && peek() == Token::COMMA) { |
3529 ReportMessageAt(scanner()->peek_location(), "param_after_rest"); | 3565 ReportMessageAt(scanner()->peek_location(), "param_after_rest"); |
3530 *ok = false; | 3566 *ok = false; |
3531 return -1; | 3567 return -1; |
3532 } | 3568 } |
3533 } | 3569 } |
3534 | 3570 |
3535 return parameter_count; | 3571 return parameter_count; |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3840 *ok = false; | 3876 *ok = false; |
3841 return; | 3877 return; |
3842 } | 3878 } |
3843 has_seen_constructor_ = true; | 3879 has_seen_constructor_ = true; |
3844 return; | 3880 return; |
3845 } | 3881 } |
3846 } | 3882 } |
3847 } } // v8::internal | 3883 } } // v8::internal |
3848 | 3884 |
3849 #endif // V8_PREPARSER_H | 3885 #endif // V8_PREPARSER_H |
OLD | NEW |