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

Unified Diff: src/parser.cc

Issue 6382006: Strict mode parameter validation. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 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 | « no previous file | src/scopes.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 2637281f080ed9f7f32fba93701c4da068a4f34e..89d73f52b6d6789aa0fc177281dac06b724c66b7 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -3296,10 +3296,25 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name,
// '(' (Identifier)*[','] ')'
Expect(Token::LPAREN, CHECK_OK);
int start_pos = scanner().location().beg_pos;
+ Scanner::Location name_loc(RelocInfo::kNoPosition, RelocInfo::kNoPosition);
Kevin Millikin (Chromium) 2011/01/21 11:41:56 This might be more readable with a factory functio
Martin Maly 2011/01/21 23:08:39 Done.
+ Scanner::Location dupe_loc(RelocInfo::kNoPosition, RelocInfo::kNoPosition);
bool done = (peek() == Token::RPAREN);
while (!done) {
Handle<String> param_name = ParseIdentifier(CHECK_OK);
+
+ // Store locations for possible future error reports.
+ if (name_loc.beg_pos == RelocInfo::kNoPosition &&
Kevin Millikin (Chromium) 2011/01/21 11:41:56 Likewise, struct Scanner::Location could have a pr
Martin Maly 2011/01/21 23:08:39 Done. The Location::IsValid felt best so I went wi
+ IsEvalOrArguments(param_name)) {
+ // Store location for later
Kevin Millikin (Chromium) 2011/01/21 11:41:56 This comment is probably redundant and so's the on
Martin Maly 2011/01/21 23:08:39 Done.
+ name_loc = scanner().location();
+ }
+ if (dupe_loc.beg_pos == RelocInfo::kNoPosition &&
+ top_scope_->IsDeclared(param_name)) {
Kevin Millikin (Chromium) 2011/01/21 11:41:56 Indentation is off here.
Martin Maly 2011/01/21 23:08:39 Done.
+ // Store location for later
+ dupe_loc = scanner().location();
+ }
+
Variable* parameter = top_scope_->DeclareLocal(param_name, Variable::VAR);
top_scope_->AddParameter(parameter);
num_parameters++;
@@ -3384,6 +3399,18 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name,
*ok = false;
return NULL;
}
+ if (name_loc.beg_pos != RelocInfo::kNoPosition) {
+ ReportMessageAt(name_loc, "strict_param_name",
+ Vector<const char*>::empty());
+ *ok = false;
+ return NULL;
+ }
+ if (dupe_loc.beg_pos != RelocInfo::kNoPosition) {
+ ReportMessageAt(dupe_loc, "strict_param_dupe",
+ Vector<const char*>::empty());
+ *ok = false;
+ return NULL;
+ }
// TODO(mmaly): Check for octal escape sequence here.
}
« no previous file with comments | « no previous file | src/scopes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698