OLD | NEW |
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/scopes.h" | 5 #include "src/scopes.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" |
9 #include "src/messages.h" | 9 #include "src/messages.h" |
10 #include "src/parser.h" | 10 #include "src/parser.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 inner_scope_uses_arguments_ = false; | 173 inner_scope_uses_arguments_ = false; |
174 force_eager_compilation_ = false; | 174 force_eager_compilation_ = false; |
175 force_context_allocation_ = (outer_scope != NULL && !is_function_scope()) | 175 force_context_allocation_ = (outer_scope != NULL && !is_function_scope()) |
176 ? outer_scope->has_forced_context_allocation() : false; | 176 ? outer_scope->has_forced_context_allocation() : false; |
177 num_var_or_const_ = 0; | 177 num_var_or_const_ = 0; |
178 num_stack_slots_ = 0; | 178 num_stack_slots_ = 0; |
179 num_heap_slots_ = 0; | 179 num_heap_slots_ = 0; |
180 num_global_slots_ = 0; | 180 num_global_slots_ = 0; |
181 num_modules_ = 0; | 181 num_modules_ = 0; |
182 module_var_ = NULL; | 182 module_var_ = NULL; |
| 183 arity_ = 0; |
183 has_simple_parameters_ = true; | 184 has_simple_parameters_ = true; |
184 rest_parameter_ = NULL; | 185 rest_parameter_ = NULL; |
185 rest_index_ = -1; | 186 rest_index_ = -1; |
186 scope_info_ = scope_info; | 187 scope_info_ = scope_info; |
187 start_position_ = RelocInfo::kNoPosition; | 188 start_position_ = RelocInfo::kNoPosition; |
188 end_position_ = RelocInfo::kNoPosition; | 189 end_position_ = RelocInfo::kNoPosition; |
189 if (!scope_info.is_null()) { | 190 if (!scope_info.is_null()) { |
190 scope_calls_eval_ = scope_info->CallsEval(); | 191 scope_calls_eval_ = scope_info->CallsEval(); |
191 language_mode_ = scope_info->language_mode(); | 192 language_mode_ = scope_info->language_mode(); |
192 is_declaration_scope_ = scope_info->is_declaration_scope(); | 193 is_declaration_scope_ = scope_info->is_declaration_scope(); |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 for (Scope* scope = this; | 459 for (Scope* scope = this; |
459 scope != NULL; | 460 scope != NULL; |
460 scope = scope->outer_scope()) { | 461 scope = scope->outer_scope()) { |
461 Variable* var = scope->LookupLocal(name); | 462 Variable* var = scope->LookupLocal(name); |
462 if (var != NULL) return var; | 463 if (var != NULL) return var; |
463 } | 464 } |
464 return NULL; | 465 return NULL; |
465 } | 466 } |
466 | 467 |
467 | 468 |
468 Variable* Scope::DeclareParameter(const AstRawString* name, VariableMode mode, | 469 Variable* Scope::DeclareParameter( |
469 bool is_rest, bool* is_duplicate) { | 470 const AstRawString* name, VariableMode mode, |
| 471 bool is_optional, bool is_rest, bool* is_duplicate) { |
470 DCHECK(!already_resolved()); | 472 DCHECK(!already_resolved()); |
471 DCHECK(is_function_scope()); | 473 DCHECK(is_function_scope()); |
| 474 DCHECK(!is_optional || !is_rest); |
472 Variable* var; | 475 Variable* var; |
473 if (mode == TEMPORARY) { | 476 if (mode == TEMPORARY) { |
474 var = NewTemporary(name); | 477 var = NewTemporary(name); |
475 has_simple_parameters_ = false; | 478 has_simple_parameters_ = false; |
476 } else { | 479 } else { |
477 var = variables_.Declare(this, name, mode, Variable::NORMAL, | 480 var = variables_.Declare(this, name, mode, Variable::NORMAL, |
478 kCreatedInitialized); | 481 kCreatedInitialized); |
479 // TODO(wingo): Avoid O(n^2) check. | 482 // TODO(wingo): Avoid O(n^2) check. |
480 *is_duplicate = IsDeclaredParameter(name); | 483 *is_duplicate = IsDeclaredParameter(name); |
481 } | 484 } |
| 485 if (!is_optional && !is_rest && arity_ == params_.length()) { |
| 486 ++arity_; |
| 487 } |
482 if (is_rest) { | 488 if (is_rest) { |
483 DCHECK_NULL(rest_parameter_); | 489 DCHECK_NULL(rest_parameter_); |
484 rest_parameter_ = var; | 490 rest_parameter_ = var; |
485 rest_index_ = num_parameters(); | 491 rest_index_ = num_parameters(); |
486 has_simple_parameters_ = false; | 492 has_simple_parameters_ = false; |
487 } | 493 } |
488 params_.Add(var, zone()); | 494 params_.Add(var, zone()); |
489 return var; | 495 return var; |
490 } | 496 } |
491 | 497 |
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1616 function_ != NULL && function_->proxy()->var()->IsContextSlot(); | 1622 function_ != NULL && function_->proxy()->var()->IsContextSlot(); |
1617 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1623 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
1618 (is_function_var_in_context ? 1 : 0); | 1624 (is_function_var_in_context ? 1 : 0); |
1619 } | 1625 } |
1620 | 1626 |
1621 | 1627 |
1622 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1628 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
1623 | 1629 |
1624 } // namespace internal | 1630 } // namespace internal |
1625 } // namespace v8 | 1631 } // namespace v8 |
OLD | NEW |