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

Unified Diff: src/preparser.h

Issue 1259013003: [es6] Refactor FormalParameter (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 5 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
« src/parser.h ('K') | « 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 18a0162913d1774a8c1d3077c1e073f7a0a3762b..e0b24328172aa3ec37bc0e6d151d089596490d6c 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;
@@ -2275,7 +2277,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);
@@ -2387,7 +2389,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.
@@ -3646,12 +3648,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]
@@ -3667,29 +3670,26 @@ int ParserBase<Traits>::ParseFormalParameterList(
// FormalsList[?Yield, ?GeneratorParameter] ,
// FormalParameter[?Yield,?GeneratorParameter]
- int arity = 0;
+ DCHECK(parameters->arity == 0);
adamk 2015/08/03 18:20:23 DCHECK_EQ
rossberg 2015/08/04 13:44:22 Done.
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;
}
« src/parser.h ('K') | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698