OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 4050 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4061 // FunctionState indicates that this function is a generator. | 4061 // FunctionState indicates that this function is a generator. |
4062 Variable* temp = top_scope_->DeclarationScope()->NewTemporary( | 4062 Variable* temp = top_scope_->DeclarationScope()->NewTemporary( |
4063 isolate()->factory()->dot_generator_object_string()); | 4063 isolate()->factory()->dot_generator_object_string()); |
4064 function_state.set_generator_object_variable(temp); | 4064 function_state.set_generator_object_variable(temp); |
4065 } | 4065 } |
4066 | 4066 |
4067 // FormalParameterList :: | 4067 // FormalParameterList :: |
4068 // '(' (Identifier)*[','] ')' | 4068 // '(' (Identifier)*[','] ')' |
4069 Expect(Token::LPAREN, CHECK_OK); | 4069 Expect(Token::LPAREN, CHECK_OK); |
4070 scope->set_start_position(scanner().location().beg_pos); | 4070 scope->set_start_position(scanner().location().beg_pos); |
4071 Scanner::Location name_loc = Scanner::Location::invalid(); | 4071 |
4072 Scanner::Location dupe_loc = Scanner::Location::invalid(); | 4072 // We don't yet know if the function will be strict, so we cannot yet |
| 4073 // produce errors for parameter names or duplicates. However, we remember |
| 4074 // the locations of these errors if they occur and produce the errors later. |
| 4075 Scanner::Location eval_args_error_log = Scanner::Location::invalid(); |
| 4076 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); |
4073 Scanner::Location reserved_loc = Scanner::Location::invalid(); | 4077 Scanner::Location reserved_loc = Scanner::Location::invalid(); |
4074 | 4078 |
4075 bool done = (peek() == Token::RPAREN); | 4079 bool done = (peek() == Token::RPAREN); |
4076 while (!done) { | 4080 while (!done) { |
4077 bool is_strict_reserved = false; | 4081 bool is_strict_reserved = false; |
4078 Handle<String> param_name = | 4082 Handle<String> param_name = |
4079 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | 4083 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
4080 | 4084 |
4081 // Store locations for possible future error reports. | 4085 // Store locations for possible future error reports. |
4082 if (!name_loc.IsValid() && IsEvalOrArguments(param_name)) { | 4086 if (!eval_args_error_log.IsValid() && IsEvalOrArguments(param_name)) { |
4083 name_loc = scanner().location(); | 4087 eval_args_error_log = scanner().location(); |
4084 } | |
4085 if (!dupe_loc.IsValid() && top_scope_->IsDeclared(param_name)) { | |
4086 duplicate_parameters = FunctionLiteral::kHasDuplicateParameters; | |
4087 dupe_loc = scanner().location(); | |
4088 } | 4088 } |
4089 if (!reserved_loc.IsValid() && is_strict_reserved) { | 4089 if (!reserved_loc.IsValid() && is_strict_reserved) { |
4090 reserved_loc = scanner().location(); | 4090 reserved_loc = scanner().location(); |
4091 } | 4091 } |
| 4092 if (!dupe_error_loc.IsValid() && top_scope_->IsDeclared(param_name)) { |
| 4093 duplicate_parameters = FunctionLiteral::kHasDuplicateParameters; |
| 4094 dupe_error_loc = scanner().location(); |
| 4095 } |
4092 | 4096 |
4093 top_scope_->DeclareParameter(param_name, VAR); | 4097 top_scope_->DeclareParameter(param_name, VAR); |
4094 num_parameters++; | 4098 num_parameters++; |
4095 if (num_parameters > Code::kMaxArguments) { | 4099 if (num_parameters > Code::kMaxArguments) { |
4096 ReportMessageAt(scanner().location(), "too_many_parameters", | 4100 ReportMessageAt(scanner().location(), "too_many_parameters", |
4097 Vector<const char*>::empty()); | 4101 Vector<const char*>::empty()); |
4098 *ok = false; | 4102 *ok = false; |
4099 return NULL; | 4103 return NULL; |
4100 } | 4104 } |
4101 done = (peek() == Token::RPAREN); | 4105 done = (peek() == Token::RPAREN); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4249 } | 4253 } |
4250 | 4254 |
4251 materialized_literal_count = function_state.materialized_literal_count(); | 4255 materialized_literal_count = function_state.materialized_literal_count(); |
4252 expected_property_count = function_state.expected_property_count(); | 4256 expected_property_count = function_state.expected_property_count(); |
4253 handler_count = function_state.handler_count(); | 4257 handler_count = function_state.handler_count(); |
4254 | 4258 |
4255 Expect(Token::RBRACE, CHECK_OK); | 4259 Expect(Token::RBRACE, CHECK_OK); |
4256 scope->set_end_position(scanner().location().end_pos); | 4260 scope->set_end_position(scanner().location().end_pos); |
4257 } | 4261 } |
4258 | 4262 |
4259 // Validate strict mode. | 4263 // Validate strict mode. We can do this only after parsing the function, |
| 4264 // since the function can declare itself strict. |
4260 if (!top_scope_->is_classic_mode()) { | 4265 if (!top_scope_->is_classic_mode()) { |
4261 if (IsEvalOrArguments(function_name)) { | 4266 if (IsEvalOrArguments(function_name)) { |
4262 ReportMessageAt(function_name_location, | 4267 ReportMessageAt(function_name_location, |
4263 "strict_eval_arguments", | 4268 "strict_eval_arguments", |
4264 Vector<const char*>::empty()); | 4269 Vector<const char*>::empty()); |
4265 *ok = false; | 4270 *ok = false; |
4266 return NULL; | 4271 return NULL; |
4267 } | 4272 } |
4268 if (name_is_strict_reserved) { | 4273 if (name_is_strict_reserved) { |
4269 ReportMessageAt(function_name_location, "unexpected_strict_reserved", | 4274 ReportMessageAt(function_name_location, "unexpected_strict_reserved", |
4270 Vector<const char*>::empty()); | 4275 Vector<const char*>::empty()); |
4271 *ok = false; | 4276 *ok = false; |
4272 return NULL; | 4277 return NULL; |
4273 } | 4278 } |
4274 if (name_loc.IsValid()) { | 4279 if (eval_args_error_log.IsValid()) { |
4275 ReportMessageAt(name_loc, "strict_eval_arguments", | 4280 ReportMessageAt(eval_args_error_log, "strict_eval_arguments", |
4276 Vector<const char*>::empty()); | 4281 Vector<const char*>::empty()); |
4277 *ok = false; | 4282 *ok = false; |
4278 return NULL; | 4283 return NULL; |
4279 } | 4284 } |
4280 if (dupe_loc.IsValid()) { | 4285 if (dupe_error_loc.IsValid()) { |
4281 ReportMessageAt(dupe_loc, "strict_param_dupe", | 4286 ReportMessageAt(dupe_error_loc, "strict_param_dupe", |
4282 Vector<const char*>::empty()); | 4287 Vector<const char*>::empty()); |
4283 *ok = false; | 4288 *ok = false; |
4284 return NULL; | 4289 return NULL; |
4285 } | 4290 } |
4286 if (reserved_loc.IsValid()) { | 4291 if (reserved_loc.IsValid()) { |
4287 ReportMessageAt(reserved_loc, "unexpected_strict_reserved", | 4292 ReportMessageAt(reserved_loc, "unexpected_strict_reserved", |
4288 Vector<const char*>::empty()); | 4293 Vector<const char*>::empty()); |
4289 *ok = false; | 4294 *ok = false; |
4290 return NULL; | 4295 return NULL; |
4291 } | 4296 } |
(...skipping 1397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5689 ASSERT(info()->isolate()->has_pending_exception()); | 5694 ASSERT(info()->isolate()->has_pending_exception()); |
5690 } else { | 5695 } else { |
5691 result = ParseProgram(); | 5696 result = ParseProgram(); |
5692 } | 5697 } |
5693 } | 5698 } |
5694 info()->SetFunction(result); | 5699 info()->SetFunction(result); |
5695 return (result != NULL); | 5700 return (result != NULL); |
5696 } | 5701 } |
5697 | 5702 |
5698 } } // namespace v8::internal | 5703 } } // namespace v8::internal |
OLD | NEW |