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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/scopes.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 3278 matching lines...) Expand 10 before | Expand all | Expand 10 after
3289 NewScope(top_scope_, Scope::FUNCTION_SCOPE, inside_with()); 3289 NewScope(top_scope_, Scope::FUNCTION_SCOPE, inside_with());
3290 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_, 3290 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_,
3291 scope); 3291 scope);
3292 TemporaryScope temp_scope(&this->temp_scope_); 3292 TemporaryScope temp_scope(&this->temp_scope_);
3293 top_scope_->SetScopeName(name); 3293 top_scope_->SetScopeName(name);
3294 3294
3295 // FormalParameterList :: 3295 // FormalParameterList ::
3296 // '(' (Identifier)*[','] ')' 3296 // '(' (Identifier)*[','] ')'
3297 Expect(Token::LPAREN, CHECK_OK); 3297 Expect(Token::LPAREN, CHECK_OK);
3298 int start_pos = scanner().location().beg_pos; 3298 int start_pos = scanner().location().beg_pos;
3299 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.
3300 Scanner::Location dupe_loc(RelocInfo::kNoPosition, RelocInfo::kNoPosition);
3299 3301
3300 bool done = (peek() == Token::RPAREN); 3302 bool done = (peek() == Token::RPAREN);
3301 while (!done) { 3303 while (!done) {
3302 Handle<String> param_name = ParseIdentifier(CHECK_OK); 3304 Handle<String> param_name = ParseIdentifier(CHECK_OK);
3305
3306 // Store locations for possible future error reports.
3307 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
3308 IsEvalOrArguments(param_name)) {
3309 // 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.
3310 name_loc = scanner().location();
3311 }
3312 if (dupe_loc.beg_pos == RelocInfo::kNoPosition &&
3313 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.
3314 // Store location for later
3315 dupe_loc = scanner().location();
3316 }
3317
3303 Variable* parameter = top_scope_->DeclareLocal(param_name, Variable::VAR); 3318 Variable* parameter = top_scope_->DeclareLocal(param_name, Variable::VAR);
3304 top_scope_->AddParameter(parameter); 3319 top_scope_->AddParameter(parameter);
3305 num_parameters++; 3320 num_parameters++;
3306 done = (peek() == Token::RPAREN); 3321 done = (peek() == Token::RPAREN);
3307 if (!done) Expect(Token::COMMA, CHECK_OK); 3322 if (!done) Expect(Token::COMMA, CHECK_OK);
3308 } 3323 }
3309 Expect(Token::RPAREN, CHECK_OK); 3324 Expect(Token::RPAREN, CHECK_OK);
3310 3325
3311 Expect(Token::LBRACE, CHECK_OK); 3326 Expect(Token::LBRACE, CHECK_OK);
3312 ZoneList<Statement*>* body = new ZoneList<Statement*>(8); 3327 ZoneList<Statement*>* body = new ZoneList<Statement*>(8);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
3370 this_property_assignments = temp_scope.this_property_assignments(); 3385 this_property_assignments = temp_scope.this_property_assignments();
3371 3386
3372 Expect(Token::RBRACE, CHECK_OK); 3387 Expect(Token::RBRACE, CHECK_OK);
3373 end_pos = scanner().location().end_pos; 3388 end_pos = scanner().location().end_pos;
3374 } 3389 }
3375 3390
3376 // Validate strict mode. 3391 // Validate strict mode.
3377 if (temp_scope_->StrictMode()) { 3392 if (temp_scope_->StrictMode()) {
3378 if (IsEvalOrArguments(name)) { 3393 if (IsEvalOrArguments(name)) {
3379 int position = function_token_position != RelocInfo::kNoPosition 3394 int position = function_token_position != RelocInfo::kNoPosition
3380 ? function_token_position 3395 ? function_token_position
Kevin Millikin (Chromium) 2011/01/21 11:41:56 We usually indent these continuations 4 spaces fro
Martin Maly 2011/01/21 23:08:39 Done.
3381 : (start_pos > 0 ? start_pos - 1 : start_pos); 3396 : (start_pos > 0 ? start_pos - 1 : start_pos);
3382 ReportMessageAt(Scanner::Location(position, start_pos), 3397 ReportMessageAt(Scanner::Location(position, start_pos),
3383 "strict_function_name", Vector<const char*>::empty()); 3398 "strict_function_name", Vector<const char*>::empty());
3384 *ok = false; 3399 *ok = false;
3385 return NULL; 3400 return NULL;
3386 } 3401 }
3402 if (name_loc.beg_pos != RelocInfo::kNoPosition) {
3403 ReportMessageAt(name_loc, "strict_param_name",
3404 Vector<const char*>::empty());
3405 *ok = false;
3406 return NULL;
3407 }
3408 if (dupe_loc.beg_pos != RelocInfo::kNoPosition) {
3409 ReportMessageAt(dupe_loc, "strict_param_dupe",
3410 Vector<const char*>::empty());
3411 *ok = false;
3412 return NULL;
3413 }
3387 // TODO(mmaly): Check for octal escape sequence here. 3414 // TODO(mmaly): Check for octal escape sequence here.
3388 } 3415 }
3389 3416
3390 FunctionLiteral* function_literal = 3417 FunctionLiteral* function_literal =
3391 new FunctionLiteral(name, 3418 new FunctionLiteral(name,
3392 top_scope_, 3419 top_scope_,
3393 body, 3420 body,
3394 materialized_literal_count, 3421 materialized_literal_count,
3395 expected_property_count, 3422 expected_property_count,
3396 only_simple_this_property_assignments, 3423 only_simple_this_property_assignments,
(...skipping 1421 matching lines...) Expand 10 before | Expand all | Expand 10 after
4818 Handle<String> source = Handle<String>(String::cast(script->source())); 4845 Handle<String> source = Handle<String>(String::cast(script->source()));
4819 result = parser.ParseProgram(source, info->is_global()); 4846 result = parser.ParseProgram(source, info->is_global());
4820 } 4847 }
4821 } 4848 }
4822 4849
4823 info->SetFunction(result); 4850 info->SetFunction(result);
4824 return (result != NULL); 4851 return (result != NULL);
4825 } 4852 }
4826 4853
4827 } } // namespace v8::internal 4854 } } // namespace v8::internal
OLDNEW
« 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