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

Side by Side Diff: src/parser.cc

Issue 899363002: Allow eval and arguments as property names (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Cleanup based on code review Created 5 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
« no previous file with comments | « no previous file | src/preparser.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/bailout-reason.h" 9 #include "src/bailout-reason.h"
10 #include "src/base/platform/platform.h" 10 #include "src/base/platform/platform.h"
(...skipping 3679 matching lines...) Expand 10 before | Expand all | Expand 10 after
3690 } 3690 }
3691 3691
3692 // FormalParameterList :: 3692 // FormalParameterList ::
3693 // '(' (Identifier)*[','] ')' 3693 // '(' (Identifier)*[','] ')'
3694 Expect(Token::LPAREN, CHECK_OK); 3694 Expect(Token::LPAREN, CHECK_OK);
3695 scope->set_start_position(scanner()->location().beg_pos); 3695 scope->set_start_position(scanner()->location().beg_pos);
3696 3696
3697 // We don't yet know if the function will be strict, so we cannot yet 3697 // We don't yet know if the function will be strict, so we cannot yet
3698 // produce errors for parameter names or duplicates. However, we remember 3698 // produce errors for parameter names or duplicates. However, we remember
3699 // the locations of these errors if they occur and produce the errors later. 3699 // the locations of these errors if they occur and produce the errors later.
3700 Scanner::Location eval_args_error_log = Scanner::Location::invalid(); 3700 Scanner::Location eval_args_error_loc = Scanner::Location::invalid();
3701 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); 3701 Scanner::Location dupe_error_loc = Scanner::Location::invalid();
3702 Scanner::Location reserved_loc = Scanner::Location::invalid(); 3702 Scanner::Location reserved_error_loc = Scanner::Location::invalid();
3703 3703
3704 bool is_rest = false; 3704 bool is_rest = false;
3705 bool done = arity_restriction == FunctionLiteral::GETTER_ARITY || 3705 bool done = arity_restriction == FunctionLiteral::GETTER_ARITY ||
3706 (peek() == Token::RPAREN && 3706 (peek() == Token::RPAREN &&
3707 arity_restriction != FunctionLiteral::SETTER_ARITY); 3707 arity_restriction != FunctionLiteral::SETTER_ARITY);
3708 while (!done) { 3708 while (!done) {
3709 bool is_strict_reserved = false; 3709 bool is_strict_reserved = false;
3710 is_rest = peek() == Token::ELLIPSIS && allow_harmony_rest_params(); 3710 is_rest = peek() == Token::ELLIPSIS && allow_harmony_rest_params();
3711 if (is_rest) { 3711 if (is_rest) {
3712 Consume(Token::ELLIPSIS); 3712 Consume(Token::ELLIPSIS);
3713 } 3713 }
3714 3714
3715 const AstRawString* param_name = 3715 const AstRawString* param_name =
3716 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); 3716 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
3717 3717
3718 // Store locations for possible future error reports. 3718 // Store locations for possible future error reports.
3719 if (!eval_args_error_log.IsValid() && IsEvalOrArguments(param_name)) { 3719 if (!eval_args_error_loc.IsValid() && IsEvalOrArguments(param_name)) {
3720 eval_args_error_log = scanner()->location(); 3720 eval_args_error_loc = scanner()->location();
3721 } 3721 }
3722 if (!reserved_loc.IsValid() && is_strict_reserved) { 3722 if (!reserved_error_loc.IsValid() && is_strict_reserved) {
3723 reserved_loc = scanner()->location(); 3723 reserved_error_loc = scanner()->location();
3724 } 3724 }
3725 if (!dupe_error_loc.IsValid() && scope_->IsDeclared(param_name)) { 3725 if (!dupe_error_loc.IsValid() && scope_->IsDeclared(param_name)) {
3726 duplicate_parameters = FunctionLiteral::kHasDuplicateParameters; 3726 duplicate_parameters = FunctionLiteral::kHasDuplicateParameters;
3727 dupe_error_loc = scanner()->location(); 3727 dupe_error_loc = scanner()->location();
3728 } 3728 }
3729 3729
3730 Variable* var = scope_->DeclareParameter(param_name, VAR, is_rest); 3730 Variable* var = scope_->DeclareParameter(param_name, VAR, is_rest);
3731 if (is_sloppy(scope->language_mode())) { 3731 if (is_sloppy(scope->language_mode())) {
3732 // TODO(sigurds) Mark every parameter as maybe assigned. This is a 3732 // TODO(sigurds) Mark every parameter as maybe assigned. This is a
3733 // conservative approximation necessary to account for parameters 3733 // conservative approximation necessary to account for parameters
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
3824 SkipLazyFunctionBody(function_name, &materialized_literal_count, 3824 SkipLazyFunctionBody(function_name, &materialized_literal_count,
3825 &expected_property_count, CHECK_OK); 3825 &expected_property_count, CHECK_OK);
3826 } else { 3826 } else {
3827 body = ParseEagerFunctionBody(function_name, pos, fvar, fvar_init_op, 3827 body = ParseEagerFunctionBody(function_name, pos, fvar, fvar_init_op,
3828 is_generator, CHECK_OK); 3828 is_generator, CHECK_OK);
3829 materialized_literal_count = function_state.materialized_literal_count(); 3829 materialized_literal_count = function_state.materialized_literal_count();
3830 expected_property_count = function_state.expected_property_count(); 3830 expected_property_count = function_state.expected_property_count();
3831 handler_count = function_state.handler_count(); 3831 handler_count = function_state.handler_count();
3832 } 3832 }
3833 3833
3834 // Validate strict mode. 3834 // Validate name and parameter names. We can do this only after parsing the
3835 // Concise methods use StrictFormalParameters. 3835 // function, since the function can declare itself strict.
3836 // Functions for which IsSimpleParameterList() returns false use 3836 CheckFunctionName(language_mode(), kind, function_name,
3837 // StrictFormalParameters. 3837 name_is_strict_reserved, function_name_location,
3838 if (is_strict(language_mode()) || IsConciseMethod(kind) || is_rest) { 3838 CHECK_OK);
3839 CheckStrictFunctionNameAndParameters(function_name, 3839 const bool use_strict_params = is_rest || IsConciseMethod(kind);
3840 name_is_strict_reserved, 3840 CheckFunctionParameterNames(language_mode(), use_strict_params,
3841 function_name_location, 3841 eval_args_error_loc, dupe_error_loc,
3842 eval_args_error_log, 3842 reserved_error_loc, CHECK_OK);
3843 dupe_error_loc, 3843
3844 reserved_loc,
3845 CHECK_OK);
3846 }
3847 if (is_strict(language_mode())) { 3844 if (is_strict(language_mode())) {
3848 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), 3845 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(),
3849 CHECK_OK); 3846 CHECK_OK);
3850 } 3847 }
3851 if (allow_harmony_scoping() && is_strict(language_mode())) { 3848 if (allow_harmony_scoping() && is_strict(language_mode())) {
3852 CheckConflictingVarDeclarations(scope, CHECK_OK); 3849 CheckConflictingVarDeclarations(scope, CHECK_OK);
3853 } 3850 }
3854 } 3851 }
3855 3852
3856 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( 3853 FunctionLiteral* function_literal = factory()->NewFunctionLiteral(
(...skipping 1572 matching lines...) Expand 10 before | Expand all | Expand 10 after
5429 } else { 5426 } else {
5430 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); 5427 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data());
5431 running_hash = StringHasher::ComputeRunningHash(running_hash, data, 5428 running_hash = StringHasher::ComputeRunningHash(running_hash, data,
5432 raw_string->length()); 5429 raw_string->length());
5433 } 5430 }
5434 } 5431 }
5435 5432
5436 return running_hash; 5433 return running_hash;
5437 } 5434 }
5438 } } // namespace v8::internal 5435 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698