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

Side by Side Diff: src/parser.cc

Issue 6349020: Make arguments read only in strict mode. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 10 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 | « src/objects-inl.h ('k') | 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 729 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 740
741 { 741 {
742 // Parse the function literal. 742 // Parse the function literal.
743 Handle<String> no_name = Factory::empty_symbol(); 743 Handle<String> no_name = Factory::empty_symbol();
744 Scope* scope = 744 Scope* scope =
745 NewScope(top_scope_, Scope::GLOBAL_SCOPE, inside_with()); 745 NewScope(top_scope_, Scope::GLOBAL_SCOPE, inside_with());
746 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_, 746 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_,
747 scope); 747 scope);
748 TemporaryScope temp_scope(&this->temp_scope_); 748 TemporaryScope temp_scope(&this->temp_scope_);
749 749
750 if (info->strict_mode()) {
751 temp_scope.EnableStrictMode();
752 }
753
750 FunctionLiteralType type = 754 FunctionLiteralType type =
751 info->is_expression() ? EXPRESSION : DECLARATION; 755 info->is_expression() ? EXPRESSION : DECLARATION;
752 bool ok = true; 756 bool ok = true;
753 result = ParseFunctionLiteral(name, RelocInfo::kNoPosition, type, &ok); 757 result = ParseFunctionLiteral(name, RelocInfo::kNoPosition, type, &ok);
754 // Make sure the results agree. 758 // Make sure the results agree.
755 ASSERT(ok == (result != NULL)); 759 ASSERT(ok == (result != NULL));
756 // The only errors should be stack overflows. 760 // The only errors should be stack overflows.
757 ASSERT(ok || stack_overflow_); 761 ASSERT(ok || stack_overflow_);
758 } 762 }
759 763
(...skipping 2773 matching lines...) Expand 10 before | Expand all | Expand 10 after
3533 materialized_literal_count = temp_scope.materialized_literal_count(); 3537 materialized_literal_count = temp_scope.materialized_literal_count();
3534 expected_property_count = temp_scope.expected_property_count(); 3538 expected_property_count = temp_scope.expected_property_count();
3535 only_simple_this_property_assignments = 3539 only_simple_this_property_assignments =
3536 temp_scope.only_simple_this_property_assignments(); 3540 temp_scope.only_simple_this_property_assignments();
3537 this_property_assignments = temp_scope.this_property_assignments(); 3541 this_property_assignments = temp_scope.this_property_assignments();
3538 3542
3539 Expect(Token::RBRACE, CHECK_OK); 3543 Expect(Token::RBRACE, CHECK_OK);
3540 end_pos = scanner().location().end_pos; 3544 end_pos = scanner().location().end_pos;
3541 } 3545 }
3542 3546
3543 // Validate strict mode. 3547 // Strict mode.
3544 if (temp_scope_->StrictMode()) { 3548 if (temp_scope_->StrictMode()) {
3545 if (IsEvalOrArguments(name)) { 3549 if (IsEvalOrArguments(name)) {
3546 int position = function_token_position != RelocInfo::kNoPosition 3550 int position = function_token_position != RelocInfo::kNoPosition
3547 ? function_token_position 3551 ? function_token_position
3548 : (start_pos > 0 ? start_pos - 1 : start_pos); 3552 : (start_pos > 0 ? start_pos - 1 : start_pos);
3549 ReportMessageAt(Scanner::Location(position, start_pos), 3553 ReportMessageAt(Scanner::Location(position, start_pos),
3550 "strict_function_name", Vector<const char*>::empty()); 3554 "strict_function_name", Vector<const char*>::empty());
3551 *ok = false; 3555 *ok = false;
3552 return NULL; 3556 return NULL;
3553 } 3557 }
3554 if (name_loc.IsValid()) { 3558 if (name_loc.IsValid()) {
3555 ReportMessageAt(name_loc, "strict_param_name", 3559 ReportMessageAt(name_loc, "strict_param_name",
3556 Vector<const char*>::empty()); 3560 Vector<const char*>::empty());
3557 *ok = false; 3561 *ok = false;
3558 return NULL; 3562 return NULL;
3559 } 3563 }
3560 if (dupe_loc.IsValid()) { 3564 if (dupe_loc.IsValid()) {
3561 ReportMessageAt(dupe_loc, "strict_param_dupe", 3565 ReportMessageAt(dupe_loc, "strict_param_dupe",
3562 Vector<const char*>::empty()); 3566 Vector<const char*>::empty());
3563 *ok = false; 3567 *ok = false;
3564 return NULL; 3568 return NULL;
3565 } 3569 }
3566 CheckOctalLiteral(start_pos, end_pos, CHECK_OK); 3570 CheckOctalLiteral(start_pos, end_pos, CHECK_OK);
3571
3572 // In strict mode, arguments are const.
3573 top_scope_->SetArgumentsConst();
3567 } 3574 }
3568 3575
3569 FunctionLiteral* function_literal = 3576 FunctionLiteral* function_literal =
3570 new FunctionLiteral(name, 3577 new FunctionLiteral(name,
3571 top_scope_, 3578 top_scope_,
3572 body, 3579 body,
3573 materialized_literal_count, 3580 materialized_literal_count,
3574 expected_property_count, 3581 expected_property_count,
3575 only_simple_this_property_assignments, 3582 only_simple_this_property_assignments,
3576 this_property_assignments, 3583 this_property_assignments,
(...skipping 1450 matching lines...) Expand 10 before | Expand all | Expand 10 after
5027 Handle<String> source = Handle<String>(String::cast(script->source())); 5034 Handle<String> source = Handle<String>(String::cast(script->source()));
5028 result = parser.ParseProgram(source, info->is_global()); 5035 result = parser.ParseProgram(source, info->is_global());
5029 } 5036 }
5030 } 5037 }
5031 5038
5032 info->SetFunction(result); 5039 info->SetFunction(result);
5033 return (result != NULL); 5040 return (result != NULL);
5034 } 5041 }
5035 5042
5036 } } // namespace v8::internal 5043 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | src/scopes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698