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/v8.h" | 5 #include "src/v8.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 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 if (var != NULL) return var; | 459 if (var != NULL) return var; |
460 } | 460 } |
461 return NULL; | 461 return NULL; |
462 } | 462 } |
463 | 463 |
464 | 464 |
465 Variable* Scope::DeclareParameter(const AstRawString* name, VariableMode mode, | 465 Variable* Scope::DeclareParameter(const AstRawString* name, VariableMode mode, |
466 bool is_rest, bool* is_duplicate) { | 466 bool is_rest, bool* is_duplicate) { |
467 DCHECK(!already_resolved()); | 467 DCHECK(!already_resolved()); |
468 DCHECK(is_function_scope()); | 468 DCHECK(is_function_scope()); |
469 | 469 Variable* var = variables_.Declare(this, name, mode, Variable::NORMAL, |
470 Variable* var; | 470 kCreatedInitialized); |
471 if (!name->IsEmpty()) { | |
472 var = variables_.Declare(this, name, mode, Variable::NORMAL, | |
473 kCreatedInitialized); | |
474 // TODO(wingo): Avoid O(n^2) check. | |
475 *is_duplicate = IsDeclaredParameter(name); | |
476 } else { | |
477 var = new (zone()) | |
478 Variable(this, name, TEMPORARY, Variable::NORMAL, kCreatedInitialized); | |
479 } | |
480 if (is_rest) { | 471 if (is_rest) { |
481 DCHECK_NULL(rest_parameter_); | 472 DCHECK_NULL(rest_parameter_); |
482 rest_parameter_ = var; | 473 rest_parameter_ = var; |
483 rest_index_ = num_parameters(); | 474 rest_index_ = num_parameters(); |
484 } | 475 } |
| 476 // TODO(wingo): Avoid O(n^2) check. |
| 477 *is_duplicate = IsDeclaredParameter(name); |
485 params_.Add(var, zone()); | 478 params_.Add(var, zone()); |
486 return var; | 479 return var; |
487 } | 480 } |
488 | 481 |
489 | 482 |
490 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode, | 483 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode, |
491 InitializationFlag init_flag, Variable::Kind kind, | 484 InitializationFlag init_flag, Variable::Kind kind, |
492 MaybeAssignedFlag maybe_assigned_flag, | 485 MaybeAssignedFlag maybe_assigned_flag, |
493 int declaration_group_start) { | 486 int declaration_group_start) { |
494 DCHECK(!already_resolved()); | 487 DCHECK(!already_resolved()); |
(...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1574 } | 1567 } |
1575 | 1568 |
1576 | 1569 |
1577 int Scope::ContextLocalCount() const { | 1570 int Scope::ContextLocalCount() const { |
1578 if (num_heap_slots() == 0) return 0; | 1571 if (num_heap_slots() == 0) return 0; |
1579 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1572 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
1580 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); | 1573 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); |
1581 } | 1574 } |
1582 } // namespace internal | 1575 } // namespace internal |
1583 } // namespace v8 | 1576 } // namespace v8 |
OLD | NEW |