Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 } | 376 } |
| 377 | 377 |
| 378 | 378 |
| 379 Variable* Scope::DeclareFunctionVar(Handle<String> name) { | 379 Variable* Scope::DeclareFunctionVar(Handle<String> name) { |
| 380 ASSERT(is_function_scope() && function_ == NULL); | 380 ASSERT(is_function_scope() && function_ == NULL); |
| 381 function_ = new Variable(this, name, Variable::CONST, true, Variable::NORMAL); | 381 function_ = new Variable(this, name, Variable::CONST, true, Variable::NORMAL); |
| 382 return function_; | 382 return function_; |
| 383 } | 383 } |
| 384 | 384 |
| 385 | 385 |
| 386 void Scope::DeclareParameter(Handle<String> name) { | 386 void Scope::DeclareParameter(Handle<String> name, Variable::Mode mode) { |
| 387 ASSERT(!already_resolved()); | 387 ASSERT(!already_resolved()); |
| 388 ASSERT(is_function_scope()); | 388 ASSERT(is_function_scope()); |
| 389 Variable* var = | 389 Variable* var = |
| 390 variables_.Declare(this, name, Variable::VAR, true, Variable::NORMAL); | 390 variables_.Declare(this, name, mode, true, Variable::NORMAL); |
| 391 params_.Add(var); | 391 params_.Add(var); |
| 392 } | 392 } |
| 393 | 393 |
| 394 | 394 |
| 395 Variable* Scope::DeclareLocal(Handle<String> name, Variable::Mode mode) { | 395 Variable* Scope::DeclareLocal(Handle<String> name, Variable::Mode mode) { |
| 396 ASSERT(!already_resolved()); | 396 ASSERT(!already_resolved()); |
| 397 // This function handles VAR and CONST modes. DYNAMIC variables are | 397 // This function handles VAR and CONST modes. DYNAMIC variables are |
| 398 // introduces during variable allocation, INTERNAL variables are allocated | 398 // introduces during variable allocation, INTERNAL variables are allocated |
| 399 // explicitly, and TEMPORARY variables are allocated via NewTemporary(). | 399 // explicitly, and TEMPORARY variables are allocated via NewTemporary(). |
| 400 ASSERT(mode == Variable::VAR || | 400 ASSERT(mode == Variable::VAR || |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 460 ASSERT(HasIllegalRedeclaration()); | 460 ASSERT(HasIllegalRedeclaration()); |
| 461 } | 461 } |
| 462 | 462 |
| 463 | 463 |
| 464 void Scope::VisitIllegalRedeclaration(AstVisitor* visitor) { | 464 void Scope::VisitIllegalRedeclaration(AstVisitor* visitor) { |
| 465 ASSERT(HasIllegalRedeclaration()); | 465 ASSERT(HasIllegalRedeclaration()); |
| 466 illegal_redecl_->Accept(visitor); | 466 illegal_redecl_->Accept(visitor); |
| 467 } | 467 } |
| 468 | 468 |
| 469 | 469 |
| 470 Declaration* Scope::CheckConflictingVarDeclarations() { | |
| 471 int length = decls_.length(); | |
| 472 for (int i = 0; i < length; i++) { | |
| 473 Declaration* decl = decls_[i]; | |
| 474 if (decl->mode() != Variable::VAR) continue; | |
| 475 Handle<String> name = decl->proxy()->name(); | |
| 476 for (Scope* scope = decl->scope(); | |
| 477 scope->is_block_scope() || scope->is_catch_scope(); | |
| 478 scope = scope->outer_scope_) { | |
| 479 Variable* other_var = scope->variables_.Lookup(name); | |
|
Lasse Reichstein
2011/09/01 07:34:04
This should be able to skip the first scope, where
Steven
2011/09/01 15:01:33
When by first scope you mean the innermost scope w
| |
| 480 if (other_var != NULL && other_var->mode() == Variable::LET) { | |
|
Lasse Reichstein
2011/09/01 07:34:04
Is it only LET declarations that can conflict, or
Steven
2011/09/01 15:01:33
Yes any non-VAR. Will fix it.
On 2011/09/01 07:34:
| |
| 481 return decl; | |
| 482 } | |
| 483 } | |
| 484 } | |
| 485 return NULL; | |
| 486 } | |
| 487 | |
| 488 | |
| 470 template<class Allocator> | 489 template<class Allocator> |
| 471 void Scope::CollectUsedVariables(List<Variable*, Allocator>* locals) { | 490 void Scope::CollectUsedVariables(List<Variable*, Allocator>* locals) { |
| 472 // Collect variables in this scope. | 491 // Collect variables in this scope. |
| 473 // Note that the function_ variable - if present - is not | 492 // Note that the function_ variable - if present - is not |
| 474 // collected here but handled separately in ScopeInfo | 493 // collected here but handled separately in ScopeInfo |
| 475 // which is the current user of this function). | 494 // which is the current user of this function). |
| 476 for (int i = 0; i < temps_.length(); i++) { | 495 for (int i = 0; i < temps_.length(); i++) { |
| 477 Variable* var = temps_[i]; | 496 Variable* var = temps_[i]; |
| 478 if (var->is_used()) { | 497 if (var->is_used()) { |
| 479 locals->Add(var); | 498 locals->Add(var); |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1131 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && | 1150 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && |
| 1132 !must_have_local_context) { | 1151 !must_have_local_context) { |
| 1133 num_heap_slots_ = 0; | 1152 num_heap_slots_ = 0; |
| 1134 } | 1153 } |
| 1135 | 1154 |
| 1136 // Allocation done. | 1155 // Allocation done. |
| 1137 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); | 1156 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); |
| 1138 } | 1157 } |
| 1139 | 1158 |
| 1140 } } // namespace v8::internal | 1159 } } // namespace v8::internal |
| OLD | NEW |