Index: src/scopes.cc |
diff --git a/src/scopes.cc b/src/scopes.cc |
index 35449643cec2dce0742737c35b33e9b559b9ab0f..2f9f6f1721eb85dce81b519b848d5acd0d059150 100644 |
--- a/src/scopes.cc |
+++ b/src/scopes.cc |
@@ -31,8 +31,7 @@ VariableMap::~VariableMap() {} |
Variable* VariableMap::Declare(Scope* scope, const AstRawString* name, |
- VariableMode mode, bool is_valid_lhs, |
- Variable::Kind kind, |
+ VariableMode mode, Variable::Kind kind, |
InitializationFlag initialization_flag, |
MaybeAssignedFlag maybe_assigned_flag) { |
// AstRawStrings are unambiguous, i.e., the same string is always represented |
@@ -43,7 +42,7 @@ Variable* VariableMap::Declare(Scope* scope, const AstRawString* name, |
if (p->value == NULL) { |
// The variable has not been declared yet -> insert it. |
DCHECK(p->key == name); |
- p->value = new (zone()) Variable(scope, name, mode, is_valid_lhs, kind, |
+ p->value = new (zone()) Variable(scope, name, mode, kind, |
initialization_flag, maybe_assigned_flag); |
} |
return reinterpret_cast<Variable*>(p->value); |
@@ -131,7 +130,6 @@ Scope::Scope(Zone* zone, Scope* inner_scope, |
Variable* variable = variables_.Declare(this, |
catch_variable_name, |
VAR, |
- true, // Valid left-hand side. |
Variable::NORMAL, |
kCreatedInitialized); |
AllocateHeapSlot(variable); |
@@ -300,23 +298,21 @@ void Scope::Initialize(bool subclass_constructor) { |
// invoking scripts |
if (is_declaration_scope()) { |
DCHECK(!subclass_constructor || is_function_scope()); |
- Variable* var = variables_.Declare( |
- this, ast_value_factory_->this_string(), |
- subclass_constructor ? CONST : VAR, false, Variable::THIS, |
- subclass_constructor ? kNeedsInitialization : kCreatedInitialized); |
- var->AllocateTo(Variable::PARAMETER, -1); |
- receiver_ = var; |
+ if (has_this_declaration()) { |
+ Variable* var = variables_.Declare( |
+ this, ast_value_factory_->this_string(), |
+ subclass_constructor ? CONST : VAR, Variable::THIS, |
+ subclass_constructor ? kNeedsInitialization : kCreatedInitialized); |
+ receiver_ = var; |
+ } |
if (subclass_constructor) { |
- new_target_ = variables_.Declare( |
- this, ast_value_factory_->new_target_string(), CONST, false, |
- Variable::NEW_TARGET, kCreatedInitialized); |
+ new_target_ = |
+ variables_.Declare(this, ast_value_factory_->new_target_string(), |
+ CONST, Variable::NEW_TARGET, kCreatedInitialized); |
new_target_->AllocateTo(Variable::PARAMETER, -2); |
new_target_->set_is_used(); |
} |
- } else { |
- DCHECK(outer_scope() != NULL); |
- receiver_ = outer_scope()->receiver(); |
} |
if (is_function_scope()) { |
@@ -326,7 +322,6 @@ void Scope::Initialize(bool subclass_constructor) { |
variables_.Declare(this, |
ast_value_factory_->arguments_string(), |
VAR, |
- true, |
Variable::ARGUMENTS, |
kCreatedInitialized); |
} |
@@ -402,7 +397,7 @@ Variable* Scope::LookupLocal(const AstRawString* name) { |
maybe_assigned_flag = kMaybeAssigned; |
} |
- Variable* var = variables_.Declare(this, name, mode, true, Variable::NORMAL, |
+ Variable* var = variables_.Declare(this, name, mode, Variable::NORMAL, |
init_flag, maybe_assigned_flag); |
var->AllocateTo(location, index); |
return var; |
@@ -418,9 +413,8 @@ Variable* Scope::LookupFunctionVar(const AstRawString* name, |
VariableMode mode; |
int index = scope_info_->FunctionContextSlotIndex(*(name->string()), &mode); |
if (index < 0) return NULL; |
- Variable* var = new(zone()) Variable( |
- this, name, mode, true /* is valid LHS */, |
- Variable::NORMAL, kCreatedInitialized); |
+ Variable* var = new (zone()) |
+ Variable(this, name, mode, Variable::NORMAL, kCreatedInitialized); |
VariableProxy* proxy = factory->NewVariableProxy(var); |
VariableDeclaration* declaration = factory->NewVariableDeclaration( |
proxy, mode, this, RelocInfo::kNoPosition); |
@@ -448,7 +442,7 @@ Variable* Scope::DeclareParameter(const AstRawString* name, VariableMode mode, |
bool is_rest) { |
DCHECK(!already_resolved()); |
DCHECK(is_function_scope()); |
- Variable* var = variables_.Declare(this, name, mode, true, Variable::NORMAL, |
+ Variable* var = variables_.Declare(this, name, mode, Variable::NORMAL, |
kCreatedInitialized); |
if (is_rest) { |
DCHECK_NULL(rest_parameter_); |
@@ -469,7 +463,7 @@ Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode, |
// explicitly, and TEMPORARY variables are allocated via NewTemporary(). |
DCHECK(IsDeclaredVariableMode(mode)); |
++num_var_or_const_; |
- return variables_.Declare(this, name, mode, true, Variable::NORMAL, init_flag, |
+ return variables_.Declare(this, name, mode, Variable::NORMAL, init_flag, |
maybe_assigned_flag); |
} |
@@ -479,7 +473,6 @@ Variable* Scope::DeclareDynamicGlobal(const AstRawString* name) { |
return variables_.Declare(this, |
name, |
DYNAMIC_GLOBAL, |
- true, |
Variable::NORMAL, |
kCreatedInitialized); |
} |
@@ -502,7 +495,6 @@ Variable* Scope::NewInternal(const AstRawString* name) { |
Variable* var = new(zone()) Variable(this, |
name, |
INTERNAL, |
- false, |
Variable::NORMAL, |
kCreatedInitialized); |
internals_.Add(var, zone()); |
@@ -515,7 +507,6 @@ Variable* Scope::NewTemporary(const AstRawString* name) { |
Variable* var = new(zone()) Variable(this, |
name, |
TEMPORARY, |
- true, |
Variable::NORMAL, |
kCreatedInitialized); |
temps_.Add(var, zone()); |
@@ -962,7 +953,6 @@ Variable* Scope::NonLocal(const AstRawString* name, VariableMode mode) { |
var = map->Declare(NULL, |
name, |
mode, |
- true, |
Variable::NORMAL, |
init_flag); |
// Allocate it by giving it a dynamic lookup. |
@@ -1162,7 +1152,7 @@ bool Scope::MustAllocate(Variable* var) { |
if (scope_calls_eval_ || inner_scope_calls_eval_) var->set_maybe_assigned(); |
} |
// Global variables do not need to be allocated. |
- return !var->IsGlobalObjectProperty() && var->is_used(); |
+ return var->is_this() || (var->is_used() && !var->IsGlobalObjectProperty()); |
} |
@@ -1253,24 +1243,42 @@ void Scope::AllocateParameterLocals(Isolate* isolate) { |
// Force context allocation of the parameter. |
var->ForceContextAllocation(); |
} |
+ AllocateParameter(var, i); |
+ } |
+} |
- if (MustAllocate(var)) { |
- if (MustAllocateInContext(var)) { |
- DCHECK(var->IsUnallocated() || var->IsContextSlot()); |
- if (var->IsUnallocated()) { |
- AllocateHeapSlot(var); |
- } |
- } else { |
- DCHECK(var->IsUnallocated() || var->IsParameter()); |
- if (var->IsUnallocated()) { |
- var->AllocateTo(Variable::PARAMETER, i); |
- } |
+ |
+void Scope::AllocateParameter(Variable* var, int index) { |
+ if (MustAllocate(var)) { |
+ if (MustAllocateInContext(var)) { |
+ DCHECK(var->IsUnallocated() || var->IsContextSlot()); |
+ if (var->IsUnallocated()) { |
+ AllocateHeapSlot(var); |
+ } |
+ } else { |
+ DCHECK(var->IsUnallocated() || var->IsParameter()); |
+ if (var->IsUnallocated()) { |
+ var->AllocateTo(Variable::PARAMETER, index); |
} |
} |
} |
} |
+void Scope::AllocateReceiver() { |
+ DCHECK_EQ(receiver()->scope(), this); |
+ |
+ if (is_script_scope()) { |
+ receiver()->AllocateTo(Variable::PARAMETER, -1); |
+ } else { |
+ if (has_forced_context_allocation()) { |
+ receiver()->ForceContextAllocation(); |
+ } |
+ AllocateParameter(receiver(), -1); |
+ } |
+} |
+ |
+ |
void Scope::AllocateNonParameterLocal(Isolate* isolate, Variable* var) { |
DCHECK(var->scope() == this); |
DCHECK(!var->IsVariable(isolate->factory()->dot_result_string()) || |
@@ -1338,6 +1346,7 @@ void Scope::AllocateVariablesRecursively(Isolate* isolate) { |
// Allocate variables for this scope. |
// Parameters must be allocated first, if any. |
if (is_function_scope()) AllocateParameterLocals(isolate); |
+ if (has_this_declaration()) AllocateReceiver(); |
AllocateNonParameterLocals(isolate); |
// Force allocation of a context for this scope if necessary. For a 'with' |