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

Unified Diff: src/preparser.cc

Issue 329413002: Throw syntax error when a getter/setter has the wrong number of params (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add test exception Created 6 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
« no previous file with comments | « src/preparser.h ('k') | test/cctest/test-parsing.cc » ('j') | 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 80a17af93934ef6902c033a339d50bef792b0708..63462c80457b952cdb96dbb12d49b86b673082f6 100644
--- a/src/preparser.cc
+++ b/src/preparser.cc
@@ -95,10 +95,11 @@ PreParserExpression PreParserTraits::ParseFunctionLiteral(
bool is_generator,
int function_token_position,
FunctionLiteral::FunctionType type,
+ FunctionLiteral::ArityRestriction arity_restriction,
bool* ok) {
return pre_parser_->ParseFunctionLiteral(
name, function_name_location, name_is_strict_reserved, is_generator,
- function_token_position, type, ok);
+ function_token_position, type, arity_restriction, ok);
}
@@ -320,6 +321,7 @@ PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) {
is_generator,
pos,
FunctionLiteral::DECLARATION,
+ FunctionLiteral::NORMAL_ARITY,
CHECK_OK);
return Statement::FunctionDeclaration();
}
@@ -799,6 +801,7 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
bool is_generator,
int function_token_pos,
FunctionLiteral::FunctionType function_type,
+ FunctionLiteral::ArityRestriction arity_restriction,
bool* ok) {
// Function ::
// '(' FormalParameterList? ')' '{' FunctionBody '}'
@@ -812,7 +815,6 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
// '(' (Identifier)*[','] ')'
Expect(Token::LPAREN, CHECK_OK);
int start_position = position();
- bool done = (peek() == Token::RPAREN);
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
@@ -820,6 +822,10 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
Scanner::Location eval_args_error_loc = Scanner::Location::invalid();
Scanner::Location dupe_error_loc = Scanner::Location::invalid();
Scanner::Location reserved_error_loc = Scanner::Location::invalid();
+
+ bool done = arity_restriction == FunctionLiteral::GETTER_ARITY ||
+ (peek() == Token::RPAREN &&
+ arity_restriction != FunctionLiteral::SETTER_ARITY);
while (!done) {
bool is_strict_reserved = false;
Identifier param_name =
@@ -837,10 +843,9 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
dupe_error_loc = scanner()->location();
}
+ if (arity_restriction == FunctionLiteral::SETTER_ARITY) break;
done = (peek() == Token::RPAREN);
- if (!done) {
- Expect(Token::COMMA, CHECK_OK);
- }
+ if (!done) Expect(Token::COMMA, CHECK_OK);
}
Expect(Token::RPAREN, CHECK_OK);
« no previous file with comments | « src/preparser.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698