Index: src/scopes.cc |
diff --git a/src/scopes.cc b/src/scopes.cc |
index d0ee8ec7f21af11758a2cb3c49dcf9f8a2aa6b18..0e2b127eeabd765deaafc1a74e2817924a1392c4 100644 |
--- a/src/scopes.cc |
+++ b/src/scopes.cc |
@@ -1,4 +1,4 @@ |
-// Copyright 2011 the V8 project authors. All rights reserved. |
+// Copyright 2012 the V8 project authors. All rights reserved. |
// Redistribution and use in source and binary forms, with or without |
// modification, are permitted provided that the following conditions are |
// met: |
@@ -274,8 +274,11 @@ bool Scope::Analyze(CompilationInfo* info) { |
top = top->outer_scope(); |
} |
- // Allocated the variables. |
- top->AllocateVariables(info->global_scope()); |
+ // Allocate the variables. |
+ { |
+ AstNodeFactory<AstNullVisitor> ast_node_factory(info->isolate()); |
+ top->AllocateVariables(info->global_scope(), &ast_node_factory); |
+ } |
#ifdef DEBUG |
if (info->isolate()->bootstrapper()->IsActive() |
@@ -417,7 +420,8 @@ Variable* Scope::LocalLookup(Handle<String> name) { |
} |
-Variable* Scope::LookupFunctionVar(Handle<String> name) { |
+Variable* Scope::LookupFunctionVar(Handle<String> name, |
+ AstNodeFactory<AstNullVisitor>* factory) { |
if (function_ != NULL && function_->name().is_identical_to(name)) { |
return function_->var(); |
} else if (!scope_info_.is_null()) { |
@@ -425,7 +429,7 @@ Variable* Scope::LookupFunctionVar(Handle<String> name) { |
VariableMode mode; |
int index = scope_info_->FunctionContextSlotIndex(*name, &mode); |
if (index < 0) return NULL; |
- Variable* var = DeclareFunctionVar(name, mode); |
+ Variable* var = DeclareFunctionVar(name, mode, factory); |
var->AllocateTo(Variable::CONTEXT, index); |
return var; |
} else { |
@@ -445,15 +449,6 @@ 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, kCreatedInitialized); |
- function_ = new(isolate_->zone()) VariableProxy(isolate_, function_var); |
- return function_var; |
-} |
- |
- |
void Scope::DeclareParameter(Handle<String> name, VariableMode mode) { |
ASSERT(!already_resolved()); |
ASSERT(is_function_scope()); |
@@ -491,18 +486,6 @@ Variable* Scope::DeclareGlobal(Handle<String> name) { |
} |
-VariableProxy* Scope::NewUnresolved(Handle<String> name, int position) { |
- // Note that we must not share the unresolved variables with |
- // the same name because they may be removed selectively via |
- // RemoveUnresolved(). |
- ASSERT(!already_resolved()); |
- VariableProxy* proxy = new(isolate_->zone()) VariableProxy( |
- isolate_, name, false, position); |
- unresolved_.Add(proxy); |
- return proxy; |
-} |
- |
- |
void Scope::RemoveUnresolved(VariableProxy* var) { |
// Most likely (always?) any variable we want to remove |
// was just added before, so we search backwards. |
@@ -625,7 +608,8 @@ void Scope::CollectStackAndContextLocals(ZoneList<Variable*>* stack_locals, |
} |
-void Scope::AllocateVariables(Scope* global_scope) { |
+void Scope::AllocateVariables(Scope* global_scope, |
+ AstNodeFactory<AstNullVisitor>* factory) { |
// 1) Propagate scope information. |
bool outer_scope_calls_non_strict_eval = false; |
if (outer_scope_ != NULL) { |
@@ -636,7 +620,7 @@ void Scope::AllocateVariables(Scope* global_scope) { |
PropagateScopeInfo(outer_scope_calls_non_strict_eval); |
// 2) Resolve variables. |
- ResolveVariablesRecursively(global_scope); |
+ ResolveVariablesRecursively(global_scope, factory); |
// 3) Allocate variables. |
AllocateVariablesRecursively(); |
@@ -899,7 +883,8 @@ Variable* Scope::NonLocal(Handle<String> name, VariableMode mode) { |
Variable* Scope::LookupRecursive(Handle<String> name, |
- BindingKind* binding_kind) { |
+ BindingKind* binding_kind, |
+ AstNodeFactory<AstNullVisitor>* factory) { |
ASSERT(binding_kind != NULL); |
// Try to find the variable in this scope. |
Variable* var = LocalLookup(name); |
@@ -916,11 +901,11 @@ Variable* Scope::LookupRecursive(Handle<String> name, |
// if any. We can do this for all scopes, since the function variable is |
// only present - if at all - for function scopes. |
*binding_kind = UNBOUND; |
- var = LookupFunctionVar(name); |
+ var = LookupFunctionVar(name, factory); |
if (var != NULL) { |
*binding_kind = BOUND; |
} else if (outer_scope_ != NULL) { |
- var = outer_scope_->LookupRecursive(name, binding_kind); |
+ var = outer_scope_->LookupRecursive(name, binding_kind, factory); |
if (*binding_kind == BOUND && (is_function_scope() || is_with_scope())) { |
var->ForceContextAllocation(); |
} |
@@ -953,7 +938,8 @@ Variable* Scope::LookupRecursive(Handle<String> name, |
void Scope::ResolveVariable(Scope* global_scope, |
- VariableProxy* proxy) { |
+ VariableProxy* proxy, |
+ AstNodeFactory<AstNullVisitor>* factory) { |
ASSERT(global_scope == NULL || global_scope->is_global_scope()); |
// If the proxy is already resolved there's nothing to do |
@@ -962,7 +948,7 @@ void Scope::ResolveVariable(Scope* global_scope, |
// Otherwise, try to resolve the variable. |
BindingKind binding_kind; |
- Variable* var = LookupRecursive(proxy->name(), &binding_kind); |
+ Variable* var = LookupRecursive(proxy->name(), &binding_kind, factory); |
switch (binding_kind) { |
case BOUND: |
// We found a variable binding. |
@@ -1003,17 +989,19 @@ void Scope::ResolveVariable(Scope* global_scope, |
} |
-void Scope::ResolveVariablesRecursively(Scope* global_scope) { |
+void Scope::ResolveVariablesRecursively( |
+ Scope* global_scope, |
+ AstNodeFactory<AstNullVisitor>* factory) { |
ASSERT(global_scope == NULL || global_scope->is_global_scope()); |
// Resolve unresolved variables for this scope. |
for (int i = 0; i < unresolved_.length(); i++) { |
- ResolveVariable(global_scope, unresolved_[i]); |
+ ResolveVariable(global_scope, unresolved_[i], factory); |
} |
// Resolve unresolved variables for inner scopes. |
for (int i = 0; i < inner_scopes_.length(); i++) { |
- inner_scopes_[i]->ResolveVariablesRecursively(global_scope); |
+ inner_scopes_[i]->ResolveVariablesRecursively(global_scope, factory); |
} |
} |