set_allow_harmony_unicode(FLAG_harmony_unicode);
set_allow_harmony_computed_property_names(
FLAG_harmony_computed_property_names);
- set_allow_harmony_rest_params(FLAG_harmony_rest_parameters);
+ set_allow_harmony_rest_parameters(FLAG_harmony_rest_parameters);
set_allow_harmony_spreadcalls(FLAG_harmony_spreadcalls);
set_allow_harmony_destructuring(FLAG_harmony_destructuring);
set_allow_harmony_spread_arrays(FLAG_harmony_spread_arrays);
ParserFormalParameters* parameters, Expression* expr,
const Scanner::Location& params_loc,
Scanner::Location* duplicate_loc, bool* ok) {
- if (parameters->scope->num_parameters() >= Code::kMaxArguments) {
+ if (parameters->arity >= Code::kMaxArguments) {
ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList);
*ok = false;
return;
parser_->scope_->RemoveUnresolved(expr->AsVariableProxy());
}
+ ++parameters->arity;
ExpressionClassifier classifier;
DeclareFormalParameter(parameters, expr, is_rest, &classifier);
if (!duplicate_loc->IsValid()) {
: NewScope(scope_, FUNCTION_SCOPE, kind);
scope->SetLanguageMode(language_mode);
ZoneList<Statement*>* body = NULL;
- int arity = 0;
+ int arity = -1;
int materialized_literal_count = -1;
int expected_property_count = -1;
DuplicateFinder duplicate_finder(scanner()->unicode_cache());
int start_position = scanner()->location().beg_pos;
scope_->set_start_position(start_position);
ParserFormalParameters formals(scope);
- arity = ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK);
+ ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK);
+ arity = formals.arity;
+ DCHECK(arity == formals.params.length());
Expect(Token::RPAREN, CHECK_OK);
int formals_end_position = scanner()->location().end_pos;
DCHECK(scope_->is_function_scope());
Block* init_block =
factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition);
- for (auto parameter : parameters.params) {
+ for (int i = 0; i < parameters.params.length(); ++i) {
+ auto parameter = parameters.params[i];
if (parameter.pattern == nullptr) continue;
DeclarationDescriptor descriptor;
descriptor.declaration_kind = DeclarationDescriptor::PARAMETER;
descriptor.init_op = Token::INIT_LET;
DeclarationParsingResult::Declaration decl(
parameter.pattern, parameter.pattern->position(),
- factory()->NewVariableProxy(parameter.var));
+ factory()->NewVariableProxy(parameters.scope->parameter(i)));
PatternRewriter::DeclareAndInitializeVariables(init_block, &descriptor,
&decl, nullptr, CHECK_OK);
}
SET_ALLOW(harmony_sloppy_let);
SET_ALLOW(harmony_unicode);
SET_ALLOW(harmony_computed_property_names);
- SET_ALLOW(harmony_rest_params);
+ SET_ALLOW(harmony_rest_parameters);
SET_ALLOW(harmony_spreadcalls);
SET_ALLOW(harmony_destructuring);
SET_ALLOW(harmony_spread_arrays);
struct ParserFormalParameters : public PreParserFormalParameters {
struct Parameter {
- Parameter(Variable* var, Expression* pattern)
- : var(var), pattern(pattern) {}
- Variable* var;
+ Parameter(const AstRawString* name, Expression* pattern, bool is_rest)
+ : name(name), pattern(pattern), is_rest(is_rest) {}
+ const AstRawString* name;
Expression* pattern;
+ bool is_rest;
};
explicit ParserFormalParameters(Scope* scope)
ZoneList<Parameter> params;
- void AddParameter(Variable* var, Expression* pattern) {
- params.Add(Parameter(var, pattern), scope->zone());
+ void AddParameter(
+ const AstRawString* name, Expression* pattern, bool is_rest) {
+ params.Add(Parameter(name, pattern, is_rest), scope->zone());
+ DCHECK_EQ(arity, params.length());
}
};
typedef ObjectLiteral::Property* ObjectLiteralProperty;
typedef ZoneList<v8::internal::Expression*>* ExpressionList;
typedef ZoneList<ObjectLiteral::Property*>* PropertyList;
- typedef const v8::internal::AstRawString* FormalParameter;
+ typedef ParserFormalParameters::Parameter FormalParameter;
typedef ParserFormalParameters FormalParameters;
typedef ZoneList<v8::internal::Statement*>* StatementList;
VariableMode mode = is_simple ? VAR : TEMPORARY;
Variable* var =
parameters->scope->DeclareParameter(name, mode, is_rest, &is_duplicate);
- parameters->AddParameter(var, is_simple ? nullptr : pattern);
+ parameters->AddParameter(name, is_simple ? nullptr : pattern, is_rest);
if (is_duplicate) {
classifier->RecordDuplicateFormalParameterError(
parser_->scanner()->location());
int start_position = scanner()->location().beg_pos;
function_scope->set_start_position(start_position);
PreParserFormalParameters formals(nullptr);
- int arity = ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK);
+ ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK);
Expect(Token::RPAREN, CHECK_OK);
int formals_end_position = scanner()->location().end_pos;
- CheckArityRestrictions(arity, arity_restriction,
+ CheckArityRestrictions(formals.arity, arity_restriction,
formals.has_rest, start_position,
formals_end_position, CHECK_OK);
allow_harmony_sloppy_(false),
allow_harmony_sloppy_let_(false),
allow_harmony_computed_property_names_(false),
- allow_harmony_rest_params_(false),
+ allow_harmony_rest_parameters_(false),
allow_harmony_spreadcalls_(false),
allow_harmony_destructuring_(false),
allow_harmony_spread_arrays_(false),
ALLOW_ACCESSORS(harmony_sloppy);
ALLOW_ACCESSORS(harmony_sloppy_let);
ALLOW_ACCESSORS(harmony_computed_property_names);
- ALLOW_ACCESSORS(harmony_rest_params);
+ ALLOW_ACCESSORS(harmony_rest_parameters);
ALLOW_ACCESSORS(harmony_spreadcalls);
ALLOW_ACCESSORS(harmony_destructuring);
ALLOW_ACCESSORS(harmony_spread_arrays);
void ParseFormalParameter(bool is_rest,
FormalParametersT* parameters,
ExpressionClassifier* classifier, bool* ok);
- int ParseFormalParameterList(FormalParametersT* parameters,
- ExpressionClassifier* classifier, bool* ok);
+ void ParseFormalParameterList(FormalParametersT* parameters,
+ ExpressionClassifier* classifier, bool* ok);
void CheckArityRestrictions(
int param_count, FunctionLiteral::ArityRestriction arity_restriction,
bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok);
bool allow_harmony_sloppy_;
bool allow_harmony_sloppy_let_;
bool allow_harmony_computed_property_names_;
- bool allow_harmony_rest_params_;
+ bool allow_harmony_rest_parameters_;
bool allow_harmony_spreadcalls_;
bool allow_harmony_destructuring_;
bool allow_harmony_spread_arrays_;
struct PreParserFormalParameters {
explicit PreParserFormalParameters(Scope* scope)
: scope(scope),
+ arity(0),
has_rest(false),
is_simple(true),
materialized_literals_count(0) {}
Scope* scope;
+ int arity;
bool has_rest;
bool is_simple;
int materialized_literals_count;
result = this->ParseArrowFunctionLiteral(parameters, args_classifier,
CHECK_OK);
} else if (allow_harmony_arrow_functions() &&
- allow_harmony_rest_params() && Check(Token::ELLIPSIS)) {
+ allow_harmony_rest_parameters() && Check(Token::ELLIPSIS)) {
// (...x) => y
Scope* scope =
this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction);
}
Consume(Token::COMMA);
bool is_rest = false;
- if (allow_harmony_rest_params() && peek() == Token::ELLIPSIS) {
+ if (allow_harmony_rest_parameters() && peek() == Token::ELLIPSIS) {
// 'x, y, ...z' in CoverParenthesizedExpressionAndArrowParameterList only
// as the formal parameters of'(x, y, ...z) => foo', and is not itself a
// valid expression or binding pattern.
*ok = false;
return;
}
+ ++parameters->arity;
Traits::DeclareFormalParameter(parameters, pattern, is_rest, classifier);
}
template <class Traits>
-int ParserBase<Traits>::ParseFormalParameterList(
+void ParserBase<Traits>::ParseFormalParameterList(
FormalParametersT* parameters, ExpressionClassifier* classifier, bool* ok) {
// FormalParameters[Yield,GeneratorParameter] :
// [empty]
// FormalsList[?Yield, ?GeneratorParameter] ,
// FormalParameter[?Yield,?GeneratorParameter]
- int arity = 0;
+ DCHECK_EQ(0, parameters->arity);
if (peek() != Token::RPAREN) {
do {
- if (++arity > Code::kMaxArguments) {
+ if (parameters->arity > Code::kMaxArguments) {
ReportMessage(MessageTemplate::kTooManyParameters);
*ok = false;
- return -1;
+ return;
}
- bool is_rest = allow_harmony_rest_params() && Check(Token::ELLIPSIS);
+ bool is_rest = allow_harmony_rest_parameters() && Check(Token::ELLIPSIS);
ParseFormalParameter(is_rest, parameters, classifier, ok);
- if (!*ok) return -1;
+ if (!*ok) return;
} while (!parameters->has_rest && Check(Token::COMMA));
if (parameters->has_rest && peek() == Token::COMMA) {
ReportMessageAt(scanner()->peek_location(),
MessageTemplate::kParamAfterRest);
*ok = false;
- return -1;
}
}
-
- return arity;
}
parser->set_allow_harmony_modules(flags.Contains(kAllowHarmonyModules));
parser->set_allow_harmony_arrow_functions(
flags.Contains(kAllowHarmonyArrowFunctions));
- parser->set_allow_harmony_rest_params(
+ parser->set_allow_harmony_rest_parameters(
flags.Contains(kAllowHarmonyRestParameters));
parser->set_allow_harmony_spreadcalls(
flags.Contains(kAllowHarmonySpreadCalls));