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

Unified Diff: src/preparser.cc

Issue 1078093002: Factor formal argument parsing into ParserBase (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Created 5 years, 8 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/messages.js ('K') | « src/preparser.h ('k') | no next file » | no next file with comments »
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 15fca26788d56ad5a970d17bcbb834b3d796f244..856c2ca8f333a961fc6b6a6535766621d93c2341 100644
--- a/src/preparser.cc
+++ b/src/preparser.cc
@@ -905,11 +905,6 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
PreParserFactory factory(NULL);
FunctionState function_state(&function_state_, &scope_, function_scope, kind,
&factory);
- // FormalParameterList ::
- // '(' (Identifier)*[','] ')'
- Expect(Token::LPAREN, CHECK_OK);
- int start_position = position();
- DuplicateFinder duplicate_finder(scanner()->unicode_cache());
// We don't yet know if the function will be strict, so we cannot yet produce
// errors for parameter names or duplicates. However, we remember the
// locations of these errors if they occur and produce the errors later.
@@ -918,43 +913,17 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
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()) {
- eval_args_error_loc = scanner()->location();
- }
- if (!reserved_error_loc.IsValid() && is_strict_reserved) {
- reserved_error_loc = scanner()->location();
- }
-
- int prev_value = scanner()->FindSymbol(&duplicate_finder, 1);
-
- if (!dupe_error_loc.IsValid() && prev_value != 0) {
- dupe_error_loc = scanner()->location();
- }
-
- if (arity_restriction == FunctionLiteral::SETTER_ARITY) break;
- done = (peek() == Token::RPAREN);
- if (!done) {
- if (is_rest) {
- ReportMessageAt(scanner()->peek_location(), "param_after_rest");
- *ok = false;
- return Expression::Default();
- }
- Expect(Token::COMMA, CHECK_OK);
- }
- }
+ Expect(Token::LPAREN, CHECK_OK);
+ int start_position = scanner()->location().beg_pos;
+ PreParserFormalParameterList params =
+ ParseFormalParameterList(&eval_args_error_loc, &dupe_error_loc,
+ &reserved_error_loc, &is_rest, CHECK_OK);
Expect(Token::RPAREN, CHECK_OK);
+ int formals_end_position = scanner()->location().end_pos;
+
+ CheckArityRestrictions(params->length(), arity_restriction, start_position,
+ formals_end_position, ok);
+ if (!*ok) return Expression::Default();
// See Parser::ParseFunctionLiteral for more information about lazy parsing
// and lazy compilation.
« src/messages.js ('K') | « src/preparser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698