| 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 1531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3466 } | 3478 } |
| 3467 } | 3479 } |
| 3468 DCHECK(false); | 3480 DCHECK(false); |
| 3469 return this->EmptyExpression(); | 3481 return this->EmptyExpression(); |
| 3470 } | 3482 } |
| 3471 | 3483 |
| 3472 | 3484 |
| 3473 template <class Traits> | 3485 template <class Traits> |
| 3474 void ParserBase<Traits>::ParseFormalParameter( | 3486 void ParserBase<Traits>::ParseFormalParameter( |
| 3475 FormalParameterScopeT* scope, FormalParameterErrorLocations* locs, | 3487 FormalParameterScopeT* scope, FormalParameterErrorLocations* locs, |
| 3476 bool is_rest, bool* ok) { | 3488 ExpressionT* initializer, bool* has_initializer, bool is_rest, bool* ok) { |
| 3477 // FormalParameter[Yield,GeneratorParameter] : | 3489 // FormalParameter[Yield,GeneratorParameter] : |
| 3478 // BindingElement[?Yield, ?GeneratorParameter] | 3490 // BindingElement[?Yield, ?GeneratorParameter] |
| 3479 bool is_strict_reserved; | 3491 bool is_strict_reserved; |
| 3492 int pos = peek_position(); |
| 3480 IdentifierT name = | 3493 IdentifierT name = |
| 3481 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, ok); | 3494 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, ok); |
| 3482 if (!*ok) return; | 3495 if (!*ok) return; |
| 3483 | 3496 |
| 3497 // TODO(caitp): assert `ExpressionT* initializer` is never null. It is |
| 3498 // currently a nullptr in some cases to prevent Arrow Functions from parsing |
| 3499 // initializers. |
| 3500 if (initializer && allow_harmony_optional_params() && Check(Token::ASSIGN)) { |
| 3501 // Optional parameter initializer |
| 3502 // let formalName = IS_UNDEFINED(arguments[i]) ? initializer : arguments[i]; |
| 3503 static const bool accept_IN = true; |
| 3504 ExpressionClassifier classifier; |
| 3505 *initializer = ParseAssignmentExpression(accept_IN, &classifier, ok); |
| 3506 if (!*ok) return; |
| 3507 *has_initializer = true; |
| 3508 } |
| 3509 |
| 3484 // Store locations for possible future error reports. | 3510 // Store locations for possible future error reports. |
| 3485 if (!locs->eval_or_arguments.IsValid() && this->IsEvalOrArguments(name)) { | 3511 if (!locs->eval_or_arguments.IsValid() && this->IsEvalOrArguments(name)) { |
| 3486 locs->eval_or_arguments = scanner()->location(); | 3512 locs->eval_or_arguments = scanner()->location(); |
| 3487 } | 3513 } |
| 3488 if (!locs->undefined.IsValid() && this->IsUndefined(name)) { | 3514 if (!locs->undefined.IsValid() && this->IsUndefined(name)) { |
| 3489 locs->undefined = scanner()->location(); | 3515 locs->undefined = scanner()->location(); |
| 3490 } | 3516 } |
| 3491 if (!locs->reserved.IsValid() && is_strict_reserved) { | 3517 if (!locs->reserved.IsValid() && is_strict_reserved) { |
| 3492 locs->reserved = scanner()->location(); | 3518 locs->reserved = scanner()->location(); |
| 3493 } | 3519 } |
| 3494 bool was_declared = Traits::DeclareFormalParameter(scope, name, is_rest); | 3520 bool was_declared = Traits::DeclareFormalParameter(scope, name, is_rest, pos); |
| 3495 if (!locs->duplicate.IsValid() && was_declared) { | 3521 if (!locs->duplicate.IsValid() && was_declared) { |
| 3496 locs->duplicate = scanner()->location(); | 3522 locs->duplicate = scanner()->location(); |
| 3497 } | 3523 } |
| 3498 } | 3524 } |
| 3499 | 3525 |
| 3500 | 3526 |
| 3501 template <class Traits> | 3527 template <class Traits> |
| 3502 int ParserBase<Traits>::ParseFormalParameterList( | 3528 int ParserBase<Traits>::ParseFormalParameterList( |
| 3503 FormalParameterScopeT* scope, FormalParameterErrorLocations* locs, | 3529 FormalParameterScopeT* scope, FormalParameterErrorLocations* locs, |
| 3504 bool* is_rest, bool* ok) { | 3530 ExpressionListT initializers, bool* has_initializers, bool* is_rest, |
| 3531 bool* ok) { |
| 3505 // FormalParameters[Yield,GeneratorParameter] : | 3532 // FormalParameters[Yield,GeneratorParameter] : |
| 3506 // [empty] | 3533 // [empty] |
| 3507 // FormalParameterList[?Yield, ?GeneratorParameter] | 3534 // FormalParameterList[?Yield, ?GeneratorParameter] |
| 3508 // | 3535 // |
| 3509 // FormalParameterList[Yield,GeneratorParameter] : | 3536 // FormalParameterList[Yield,GeneratorParameter] : |
| 3510 // FunctionRestParameter[?Yield] | 3537 // FunctionRestParameter[?Yield] |
| 3511 // FormalsList[?Yield, ?GeneratorParameter] | 3538 // FormalsList[?Yield, ?GeneratorParameter] |
| 3512 // FormalsList[?Yield, ?GeneratorParameter] , FunctionRestParameter[?Yield] | 3539 // FormalsList[?Yield, ?GeneratorParameter] , FunctionRestParameter[?Yield] |
| 3513 // | 3540 // |
| 3514 // FormalsList[Yield,GeneratorParameter] : | 3541 // FormalsList[Yield,GeneratorParameter] : |
| 3515 // FormalParameter[?Yield, ?GeneratorParameter] | 3542 // FormalParameter[?Yield, ?GeneratorParameter] |
| 3516 // FormalsList[?Yield, ?GeneratorParameter] , | 3543 // FormalsList[?Yield, ?GeneratorParameter] , |
| 3517 // FormalParameter[?Yield,?GeneratorParameter] | 3544 // FormalParameter[?Yield,?GeneratorParameter] |
| 3518 | 3545 |
| 3519 int parameter_count = 0; | 3546 int parameter_count = 0; |
| 3520 | 3547 |
| 3521 if (peek() != Token::RPAREN) { | 3548 if (peek() != Token::RPAREN) { |
| 3549 DCHECK(scope_->is_function_scope()); |
| 3522 do { | 3550 do { |
| 3551 Scope* param_scope = NewScope(scope_, BLOCK_SCOPE); |
| 3552 param_scope->set_start_position(scanner()->peek_location().beg_pos); |
| 3553 BlockState param_state(&scope_, param_scope); |
| 3554 |
| 3523 if (++parameter_count > Code::kMaxArguments) { | 3555 if (++parameter_count > Code::kMaxArguments) { |
| 3524 ReportMessage("too_many_parameters"); | 3556 ReportMessage("too_many_parameters"); |
| 3525 *ok = false; | 3557 *ok = false; |
| 3526 return -1; | 3558 return -1; |
| 3527 } | 3559 } |
| 3528 *is_rest = allow_harmony_rest_params() && Check(Token::ELLIPSIS); | 3560 *is_rest = allow_harmony_rest_params() && Check(Token::ELLIPSIS); |
| 3529 ParseFormalParameter(scope, locs, *is_rest, ok); | 3561 |
| 3562 bool has_initializer = false; |
| 3563 ExpressionT initializer = this->EmptyExpression(); |
| 3564 ParseFormalParameter(scope, locs, &initializer, &has_initializer, |
| 3565 *is_rest, ok); |
| 3530 if (!*ok) return -1; | 3566 if (!*ok) return -1; |
| 3567 param_scope->set_end_position(scanner()->location().end_pos); |
| 3568 initializers->Add(initializer, zone()); |
| 3569 if (has_initializer) *has_initializers = true; |
| 3531 } while (!*is_rest && Check(Token::COMMA)); | 3570 } while (!*is_rest && Check(Token::COMMA)); |
| 3532 | 3571 |
| 3533 if (*is_rest && peek() == Token::COMMA) { | 3572 if (*is_rest && peek() == Token::COMMA) { |
| 3534 ReportMessageAt(scanner()->peek_location(), "param_after_rest"); | 3573 ReportMessageAt(scanner()->peek_location(), "param_after_rest"); |
| 3535 *ok = false; | 3574 *ok = false; |
| 3536 return -1; | 3575 return -1; |
| 3537 } | 3576 } |
| 3538 } | 3577 } |
| 3539 | 3578 |
| 3540 return parameter_count; | 3579 return parameter_count; |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3845 *ok = false; | 3884 *ok = false; |
| 3846 return; | 3885 return; |
| 3847 } | 3886 } |
| 3848 has_seen_constructor_ = true; | 3887 has_seen_constructor_ = true; |
| 3849 return; | 3888 return; |
| 3850 } | 3889 } |
| 3851 } | 3890 } |
| 3852 } } // v8::internal | 3891 } } // v8::internal |
| 3853 | 3892 |
| 3854 #endif // V8_PREPARSER_H | 3893 #endif // V8_PREPARSER_H |
| OLD | NEW |