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 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 scope != NULL; | 445 scope != NULL; |
446 scope = scope->outer_scope()) { | 446 scope = scope->outer_scope()) { |
447 Variable* var = scope->LookupLocal(name); | 447 Variable* var = scope->LookupLocal(name); |
448 if (var != NULL) return var; | 448 if (var != NULL) return var; |
449 } | 449 } |
450 return NULL; | 450 return NULL; |
451 } | 451 } |
452 | 452 |
453 | 453 |
454 Variable* Scope::DeclareParameter(const AstRawString* name, VariableMode mode, | 454 Variable* Scope::DeclareParameter(const AstRawString* name, VariableMode mode, |
455 bool is_rest) { | 455 bool is_rest, bool* is_duplicate) { |
456 DCHECK(!already_resolved()); | 456 DCHECK(!already_resolved()); |
457 DCHECK(is_function_scope()); | 457 DCHECK(is_function_scope()); |
458 Variable* var = variables_.Declare(this, name, mode, Variable::NORMAL, | 458 Variable* var = variables_.Declare(this, name, mode, Variable::NORMAL, |
459 kCreatedInitialized); | 459 kCreatedInitialized); |
460 if (is_rest) { | 460 if (is_rest) { |
461 DCHECK_NULL(rest_parameter_); | 461 DCHECK_NULL(rest_parameter_); |
462 rest_parameter_ = var; | 462 rest_parameter_ = var; |
463 rest_index_ = num_parameters(); | 463 rest_index_ = num_parameters(); |
464 } | 464 } |
| 465 // TODO(wingo): Avoid O(n^2) check. |
| 466 *is_duplicate = IsDeclaredParameter(name); |
465 params_.Add(var, zone()); | 467 params_.Add(var, zone()); |
466 return var; | 468 return var; |
467 } | 469 } |
468 | 470 |
469 | 471 |
470 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode, | 472 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode, |
471 InitializationFlag init_flag, Variable::Kind kind, | 473 InitializationFlag init_flag, Variable::Kind kind, |
472 MaybeAssignedFlag maybe_assigned_flag) { | 474 MaybeAssignedFlag maybe_assigned_flag) { |
473 DCHECK(!already_resolved()); | 475 DCHECK(!already_resolved()); |
474 // This function handles VAR, LET, and CONST modes. DYNAMIC variables are | 476 // This function handles VAR, LET, and CONST modes. DYNAMIC variables are |
(...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1488 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); | 1490 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); |
1489 } | 1491 } |
1490 | 1492 |
1491 | 1493 |
1492 int Scope::ContextLocalCount() const { | 1494 int Scope::ContextLocalCount() const { |
1493 if (num_heap_slots() == 0) return 0; | 1495 if (num_heap_slots() == 0) return 0; |
1494 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1496 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
1495 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); | 1497 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); |
1496 } | 1498 } |
1497 } } // namespace v8::internal | 1499 } } // namespace v8::internal |
OLD | NEW |