| Index: src/preparser.h
|
| diff --git a/src/preparser.h b/src/preparser.h
|
| index c84009245457610b52a55ef41d8de557f8649c89..3d2c3b5adb2e562c56b4121d6a1a426972f2bfe1 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;
|
| }
|
|
|
| @@ -3473,14 +3485,28 @@ 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;
|
|
|
| + // TODO(caitp): assert `ExpressionT* initializer` is never null. It is
|
| + // currently a nullptr in some cases to prevent Arrow Functions from parsing
|
| + // initializers.
|
| + if (initializer && allow_harmony_optional_params() && Check(Token::ASSIGN)) {
|
| + // 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();
|
| @@ -3491,7 +3517,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();
|
| }
|
| @@ -3501,7 +3527,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]
|
| @@ -3519,15 +3546,27 @@ int ParserBase<Traits>::ParseFormalParameterList(
|
| int parameter_count = 0;
|
|
|
| if (peek() != Token::RPAREN) {
|
| + DCHECK(scope_->is_function_scope());
|
| 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) {
|
|
|