Chromium Code Reviews| Index: src/preparser.h |
| diff --git a/src/preparser.h b/src/preparser.h |
| index 93642812fe495f54f6e1a5fc44ec6466e58da312..7a9f8c1dc062d8daf026385b6146d2dabc2dce58 100644 |
| --- a/src/preparser.h |
| +++ b/src/preparser.h |
| @@ -84,6 +84,7 @@ class ParserBase : public Traits { |
| public: |
| // Shorten type names defined by Traits. |
| typedef typename Traits::Type::Expression ExpressionT; |
| + typedef typename Traits::Type::ExpressionList ExpressionListT; |
| typedef typename Traits::Type::Identifier IdentifierT; |
| typedef typename Traits::Type::FormalParameter FormalParameterT; |
| typedef typename Traits::Type::FormalParameterScope FormalParameterScopeT; |
| @@ -115,6 +116,7 @@ class ParserBase : public Traits { |
| allow_harmony_computed_property_names_(false), |
| allow_harmony_rest_params_(false), |
| allow_harmony_spreadcalls_(false), |
| + allow_harmony_optional_params_(false), |
| allow_strong_mode_(false) {} |
| // Getters that indicate whether certain syntactical constructs are |
| @@ -141,6 +143,9 @@ class ParserBase : public Traits { |
| bool allow_harmony_destructuring() const { |
| return allow_harmony_destructuring_; |
| } |
| + bool allow_harmony_optional_params() const { |
| + return allow_harmony_optional_params_; |
| + } |
| bool allow_strong_mode() const { return allow_strong_mode_; } |
| @@ -179,6 +184,9 @@ class ParserBase : public Traits { |
| void set_allow_harmony_destructuring(bool allow) { |
| allow_harmony_destructuring_ = allow; |
| } |
| + void set_allow_harmony_optional_params(bool allow) { |
| + allow_harmony_optional_params_ = allow; |
| + } |
| protected: |
| @@ -764,11 +772,14 @@ class ParserBase : public Traits { |
| bool* ok); |
| void ParseFormalParameter(FormalParameterScopeT* scope, |
| - FormalParameterErrorLocations* locs, bool is_rest, |
| - bool* ok); |
| + FormalParameterErrorLocations* locs, |
| + ExpressionT* initializer, bool* has_initializer, |
| + bool is_rest, bool* ok); |
| int ParseFormalParameterList(FormalParameterScopeT* scope, |
| FormalParameterErrorLocations* locs, |
| - bool* has_rest, bool* ok); |
| + ExpressionListT initializers, |
| + bool* has_initializers, bool* has_rest, |
| + bool* ok); |
| void CheckArityRestrictions( |
| int param_count, FunctionLiteral::ArityRestriction arity_restriction, |
| int formals_start_pos, int formals_end_pos, bool* ok); |
| @@ -869,6 +880,7 @@ class ParserBase : public Traits { |
| bool allow_harmony_rest_params_; |
| bool allow_harmony_spreadcalls_; |
| bool allow_harmony_destructuring_; |
| + bool allow_harmony_optional_params_; |
| bool allow_strong_mode_; |
| }; |
| @@ -1724,8 +1736,8 @@ class PreParserTraits { |
| } |
| V8_INLINE bool DeclareFormalParameter(DuplicateFinder* scope, |
| - PreParserIdentifier param, |
| - bool is_rest); |
| + PreParserIdentifier param, bool is_rest, |
| + int pos); |
| void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {} |
| @@ -1921,7 +1933,7 @@ PreParserExpression PreParserTraits::SpreadCallNew(PreParserExpression function, |
| bool PreParserTraits::DeclareFormalParameter( |
| DuplicateFinder* duplicate_finder, PreParserIdentifier current_identifier, |
| - bool is_rest) { |
| + bool is_rest, int pos) { |
| return pre_parser_->scanner()->FindSymbol(duplicate_finder, 1) != 0; |
| } |
| @@ -3468,14 +3480,25 @@ ParserBase<Traits>::ParseMemberExpressionContinuation( |
| template <class Traits> |
| void ParserBase<Traits>::ParseFormalParameter( |
| FormalParameterScopeT* scope, FormalParameterErrorLocations* locs, |
| - bool is_rest, bool* ok) { |
| + ExpressionT* initializer, bool* has_initializer, bool is_rest, bool* ok) { |
| // FormalParameter[Yield,GeneratorParameter] : |
| // BindingElement[?Yield, ?GeneratorParameter] |
| bool is_strict_reserved; |
| + int pos = peek_position(); |
| IdentifierT name = |
| ParseIdentifierOrStrictReservedWord(&is_strict_reserved, ok); |
| if (!*ok) return; |
| + 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
|
| + // Optional parameter initializer |
| + // let formalName = IS_UNDEFINED(arguments[i]) ? initializer : arguments[i]; |
| + static const bool accept_IN = true; |
| + ExpressionClassifier classifier; |
| + *initializer = ParseAssignmentExpression(accept_IN, &classifier, ok); |
| + if (!*ok) return; |
| + *has_initializer = true; |
| + } |
| + |
| // Store locations for possible future error reports. |
| if (!locs->eval_or_arguments.IsValid() && this->IsEvalOrArguments(name)) { |
| locs->eval_or_arguments = scanner()->location(); |
| @@ -3486,7 +3509,7 @@ void ParserBase<Traits>::ParseFormalParameter( |
| if (!locs->reserved.IsValid() && is_strict_reserved) { |
| locs->reserved = scanner()->location(); |
| } |
| - bool was_declared = Traits::DeclareFormalParameter(scope, name, is_rest); |
| + bool was_declared = Traits::DeclareFormalParameter(scope, name, is_rest, pos); |
| if (!locs->duplicate.IsValid() && was_declared) { |
| locs->duplicate = scanner()->location(); |
| } |
| @@ -3496,7 +3519,8 @@ void ParserBase<Traits>::ParseFormalParameter( |
| template <class Traits> |
| int ParserBase<Traits>::ParseFormalParameterList( |
| FormalParameterScopeT* scope, FormalParameterErrorLocations* locs, |
| - bool* is_rest, bool* ok) { |
| + ExpressionListT initializers, bool* has_initializers, bool* is_rest, |
| + bool* ok) { |
| // FormalParameters[Yield,GeneratorParameter] : |
| // [empty] |
| // FormalParameterList[?Yield, ?GeneratorParameter] |
| @@ -3514,15 +3538,27 @@ int ParserBase<Traits>::ParseFormalParameterList( |
| int parameter_count = 0; |
| if (peek() != Token::RPAREN) { |
| + 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
|
| do { |
| + Scope* param_scope = NewScope(scope_, BLOCK_SCOPE); |
| + param_scope->set_start_position(scanner()->peek_location().beg_pos); |
| + BlockState param_state(&scope_, param_scope); |
| + |
| if (++parameter_count > Code::kMaxArguments) { |
| ReportMessage("too_many_parameters"); |
| *ok = false; |
| return -1; |
| } |
| *is_rest = allow_harmony_rest_params() && Check(Token::ELLIPSIS); |
| - ParseFormalParameter(scope, locs, *is_rest, ok); |
| + |
| + bool has_initializer = false; |
| + ExpressionT initializer = this->EmptyExpression(); |
| + ParseFormalParameter(scope, locs, &initializer, &has_initializer, |
| + *is_rest, ok); |
| if (!*ok) return -1; |
| + param_scope->set_end_position(scanner()->location().end_pos); |
| + initializers->Add(initializer, zone()); |
| + if (has_initializer) *has_initializers = true; |
| } while (!*is_rest && Check(Token::COMMA)); |
| if (*is_rest && peek() == Token::COMMA) { |