Index: src/scopes.cc |
diff --git a/src/scopes.cc b/src/scopes.cc |
index 0f84126e26365dbf08f463c15fb8d6bef48733eb..cfdaa87821450abac42e1a32eae5a03ef4c2f460 100644 |
--- a/src/scopes.cc |
+++ b/src/scopes.cc |
@@ -83,16 +83,23 @@ VariableMap::VariableMap() : HashMap(Match, &LocalsMapAllocator, 8) {} |
VariableMap::~VariableMap() {} |
-Variable* VariableMap::Declare(Scope* scope, |
- Handle<String> name, |
- VariableMode mode, |
- bool is_valid_lhs, |
- Variable::Kind kind) { |
+Variable* VariableMap::Declare( |
+ Scope* scope, |
+ Handle<String> name, |
+ VariableMode mode, |
+ bool is_valid_lhs, |
+ Variable::Kind kind, |
+ InitializationFlag initialization_flag) { |
HashMap::Entry* p = HashMap::Lookup(name.location(), name->Hash(), true); |
if (p->value == NULL) { |
// The variable has not been declared yet -> insert it. |
ASSERT(p->key == name.location()); |
- p->value = new Variable(scope, name, mode, is_valid_lhs, kind); |
+ p->value = new Variable(scope, |
+ name, |
+ mode, |
+ is_valid_lhs, |
+ kind, |
+ initialization_flag); |
} |
return reinterpret_cast<Variable*>(p->value); |
} |
@@ -180,7 +187,8 @@ Scope::Scope(Scope* inner_scope, Handle<String> catch_variable_name) |
catch_variable_name, |
VAR, |
true, // Valid left-hand side. |
- Variable::NORMAL); |
+ Variable::NORMAL, |
+ CREATED_INITIALIZED); |
AllocateHeapSlot(variable); |
} |
@@ -308,7 +316,8 @@ void Scope::Initialize() { |
isolate_->factory()->this_symbol(), |
VAR, |
false, |
- Variable::THIS); |
+ Variable::THIS, |
+ CREATED_INITIALIZED); |
var->AllocateTo(Variable::PARAMETER, -1); |
receiver_ = var; |
} else { |
@@ -324,7 +333,8 @@ void Scope::Initialize() { |
isolate_->factory()->arguments_symbol(), |
VAR, |
true, |
- Variable::ARGUMENTS); |
+ Variable::ARGUMENTS, |
+ CREATED_INITIALIZED); |
} |
} |
@@ -373,20 +383,27 @@ Variable* Scope::LocalLookup(Handle<String> name) { |
// Check context slot lookup. |
VariableMode mode; |
- int index = scope_info_->ContextSlotIndex(*name, &mode); |
+ InitializationFlag init_flag; |
+ int index = scope_info_->ContextSlotIndex(*name, &mode, &init_flag); |
if (index < 0) { |
// Check parameters. |
mode = VAR; |
+ init_flag = CREATED_INITIALIZED; |
index = scope_info_->ParameterIndex(*name); |
if (index < 0) { |
// Check the function name. |
- index = scope_info_->FunctionContextSlotIndex(*name, NULL); |
+ index = scope_info_->FunctionContextSlotIndex(*name, &mode); |
if (index < 0) return NULL; |
} |
} |
Variable* var = |
- variables_.Declare(this, name, mode, true, Variable::NORMAL); |
+ variables_.Declare(this, |
+ name, |
+ mode, |
+ true, |
+ Variable::NORMAL, |
+ init_flag); |
var->AllocateTo(Variable::CONTEXT, index); |
return var; |
} |
@@ -405,8 +422,8 @@ Variable* Scope::Lookup(Handle<String> name) { |
Variable* Scope::DeclareFunctionVar(Handle<String> name, VariableMode mode) { |
ASSERT(is_function_scope() && function_ == NULL); |
- Variable* function_var = |
- new Variable(this, name, mode, true, Variable::NORMAL); |
+ Variable* function_var = new Variable( |
+ this, name, mode, true, Variable::NORMAL, CREATED_INITIALIZED); |
function_ = new(isolate_->zone()) VariableProxy(isolate_, function_var); |
return function_var; |
} |
@@ -415,13 +432,15 @@ Variable* Scope::DeclareFunctionVar(Handle<String> name, VariableMode mode) { |
void Scope::DeclareParameter(Handle<String> name, VariableMode mode) { |
ASSERT(!already_resolved()); |
ASSERT(is_function_scope()); |
- Variable* var = |
- variables_.Declare(this, name, mode, true, Variable::NORMAL); |
+ Variable* var = variables_.Declare( |
+ this, name, mode, true, Variable::NORMAL, CREATED_INITIALIZED); |
params_.Add(var); |
} |
-Variable* Scope::DeclareLocal(Handle<String> name, VariableMode mode) { |
+Variable* Scope::DeclareLocal(Handle<String> name, |
+ VariableMode mode, |
+ InitializationFlag init_flag) { |
ASSERT(!already_resolved()); |
// This function handles VAR and CONST modes. DYNAMIC variables are |
// introduces during variable allocation, INTERNAL variables are allocated |
@@ -431,15 +450,19 @@ Variable* Scope::DeclareLocal(Handle<String> name, VariableMode mode) { |
mode == CONST_HARMONY || |
mode == LET); |
++num_var_or_const_; |
- return variables_.Declare(this, name, mode, true, Variable::NORMAL); |
+ return |
+ variables_.Declare(this, name, mode, true, Variable::NORMAL, init_flag); |
} |
Variable* Scope::DeclareGlobal(Handle<String> name) { |
ASSERT(is_global_scope()); |
- return variables_.Declare(this, name, DYNAMIC_GLOBAL, |
+ return variables_.Declare(this, |
+ name, |
+ DYNAMIC_GLOBAL, |
true, |
- Variable::NORMAL); |
+ Variable::NORMAL, |
+ CREATED_INITIALIZED); |
} |
@@ -473,7 +496,8 @@ Variable* Scope::NewTemporary(Handle<String> name) { |
name, |
TEMPORARY, |
true, |
- Variable::NORMAL); |
+ Variable::NORMAL, |
+ CREATED_INITIALIZED); |
temps_.Add(var); |
return var; |
} |
@@ -812,7 +836,14 @@ Variable* Scope::NonLocal(Handle<String> name, VariableMode mode) { |
Variable* var = map->Lookup(name); |
if (var == NULL) { |
// Declare a new non-local. |
- var = map->Declare(NULL, name, mode, true, Variable::NORMAL); |
+ InitializationFlag init_flag = (mode == VAR) |
+ ? CREATED_INITIALIZED : NEEDS_INITIALIZATION; |
+ var = map->Declare(NULL, |
+ name, |
+ mode, |
+ true, |
+ Variable::NORMAL, |
+ init_flag); |
// Allocate it by giving it a dynamic lookup. |
var->AllocateTo(Variable::LOOKUP, -1); |
} |