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

Unified Diff: src/parser.cc

Issue 1178523002: Support rest parameters in arrow functions (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Remove bogus DCHECK; function could be of simple x=>y form, thus not valid ArrowFormalParameters Created 5 years, 6 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
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 816849748869720029796504e4d282dc6ca1bb2e..0edaceddde6ff00d1358dba96bf6e4a7c664de5e 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -3759,9 +3759,9 @@ Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) {
}
-void ParserTraits::DeclareArrowFunctionParameters(
+void ParserTraits::ParseArrowFunctionFormalParameters(
Scope* scope, Expression* expr, const Scanner::Location& params_loc,
- Scanner::Location* duplicate_loc, bool* ok) {
+ bool has_rest, Scanner::Location* duplicate_loc, bool* ok) {
if (scope->num_parameters() >= Code::kMaxArguments) {
ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList);
*ok = false;
@@ -3785,13 +3785,15 @@ void ParserTraits::DeclareArrowFunctionParameters(
DCHECK_EQ(binop->op(), Token::COMMA);
Expression* left = binop->left();
Expression* right = binop->right();
- DeclareArrowFunctionParameters(scope, left, params_loc, duplicate_loc, ok);
+ // Only the right-most expression may be a rest parameter.
+ bool has_rest = false;
+ ParseArrowFunctionFormalParameters(scope, left, params_loc, has_rest,
+ duplicate_loc, ok);
if (!*ok) return;
// LHS of comma expression should be unparenthesized.
expr = right;
}
- // TODO(wingo): Support rest parameters.
DCHECK(expr->IsVariableProxy());
DCHECK(!expr->AsVariableProxy()->is_this());
@@ -3804,17 +3806,11 @@ void ParserTraits::DeclareArrowFunctionParameters(
// parse-time side-effect.
parser_->scope_->RemoveUnresolved(expr->AsVariableProxy());
- bool is_rest = false;
ExpressionClassifier classifier;
- DeclareFormalParameter(scope, raw_name, &classifier, is_rest);
- *duplicate_loc = classifier.duplicate_formal_parameter_error().location;
-}
-
-
-void ParserTraits::ParseArrowFunctionFormalParameters(
- Scope* scope, Expression* params, const Scanner::Location& params_loc,
- bool* is_rest, Scanner::Location* duplicate_loc, bool* ok) {
- DeclareArrowFunctionParameters(scope, params, params_loc, duplicate_loc, ok);
+ DeclareFormalParameter(scope, raw_name, &classifier, has_rest);
+ if (!duplicate_loc->IsValid()) {
Dmitry Lomov (no reviews) 2015/06/10 11:04:41 Oops, thanks for fixing this! Can we add a test th
wingo 2015/06/10 13:21:10 Sure. I'll see if I can cook one up for this CL a
+ *duplicate_loc = classifier.duplicate_formal_parameter_error().location;
+ }
}
« src/expression-classifier.h ('K') | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698