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

Unified Diff: src/preparser.cc

Issue 885243002: Implement parsing of ES6 Rest Parameters (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 11 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/preparser.h ('k') | src/scanner.cc » ('j') | src/scanner.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/preparser.cc
diff --git a/src/preparser.cc b/src/preparser.cc
index ed57facce88a0c97889df1eb445278ba32a42bef..6cf0f1db4589797c2f2eaa5affe46167d0412636 100644
--- a/src/preparser.cc
+++ b/src/preparser.cc
@@ -878,11 +878,17 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
Scanner::Location dupe_error_loc = Scanner::Location::invalid();
Scanner::Location reserved_error_loc = Scanner::Location::invalid();
+ bool is_rest = false;
bool done = arity_restriction == FunctionLiteral::GETTER_ARITY ||
(peek() == Token::RPAREN &&
arity_restriction != FunctionLiteral::SETTER_ARITY);
while (!done) {
bool is_strict_reserved = false;
+ is_rest = peek() == Token::ELLIPSIS && allow_harmony_rest_params();
+ if (is_rest) {
+ Consume(Token::ELLIPSIS);
+ }
+
Identifier param_name =
ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
if (!eval_args_error_loc.IsValid() && param_name.IsEvalOrArguments()) {
@@ -900,7 +906,14 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
if (arity_restriction == FunctionLiteral::SETTER_ARITY) break;
done = (peek() == Token::RPAREN);
- if (!done) Expect(Token::COMMA, CHECK_OK);
+ if (!done) {
+ if (is_rest) {
+ ReportMessageAt(scanner()->peek_location(), "param_after_rest");
+ *ok = false;
+ return Expression::Default();
+ }
+ Expect(Token::COMMA, CHECK_OK);
+ }
}
Expect(Token::RPAREN, CHECK_OK);
@@ -921,7 +934,7 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
// Validate strict mode. We can do this only after parsing the function,
// since the function can declare itself strict.
// Concise methods use StrictFormalParameters.
- if (strict_mode() == STRICT || IsConciseMethod(kind)) {
+ if (strict_mode() == STRICT || IsConciseMethod(kind) || is_rest) {
if (function_name.IsEvalOrArguments()) {
ReportMessageAt(function_name_location, "strict_eval_arguments");
*ok = false;
« no previous file with comments | « src/preparser.h ('k') | src/scanner.cc » ('j') | src/scanner.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698