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