| Index: src/preparser.h
|
| diff --git a/src/preparser.h b/src/preparser.h
|
| index 8184bd8d5f5af2bc93a872c80c71ab3b7cce8001..982a16bce214e2c12d6b34a8733ad350df51a647 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;
|
| @@ -764,11 +765,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);
|
| @@ -3468,7 +3472,7 @@ 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;
|
| @@ -3476,6 +3480,16 @@ void ParserBase<Traits>::ParseFormalParameter(
|
| ParseIdentifierOrStrictReservedWord(&is_strict_reserved, ok);
|
| if (!*ok) return;
|
|
|
| + if (Check(Token::ASSIGN)) {
|
| + // Optional argument 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();
|
| @@ -3496,7 +3510,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]
|
| @@ -3512,17 +3527,24 @@ int ParserBase<Traits>::ParseFormalParameterList(
|
| // FormalParameter[?Yield,?GeneratorParameter]
|
|
|
| int parameter_count = 0;
|
| -
|
| + DCHECK(scope_->is_function_scope());
|
| if (peek() != Token::RPAREN) {
|
| + Scope* param_scope = NewScope(scope_, BLOCK_SCOPE);
|
| + BlockState param_state(&scope_, param_scope);
|
| do {
|
| if (++parameter_count > Code::kMaxArguments) {
|
| ReportMessage("too_many_parameters");
|
| *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, 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) {
|
| @@ -3586,7 +3608,10 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(
|
| typename Traits::Type::Factory function_factory(ast_value_factory());
|
| FunctionState function_state(&function_state_, &scope_, scope,
|
| kArrowFunction, &function_factory);
|
| -
|
| + DCHECK(scope->is_arrow_scope());
|
| + Scope* function_body = NewScope(scope, FUNCTION_BODY_SCOPE);
|
| + DCHECK_EQ(scope->function_body(), function_body);
|
| + BlockState function_body_state(&scope_, function_body);
|
| if (peek() == Token::ARROW) {
|
| BindingPatternUnexpectedToken(classifier);
|
| }
|
|
|