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

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: Kevin's feedback 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/scanner-base.h » ('j') | src/scanner-base.h » ('J')
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 = Scanner::NoLocation();
3300 Scanner::Location dupe_loc = Scanner::NoLocation();
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.IsValid() && IsEvalOrArguments(param_name)) {
3308 name_loc = scanner().location();
3309 }
3310 if (!dupe_loc.IsValid() && top_scope_->IsDeclared(param_name)) {
3311 dupe_loc = scanner().location();
3312 }
3313
3303 Variable* parameter = top_scope_->DeclareLocal(param_name, Variable::VAR); 3314 Variable* parameter = top_scope_->DeclareLocal(param_name, Variable::VAR);
3304 top_scope_->AddParameter(parameter); 3315 top_scope_->AddParameter(parameter);
3305 num_parameters++; 3316 num_parameters++;
3306 done = (peek() == Token::RPAREN); 3317 done = (peek() == Token::RPAREN);
3307 if (!done) Expect(Token::COMMA, CHECK_OK); 3318 if (!done) Expect(Token::COMMA, CHECK_OK);
3308 } 3319 }
3309 Expect(Token::RPAREN, CHECK_OK); 3320 Expect(Token::RPAREN, CHECK_OK);
3310 3321
3311 Expect(Token::LBRACE, CHECK_OK); 3322 Expect(Token::LBRACE, CHECK_OK);
3312 ZoneList<Statement*>* body = new ZoneList<Statement*>(8); 3323 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(); 3381 this_property_assignments = temp_scope.this_property_assignments();
3371 3382
3372 Expect(Token::RBRACE, CHECK_OK); 3383 Expect(Token::RBRACE, CHECK_OK);
3373 end_pos = scanner().location().end_pos; 3384 end_pos = scanner().location().end_pos;
3374 } 3385 }
3375 3386
3376 // Validate strict mode. 3387 // Validate strict mode.
3377 if (temp_scope_->StrictMode()) { 3388 if (temp_scope_->StrictMode()) {
3378 if (IsEvalOrArguments(name)) { 3389 if (IsEvalOrArguments(name)) {
3379 int position = function_token_position != RelocInfo::kNoPosition 3390 int position = function_token_position != RelocInfo::kNoPosition
3380 ? function_token_position 3391 ? function_token_position
3381 : (start_pos > 0 ? start_pos - 1 : start_pos); 3392 : (start_pos > 0 ? start_pos - 1 : start_pos);
3382 ReportMessageAt(Scanner::Location(position, start_pos), 3393 ReportMessageAt(Scanner::Location(position, start_pos),
3383 "strict_function_name", Vector<const char*>::empty()); 3394 "strict_function_name", Vector<const char*>::empty());
3384 *ok = false; 3395 *ok = false;
3385 return NULL; 3396 return NULL;
3386 } 3397 }
3398 if (name_loc.beg_pos != RelocInfo::kNoPosition) {
Lasse Reichstein 2011/01/25 13:03:55 Use name_loc.IsValid() here and below.
Martin Maly 2011/01/25 17:21:25 Done.
3399 ReportMessageAt(name_loc, "strict_param_name",
3400 Vector<const char*>::empty());
3401 *ok = false;
3402 return NULL;
3403 }
3404 if (dupe_loc.beg_pos != RelocInfo::kNoPosition) {
3405 ReportMessageAt(dupe_loc, "strict_param_dupe",
3406 Vector<const char*>::empty());
3407 *ok = false;
3408 return NULL;
3409 }
3387 // TODO(mmaly): Check for octal escape sequence here. 3410 // TODO(mmaly): Check for octal escape sequence here.
3388 } 3411 }
3389 3412
3390 FunctionLiteral* function_literal = 3413 FunctionLiteral* function_literal =
3391 new FunctionLiteral(name, 3414 new FunctionLiteral(name,
3392 top_scope_, 3415 top_scope_,
3393 body, 3416 body,
3394 materialized_literal_count, 3417 materialized_literal_count,
3395 expected_property_count, 3418 expected_property_count,
3396 only_simple_this_property_assignments, 3419 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())); 4841 Handle<String> source = Handle<String>(String::cast(script->source()));
4819 result = parser.ParseProgram(source, info->is_global()); 4842 result = parser.ParseProgram(source, info->is_global());
4820 } 4843 }
4821 } 4844 }
4822 4845
4823 info->SetFunction(result); 4846 info->SetFunction(result);
4824 return (result != NULL); 4847 return (result != NULL);
4825 } 4848 }
4826 4849
4827 } } // namespace v8::internal 4850 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/scanner-base.h » ('j') | src/scanner-base.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698