Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Unified Diff: src/preparser.h

Issue 1259013003: [es6] Refactor FormalParameter (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Comments Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index a3ae91c60281e4df0950049aa0170c10a717a6e4..3bd0953cb627122adaf0691918545a8034469ecb 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -103,7 +103,7 @@ class ParserBase : public Traits {
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),
@@ -121,7 +121,7 @@ class ParserBase : public Traits {
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);
@@ -702,8 +702,8 @@ class ParserBase : public Traits {
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);
@@ -801,7 +801,7 @@ class ParserBase : public Traits {
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_;
@@ -1315,10 +1315,12 @@ class PreParserFactory {
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;
@@ -2274,7 +2276,7 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier,
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);
@@ -2386,7 +2388,7 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression(
}
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.
@@ -3645,12 +3647,13 @@ void ParserBase<Traits>::ParseFormalParameter(
*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]
@@ -3666,29 +3669,26 @@ int ParserBase<Traits>::ParseFormalParameterList(
// 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;
}
« no previous file with comments | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698