// ----------------------------------------------------------------------------
// Implementation of Scope
-Scope::Scope(Isolate* isolate, Zone* zone, Scope* outer_scope,
- ScopeType scope_type, AstValueFactory* ast_value_factory)
- : isolate_(isolate),
- inner_scopes_(4, zone),
+Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type,
+ AstValueFactory* ast_value_factory)
+ : inner_scopes_(4, zone),
variables_(zone),
internals_(4, zone),
temps_(4, zone),
}
-Scope::Scope(Isolate* isolate, Zone* zone, Scope* inner_scope,
- ScopeType scope_type, Handle<ScopeInfo> scope_info,
- AstValueFactory* value_factory)
- : isolate_(isolate),
- inner_scopes_(4, zone),
+Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type,
+ Handle<ScopeInfo> scope_info, AstValueFactory* value_factory)
+ : inner_scopes_(4, zone),
variables_(zone),
internals_(4, zone),
temps_(4, zone),
}
-Scope::Scope(Isolate* isolate, Zone* zone, Scope* inner_scope,
+Scope::Scope(Zone* zone, Scope* inner_scope,
const AstRawString* catch_variable_name,
AstValueFactory* value_factory)
- : isolate_(isolate),
- inner_scopes_(1, zone),
+ : inner_scopes_(1, zone),
variables_(zone),
internals_(0, zone),
temps_(0, zone),
while (!context->IsNativeContext()) {
if (context->IsWithContext()) {
Scope* with_scope = new (zone)
- Scope(isolate, zone, current_scope, WITH_SCOPE,
- Handle<ScopeInfo>::null(), script_scope->ast_value_factory_);
+ Scope(zone, current_scope, WITH_SCOPE, Handle<ScopeInfo>::null(),
+ script_scope->ast_value_factory_);
current_scope = with_scope;
// All the inner scopes are inside a with.
contains_with = true;
}
} else if (context->IsScriptContext()) {
ScopeInfo* scope_info = ScopeInfo::cast(context->extension());
- current_scope = new (zone) Scope(
- isolate, zone, current_scope, SCRIPT_SCOPE,
- Handle<ScopeInfo>(scope_info), script_scope->ast_value_factory_);
+ current_scope = new (zone) Scope(zone, current_scope, SCRIPT_SCOPE,
+ Handle<ScopeInfo>(scope_info),
+ script_scope->ast_value_factory_);
} else if (context->IsModuleContext()) {
ScopeInfo* scope_info = ScopeInfo::cast(context->module()->scope_info());
- current_scope = new (zone) Scope(
- isolate, zone, current_scope, MODULE_SCOPE,
- Handle<ScopeInfo>(scope_info), script_scope->ast_value_factory_);
+ current_scope = new (zone) Scope(zone, current_scope, MODULE_SCOPE,
+ Handle<ScopeInfo>(scope_info),
+ script_scope->ast_value_factory_);
} else if (context->IsFunctionContext()) {
ScopeInfo* scope_info = context->closure()->shared()->scope_info();
- current_scope = new (zone) Scope(
- isolate, zone, current_scope, FUNCTION_SCOPE,
- Handle<ScopeInfo>(scope_info), script_scope->ast_value_factory_);
+ current_scope = new (zone) Scope(zone, current_scope, FUNCTION_SCOPE,
+ Handle<ScopeInfo>(scope_info),
+ script_scope->ast_value_factory_);
if (scope_info->IsAsmFunction()) current_scope->asm_function_ = true;
if (scope_info->IsAsmModule()) current_scope->asm_module_ = true;
} else if (context->IsBlockContext()) {
ScopeInfo* scope_info = ScopeInfo::cast(context->extension());
- current_scope = new (zone) Scope(
- isolate, zone, current_scope, BLOCK_SCOPE,
- Handle<ScopeInfo>(scope_info), script_scope->ast_value_factory_);
+ current_scope = new (zone)
+ Scope(zone, current_scope, BLOCK_SCOPE, Handle<ScopeInfo>(scope_info),
+ script_scope->ast_value_factory_);
} else {
DCHECK(context->IsCatchContext());
String* name = String::cast(context->extension());
current_scope = new (zone) Scope(
- isolate, zone, current_scope,
+ zone, current_scope,
script_scope->ast_value_factory_->GetString(Handle<String>(name)),
script_scope->ast_value_factory_);
}
if (!ResolveVariablesRecursively(info, factory)) return false;
// 4) Allocate variables.
- AllocateVariablesRecursively();
+ AllocateVariablesRecursively(info->isolate());
return true;
}
}
-Handle<ScopeInfo> Scope::GetScopeInfo() {
+Handle<ScopeInfo> Scope::GetScopeInfo(Isolate* isolate) {
if (scope_info_.is_null()) {
- scope_info_ = ScopeInfo::Create(isolate(), zone(), this);
+ scope_info_ = ScopeInfo::Create(isolate, zone(), this);
}
return scope_info_;
}
-void Scope::GetNestedScopeChain(
- List<Handle<ScopeInfo> >* chain,
- int position) {
- if (!is_eval_scope()) chain->Add(Handle<ScopeInfo>(GetScopeInfo()));
+void Scope::GetNestedScopeChain(Isolate* isolate,
+ List<Handle<ScopeInfo> >* chain, int position) {
+ if (!is_eval_scope()) chain->Add(Handle<ScopeInfo>(GetScopeInfo(isolate)));
for (int i = 0; i < inner_scopes_.length(); i++) {
Scope* scope = inner_scopes_[i];
int end_pos = scope->end_position();
DCHECK(beg_pos >= 0 && end_pos >= 0);
if (beg_pos <= position && position < end_pos) {
- scope->GetNestedScopeChain(chain, position);
+ scope->GetNestedScopeChain(isolate, chain, position);
return;
}
}
}
-bool Scope::HasArgumentsParameter() {
+bool Scope::HasArgumentsParameter(Isolate* isolate) {
for (int i = 0; i < params_.length(); i++) {
if (params_[i]->name().is_identical_to(
- isolate_->factory()->arguments_string())) {
+ isolate->factory()->arguments_string())) {
return true;
}
}
}
-void Scope::AllocateParameterLocals() {
+void Scope::AllocateParameterLocals(Isolate* isolate) {
DCHECK(is_function_scope());
Variable* arguments = LookupLocal(ast_value_factory_->arguments_string());
DCHECK(arguments != NULL); // functions have 'arguments' declared implicitly
bool uses_sloppy_arguments = false;
- if (MustAllocate(arguments) && !HasArgumentsParameter()) {
+ if (MustAllocate(arguments) && !HasArgumentsParameter(isolate)) {
// 'arguments' is used. Unless there is also a parameter called
// 'arguments', we must be conservative and allocate all parameters to
// the context assuming they will be captured by the arguments object.
}
-void Scope::AllocateNonParameterLocal(Variable* var) {
+void Scope::AllocateNonParameterLocal(Isolate* isolate, Variable* var) {
DCHECK(var->scope() == this);
- DCHECK(!var->IsVariable(isolate_->factory()->dot_result_string()) ||
+ DCHECK(!var->IsVariable(isolate->factory()->dot_result_string()) ||
!var->IsStackLocal());
if (var->IsUnallocated() && MustAllocate(var)) {
if (MustAllocateInContext(var)) {
}
-void Scope::AllocateNonParameterLocals() {
+void Scope::AllocateNonParameterLocals(Isolate* isolate) {
// All variables that have no rewrite yet are non-parameter locals.
for (int i = 0; i < temps_.length(); i++) {
- AllocateNonParameterLocal(temps_[i]);
+ AllocateNonParameterLocal(isolate, temps_[i]);
}
for (int i = 0; i < internals_.length(); i++) {
- AllocateNonParameterLocal(internals_[i]);
+ AllocateNonParameterLocal(isolate, internals_[i]);
}
ZoneList<VarAndOrder> vars(variables_.occupancy(), zone());
vars.Sort(VarAndOrder::Compare);
int var_count = vars.length();
for (int i = 0; i < var_count; i++) {
- AllocateNonParameterLocal(vars[i].var());
+ AllocateNonParameterLocal(isolate, vars[i].var());
}
// For now, function_ must be allocated at the very end. If it gets
// because of the current ScopeInfo implementation (see
// ScopeInfo::ScopeInfo(FunctionScope* scope) constructor).
if (function_ != NULL) {
- AllocateNonParameterLocal(function_->proxy()->var());
+ AllocateNonParameterLocal(isolate, function_->proxy()->var());
}
if (rest_parameter_) {
- AllocateNonParameterLocal(rest_parameter_);
+ AllocateNonParameterLocal(isolate, rest_parameter_);
}
}
-void Scope::AllocateVariablesRecursively() {
+void Scope::AllocateVariablesRecursively(Isolate* isolate) {
// Allocate variables for inner scopes.
for (int i = 0; i < inner_scopes_.length(); i++) {
- inner_scopes_[i]->AllocateVariablesRecursively();
+ inner_scopes_[i]->AllocateVariablesRecursively(isolate);
}
// If scope is already resolved, we still need to allocate
// Allocate variables for this scope.
// Parameters must be allocated first, if any.
- if (is_function_scope()) AllocateParameterLocals();
- AllocateNonParameterLocals();
+ if (is_function_scope()) AllocateParameterLocals(isolate);
+ AllocateNonParameterLocals(isolate);
// Force allocation of a context for this scope if necessary. For a 'with'
// scope and for a function scope that makes an 'eval' call we need a context,
// ---------------------------------------------------------------------------
// Construction
- Scope(Isolate* isolate, Zone* zone, Scope* outer_scope, ScopeType scope_type,
+ Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type,
AstValueFactory* value_factory);
// Compute top scope and allocate variables. For lazy compilation the top
// tree and its children are reparented.
Scope* FinalizeBlockScope();
- Isolate* isolate() const { return isolate_; }
Zone* zone() const { return zone_; }
// ---------------------------------------------------------------------------
// where var declarations will be hoisted to in the implementation.
Scope* DeclarationScope();
- Handle<ScopeInfo> GetScopeInfo();
+ Handle<ScopeInfo> GetScopeInfo(Isolate* isolate);
// Get the chain of nested scopes within this scope for the source statement
// position. The scopes will be added to the list from the outermost scope to
// the innermost scope. Only nested block, catch or with scopes are tracked
// and will be returned, but no inner function scopes.
- void GetNestedScopeChain(List<Handle<ScopeInfo> >* chain,
+ void GetNestedScopeChain(Isolate* isolate, List<Handle<ScopeInfo> >* chain,
int statement_position);
// ---------------------------------------------------------------------------
protected:
friend class ParserFactory;
- Isolate* const isolate_;
-
// Scope tree.
Scope* outer_scope_; // the immediately enclosing outer scope, or NULL
ZoneList<Scope*> inner_scopes_; // the immediately enclosed inner scopes
// Predicates.
bool MustAllocate(Variable* var);
bool MustAllocateInContext(Variable* var);
- bool HasArgumentsParameter();
+ bool HasArgumentsParameter(Isolate* isolate);
// Variable allocation.
void AllocateStackSlot(Variable* var);
void AllocateHeapSlot(Variable* var);
- void AllocateParameterLocals();
- void AllocateNonParameterLocal(Variable* var);
- void AllocateNonParameterLocals();
- void AllocateVariablesRecursively();
+ void AllocateParameterLocals(Isolate* isolate);
+ void AllocateNonParameterLocal(Isolate* isolate, Variable* var);
+ void AllocateNonParameterLocals(Isolate* isolate);
+ void AllocateVariablesRecursively(Isolate* isolate);
void AllocateModulesRecursively(Scope* host_scope);
// Resolve and fill in the allocation information for all variables
private:
// Construct a scope based on the scope info.
- Scope(Isolate* isolate, Zone* zone, Scope* inner_scope, ScopeType type,
+ Scope(Zone* zone, Scope* inner_scope, ScopeType type,
Handle<ScopeInfo> scope_info, AstValueFactory* value_factory);
// Construct a catch scope with a binding for the name.
- Scope(Isolate* isolate, Zone* zone, Scope* inner_scope,
- const AstRawString* catch_variable_name,
+ Scope(Zone* zone, Scope* inner_scope, const AstRawString* catch_variable_name,
AstValueFactory* value_factory);
void AddInnerScope(Scope* inner_scope) {