| Index: src/preparser.h
|
| diff --git a/src/preparser.h b/src/preparser.h
|
| index c60318be3e35b02e965becaac68f05ec40007840..58f61058c6a8e7859b79e0c8ec0f11b48637367d 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;
|
| @@ -694,10 +695,16 @@ class ParserBase : public Traits {
|
| bool* ok);
|
|
|
| void ParseFormalParameter(FormalParameterScopeT* scope,
|
| - FormalParameterErrorLocations* locs, bool is_rest,
|
| + Scope* initializer_scope,
|
| + FormalParameterErrorLocations* locs,
|
| + ExpressionT* initializer,
|
| + bool* has_initializer, bool is_rest,
|
| bool* ok);
|
| int ParseFormalParameterList(FormalParameterScopeT* scope,
|
| + Scope* initializer_scope,
|
| FormalParameterErrorLocations* locs,
|
| + ExpressionListT initializers,
|
| + bool* has_initializers,
|
| bool* has_rest, bool* ok);
|
| void CheckArityRestrictions(
|
| int param_count, FunctionLiteral::ArityRestriction arity_restriction,
|
| @@ -3343,8 +3350,9 @@ ParserBase<Traits>::ParseMemberExpressionContinuation(
|
|
|
| template <class Traits>
|
| void ParserBase<Traits>::ParseFormalParameter(
|
| - FormalParameterScopeT* scope, FormalParameterErrorLocations* locs,
|
| - bool is_rest, bool* ok) {
|
| + FormalParameterScopeT* scope, Scope* parameter_scope,
|
| + FormalParameterErrorLocations* locs,
|
| + ExpressionT* initializer, bool* has_initializer, bool is_rest, bool* ok) {
|
| // FormalParameter[Yield,GeneratorParameter] :
|
| // BindingElement[?Yield, ?GeneratorParameter]
|
| bool is_strict_reserved;
|
| @@ -3352,6 +3360,17 @@ void ParserBase<Traits>::ParseFormalParameter(
|
| ParseIdentifierOrStrictReservedWord(&is_strict_reserved, ok);
|
| if (!*ok) return;
|
|
|
| + if (parameter_scope && Check(Token::ASSIGN)) {
|
| + // Optional argument initializer
|
| + // let formalName = IS_UNDEFINED(arguments[i]) ? initializer : arguments[i];
|
| + BlockState state(&scope_, NewScope(parameter_scope, BLOCK_SCOPE));
|
| + 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();
|
| @@ -3371,8 +3390,10 @@ void ParserBase<Traits>::ParseFormalParameter(
|
|
|
| template <class Traits>
|
| int ParserBase<Traits>::ParseFormalParameterList(
|
| - FormalParameterScopeT* scope, FormalParameterErrorLocations* locs,
|
| - bool* is_rest, bool* ok) {
|
| + FormalParameterScopeT* scope, Scope* parameter_scope,
|
| + FormalParameterErrorLocations* locs,
|
| + ExpressionListT initializers, bool* has_initializers, bool* is_rest,
|
| + bool* ok) {
|
| // FormalParameters[Yield,GeneratorParameter] :
|
| // [empty]
|
| // FormalParameterList[?Yield, ?GeneratorParameter]
|
| @@ -3389,6 +3410,8 @@ int ParserBase<Traits>::ParseFormalParameterList(
|
|
|
| int parameter_count = 0;
|
|
|
| + BlockState parameter_block(&scope_, parameter_scope);
|
| +
|
| if (peek() != Token::RPAREN) {
|
| do {
|
| if (++parameter_count > Code::kMaxArguments) {
|
| @@ -3396,9 +3419,14 @@ int ParserBase<Traits>::ParseFormalParameterList(
|
| *ok = false;
|
| return -1;
|
| }
|
| + bool has_initializer = false;
|
| + ExpressionT initializer = this->EmptyExpression();
|
| *is_rest = allow_harmony_rest_params() && Check(Token::ELLIPSIS);
|
| - ParseFormalParameter(scope, locs, *is_rest, ok);
|
| + ParseFormalParameter(scope, parameter_scope, locs, &initializer,
|
| + &has_initializer, *is_rest, ok);
|
| if (!*ok) return -1;
|
| + initializers->Add(initializer, zone());
|
| + if (has_initializer) *has_initializers = true;
|
| } while (!*is_rest && Check(Token::COMMA));
|
|
|
| if (*is_rest && peek() == Token::COMMA) {
|
|
|