V8 Project
v8::internal::Scope Class Reference

#include <scopes.h>

+ Inheritance diagram for v8::internal::Scope:
+ Collaboration diagram for v8::internal::Scope:

Public Member Functions

 Scope (Scope *outer_scope, ScopeType scope_type, AstValueFactory *value_factory, Zone *zone)
 
void SetScopeName (const AstRawString *scope_name)
 
void Initialize ()
 
ScopeFinalizeBlockScope ()
 
Zonezone () const
 
VariableLookupLocal (const AstRawString *name)
 
VariableLookupFunctionVar (const AstRawString *name, AstNodeFactory< AstNullVisitor > *factory)
 
VariableLookup (const AstRawString *name)
 
void DeclareFunctionVar (VariableDeclaration *declaration)
 
VariableDeclareParameter (const AstRawString *name, VariableMode mode)
 
VariableDeclareLocal (const AstRawString *name, VariableMode mode, InitializationFlag init_flag, MaybeAssignedFlag maybe_assigned_flag=kNotAssigned, Interface *interface=Interface::NewValue())
 
VariableDeclareDynamicGlobal (const AstRawString *name)
 
template<class Visitor >
VariableProxy * NewUnresolved (AstNodeFactory< Visitor > *factory, const AstRawString *name, Interface *interface=Interface::NewValue(), int position=RelocInfo::kNoPosition)
 
void RemoveUnresolved (VariableProxy *var)
 
VariableNewInternal (const AstRawString *name)
 
VariableNewTemporary (const AstRawString *name)
 
void AddDeclaration (Declaration *declaration)
 
void SetIllegalRedeclaration (Expression *expression)
 
void VisitIllegalRedeclaration (AstVisitor *visitor)
 
bool HasIllegalRedeclaration () const
 
DeclarationCheckConflictingVarDeclarations ()
 
void RecordWithStatement ()
 
void RecordEvalCall ()
 
void SetStrictMode (StrictMode strict_mode)
 
void SetAsmModule ()
 
int start_position () const
 
void set_start_position (int statement_pos)
 
int end_position () const
 
void set_end_position (int statement_pos)
 
void ForceContextAllocation ()
 
bool has_forced_context_allocation () const
 
bool is_eval_scope () const
 
bool is_function_scope () const
 
bool is_module_scope () const
 
bool is_global_scope () const
 
bool is_catch_scope () const
 
bool is_block_scope () const
 
bool is_with_scope () const
 
bool is_declaration_scope () const
 
bool is_strict_eval_scope () const
 
bool calls_eval () const
 
bool calls_sloppy_eval ()
 
bool outer_scope_calls_sloppy_eval () const
 
bool asm_module () const
 
bool asm_function () const
 
bool inside_with () const
 
bool contains_with () const
 
ScopeType scope_type () const
 
StrictMode strict_mode () const
 
Variablereceiver ()
 
VariableDeclaration * function () const
 
Variableparameter (int index) const
 
int num_parameters () const
 
Variablearguments () const
 
ZoneList< Declaration * > * declarations ()
 
ZoneList< Scope * > * inner_scopes ()
 
Scopeouter_scope () const
 
Interfaceinterface () const
 
void CollectStackAndContextLocals (ZoneList< Variable * > *stack_locals, ZoneList< Variable * > *context_locals)
 
int num_var_or_const ()
 
int num_stack_slots () const
 
int num_heap_slots () const
 
int StackLocalCount () const
 
int ContextLocalCount () const
 
int num_modules () const
 
Variablemodule_var () const
 
void ForceEagerCompilation ()
 
bool AllowsLazyCompilation () const
 
bool AllowsLazyCompilationWithoutContext () const
 
bool HasTrivialOuterContext () const
 
bool HasLazyCompilableOuterContext () const
 
int ContextChainLength (Scope *scope)
 
ScopeGlobalScope ()
 
ScopeDeclarationScope ()
 
Handle< ScopeInfoGetScopeInfo ()
 
void GetNestedScopeChain (List< Handle< ScopeInfo > > *chain, int statement_position)
 
bool IsDeclared (const AstRawString *name)
 
- Public Member Functions inherited from v8::internal::ZoneObject
 INLINE (void *operator new(size_t size, Zone *zone))
 
void operator delete (void *, size_t)
 
void operator delete (void *pointer, Zone *zone)
 

Static Public Member Functions

static bool Analyze (CompilationInfo *info)
 
static ScopeDeserializeScopeChain (Context *context, Scope *global_scope, Zone *zone)
 

Protected Types

enum  BindingKind {
  BOUND , BOUND_EVAL_SHADOWED , UNBOUND , UNBOUND_EVAL_SHADOWED ,
  DYNAMIC_LOOKUP
}
 

Protected Member Functions

bool already_resolved ()
 
VariableNonLocal (const AstRawString *name, VariableMode mode)
 
VariableLookupRecursive (VariableProxy *proxy, BindingKind *binding_kind, AstNodeFactory< AstNullVisitor > *factory)
 
MUST_USE_RESULT bool ResolveVariable (CompilationInfo *info, VariableProxy *proxy, AstNodeFactory< AstNullVisitor > *factory)
 
MUST_USE_RESULT bool ResolveVariablesRecursively (CompilationInfo *info, AstNodeFactory< AstNullVisitor > *factory)
 
void PropagateScopeInfo (bool outer_scope_calls_sloppy_eval)
 
bool HasTrivialContext () const
 
bool MustAllocate (Variable *var)
 
bool MustAllocateInContext (Variable *var)
 
bool HasArgumentsParameter ()
 
void AllocateStackSlot (Variable *var)
 
void AllocateHeapSlot (Variable *var)
 
void AllocateParameterLocals ()
 
void AllocateNonParameterLocal (Variable *var)
 
void AllocateNonParameterLocals ()
 
void AllocateVariablesRecursively ()
 
void AllocateModulesRecursively (Scope *host_scope)
 
MUST_USE_RESULT bool AllocateVariables (CompilationInfo *info, AstNodeFactory< AstNullVisitor > *factory)
 

Protected Attributes

Isolate *const isolate_
 
Scopeouter_scope_
 
ZoneList< Scope * > inner_scopes_
 
ScopeType scope_type_
 
const AstRawStringscope_name_
 
VariableMap variables_
 
ZoneList< Variable * > internals_
 
ZoneList< Variable * > temps_
 
ZoneList< Variable * > params_
 
DynamicScopePartdynamics_
 
ZoneList< VariableProxy * > unresolved_
 
ZoneList< Declaration * > decls_
 
Variablereceiver_
 
VariableDeclaration * function_
 
Variablearguments_
 
Interfaceinterface_
 
Expressionillegal_redecl_
 
bool scope_inside_with_
 
bool scope_contains_with_
 
bool scope_calls_eval_
 
bool asm_module_
 
bool asm_function_
 
StrictMode strict_mode_
 
int start_position_
 
int end_position_
 
bool outer_scope_calls_sloppy_eval_
 
bool inner_scope_calls_eval_
 
bool force_eager_compilation_
 
bool force_context_allocation_
 
bool already_resolved_
 
int num_var_or_const_
 
int num_stack_slots_
 
int num_heap_slots_
 
int num_modules_
 
Variablemodule_var_
 
Handle< ScopeInfoscope_info_
 

Private Member Functions

 Scope (Scope *inner_scope, ScopeType type, Handle< ScopeInfo > scope_info, AstValueFactory *value_factory, Zone *zone)
 
 Scope (Scope *inner_scope, const AstRawString *catch_variable_name, AstValueFactory *value_factory, Zone *zone)
 
void AddInnerScope (Scope *inner_scope)
 
void SetDefaults (ScopeType type, Scope *outer_scope, Handle< ScopeInfo > scope_info)
 

Private Attributes

AstValueFactoryast_value_factory_
 
Zonezone_
 

Friends

class ParserFactory
 

Detailed Description

Definition at line 70 of file scopes.h.

Member Enumeration Documentation

◆ BindingKind

Enumerator
BOUND 
BOUND_EVAL_SHADOWED 
UNBOUND 
UNBOUND_EVAL_SHADOWED 
DYNAMIC_LOOKUP 

Definition at line 516 of file scopes.h.

516  {
517  // The variable reference could be statically resolved to a variable binding
518  // which is returned. There is no 'with' statement between the reference and
519  // the binding and no scope between the reference scope (inclusive) and
520  // binding scope (exclusive) makes a sloppy 'eval' call.
521  BOUND,
522 
523  // The variable reference could be statically resolved to a variable binding
524  // which is returned. There is no 'with' statement between the reference and
525  // the binding, but some scope between the reference scope (inclusive) and
526  // binding scope (exclusive) makes a sloppy 'eval' call, that might
527  // possibly introduce variable bindings shadowing the found one. Thus the
528  // found variable binding is just a guess.
530 
531  // The variable reference could not be statically resolved to any binding
532  // and thus should be considered referencing a global variable. NULL is
533  // returned. The variable reference is not inside any 'with' statement and
534  // no scope between the reference scope (inclusive) and global scope
535  // (exclusive) makes a sloppy 'eval' call.
536  UNBOUND,
537 
538  // The variable reference could not be statically resolved to any binding
539  // NULL is returned. The variable reference is not inside any 'with'
540  // statement, but some scope between the reference scope (inclusive) and
541  // global scope (exclusive) makes a sloppy 'eval' call, that might
542  // possibly introduce a variable binding. Thus the reference should be
543  // considered referencing a global variable unless it is shadowed by an
544  // 'eval' introduced binding.
546 
547  // The variable could not be statically resolved and needs to be looked up
548  // dynamically. NULL is returned. There are two possible reasons:
549  // * A 'with' statement has been encountered and there is no variable
550  // binding for the name between the variable reference and the 'with'.
551  // The variable potentially references a property of the 'with' object.
552  // * The code is being executed as part of a call to 'eval' and the calling
553  // context chain contains either a variable binding for the name or it
554  // contains a 'with' context.
556  };

Constructor & Destructor Documentation

◆ Scope() [1/3]

v8::internal::Scope::Scope ( Scope outer_scope,
ScopeType  scope_type,
AstValueFactory value_factory,
Zone zone 
)

Definition at line 70 of file scopes.cc.

72  : isolate_(zone->isolate()),
73  inner_scopes_(4, zone),
75  internals_(4, zone),
76  temps_(4, zone),
77  params_(4, zone),
78  unresolved_(16, zone),
79  decls_(4, zone),
80  interface_(FLAG_harmony_modules &&
83  already_resolved_(false),
84  ast_value_factory_(ast_value_factory),
85  zone_(zone) {
87  // The outermost scope must be a global scope.
90 }
static Handle< T > null()
Definition: handles.h:123
static Interface * NewModule(Zone *zone)
Definition: interface.h:54
void SetDefaults(ScopeType type, Scope *outer_scope, Handle< ScopeInfo > scope_info)
Definition: scopes.cc:149
ZoneList< Variable * > temps_
Definition: scopes.h:441
ZoneList< VariableProxy * > unresolved_
Definition: scopes.h:447
Scope * outer_scope() const
Definition: scopes.h:333
ZoneList< Scope * > inner_scopes_
Definition: scopes.h:424
VariableMap variables_
Definition: scopes.h:437
ZoneList< Variable * > params_
Definition: scopes.h:443
bool HasIllegalRedeclaration() const
Definition: scopes.h:198
ZoneList< Declaration * > decls_
Definition: scopes.h:449
ScopeType scope_type() const
Definition: scopes.h:299
Isolate *const isolate_
Definition: scopes.h:420
bool already_resolved_
Definition: scopes.h:489
ZoneList< Variable * > internals_
Definition: scopes.h:439
Zone * zone() const
Definition: scopes.h:98
AstValueFactory * ast_value_factory_
Definition: scopes.h:623
Interface * interface_
Definition: scopes.h:457
Isolate * isolate() const
Definition: zone.h:68
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
#define DCHECK(condition)
Definition: logging.h:205
@ MODULE_SCOPE
Definition: globals.h:648
@ GLOBAL_SCOPE
Definition: globals.h:649

References DCHECK, v8::internal::GLOBAL_SCOPE, HasIllegalRedeclaration(), NULL, outer_scope(), scope_type(), and SetDefaults().

Referenced by DeserializeScopeChain().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Scope() [2/3]

v8::internal::Scope::Scope ( Scope inner_scope,
ScopeType  type,
Handle< ScopeInfo scope_info,
AstValueFactory value_factory,
Zone zone 
)
private

Definition at line 93 of file scopes.cc.

98  : isolate_(zone->isolate()),
99  inner_scopes_(4, zone),
100  variables_(zone),
101  internals_(4, zone),
102  temps_(4, zone),
103  params_(4, zone),
104  unresolved_(16, zone),
105  decls_(4, zone),
106  interface_(NULL),
107  already_resolved_(true),
108  ast_value_factory_(value_factory),
109  zone_(zone) {
110  SetDefaults(scope_type, NULL, scope_info);
111  if (!scope_info.is_null()) {
112  num_heap_slots_ = scope_info_->ContextLength();
113  }
114  // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context.
116  static_cast<int>(Context::MIN_CONTEXT_SLOTS));
117  AddInnerScope(inner_scope);
118 }
Handle< ScopeInfo > scope_info_
Definition: scopes.h:505
void AddInnerScope(Scope *inner_scope)
Definition: scopes.h:612
static LifetimePosition Max(LifetimePosition a, LifetimePosition b)

References AddInnerScope(), v8::internal::Handle< T >::is_null(), v8::internal::Max(), v8::internal::Context::MIN_CONTEXT_SLOTS, NULL, num_heap_slots_, scope_info_, scope_type(), and SetDefaults().

+ Here is the call graph for this function:

◆ Scope() [3/3]

v8::internal::Scope::Scope ( Scope inner_scope,
const AstRawString catch_variable_name,
AstValueFactory value_factory,
Zone zone 
)
private

Definition at line 121 of file scopes.cc.

123  : isolate_(zone->isolate()),
124  inner_scopes_(1, zone),
125  variables_(zone),
126  internals_(0, zone),
127  temps_(0, zone),
128  params_(0, zone),
129  unresolved_(0, zone),
130  decls_(0, zone),
131  interface_(NULL),
132  already_resolved_(true),
133  ast_value_factory_(value_factory),
134  zone_(zone) {
136  AddInnerScope(inner_scope);
139  Variable* variable = variables_.Declare(this,
140  catch_variable_name,
141  VAR,
142  true, // Valid left-hand side.
145  AllocateHeapSlot(variable);
146 }
void AllocateHeapSlot(Variable *var)
Definition: scopes.cc:1238
Variable * Declare(Scope *scope, const AstRawString *name, VariableMode mode, bool is_valid_lhs, Variable::Kind kind, InitializationFlag initialization_flag, MaybeAssignedFlag maybe_assigned_flag=kNotAssigned, Interface *interface=Interface::NewValue())
Definition: scopes.cc:33
@ kCreatedInitialized
Definition: globals.h:753

References AddInnerScope(), AllocateHeapSlot(), v8::internal::CATCH_SCOPE, v8::internal::VariableMap::Declare(), v8::internal::kCreatedInitialized, v8::internal::Context::MIN_CONTEXT_SLOTS, v8::internal::Variable::NORMAL, NULL, num_heap_slots_, num_var_or_const_, SetDefaults(), v8::internal::VAR, and variables_.

+ Here is the call graph for this function:

Member Function Documentation

◆ AddDeclaration()

void v8::internal::Scope::AddDeclaration ( Declaration declaration)

Definition at line 525 of file scopes.cc.

525  {
526  decls_.Add(declaration, zone());
527 }

References decls_, and zone().

Referenced by v8::internal::Parser::Declare().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AddInnerScope()

void v8::internal::Scope::AddInnerScope ( Scope inner_scope)
inlineprivate

Definition at line 612 of file scopes.h.

612  {
613  if (inner_scope != NULL) {
614  inner_scopes_.Add(inner_scope, zone_);
615  inner_scope->outer_scope_ = this;
616  }
617  }

References inner_scopes_, NULL, outer_scope_, and zone_.

Referenced by DeserializeScopeChain(), FinalizeBlockScope(), and Scope().

+ Here is the caller graph for this function:

◆ AllocateHeapSlot()

void v8::internal::Scope::AllocateHeapSlot ( Variable var)
protected

Definition at line 1238 of file scopes.cc.

1238  {
1239  var->AllocateTo(Variable::CONTEXT, num_heap_slots_++);
1240 }

References v8::internal::Variable::AllocateTo(), v8::internal::Variable::CONTEXT, and num_heap_slots_.

Referenced by AllocateNonParameterLocal(), AllocateParameterLocals(), and Scope().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AllocateModulesRecursively()

void v8::internal::Scope::AllocateModulesRecursively ( Scope host_scope)
protected

Definition at line 1382 of file scopes.cc.

1382  {
1383  if (already_resolved()) return;
1384  if (is_module_scope()) {
1386  DCHECK(module_var_ == NULL);
1387  module_var_ =
1388  host_scope->NewInternal(ast_value_factory_->dot_module_string());
1389  ++host_scope->num_modules_;
1390  }
1391 
1392  for (int i = 0; i < inner_scopes_.length(); i++) {
1393  Scope* inner_scope = inner_scopes_.at(i);
1394  inner_scope->AllocateModulesRecursively(host_scope);
1395  }
1396 }
Variable * module_var_
Definition: scopes.h:502
Scope(Scope *outer_scope, ScopeType scope_type, AstValueFactory *value_factory, Zone *zone)
Definition: scopes.cc:70
bool already_resolved()
Definition: scopes.h:506
bool is_module_scope() const
Definition: scopes.h:266

References AllocateModulesRecursively(), already_resolved(), ast_value_factory_, DCHECK, inner_scopes_, interface_, is_module_scope(), v8::internal::Interface::IsFrozen(), module_var_, NewInternal(), NULL, and num_modules_.

Referenced by AllocateModulesRecursively(), and AllocateVariables().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AllocateNonParameterLocal()

void v8::internal::Scope::AllocateNonParameterLocal ( Variable var)
protected

Definition at line 1299 of file scopes.cc.

1299  {
1300  DCHECK(var->scope() == this);
1301  DCHECK(!var->IsVariable(isolate_->factory()->dot_result_string()) ||
1302  !var->IsStackLocal());
1303  if (var->IsUnallocated() && MustAllocate(var)) {
1304  if (MustAllocateInContext(var)) {
1305  AllocateHeapSlot(var);
1306  } else {
1307  AllocateStackSlot(var);
1308  }
1309  }
1310 }
Factory * factory()
Definition: isolate.h:982
void AllocateStackSlot(Variable *var)
Definition: scopes.cc:1233
bool MustAllocateInContext(Variable *var)
Definition: scopes.cc:1200
bool MustAllocate(Variable *var)
Definition: scopes.cc:1179

References AllocateHeapSlot(), AllocateStackSlot(), DCHECK, v8::internal::Isolate::factory(), isolate_, v8::internal::Variable::IsStackLocal(), v8::internal::Variable::IsUnallocated(), v8::internal::Variable::IsVariable(), MustAllocate(), MustAllocateInContext(), and v8::internal::Variable::scope().

Referenced by AllocateNonParameterLocals().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AllocateNonParameterLocals()

void v8::internal::Scope::AllocateNonParameterLocals ( )
protected

Definition at line 1313 of file scopes.cc.

1313  {
1314  // All variables that have no rewrite yet are non-parameter locals.
1315  for (int i = 0; i < temps_.length(); i++) {
1317  }
1318 
1319  for (int i = 0; i < internals_.length(); i++) {
1321  }
1322 
1323  ZoneList<VarAndOrder> vars(variables_.occupancy(), zone());
1324  for (VariableMap::Entry* p = variables_.Start();
1325  p != NULL;
1326  p = variables_.Next(p)) {
1327  Variable* var = reinterpret_cast<Variable*>(p->value);
1328  vars.Add(VarAndOrder(var, p->order), zone());
1329  }
1330  vars.Sort(VarAndOrder::Compare);
1331  int var_count = vars.length();
1332  for (int i = 0; i < var_count; i++) {
1333  AllocateNonParameterLocal(vars[i].var());
1334  }
1335 
1336  // For now, function_ must be allocated at the very end. If it gets
1337  // allocated in the context, it must be the last slot in the context,
1338  // because of the current ScopeInfo implementation (see
1339  // ScopeInfo::ScopeInfo(FunctionScope* scope) constructor).
1340  if (function_ != NULL) {
1341  AllocateNonParameterLocal(function_->proxy()->var());
1342  }
1343 }
void AllocateNonParameterLocal(Variable *var)
Definition: scopes.cc:1299
VariableDeclaration * function_
Definition: scopes.h:453
Entry * Next(Entry *p) const
Definition: hashmap.h:226
uint32_t occupancy() const
Definition: hashmap.h:61
static int Compare(const VarAndOrder *a, const VarAndOrder *b)
Definition: scopes.cc:574

References v8::internal::List< T, AllocationPolicy >::Add(), AllocateNonParameterLocal(), v8::internal::VarAndOrder::Compare(), function_, internals_, v8::internal::TemplateHashMapImpl< AllocationPolicy >::Next(), NULL, v8::internal::TemplateHashMapImpl< AllocationPolicy >::occupancy(), v8::internal::List< T, AllocationPolicy >::Sort(), v8::internal::TemplateHashMapImpl< AllocationPolicy >::Start(), temps_, variables_, and zone().

Referenced by AllocateVariablesRecursively().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AllocateParameterLocals()

void v8::internal::Scope::AllocateParameterLocals ( )
protected

Definition at line 1243 of file scopes.cc.

1243  {
1245  Variable* arguments = LookupLocal(ast_value_factory_->arguments_string());
1246  DCHECK(arguments != NULL); // functions have 'arguments' declared implicitly
1247 
1248  bool uses_sloppy_arguments = false;
1249 
1251  // 'arguments' is used. Unless there is also a parameter called
1252  // 'arguments', we must be conservative and allocate all parameters to
1253  // the context assuming they will be captured by the arguments object.
1254  // If we have a parameter named 'arguments', a (new) value is always
1255  // assigned to it via the function invocation. Then 'arguments' denotes
1256  // that specific parameter value and cannot be used to access the
1257  // parameters, which is why we don't need to allocate an arguments
1258  // object in that case.
1259 
1260  // We are using 'arguments'. Tell the code generator that is needs to
1261  // allocate the arguments object by setting 'arguments_'.
1263 
1264  // In strict mode 'arguments' does not alias formal parameters.
1265  // Therefore in strict mode we allocate parameters as if 'arguments'
1266  // were not used.
1267  uses_sloppy_arguments = strict_mode() == SLOPPY;
1268  }
1269 
1270  // The same parameter may occur multiple times in the parameters_ list.
1271  // If it does, and if it is not copied into the context object, it must
1272  // receive the highest parameter index for that parameter; thus iteration
1273  // order is relevant!
1274  for (int i = params_.length() - 1; i >= 0; --i) {
1275  Variable* var = params_[i];
1276  DCHECK(var->scope() == this);
1277  if (uses_sloppy_arguments || has_forced_context_allocation()) {
1278  // Force context allocation of the parameter.
1279  var->ForceContextAllocation();
1280  }
1281 
1282  if (MustAllocate(var)) {
1283  if (MustAllocateInContext(var)) {
1284  DCHECK(var->IsUnallocated() || var->IsContextSlot());
1285  if (var->IsUnallocated()) {
1286  AllocateHeapSlot(var);
1287  }
1288  } else {
1289  DCHECK(var->IsUnallocated() || var->IsParameter());
1290  if (var->IsUnallocated()) {
1291  var->AllocateTo(Variable::PARAMETER, i);
1292  }
1293  }
1294  }
1295  }
1296 }
bool is_function_scope() const
Definition: scopes.h:265
bool HasArgumentsParameter()
Definition: scopes.cc:1222
Variable * arguments() const
Definition: scopes.h:324
StrictMode strict_mode() const
Definition: scopes.h:302
bool has_forced_context_allocation() const
Definition: scopes.h:256
Variable * arguments_
Definition: scopes.h:455
Variable * LookupLocal(const AstRawString *name)
Definition: scopes.cc:375

References AllocateHeapSlot(), v8::internal::Variable::AllocateTo(), arguments(), arguments_, ast_value_factory_, DCHECK, v8::internal::Variable::ForceContextAllocation(), has_forced_context_allocation(), HasArgumentsParameter(), is_function_scope(), v8::internal::Variable::IsContextSlot(), v8::internal::Variable::IsParameter(), v8::internal::Variable::IsUnallocated(), LookupLocal(), MustAllocate(), MustAllocateInContext(), NULL, v8::internal::Variable::PARAMETER, params_, v8::internal::Variable::scope(), v8::internal::SLOPPY, and strict_mode().

Referenced by AllocateVariablesRecursively().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AllocateStackSlot()

void v8::internal::Scope::AllocateStackSlot ( Variable var)
protected

Definition at line 1233 of file scopes.cc.

1233  {
1234  var->AllocateTo(Variable::LOCAL, num_stack_slots_++);
1235 }

References v8::internal::Variable::AllocateTo(), v8::internal::Variable::LOCAL, and num_stack_slots_.

Referenced by AllocateNonParameterLocal().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AllocateVariables()

bool v8::internal::Scope::AllocateVariables ( CompilationInfo info,
AstNodeFactory< AstNullVisitor > *  factory 
)
protected

Definition at line 636 of file scopes.cc.

637  {
638  // 1) Propagate scope information.
639  bool outer_scope_calls_sloppy_eval = false;
640  if (outer_scope_ != NULL) {
644  }
646 
647  // 2) Allocate module instances.
648  if (FLAG_harmony_modules && (is_global_scope() || is_module_scope())) {
649  DCHECK(num_modules_ == 0);
651  }
652 
653  // 3) Resolve variables.
654  if (!ResolveVariablesRecursively(info, factory)) return false;
655 
656  // 4) Allocate variables.
658 
659  return true;
660 }
bool is_global_scope() const
Definition: scopes.h:267
Scope * outer_scope_
Definition: scopes.h:423
bool calls_sloppy_eval()
Definition: scopes.h:281
void AllocateVariablesRecursively()
Definition: scopes.cc:1346
void PropagateScopeInfo(bool outer_scope_calls_sloppy_eval)
Definition: scopes.cc:1156
bool outer_scope_calls_sloppy_eval() const
Definition: scopes.h:284
void AllocateModulesRecursively(Scope *host_scope)
Definition: scopes.cc:1382
MUST_USE_RESULT bool ResolveVariablesRecursively(CompilationInfo *info, AstNodeFactory< AstNullVisitor > *factory)
Definition: scopes.cc:1136

References AllocateModulesRecursively(), AllocateVariablesRecursively(), calls_sloppy_eval(), DCHECK, is_global_scope(), is_module_scope(), NULL, num_modules_, outer_scope_, outer_scope_calls_sloppy_eval(), PropagateScopeInfo(), and ResolveVariablesRecursively().

Referenced by Analyze().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AllocateVariablesRecursively()

void v8::internal::Scope::AllocateVariablesRecursively ( )
protected

Definition at line 1346 of file scopes.cc.

1346  {
1347  // Allocate variables for inner scopes.
1348  for (int i = 0; i < inner_scopes_.length(); i++) {
1349  inner_scopes_[i]->AllocateVariablesRecursively();
1350  }
1351 
1352  // If scope is already resolved, we still need to allocate
1353  // variables in inner scopes which might not had been resolved yet.
1354  if (already_resolved()) return;
1355  // The number of slots required for variables.
1356  num_stack_slots_ = 0;
1358 
1359  // Allocate variables for this scope.
1360  // Parameters must be allocated first, if any.
1363 
1364  // Force allocation of a context for this scope if necessary. For a 'with'
1365  // scope and for a function scope that makes an 'eval' call we need a context,
1366  // even if no local variables were statically allocated in the scope.
1367  // Likewise for modules.
1368  bool must_have_context = is_with_scope() || is_module_scope() ||
1369  (is_function_scope() && calls_eval());
1370 
1371  // If we didn't allocate any locals in the local context, then we only
1372  // need the minimal number of slots if we must have a context.
1373  if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && !must_have_context) {
1374  num_heap_slots_ = 0;
1375  }
1376 
1377  // Allocation done.
1379 }
void AllocateParameterLocals()
Definition: scopes.cc:1243
void AllocateNonParameterLocals()
Definition: scopes.cc:1313
bool calls_eval() const
Definition: scopes.h:280
bool is_with_scope() const
Definition: scopes.h:270

References AllocateNonParameterLocals(), AllocateParameterLocals(), already_resolved(), calls_eval(), DCHECK, inner_scopes_, is_function_scope(), is_module_scope(), is_with_scope(), v8::internal::Context::MIN_CONTEXT_SLOTS, num_heap_slots_, and num_stack_slots_.

Referenced by AllocateVariables().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AllowsLazyCompilation()

bool v8::internal::Scope::AllowsLazyCompilation ( ) const

Definition at line 705 of file scopes.cc.

705  {
707 }
bool force_eager_compilation_
Definition: scopes.h:484
bool HasLazyCompilableOuterContext() const
Definition: scopes.cc:687

References force_eager_compilation_, and HasLazyCompilableOuterContext().

Referenced by v8::internal::CompilationInfo::ShouldSelfOptimize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AllowsLazyCompilationWithoutContext()

bool v8::internal::Scope::AllowsLazyCompilationWithoutContext ( ) const

Definition at line 710 of file scopes.cc.

710  {
712 }
bool HasTrivialOuterContext() const
Definition: scopes.cc:677

References force_eager_compilation_, and HasTrivialOuterContext().

+ Here is the call graph for this function:

◆ already_resolved()

bool v8::internal::Scope::already_resolved ( )
inlineprotected

Definition at line 506 of file scopes.h.

506 { return already_resolved_; }

References already_resolved_.

Referenced by AllocateModulesRecursively(), AllocateVariablesRecursively(), Analyze(), DeclareLocal(), DeclareParameter(), ForceContextAllocation(), Initialize(), LookupRecursive(), NewInternal(), NewTemporary(), and NewUnresolved().

+ Here is the caller graph for this function:

◆ Analyze()

bool v8::internal::Scope::Analyze ( CompilationInfo info)
static

Definition at line 260 of file scopes.cc.

260  {
261  DCHECK(info->function() != NULL);
262  Scope* scope = info->function()->scope();
263  Scope* top = scope;
264 
265  // Traverse the scope tree up to the first unresolved scope or the global
266  // scope and start scope resolution and variable allocation from that scope.
267  while (!top->is_global_scope() &&
268  !top->outer_scope()->already_resolved()) {
269  top = top->outer_scope();
270  }
271 
272  // Allocate the variables.
273  {
274  AstNodeFactory<AstNullVisitor> ast_node_factory(
275  info->zone(), info->ast_value_factory(), info->ast_node_id_gen());
276  if (!top->AllocateVariables(info, &ast_node_factory)) return false;
277  }
278 
279 #ifdef DEBUG
280  if (info->isolate()->bootstrapper()->IsActive()
281  ? FLAG_print_builtin_scopes
282  : FLAG_print_scopes) {
283  scope->Print();
284  }
285 
286  if (FLAG_harmony_modules && FLAG_print_interfaces && top->is_global_scope()) {
287  PrintF("global : ");
288  top->interface()->Print();
289  }
290 #endif
291 
292  info->PrepareForCompilation(scope);
293  return true;
294 }
void PrintF(const char *format,...)
Definition: utils.cc:80

References AllocateVariables(), already_resolved(), v8::internal::CompilationInfo::ast_node_id_gen(), v8::internal::CompilationInfo::ast_value_factory(), v8::internal::Isolate::bootstrapper(), DCHECK, v8::internal::CompilationInfo::function(), interface(), is_global_scope(), v8::internal::CompilationInfo::isolate(), NULL, outer_scope(), v8::internal::CompilationInfo::PrepareForCompilation(), v8::internal::PrintF(), and v8::internal::CompilationInfo::zone().

Referenced by v8::internal::CompileOptimizedPrologue(), v8::internal::CompileUnoptimizedCode(), v8::internal::compiler::Parse(), v8::internal::ScopeIterator::ScopeIterator(), and v8::internal::HOptimizedGraphBuilder::TryInline().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ arguments()

Variable* v8::internal::Scope::arguments ( ) const
inline

Definition at line 324 of file scopes.h.

324 { return arguments_; }

References arguments_.

Referenced by AllocateParameterLocals(), v8::internal::compiler::AstGraphBuilder::CreateGraph(), v8::internal::HOptimizedGraphBuilder::SetUpScope(), and v8::internal::compiler::JSInliner::TryInlineCall().

+ Here is the caller graph for this function:

◆ asm_function()

bool v8::internal::Scope::asm_function ( ) const
inline

Definition at line 288 of file scopes.h.

288 { return asm_function_; }

References asm_function_.

Referenced by v8::internal::ScopeInfo::Create().

+ Here is the caller graph for this function:

◆ asm_module()

bool v8::internal::Scope::asm_module ( ) const
inline

Definition at line 287 of file scopes.h.

287 { return asm_module_; }

References asm_module_.

Referenced by v8::internal::ScopeInfo::Create().

+ Here is the caller graph for this function:

◆ calls_eval()

bool v8::internal::Scope::calls_eval ( ) const
inline

Definition at line 280 of file scopes.h.

280 { return scope_calls_eval_; }
bool scope_calls_eval_
Definition: scopes.h:470

References scope_calls_eval_.

Referenced by AllocateVariablesRecursively(), v8::internal::HOptimizedGraphBuilder::BuildGraph(), and v8::internal::ScopeInfo::Create().

+ Here is the caller graph for this function:

◆ calls_sloppy_eval()

bool v8::internal::Scope::calls_sloppy_eval ( )
inline

Definition at line 281 of file scopes.h.

281  {
283  }
StrictMode strict_mode_
Definition: scopes.h:476

References scope_calls_eval_, v8::internal::SLOPPY, and strict_mode_.

Referenced by AllocateVariables(), LookupRecursive(), and PropagateScopeInfo().

+ Here is the caller graph for this function:

◆ CheckConflictingVarDeclarations()

Declaration * v8::internal::Scope::CheckConflictingVarDeclarations ( )

Definition at line 545 of file scopes.cc.

545  {
546  int length = decls_.length();
547  for (int i = 0; i < length; i++) {
548  Declaration* decl = decls_[i];
549  if (decl->mode() != VAR) continue;
550  const AstRawString* name = decl->proxy()->raw_name();
551 
552  // Iterate through all scopes until and including the declaration scope.
553  Scope* previous = NULL;
554  Scope* current = decl->scope();
555  do {
556  // There is a conflict if there exists a non-VAR binding.
557  Variable* other_var = current->variables_.Lookup(name);
558  if (other_var != NULL && other_var->mode() != VAR) {
559  return decl;
560  }
561  previous = current;
562  current = current->outer_scope_;
563  } while (!previous->is_declaration_scope());
564  }
565  return NULL;
566 }
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in name

References decls_, is_declaration_scope(), v8::internal::VariableMap::Lookup(), v8::internal::Declaration::mode(), v8::internal::Variable::mode(), name, NULL, outer_scope_, v8::internal::Declaration::proxy(), v8::internal::Declaration::scope(), v8::internal::VAR, and variables_.

Referenced by v8::internal::Parser::CheckConflictingVarDeclarations().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CollectStackAndContextLocals()

void v8::internal::Scope::CollectStackAndContextLocals ( ZoneList< Variable * > *  stack_locals,
ZoneList< Variable * > *  context_locals 
)

Definition at line 584 of file scopes.cc.

585  {
586  DCHECK(stack_locals != NULL);
587  DCHECK(context_locals != NULL);
588 
589  // Collect internals which are always allocated on the heap.
590  for (int i = 0; i < internals_.length(); i++) {
591  Variable* var = internals_[i];
592  if (var->is_used()) {
593  DCHECK(var->IsContextSlot());
594  context_locals->Add(var, zone());
595  }
596  }
597 
598  // Collect temporaries which are always allocated on the stack, unless the
599  // context as a whole has forced context allocation.
600  for (int i = 0; i < temps_.length(); i++) {
601  Variable* var = temps_[i];
602  if (var->is_used()) {
603  if (var->IsContextSlot()) {
605  context_locals->Add(var, zone());
606  } else {
607  DCHECK(var->IsStackLocal());
608  stack_locals->Add(var, zone());
609  }
610  }
611  }
612 
613  // Collect declared local variables.
614  ZoneList<VarAndOrder> vars(variables_.occupancy(), zone());
615  for (VariableMap::Entry* p = variables_.Start();
616  p != NULL;
617  p = variables_.Next(p)) {
618  Variable* var = reinterpret_cast<Variable*>(p->value);
619  if (var->is_used()) {
620  vars.Add(VarAndOrder(var, p->order), zone());
621  }
622  }
623  vars.Sort(VarAndOrder::Compare);
624  int var_count = vars.length();
625  for (int i = 0; i < var_count; i++) {
626  Variable* var = vars[i].var();
627  if (var->IsStackLocal()) {
628  stack_locals->Add(var, zone());
629  } else if (var->IsContextSlot()) {
630  context_locals->Add(var, zone());
631  }
632  }
633 }

References v8::internal::List< T, AllocationPolicy >::Add(), v8::internal::VarAndOrder::Compare(), DCHECK, has_forced_context_allocation(), internals_, v8::internal::Variable::is_used(), v8::internal::Variable::IsContextSlot(), v8::internal::Variable::IsStackLocal(), v8::internal::TemplateHashMapImpl< AllocationPolicy >::Next(), NULL, v8::internal::TemplateHashMapImpl< AllocationPolicy >::occupancy(), v8::internal::List< T, AllocationPolicy >::Sort(), v8::internal::TemplateHashMapImpl< AllocationPolicy >::Start(), temps_, variables_, and zone().

Referenced by v8::internal::ScopeInfo::Create(), v8::internal::AstTyper::ObserveTypesAtOsrEntry(), and v8::internal::FunctionInfoListener::SerializeFunctionScope().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ contains_with()

bool v8::internal::Scope::contains_with ( ) const
inline

Definition at line 293 of file scopes.h.

293 { return scope_contains_with_; }
bool scope_contains_with_
Definition: scopes.h:467

References scope_contains_with_.

Referenced by DeserializeScopeChain().

+ Here is the caller graph for this function:

◆ ContextChainLength()

int v8::internal::Scope::ContextChainLength ( Scope scope)

Definition at line 715 of file scopes.cc.

715  {
716  int n = 0;
717  for (Scope* s = this; s != scope; s = s->outer_scope_) {
718  DCHECK(s != NULL); // scope must be in the scope chain
719  if (s->is_with_scope() || s->num_heap_slots() > 0) n++;
720  // Catch and module scopes always have heap slots.
721  DCHECK(!s->is_catch_scope() || s->num_heap_slots() > 0);
722  DCHECK(!s->is_module_scope() || s->num_heap_slots() > 0);
723  }
724  return n;
725 }

References DCHECK, NULL, and outer_scope_.

Referenced by v8::internal::HOptimizedGraphBuilder::BuildContextChainWalk(), v8::internal::compiler::AstGraphBuilder::BuildVariableAssignment(), and v8::internal::compiler::AstGraphBuilder::BuildVariableLoad().

+ Here is the caller graph for this function:

◆ ContextLocalCount()

int v8::internal::Scope::ContextLocalCount ( ) const

Definition at line 1405 of file scopes.cc.

1405  {
1406  if (num_heap_slots() == 0) return 0;
1408  (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0);
1409 }
int num_heap_slots() const
Definition: scopes.h:352

References function_, v8::internal::Context::MIN_CONTEXT_SLOTS, NULL, and num_heap_slots().

Referenced by v8::internal::ScopeInfo::Create(), v8::internal::AstTyper::ObserveTypesAtOsrEntry(), and v8::internal::FunctionInfoListener::SerializeFunctionScope().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ declarations()

ZoneList<Declaration*>* v8::internal::Scope::declarations ( )
inline

Definition at line 327 of file scopes.h.

327 { return &decls_; }

References decls_.

Referenced by v8::internal::FullCodeGenerator::AllocateModules(), v8::internal::HOptimizedGraphBuilder::BuildGraph(), v8::internal::compiler::AstGraphBuilder::CreateGraph(), v8::internal::AstTyper::Run(), and v8::internal::HOptimizedGraphBuilder::TryInline().

+ Here is the caller graph for this function:

◆ DeclarationScope()

Scope * v8::internal::Scope::DeclarationScope ( )

Definition at line 737 of file scopes.cc.

737  {
738  Scope* scope = this;
739  while (!scope->is_declaration_scope()) {
740  scope = scope->outer_scope();
741  }
742  return scope;
743 }

References is_declaration_scope(), and outer_scope().

Referenced by v8::internal::ParserTraits::CheckFunctionLiteralInsideTopLevelObjectLiteral(), v8::internal::ParserTraits::CheckPossibleEvalCall(), HasLazyCompilableOuterContext(), and v8::internal::Parser::ParseFunctionLiteral().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DeclareDynamicGlobal()

Variable * v8::internal::Scope::DeclareDynamicGlobal ( const AstRawString name)

Definition at line 476 of file scopes.cc.

476  {
478  return variables_.Declare(this,
479  name,
481  true,
484 }
@ DYNAMIC_GLOBAL
Definition: globals.h:689

References DCHECK, v8::internal::VariableMap::Declare(), v8::internal::DYNAMIC_GLOBAL, is_global_scope(), v8::internal::kCreatedInitialized, name, v8::internal::Variable::NORMAL, and variables_.

Referenced by ResolveVariable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DeclareFunctionVar()

void v8::internal::Scope::DeclareFunctionVar ( VariableDeclaration *  declaration)
inline

Definition at line 120 of file scopes.h.

120  {
122  function_ = declaration;
123  }

References DCHECK, function_, and is_function_scope().

Referenced by LookupFunctionVar().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DeclareLocal()

Variable * v8::internal::Scope::DeclareLocal ( const AstRawString name,
VariableMode  mode,
InitializationFlag  init_flag,
MaybeAssignedFlag  maybe_assigned_flag = kNotAssigned,
Interface interface = Interface::NewValue() 
)

Definition at line 461 of file scopes.cc.

464  {
466  // This function handles VAR, LET, and CONST modes. DYNAMIC variables are
467  // introduces during variable allocation, INTERNAL variables are allocated
468  // explicitly, and TEMPORARY variables are allocated via NewTemporary().
471  return variables_.Declare(this, name, mode, true, Variable::NORMAL, init_flag,
472  maybe_assigned_flag, interface);
473 }
Interface * interface() const
Definition: scopes.h:336
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long mode(MIPS only)") DEFINE_BOOL(enable_always_align_csp
bool IsDeclaredVariableMode(VariableMode mode)
Definition: globals.h:705

References already_resolved(), DCHECK, v8::internal::VariableMap::Declare(), interface(), v8::internal::IsDeclaredVariableMode(), mode(), name, v8::internal::Variable::NORMAL, num_var_or_const_, and variables_.

Referenced by v8::internal::Parser::Declare(), and v8::internal::Parser::ParseTryStatement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DeclareParameter()

Variable * v8::internal::Scope::DeclareParameter ( const AstRawString name,
VariableMode  mode 
)

Definition at line 451 of file scopes.cc.

451  {
454  Variable* var = variables_.Declare(this, name, mode, true, Variable::NORMAL,
456  params_.Add(var, zone());
457  return var;
458 }

References already_resolved(), DCHECK, v8::internal::VariableMap::Declare(), is_function_scope(), v8::internal::kCreatedInitialized, mode(), name, v8::internal::Variable::NORMAL, params_, variables_, and zone().

Referenced by v8::internal::CheckAndDeclareArrowParameter().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DeserializeScopeChain()

Scope * v8::internal::Scope::DeserializeScopeChain ( Context context,
Scope global_scope,
Zone zone 
)
static

Definition at line 187 of file scopes.cc.

188  {
189  // Reconstruct the outer scope chain from a closure's context chain.
190  Scope* current_scope = NULL;
191  Scope* innermost_scope = NULL;
192  bool contains_with = false;
193  while (!context->IsNativeContext()) {
194  if (context->IsWithContext()) {
195  Scope* with_scope = new(zone) Scope(current_scope,
196  WITH_SCOPE,
198  global_scope->ast_value_factory_,
199  zone);
200  current_scope = with_scope;
201  // All the inner scopes are inside a with.
202  contains_with = true;
203  for (Scope* s = innermost_scope; s != NULL; s = s->outer_scope()) {
204  s->scope_inside_with_ = true;
205  }
206  } else if (context->IsGlobalContext()) {
207  ScopeInfo* scope_info = ScopeInfo::cast(context->extension());
208  current_scope = new(zone) Scope(current_scope,
209  GLOBAL_SCOPE,
210  Handle<ScopeInfo>(scope_info),
211  global_scope->ast_value_factory_,
212  zone);
213  } else if (context->IsModuleContext()) {
214  ScopeInfo* scope_info = ScopeInfo::cast(context->module()->scope_info());
215  current_scope = new(zone) Scope(current_scope,
216  MODULE_SCOPE,
217  Handle<ScopeInfo>(scope_info),
218  global_scope->ast_value_factory_,
219  zone);
220  } else if (context->IsFunctionContext()) {
221  ScopeInfo* scope_info = context->closure()->shared()->scope_info();
222  current_scope = new(zone) Scope(current_scope,
224  Handle<ScopeInfo>(scope_info),
225  global_scope->ast_value_factory_,
226  zone);
227  if (scope_info->IsAsmFunction()) current_scope->asm_function_ = true;
228  if (scope_info->IsAsmModule()) current_scope->asm_module_ = true;
229  } else if (context->IsBlockContext()) {
230  ScopeInfo* scope_info = ScopeInfo::cast(context->extension());
231  current_scope = new(zone) Scope(current_scope,
232  BLOCK_SCOPE,
233  Handle<ScopeInfo>(scope_info),
234  global_scope->ast_value_factory_,
235  zone);
236  } else {
237  DCHECK(context->IsCatchContext());
238  String* name = String::cast(context->extension());
239  current_scope = new (zone) Scope(
240  current_scope,
241  global_scope->ast_value_factory_->GetString(Handle<String>(name)),
242  global_scope->ast_value_factory_, zone);
243  }
244  if (contains_with) current_scope->RecordWithStatement();
245  if (innermost_scope == NULL) innermost_scope = current_scope;
246 
247  // Forget about a with when we move to a context for a different function.
248  if (context->previous()->closure() != context->closure()) {
249  contains_with = false;
250  }
251  context = context->previous();
252  }
253 
254  global_scope->AddInnerScope(current_scope);
255  global_scope->PropagateScopeInfo(false);
256  return (innermost_scope == NULL) ? global_scope : innermost_scope;
257 }
bool contains_with() const
Definition: scopes.h:293
@ FUNCTION_SCOPE
Definition: globals.h:647

References AddInnerScope(), asm_function_, asm_module_, ast_value_factory_, v8::internal::BLOCK_SCOPE, v8::internal::Context::closure(), contains_with(), DCHECK, v8::internal::Context::extension(), v8::internal::FUNCTION_SCOPE, v8::internal::AstValueFactory::GetString(), v8::internal::GLOBAL_SCOPE, v8::internal::ScopeInfo::IsAsmFunction(), v8::internal::ScopeInfo::IsAsmModule(), v8::internal::Context::IsBlockContext(), v8::internal::Context::IsCatchContext(), v8::internal::Context::IsFunctionContext(), v8::internal::Context::IsGlobalContext(), v8::internal::Context::IsModuleContext(), v8::internal::Context::IsNativeContext(), v8::internal::Context::IsWithContext(), v8::internal::Context::module(), v8::internal::MODULE_SCOPE, name, NULL, v8::internal::Context::previous(), PropagateScopeInfo(), RecordWithStatement(), Scope(), v8::internal::WITH_SCOPE, and zone().

Referenced by v8::internal::Parser::DoParseProgram(), and v8::internal::Parser::ParseLazy().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ end_position()

int v8::internal::Scope::end_position ( ) const
inline

Definition at line 246 of file scopes.h.

246 { return end_position_; }

References end_position_.

Referenced by GetNestedScopeChain(), and v8::internal::Parser::ParseFunctionLiteral().

+ Here is the caller graph for this function:

◆ FinalizeBlockScope()

Scope * v8::internal::Scope::FinalizeBlockScope ( )

Definition at line 345 of file scopes.cc.

345  {
347  DCHECK(internals_.is_empty());
348  DCHECK(temps_.is_empty());
349  DCHECK(params_.is_empty());
350 
351  if (num_var_or_const() > 0) return this;
352 
353  // Remove this scope from outer scope.
354  for (int i = 0; i < outer_scope_->inner_scopes_.length(); i++) {
355  if (outer_scope_->inner_scopes_[i] == this) {
356  outer_scope_->inner_scopes_.Remove(i);
357  break;
358  }
359  }
360 
361  // Reparent inner scopes.
362  for (int i = 0; i < inner_scopes_.length(); i++) {
364  }
365 
366  // Move unresolved variables
367  for (int i = 0; i < unresolved_.length(); i++) {
369  }
370 
371  return NULL;
372 }
void Add(const T &element, AllocationPolicy allocator=AllocationPolicy())
Definition: list-inl.h:17
bool is_block_scope() const
Definition: scopes.h:269
int num_var_or_const()
Definition: scopes.h:348

References v8::internal::List< T, AllocationPolicy >::Add(), AddInnerScope(), DCHECK, inner_scopes_, internals_, is_block_scope(), NULL, num_var_or_const(), outer_scope(), outer_scope_, params_, temps_, unresolved_, and zone().

Referenced by v8::internal::Parser::ParseForStatement(), and v8::internal::Parser::ParseScopedBlock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ForceContextAllocation()

void v8::internal::Scope::ForceContextAllocation ( )
inline

Definition at line 252 of file scopes.h.

252  {
255  }
bool force_context_allocation_
Definition: scopes.h:485

References already_resolved(), DCHECK, and force_context_allocation_.

+ Here is the call graph for this function:

◆ ForceEagerCompilation()

void v8::internal::Scope::ForceEagerCompilation ( )
inline

Definition at line 364 of file scopes.h.

364 { force_eager_compilation_ = true; }

References force_eager_compilation_.

Referenced by v8::internal::Parser::ParseNativeDeclaration().

+ Here is the caller graph for this function:

◆ function()

VariableDeclaration* v8::internal::Scope::function ( ) const
inline

Definition at line 309 of file scopes.h.

309  {
311  return function_;
312  }

References DCHECK, function_, and is_function_scope().

Referenced by v8::internal::HOptimizedGraphBuilder::BuildGraph(), v8::internal::ScopeInfo::Create(), v8::internal::compiler::AstGraphBuilder::CreateGraph(), and v8::internal::AstTyper::Run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetNestedScopeChain()

void v8::internal::Scope::GetNestedScopeChain ( List< Handle< ScopeInfo > > *  chain,
int  statement_position 
)

Definition at line 754 of file scopes.cc.

756  {
757  if (!is_eval_scope()) chain->Add(Handle<ScopeInfo>(GetScopeInfo()));
758 
759  for (int i = 0; i < inner_scopes_.length(); i++) {
760  Scope* scope = inner_scopes_[i];
761  int beg_pos = scope->start_position();
762  int end_pos = scope->end_position();
763  DCHECK(beg_pos >= 0 && end_pos >= 0);
764  if (beg_pos <= position && position < end_pos) {
765  scope->GetNestedScopeChain(chain, position);
766  return;
767  }
768  }
769 }
bool is_eval_scope() const
Definition: scopes.h:264
Handle< ScopeInfo > GetScopeInfo()
Definition: scopes.cc:746

References DCHECK, end_position(), GetNestedScopeChain(), GetScopeInfo(), inner_scopes_, is_eval_scope(), and start_position().

Referenced by GetNestedScopeChain(), and v8::internal::ScopeIterator::RetrieveScopeChain().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetScopeInfo()

Handle< ScopeInfo > v8::internal::Scope::GetScopeInfo ( )

Definition at line 746 of file scopes.cc.

746  {
747  if (scope_info_.is_null()) {
749  }
750  return scope_info_;
751 }
static Handle< ScopeInfo > Create(Scope *scope, Zone *zone)
Definition: scopeinfo.cc:16

References v8::internal::ScopeInfo::Create(), scope_info_, and zone().

Referenced by v8::internal::FullCodeGenerator::AllocateModules(), and GetNestedScopeChain().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GlobalScope()

Scope * v8::internal::Scope::GlobalScope ( )

Definition at line 728 of file scopes.cc.

728  {
729  Scope* scope = this;
730  while (!scope->is_global_scope()) {
731  scope = scope->outer_scope();
732  }
733  return scope;
734 }

References is_global_scope(), and outer_scope().

+ Here is the call graph for this function:

◆ has_forced_context_allocation()

bool v8::internal::Scope::has_forced_context_allocation ( ) const
inline

Definition at line 256 of file scopes.h.

256  {
258  }

References force_context_allocation_.

Referenced by AllocateParameterLocals(), CollectStackAndContextLocals(), MustAllocateInContext(), and SetDefaults().

+ Here is the caller graph for this function:

◆ HasArgumentsParameter()

bool v8::internal::Scope::HasArgumentsParameter ( )
protected

Definition at line 1222 of file scopes.cc.

1222  {
1223  for (int i = 0; i < params_.length(); i++) {
1224  if (params_[i]->name().is_identical_to(
1225  isolate_->factory()->arguments_string())) {
1226  return true;
1227  }
1228  }
1229  return false;
1230 }

References v8::internal::Isolate::factory(), isolate_, name, and params_.

Referenced by AllocateParameterLocals().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HasIllegalRedeclaration()

bool v8::internal::Scope::HasIllegalRedeclaration ( ) const
inline

Definition at line 198 of file scopes.h.

198 { return illegal_redecl_ != NULL; }
Expression * illegal_redecl_
Definition: scopes.h:460

References illegal_redecl_, and NULL.

Referenced by v8::internal::HOptimizedGraphBuilder::BuildGraph(), v8::internal::OptimizedCompileJob::CreateGraph(), Scope(), SetIllegalRedeclaration(), and VisitIllegalRedeclaration().

+ Here is the caller graph for this function:

◆ HasLazyCompilableOuterContext()

bool v8::internal::Scope::HasLazyCompilableOuterContext ( ) const

Definition at line 687 of file scopes.cc.

687  {
688  Scope* outer = outer_scope_;
689  if (outer == NULL) return true;
690  // We have to prevent lazy compilation if this scope is inside a with scope
691  // and all declaration scopes between them have empty contexts. Such
692  // declaration scopes may become invisible during scope info deserialization.
693  outer = outer->DeclarationScope();
694  bool found_non_trivial_declarations = false;
695  for (const Scope* scope = outer; scope != NULL; scope = scope->outer_scope_) {
696  if (scope->is_with_scope() && !found_non_trivial_declarations) return false;
697  if (scope->is_declaration_scope() && scope->num_heap_slots() > 0) {
698  found_non_trivial_declarations = true;
699  }
700  }
701  return true;
702 }
Scope * DeclarationScope()
Definition: scopes.cc:737

References DeclarationScope(), NULL, and outer_scope_.

Referenced by AllowsLazyCompilation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HasTrivialContext()

bool v8::internal::Scope::HasTrivialContext ( ) const
protected

Definition at line 663 of file scopes.cc.

663  {
664  // A function scope has a trivial context if it always is the global
665  // context. We iteratively scan out the context chain to see if
666  // there is anything that makes this scope non-trivial; otherwise we
667  // return true.
668  for (const Scope* scope = this; scope != NULL; scope = scope->outer_scope_) {
669  if (scope->is_eval_scope()) return false;
670  if (scope->scope_inside_with_) return false;
671  if (scope->num_heap_slots_ > 0) return false;
672  }
673  return true;
674 }

References NULL.

Referenced by HasTrivialOuterContext().

+ Here is the caller graph for this function:

◆ HasTrivialOuterContext()

bool v8::internal::Scope::HasTrivialOuterContext ( ) const

Definition at line 677 of file scopes.cc.

677  {
678  Scope* outer = outer_scope_;
679  if (outer == NULL) return true;
680  // Note that the outer context may be trivial in general, but the current
681  // scope may be inside a 'with' statement in which case the outer context
682  // for this scope is not trivial.
683  return !scope_inside_with_ && outer->HasTrivialContext();
684 }
bool scope_inside_with_
Definition: scopes.h:465

References HasTrivialContext(), NULL, outer_scope_, and scope_inside_with_.

Referenced by AllowsLazyCompilationWithoutContext().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Initialize()

void v8::internal::Scope::Initialize ( )

Definition at line 297 of file scopes.cc.

297  {
299 
300  // Add this scope as a new inner scope of the outer scope.
301  if (outer_scope_ != NULL) {
302  outer_scope_->inner_scopes_.Add(this, zone());
304  } else {
306  }
307 
308  // Declare convenience variables.
309  // Declare and allocate receiver (even for the global scope, and even
310  // if naccesses_ == 0).
311  // NOTE: When loading parameters in the global scope, we must take
312  // care not to access them as properties of the global object, but
313  // instead load them directly from the stack. Currently, the only
314  // such parameter is 'this' which is passed on the stack when
315  // invoking scripts
316  if (is_declaration_scope()) {
317  Variable* var =
318  variables_.Declare(this,
319  ast_value_factory_->this_string(),
320  VAR,
321  false,
325  receiver_ = var;
326  } else {
327  DCHECK(outer_scope() != NULL);
329  }
330 
331  if (is_function_scope()) {
332  // Declare 'arguments' variable which exists in all functions.
333  // Note that it might never be accessed, in which case it won't be
334  // allocated during variable allocation.
335  variables_.Declare(this,
336  ast_value_factory_->arguments_string(),
337  VAR,
338  true,
341  }
342 }
Variable * receiver()
Definition: scopes.h:305
Variable * receiver_
Definition: scopes.h:451
bool is_declaration_scope() const
Definition: scopes.h:271
void AllocateTo(Location location, int index)
Definition: variables.h:131

References v8::internal::Variable::AllocateTo(), already_resolved(), v8::internal::Variable::ARGUMENTS, ast_value_factory_, DCHECK, v8::internal::VariableMap::Declare(), inner_scopes_, is_declaration_scope(), is_function_scope(), is_with_scope(), v8::internal::kCreatedInitialized, NULL, outer_scope(), outer_scope_, v8::internal::Variable::PARAMETER, receiver(), receiver_, scope_inside_with_, v8::internal::Variable::THIS, v8::internal::VAR, variables_, and zone().

Referenced by v8::internal::Parser::DesugarLetBindingsInForStatement(), and v8::internal::Parser::NewScope().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ inner_scopes()

ZoneList<Scope*>* v8::internal::Scope::inner_scopes ( )
inline

Definition at line 330 of file scopes.h.

330 { return &inner_scopes_; }

References inner_scopes_.

◆ inside_with()

bool v8::internal::Scope::inside_with ( ) const
inline

Definition at line 291 of file scopes.h.

291 { return scope_inside_with_; }

References scope_inside_with_.

◆ interface()

Interface* v8::internal::Scope::interface ( ) const
inline

Definition at line 336 of file scopes.h.

336 { return interface_; }

References interface_.

Referenced by v8::internal::FullCodeGenerator::AllocateModules(), Analyze(), DeclareLocal(), NewUnresolved(), and v8::internal::Parser::ParseModuleUrl().

+ Here is the caller graph for this function:

◆ is_block_scope()

bool v8::internal::Scope::is_block_scope ( ) const
inline

Definition at line 269 of file scopes.h.

269 { return scope_type_ == BLOCK_SCOPE; }
ScopeType scope_type_
Definition: scopes.h:427

References v8::internal::BLOCK_SCOPE, and scope_type_.

Referenced by v8::internal::Parser::Declare(), FinalizeBlockScope(), MustAllocate(), and MustAllocateInContext().

+ Here is the caller graph for this function:

◆ is_catch_scope()

bool v8::internal::Scope::is_catch_scope ( ) const
inline

Definition at line 268 of file scopes.h.

268 { return scope_type_ == CATCH_SCOPE; }

References v8::internal::CATCH_SCOPE, and scope_type_.

Referenced by MustAllocate(), and MustAllocateInContext().

+ Here is the caller graph for this function:

◆ is_declaration_scope()

bool v8::internal::Scope::is_declaration_scope ( ) const
inline

Definition at line 271 of file scopes.h.

271  {
272  return is_eval_scope() || is_function_scope() ||
274  }

References is_eval_scope(), is_function_scope(), is_global_scope(), and is_module_scope().

Referenced by CheckConflictingVarDeclarations(), DeclarationScope(), and Initialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ is_eval_scope()

bool v8::internal::Scope::is_eval_scope ( ) const
inline

Definition at line 264 of file scopes.h.

264 { return scope_type_ == EVAL_SCOPE; }

References v8::internal::EVAL_SCOPE, and scope_type_.

Referenced by v8::internal::Parser::Declare(), GetNestedScopeChain(), is_declaration_scope(), is_strict_eval_scope(), v8::internal::Parser::ParseReturnStatement(), and v8::internal::Rewriter::Rewrite().

+ Here is the caller graph for this function:

◆ is_function_scope()

bool v8::internal::Scope::is_function_scope ( ) const
inline

◆ is_global_scope()

◆ is_module_scope()

bool v8::internal::Scope::is_module_scope ( ) const
inline

Definition at line 266 of file scopes.h.

266 { return scope_type_ == MODULE_SCOPE; }

References v8::internal::MODULE_SCOPE, and scope_type_.

Referenced by AllocateModulesRecursively(), AllocateVariables(), AllocateVariablesRecursively(), v8::internal::Parser::Declare(), is_declaration_scope(), MustAllocate(), and MustAllocateInContext().

+ Here is the caller graph for this function:

◆ is_strict_eval_scope()

bool v8::internal::Scope::is_strict_eval_scope ( ) const
inline

Definition at line 275 of file scopes.h.

275  {
276  return is_eval_scope() && strict_mode_ == STRICT;
277  }

References is_eval_scope(), v8::internal::STRICT, and strict_mode_.

Referenced by v8::internal::Parser::Declare().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ is_with_scope()

bool v8::internal::Scope::is_with_scope ( ) const
inline

Definition at line 270 of file scopes.h.

270 { return scope_type_ == WITH_SCOPE; }

References scope_type_, and v8::internal::WITH_SCOPE.

Referenced by AllocateVariablesRecursively(), Initialize(), and LookupRecursive().

+ Here is the caller graph for this function:

◆ IsDeclared()

bool v8::internal::Scope::IsDeclared ( const AstRawString name)
inline

Definition at line 399 of file scopes.h.

399  {
400  // During formal parameter list parsing the scope only contains
401  // two variables inserted at initialization: "this" and "arguments".
402  // "this" is an invalid parameter name and "arguments" is invalid parameter
403  // name in strict mode. Therefore looking up with the map which includes
404  // "this" and "arguments" in addition to all formal parameters is safe.
405  return variables_.Lookup(name) != NULL;
406  }
Variable * Lookup(const AstRawString *name)
Definition: scopes.cc:55

References v8::internal::VariableMap::Lookup(), name, NULL, and variables_.

Referenced by v8::internal::CheckAndDeclareArrowParameter().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Lookup()

Variable * v8::internal::Scope::Lookup ( const AstRawString name)

Definition at line 440 of file scopes.cc.

440  {
441  for (Scope* scope = this;
442  scope != NULL;
443  scope = scope->outer_scope()) {
444  Variable* var = scope->LookupLocal(name);
445  if (var != NULL) return var;
446  }
447  return NULL;
448 }

References name, and NULL.

Referenced by v8::internal::Parser::Declare().

+ Here is the caller graph for this function:

◆ LookupFunctionVar()

Variable * v8::internal::Scope::LookupFunctionVar ( const AstRawString name,
AstNodeFactory< AstNullVisitor > *  factory 
)

Definition at line 416 of file scopes.cc.

417  {
418  if (function_ != NULL && function_->proxy()->raw_name() == name) {
419  return function_->proxy()->var();
420  } else if (!scope_info_.is_null()) {
421  // If we are backed by a scope info, try to lookup the variable there.
423  int index = scope_info_->FunctionContextSlotIndex(*(name->string()), &mode);
424  if (index < 0) return NULL;
425  Variable* var = new(zone()) Variable(
426  this, name, mode, true /* is valid LHS */,
428  VariableProxy* proxy = factory->NewVariableProxy(var);
429  VariableDeclaration* declaration = factory->NewVariableDeclaration(
430  proxy, mode, this, RelocInfo::kNoPosition);
431  DeclareFunctionVar(declaration);
432  var->AllocateTo(Variable::CONTEXT, index);
433  return var;
434  } else {
435  return NULL;
436  }
437 }
static const int kNoPosition
Definition: assembler.h:317
void DeclareFunctionVar(VariableDeclaration *declaration)
Definition: scopes.h:120

References v8::internal::Variable::AllocateTo(), v8::internal::Variable::CONTEXT, DeclareFunctionVar(), function_, v8::internal::kCreatedInitialized, v8::internal::RelocInfo::kNoPosition, mode(), name, v8::internal::Variable::NORMAL, NULL, scope_info_, and zone().

Referenced by LookupRecursive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ LookupLocal()

Variable * v8::internal::Scope::LookupLocal ( const AstRawString name)

Definition at line 375 of file scopes.cc.

375  {
376  Variable* result = variables_.Lookup(name);
377  if (result != NULL || scope_info_.is_null()) {
378  return result;
379  }
380  // The Scope is backed up by ScopeInfo. This means it cannot operate in a
381  // heap-independent mode, and all strings must be internalized immediately. So
382  // it's ok to get the Handle<String> here.
383  Handle<String> name_handle = name->string();
384  // If we have a serialized scope info, we might find the variable there.
385  // There should be no local slot with the given name.
386  DCHECK(scope_info_->StackSlotIndex(*name_handle) < 0);
387 
388  // Check context slot lookup.
391  InitializationFlag init_flag;
392  MaybeAssignedFlag maybe_assigned_flag;
393  int index = ScopeInfo::ContextSlotIndex(scope_info_, name_handle, &mode,
394  &init_flag, &maybe_assigned_flag);
395  if (index < 0) {
396  // Check parameters.
397  index = scope_info_->ParameterIndex(*name_handle);
398  if (index < 0) return NULL;
399 
400  mode = DYNAMIC;
401  location = Variable::LOOKUP;
402  init_flag = kCreatedInitialized;
403  // Be conservative and flag parameters as maybe assigned. Better information
404  // would require ScopeInfo to serialize the maybe_assigned bit also for
405  // parameters.
406  maybe_assigned_flag = kMaybeAssigned;
407  }
408 
409  Variable* var = variables_.Declare(this, name, mode, true, Variable::NORMAL,
410  init_flag, maybe_assigned_flag);
411  var->AllocateTo(location, index);
412  return var;
413 }
static int ContextSlotIndex(Handle< ScopeInfo > scope_info, Handle< String > name, VariableMode *mode, InitializationFlag *init_flag, MaybeAssignedFlag *maybe_assigned_flag)
Definition: scopeinfo.cc:296
InitializationFlag
Definition: globals.h:751
@ kMaybeAssigned
Definition: globals.h:757

References v8::internal::Variable::AllocateTo(), v8::internal::Variable::CONTEXT, v8::internal::ScopeInfo::ContextSlotIndex(), DCHECK, v8::internal::VariableMap::Declare(), v8::internal::DYNAMIC, v8::internal::kCreatedInitialized, v8::internal::kMaybeAssigned, v8::internal::VariableMap::Lookup(), v8::internal::Variable::LOOKUP, mode(), name, v8::internal::Variable::NORMAL, NULL, scope_info_, and variables_.

Referenced by AllocateParameterLocals(), v8::internal::ModuleInfo::Create(), v8::internal::Parser::Declare(), LookupRecursive(), and v8::internal::Parser::ParseModuleLiteral().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ LookupRecursive()

Variable * v8::internal::Scope::LookupRecursive ( VariableProxy *  proxy,
BindingKind binding_kind,
AstNodeFactory< AstNullVisitor > *  factory 
)
protected

Definition at line 963 of file scopes.cc.

965  {
966  DCHECK(binding_kind != NULL);
967  if (already_resolved() && is_with_scope()) {
968  // Short-cut: if the scope is deserialized from a scope info, variable
969  // allocation is already fixed. We can simply return with dynamic lookup.
970  *binding_kind = DYNAMIC_LOOKUP;
971  return NULL;
972  }
973 
974  // Try to find the variable in this scope.
975  Variable* var = LookupLocal(proxy->raw_name());
976 
977  // We found a variable and we are done. (Even if there is an 'eval' in
978  // this scope which introduces the same variable again, the resulting
979  // variable remains the same.)
980  if (var != NULL) {
981  *binding_kind = BOUND;
982  return var;
983  }
984 
985  // We did not find a variable locally. Check against the function variable,
986  // if any. We can do this for all scopes, since the function variable is
987  // only present - if at all - for function scopes.
988  *binding_kind = UNBOUND;
989  var = LookupFunctionVar(proxy->raw_name(), factory);
990  if (var != NULL) {
991  *binding_kind = BOUND;
992  } else if (outer_scope_ != NULL) {
993  var = outer_scope_->LookupRecursive(proxy, binding_kind, factory);
994  if (*binding_kind == BOUND && (is_function_scope() || is_with_scope())) {
995  var->ForceContextAllocation();
996  }
997  } else {
999  }
1000 
1001  if (is_with_scope()) {
1003  // The current scope is a with scope, so the variable binding can not be
1004  // statically resolved. However, note that it was necessary to do a lookup
1005  // in the outer scope anyway, because if a binding exists in an outer scope,
1006  // the associated variable has to be marked as potentially being accessed
1007  // from inside of an inner with scope (the property may not be in the 'with'
1008  // object).
1009  if (var != NULL && proxy->is_assigned()) var->set_maybe_assigned();
1010  *binding_kind = DYNAMIC_LOOKUP;
1011  return NULL;
1012  } else if (calls_sloppy_eval()) {
1013  // A variable binding may have been found in an outer scope, but the current
1014  // scope makes a sloppy 'eval' call, so the found variable may not be
1015  // the correct one (the 'eval' may introduce a binding with the same name).
1016  // In that case, change the lookup result to reflect this situation.
1017  if (*binding_kind == BOUND) {
1018  *binding_kind = BOUND_EVAL_SHADOWED;
1019  } else if (*binding_kind == UNBOUND) {
1020  *binding_kind = UNBOUND_EVAL_SHADOWED;
1021  }
1022  }
1023  return var;
1024 }
Variable * LookupFunctionVar(const AstRawString *name, AstNodeFactory< AstNullVisitor > *factory)
Definition: scopes.cc:416
Variable * LookupRecursive(VariableProxy *proxy, BindingKind *binding_kind, AstNodeFactory< AstNullVisitor > *factory)
Definition: scopes.cc:963
void ForceContextAllocation()
Definition: variables.h:77

References already_resolved(), BOUND, BOUND_EVAL_SHADOWED, calls_sloppy_eval(), DCHECK, DYNAMIC_LOOKUP, v8::internal::Variable::ForceContextAllocation(), is_function_scope(), is_global_scope(), is_with_scope(), LookupFunctionVar(), LookupLocal(), LookupRecursive(), NULL, outer_scope_, v8::internal::Variable::set_maybe_assigned(), UNBOUND, and UNBOUND_EVAL_SHADOWED.

Referenced by LookupRecursive(), and ResolveVariable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ module_var()

Variable* v8::internal::Scope::module_var ( ) const
inline

Definition at line 361 of file scopes.h.

361 { return module_var_; }

References module_var_.

Referenced by v8::internal::FullCodeGenerator::AllocateModules().

+ Here is the caller graph for this function:

◆ MustAllocate()

bool v8::internal::Scope::MustAllocate ( Variable var)
protected

Definition at line 1179 of file scopes.cc.

1179  {
1180  // Give var a read/write use if there is a chance it might be accessed
1181  // via an eval() call. This is only possible if the variable has a
1182  // visible name.
1183  if ((var->is_this() || !var->raw_name()->IsEmpty()) &&
1184  (var->has_forced_context_allocation() ||
1188  is_catch_scope() ||
1189  is_block_scope() ||
1190  is_module_scope() ||
1191  is_global_scope())) {
1192  var->set_is_used();
1193  if (scope_calls_eval_ || inner_scope_calls_eval_) var->set_maybe_assigned();
1194  }
1195  // Global variables do not need to be allocated.
1196  return !var->IsGlobalObjectProperty() && var->is_used();
1197 }
bool inner_scope_calls_eval_
Definition: scopes.h:483
bool is_catch_scope() const
Definition: scopes.h:268

References v8::internal::Variable::has_forced_context_allocation(), inner_scope_calls_eval_, is_block_scope(), is_catch_scope(), is_global_scope(), is_module_scope(), v8::internal::Variable::is_this(), v8::internal::Variable::is_used(), v8::internal::AstString::IsEmpty(), v8::internal::Variable::IsGlobalObjectProperty(), v8::internal::Variable::raw_name(), scope_calls_eval_, scope_contains_with_, v8::internal::Variable::set_is_used(), and v8::internal::Variable::set_maybe_assigned().

Referenced by AllocateNonParameterLocal(), and AllocateParameterLocals().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MustAllocateInContext()

bool v8::internal::Scope::MustAllocateInContext ( Variable var)
protected

Definition at line 1200 of file scopes.cc.

1200  {
1201  // If var is accessed from an inner scope, or if there is a possibility
1202  // that it might be accessed from the current or an inner scope (through
1203  // an eval() call or a runtime with lookup), it must be allocated in the
1204  // context.
1205  //
1206  // Exceptions: If the scope as a whole has forced context allocation, all
1207  // variables will have context allocation, even temporaries. Otherwise
1208  // temporary variables are always stack-allocated. Catch-bound variables are
1209  // always context-allocated.
1210  if (has_forced_context_allocation()) return true;
1211  if (var->mode() == TEMPORARY) return false;
1212  if (var->mode() == INTERNAL) return true;
1213  if (is_catch_scope() || is_block_scope() || is_module_scope()) return true;
1214  if (is_global_scope() && IsLexicalVariableMode(var->mode())) return true;
1215  return var->has_forced_context_allocation() ||
1219 }
bool IsLexicalVariableMode(VariableMode mode)
Definition: globals.h:710

References has_forced_context_allocation(), v8::internal::Variable::has_forced_context_allocation(), inner_scope_calls_eval_, v8::internal::INTERNAL, is_block_scope(), is_catch_scope(), is_global_scope(), is_module_scope(), v8::internal::IsLexicalVariableMode(), v8::internal::Variable::mode(), scope_calls_eval_, scope_contains_with_, and v8::internal::TEMPORARY.

Referenced by AllocateNonParameterLocal(), and AllocateParameterLocals().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ NewInternal()

Variable * v8::internal::Scope::NewInternal ( const AstRawString name)

Definition at line 499 of file scopes.cc.

499  {
501  Variable* var = new(zone()) Variable(this,
502  name,
503  INTERNAL,
504  false,
507  internals_.Add(var, zone());
508  return var;
509 }

References already_resolved(), DCHECK, v8::internal::INTERNAL, internals_, v8::internal::kCreatedInitialized, name, v8::internal::Variable::NORMAL, and zone().

Referenced by AllocateModulesRecursively().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ NewTemporary()

Variable * v8::internal::Scope::NewTemporary ( const AstRawString name)

Definition at line 512 of file scopes.cc.

512  {
514  Variable* var = new(zone()) Variable(this,
515  name,
516  TEMPORARY,
517  true,
520  temps_.Add(var, zone());
521  return var;
522 }

References already_resolved(), DCHECK, v8::internal::kCreatedInitialized, name, v8::internal::Variable::NORMAL, v8::internal::TEMPORARY, temps_, and zone().

Referenced by v8::internal::Rewriter::Rewrite().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ NewUnresolved()

template<class Visitor >
VariableProxy* v8::internal::Scope::NewUnresolved ( AstNodeFactory< Visitor > *  factory,
const AstRawString name,
Interface interface = Interface::NewValue(),
int  position = RelocInfo::kNoPosition 
)
inline

Definition at line 145 of file scopes.h.

148  {
149  // Note that we must not share the unresolved variables with
150  // the same name because they may be removed selectively via
151  // RemoveUnresolved().
153  VariableProxy* proxy =
154  factory->NewVariableProxy(name, false, interface, position);
155  unresolved_.Add(proxy, zone_);
156  return proxy;
157  }

References v8::internal::List< T, AllocationPolicy >::Add(), already_resolved(), DCHECK, interface(), name, unresolved_, and zone_.

Referenced by v8::internal::ParserTraits::ExpressionFromIdentifier(), v8::internal::Parser::NewUnresolved(), and v8::internal::Parser::ParseVariableDeclarations().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ NonLocal()

Variable * v8::internal::Scope::NonLocal ( const AstRawString name,
VariableMode  mode 
)
protected

Definition at line 942 of file scopes.cc.

942  {
943  if (dynamics_ == NULL) dynamics_ = new (zone()) DynamicScopePart(zone());
944  VariableMap* map = dynamics_->GetMap(mode);
945  Variable* var = map->Lookup(name);
946  if (var == NULL) {
947  // Declare a new non-local.
948  InitializationFlag init_flag = (mode == VAR)
950  var = map->Declare(NULL,
951  name,
952  mode,
953  true,
955  init_flag);
956  // Allocate it by giving it a dynamic lookup.
957  var->AllocateTo(Variable::LOOKUP, -1);
958  }
959  return var;
960 }
VariableMap * GetMap(VariableMode mode)
Definition: scopes.h:50
DynamicScopePart * dynamics_
Definition: scopes.h:445
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf map
@ kNeedsInitialization
Definition: globals.h:752

References v8::internal::Variable::AllocateTo(), dynamics_, v8::internal::DynamicScopePart::GetMap(), v8::internal::kCreatedInitialized, v8::internal::kNeedsInitialization, v8::internal::Variable::LOOKUP, map, mode(), name, v8::internal::Variable::NORMAL, NULL, v8::internal::VAR, and zone().

Referenced by ResolveVariable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ num_heap_slots()

int v8::internal::Scope::num_heap_slots ( ) const
inline

Definition at line 352 of file scopes.h.

352 { return num_heap_slots_; }

References num_heap_slots_.

Referenced by ContextLocalCount(), v8::internal::ScopeInfo::Create(), v8::internal::CompilationInfo::num_heap_slots(), and v8::internal::HOptimizedGraphBuilder::TryInline().

+ Here is the caller graph for this function:

◆ num_modules()

int v8::internal::Scope::num_modules ( ) const
inline

Definition at line 358 of file scopes.h.

358 { return num_modules_; }

References num_modules_.

Referenced by v8::internal::FullCodeGenerator::VisitDeclarations().

+ Here is the caller graph for this function:

◆ num_parameters()

◆ num_stack_slots()

int v8::internal::Scope::num_stack_slots ( ) const
inline

Definition at line 351 of file scopes.h.

351 { return num_stack_slots_; }

References num_stack_slots_.

Referenced by v8::internal::ScopeInfo::Create(), v8::internal::OptimizedCompileJob::CreateGraph(), and StackLocalCount().

+ Here is the caller graph for this function:

◆ num_var_or_const()

int v8::internal::Scope::num_var_or_const ( )
inline

Definition at line 348 of file scopes.h.

348 { return num_var_or_const_; }

References num_var_or_const_.

Referenced by FinalizeBlockScope().

+ Here is the caller graph for this function:

◆ outer_scope()

Scope* v8::internal::Scope::outer_scope ( ) const
inline

Definition at line 333 of file scopes.h.

333 { return outer_scope_; }

References outer_scope_.

Referenced by Analyze(), DeclarationScope(), FinalizeBlockScope(), GlobalScope(), Initialize(), Scope(), v8::internal::FunctionInfoListener::SerializeFunctionScope(), and SetDefaults().

+ Here is the caller graph for this function:

◆ outer_scope_calls_sloppy_eval()

bool v8::internal::Scope::outer_scope_calls_sloppy_eval ( ) const
inline

Definition at line 284 of file scopes.h.

284  {
286  }
bool outer_scope_calls_sloppy_eval_
Definition: scopes.h:482

References outer_scope_calls_sloppy_eval_.

Referenced by AllocateVariables(), and PropagateScopeInfo().

+ Here is the caller graph for this function:

◆ parameter()

Variable* v8::internal::Scope::parameter ( int  index) const
inline

Definition at line 316 of file scopes.h.

316  {
318  return params_[index];
319  }

References DCHECK, is_function_scope(), and params_.

Referenced by v8::internal::compiler::AstGraphBuilder::BuildLocalFunctionContext(), v8::internal::ScopeInfo::Create(), v8::internal::LCodeGen::GeneratePrologue(), and v8::internal::AstTyper::ObserveTypesAtOsrEntry().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PropagateScopeInfo()

void v8::internal::Scope::PropagateScopeInfo ( bool  outer_scope_calls_sloppy_eval)
protected

Definition at line 1156 of file scopes.cc.

1156  {
1159  }
1160 
1161  bool calls_sloppy_eval =
1163  for (int i = 0; i < inner_scopes_.length(); i++) {
1164  Scope* inner = inner_scopes_[i];
1165  inner->PropagateScopeInfo(calls_sloppy_eval);
1166  if (inner->scope_calls_eval_ || inner->inner_scope_calls_eval_) {
1167  inner_scope_calls_eval_ = true;
1168  }
1169  if (inner->force_eager_compilation_) {
1170  force_eager_compilation_ = true;
1171  }
1172  if (asm_module_ && inner->scope_type() == FUNCTION_SCOPE) {
1173  inner->asm_function_ = true;
1174  }
1175  }
1176 }

References asm_function_, asm_module_, calls_sloppy_eval(), force_eager_compilation_, v8::internal::FUNCTION_SCOPE, inner_scope_calls_eval_, inner_scopes_, outer_scope_calls_sloppy_eval(), outer_scope_calls_sloppy_eval_, PropagateScopeInfo(), scope_calls_eval_, and scope_type().

Referenced by AllocateVariables(), DeserializeScopeChain(), and PropagateScopeInfo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ receiver()

Variable* v8::internal::Scope::receiver ( )
inline

Definition at line 305 of file scopes.h.

305 { return receiver_; }

References receiver_.

Referenced by Initialize(), v8::internal::AstTyper::ObserveTypesAtOsrEntry(), and v8::internal::ParserTraits::ThisExpression().

+ Here is the caller graph for this function:

◆ RecordEvalCall()

void v8::internal::Scope::RecordEvalCall ( )
inline

Definition at line 212 of file scopes.h.

212 { if (!is_global_scope()) scope_calls_eval_ = true; }

References is_global_scope(), and scope_calls_eval_.

Referenced by v8::internal::ParserTraits::CheckPossibleEvalCall().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RecordWithStatement()

void v8::internal::Scope::RecordWithStatement ( )
inline

Definition at line 209 of file scopes.h.

209 { scope_contains_with_ = true; }

References scope_contains_with_.

Referenced by DeserializeScopeChain().

+ Here is the caller graph for this function:

◆ RemoveUnresolved()

void v8::internal::Scope::RemoveUnresolved ( VariableProxy *  var)

Definition at line 487 of file scopes.cc.

487  {
488  // Most likely (always?) any variable we want to remove
489  // was just added before, so we search backwards.
490  for (int i = unresolved_.length(); i-- > 0;) {
491  if (unresolved_[i] == var) {
493  return;
494  }
495  }
496 }
T Remove(int i)
Definition: list-inl.h:103

References v8::internal::List< T, AllocationPolicy >::Remove(), and unresolved_.

+ Here is the call graph for this function:

◆ ResolveVariable()

bool v8::internal::Scope::ResolveVariable ( CompilationInfo info,
VariableProxy *  proxy,
AstNodeFactory< AstNullVisitor > *  factory 
)
protected

Definition at line 1027 of file scopes.cc.

1029  {
1030  DCHECK(info->global_scope()->is_global_scope());
1031 
1032  // If the proxy is already resolved there's nothing to do
1033  // (functions and consts may be resolved by the parser).
1034  if (proxy->var() != NULL) return true;
1035 
1036  // Otherwise, try to resolve the variable.
1037  BindingKind binding_kind;
1038  Variable* var = LookupRecursive(proxy, &binding_kind, factory);
1039  switch (binding_kind) {
1040  case BOUND:
1041  // We found a variable binding.
1042  break;
1043 
1044  case BOUND_EVAL_SHADOWED:
1045  // We either found a variable binding that might be shadowed by eval or
1046  // gave up on it (e.g. by encountering a local with the same in the outer
1047  // scope which was not promoted to a context, this can happen if we use
1048  // debugger to evaluate arbitrary expressions at a break point).
1049  if (var->IsGlobalObjectProperty()) {
1050  var = NonLocal(proxy->raw_name(), DYNAMIC_GLOBAL);
1051  } else if (var->is_dynamic()) {
1052  var = NonLocal(proxy->raw_name(), DYNAMIC);
1053  } else {
1054  Variable* invalidated = var;
1055  var = NonLocal(proxy->raw_name(), DYNAMIC_LOCAL);
1056  var->set_local_if_not_shadowed(invalidated);
1057  }
1058  break;
1059 
1060  case UNBOUND:
1061  // No binding has been found. Declare a variable on the global object.
1062  var = info->global_scope()->DeclareDynamicGlobal(proxy->raw_name());
1063  break;
1064 
1065  case UNBOUND_EVAL_SHADOWED:
1066  // No binding has been found. But some scope makes a sloppy 'eval' call.
1067  var = NonLocal(proxy->raw_name(), DYNAMIC_GLOBAL);
1068  break;
1069 
1070  case DYNAMIC_LOOKUP:
1071  // The variable could not be resolved statically.
1072  var = NonLocal(proxy->raw_name(), DYNAMIC);
1073  break;
1074  }
1075 
1076  DCHECK(var != NULL);
1077  if (proxy->is_assigned()) var->set_maybe_assigned();
1078 
1079  if (FLAG_harmony_scoping && strict_mode() == STRICT &&
1080  var->is_const_mode() && proxy->is_assigned()) {
1081  // Assignment to const. Throw a syntax error.
1082  MessageLocation location(
1083  info->script(), proxy->position(), proxy->position());
1084  Isolate* isolate = info->isolate();
1085  Factory* factory = isolate->factory();
1086  Handle<JSArray> array = factory->NewJSArray(0);
1087  Handle<Object> error;
1088  MaybeHandle<Object> maybe_error =
1089  factory->NewSyntaxError("harmony_const_assign", array);
1090  if (maybe_error.ToHandle(&error)) isolate->Throw(*error, &location);
1091  return false;
1092  }
1093 
1094  if (FLAG_harmony_modules) {
1095  bool ok;
1096 #ifdef DEBUG
1097  if (FLAG_print_interface_details) {
1098  PrintF("# Resolve %.*s:\n", var->raw_name()->length(),
1099  var->raw_name()->raw_data());
1100  }
1101 #endif
1102  proxy->interface()->Unify(var->interface(), zone(), &ok);
1103  if (!ok) {
1104 #ifdef DEBUG
1105  if (FLAG_print_interfaces) {
1106  PrintF("SCOPES TYPE ERROR\n");
1107  PrintF("proxy: ");
1108  proxy->interface()->Print();
1109  PrintF("var: ");
1110  var->interface()->Print();
1111  }
1112 #endif
1113 
1114  // Inconsistent use of module. Throw a syntax error.
1115  // TODO(rossberg): generate more helpful error message.
1116  MessageLocation location(
1117  info->script(), proxy->position(), proxy->position());
1118  Isolate* isolate = info->isolate();
1119  Factory* factory = isolate->factory();
1120  Handle<JSArray> array = factory->NewJSArray(1);
1121  JSObject::SetElement(array, 0, var->name(), NONE, STRICT).Assert();
1122  Handle<Object> error;
1123  MaybeHandle<Object> maybe_error =
1124  factory->NewSyntaxError("module_type_error", array);
1125  if (maybe_error.ToHandle(&error)) isolate->Throw(*error, &location);
1126  return false;
1127  }
1128  }
1129 
1130  proxy->BindTo(var);
1131 
1132  return true;
1133 }
static MUST_USE_RESULT MaybeHandle< Object > SetElement(Handle< JSObject > object, uint32_t index, Handle< Object > value, PropertyAttributes attributes, StrictMode strict_mode, bool check_prototype=true, SetPropertyMode set_mode=SET_PROPERTY)
Definition: objects.cc:12336
Variable * NonLocal(const AstRawString *name, VariableMode mode)
Definition: scopes.cc:942
@ DYNAMIC_LOCAL
Definition: globals.h:693
@ NONE

References BOUND, BOUND_EVAL_SHADOWED, DCHECK, DeclareDynamicGlobal(), v8::internal::DYNAMIC, v8::internal::DYNAMIC_GLOBAL, v8::internal::DYNAMIC_LOCAL, DYNAMIC_LOOKUP, v8::internal::Isolate::factory(), v8::internal::CompilationInfo::global_scope(), v8::internal::Variable::interface(), v8::internal::Variable::is_const_mode(), v8::internal::Variable::is_dynamic(), is_global_scope(), v8::internal::Variable::IsGlobalObjectProperty(), v8::internal::CompilationInfo::isolate(), v8::internal::AstRawString::length(), LookupRecursive(), v8::internal::Variable::name(), NONE, NonLocal(), NULL, v8::internal::PrintF(), v8::internal::AstRawString::raw_data(), v8::internal::Variable::raw_name(), v8::internal::CompilationInfo::script(), v8::internal::Variable::set_local_if_not_shadowed(), v8::internal::Variable::set_maybe_assigned(), v8::internal::JSObject::SetElement(), v8::internal::STRICT, strict_mode(), v8::internal::Isolate::Throw(), UNBOUND, UNBOUND_EVAL_SHADOWED, and zone().

Referenced by ResolveVariablesRecursively().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ResolveVariablesRecursively()

bool v8::internal::Scope::ResolveVariablesRecursively ( CompilationInfo info,
AstNodeFactory< AstNullVisitor > *  factory 
)
protected

Definition at line 1136 of file scopes.cc.

1138  {
1139  DCHECK(info->global_scope()->is_global_scope());
1140 
1141  // Resolve unresolved variables for this scope.
1142  for (int i = 0; i < unresolved_.length(); i++) {
1143  if (!ResolveVariable(info, unresolved_[i], factory)) return false;
1144  }
1145 
1146  // Resolve unresolved variables for inner scopes.
1147  for (int i = 0; i < inner_scopes_.length(); i++) {
1148  if (!inner_scopes_[i]->ResolveVariablesRecursively(info, factory))
1149  return false;
1150  }
1151 
1152  return true;
1153 }
MUST_USE_RESULT bool ResolveVariable(CompilationInfo *info, VariableProxy *proxy, AstNodeFactory< AstNullVisitor > *factory)
Definition: scopes.cc:1027

References DCHECK, v8::internal::CompilationInfo::global_scope(), inner_scopes_, is_global_scope(), ResolveVariable(), and unresolved_.

Referenced by AllocateVariables().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ scope_type()

ScopeType v8::internal::Scope::scope_type ( ) const
inline

Definition at line 299 of file scopes.h.

299 { return scope_type_; }

References scope_type_.

Referenced by v8::internal::ScopeInfo::Create(), PropagateScopeInfo(), Scope(), and SetDefaults().

+ Here is the caller graph for this function:

◆ set_end_position()

void v8::internal::Scope::set_end_position ( int  statement_pos)
inline

◆ set_start_position()

void v8::internal::Scope::set_start_position ( int  statement_pos)
inline

Definition at line 243 of file scopes.h.

243  {
244  start_position_ = statement_pos;
245  }

References start_position_.

Referenced by v8::internal::Parser::ParseForStatement(), v8::internal::Parser::ParseFunctionLiteral(), v8::internal::Parser::ParseModuleLiteral(), v8::internal::Parser::ParseScopedBlock(), v8::internal::Parser::ParseSourceElements(), v8::internal::Parser::ParseTryStatement(), and v8::internal::Parser::ParseWithStatement().

+ Here is the caller graph for this function:

◆ SetAsmModule()

void v8::internal::Scope::SetAsmModule ( )
inline

Definition at line 218 of file scopes.h.

218 { asm_module_ = true; }

References asm_module_.

◆ SetDefaults()

void v8::internal::Scope::SetDefaults ( ScopeType  type,
Scope outer_scope,
Handle< ScopeInfo scope_info 
)
private

Definition at line 149 of file scopes.cc.

151  {
154  scope_name_ = ast_value_factory_->empty_string();
155  dynamics_ = NULL;
156  receiver_ = NULL;
157  function_ = NULL;
158  arguments_ = NULL;
160  scope_inside_with_ = false;
161  scope_contains_with_ = false;
162  scope_calls_eval_ = false;
163  asm_module_ = false;
165  // Inherit the strict mode from the parent scope.
168  inner_scope_calls_eval_ = false;
169  force_eager_compilation_ = false;
172  num_var_or_const_ = 0;
173  num_stack_slots_ = 0;
174  num_heap_slots_ = 0;
175  num_modules_ = 0;
176  module_var_ = NULL,
177  scope_info_ = scope_info;
180  if (!scope_info.is_null()) {
181  scope_calls_eval_ = scope_info->CallsEval();
182  strict_mode_ = scope_info->strict_mode();
183  }
184 }
const AstRawString * scope_name_
Definition: scopes.h:430

References arguments_, asm_function_, asm_module_, ast_value_factory_, dynamics_, end_position_, force_context_allocation_, force_eager_compilation_, function_, has_forced_context_allocation(), illegal_redecl_, inner_scope_calls_eval_, is_function_scope(), v8::internal::Handle< T >::is_null(), v8::internal::RelocInfo::kNoPosition, module_var_, NULL, num_heap_slots_, num_modules_, num_stack_slots_, num_var_or_const_, outer_scope(), outer_scope_, outer_scope_calls_sloppy_eval_, receiver_, scope_calls_eval_, scope_contains_with_, scope_info_, scope_inside_with_, scope_name_, scope_type(), scope_type_, v8::internal::SLOPPY, start_position_, and strict_mode_.

Referenced by Scope().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetIllegalRedeclaration()

void v8::internal::Scope::SetIllegalRedeclaration ( Expression expression)

Definition at line 530 of file scopes.cc.

530  {
531  // Record only the first illegal redeclaration.
532  if (!HasIllegalRedeclaration()) {
533  illegal_redecl_ = expression;
534  }
536 }

References DCHECK, HasIllegalRedeclaration(), and illegal_redecl_.

Referenced by v8::internal::Parser::Declare().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetScopeName()

void v8::internal::Scope::SetScopeName ( const AstRawString scope_name)
inline

Definition at line 87 of file scopes.h.

87  {
88  scope_name_ = scope_name;
89  }

References scope_name_.

◆ SetStrictMode()

void v8::internal::Scope::SetStrictMode ( StrictMode  strict_mode)
inline

Definition at line 215 of file scopes.h.

References strict_mode(), and strict_mode_.

Referenced by v8::internal::Parser::ParseLazy(), and v8::internal::Parser::ParseModuleLiteral().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ StackLocalCount()

int v8::internal::Scope::StackLocalCount ( ) const

Definition at line 1399 of file scopes.cc.

1399  {
1400  return num_stack_slots() -
1401  (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0);
1402 }
int num_stack_slots() const
Definition: scopes.h:351

References function_, NULL, and num_stack_slots().

Referenced by v8::internal::ScopeInfo::Create(), v8::internal::AstTyper::ObserveTypesAtOsrEntry(), and v8::internal::FunctionInfoListener::SerializeFunctionScope().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ start_position()

int v8::internal::Scope::start_position ( ) const
inline

Definition at line 242 of file scopes.h.

242 { return start_position_; }

References start_position_.

Referenced by GetNestedScopeChain(), and v8::internal::Parser::ParseFunctionLiteral().

+ Here is the caller graph for this function:

◆ strict_mode()

StrictMode v8::internal::Scope::strict_mode ( ) const
inline

Definition at line 302 of file scopes.h.

302 { return strict_mode_; }

References strict_mode_.

Referenced by AllocateParameterLocals(), v8::internal::ScopeInfo::Create(), v8::internal::Parser::Declare(), v8::internal::Parser::ParseFunctionLiteral(), v8::internal::Parser::ParseLazy(), v8::internal::Parser::ParseVariableDeclarations(), ResolveVariable(), and SetStrictMode().

+ Here is the caller graph for this function:

◆ VisitIllegalRedeclaration()

void v8::internal::Scope::VisitIllegalRedeclaration ( AstVisitor visitor)

Definition at line 539 of file scopes.cc.

539  {
541  illegal_redecl_->Accept(visitor);
542 }
virtual void Accept(AstVisitor *v)=0

References v8::internal::AstNode::Accept(), DCHECK, HasIllegalRedeclaration(), and illegal_redecl_.

+ Here is the call graph for this function:

◆ zone()

Zone* v8::internal::Scope::zone ( ) const
inline

Definition at line 98 of file scopes.h.

98 { return zone_; }

References zone_.

Referenced by AddDeclaration(), AllocateNonParameterLocals(), CollectStackAndContextLocals(), DeclareParameter(), DeserializeScopeChain(), FinalizeBlockScope(), GetScopeInfo(), Initialize(), LookupFunctionVar(), NewInternal(), NewTemporary(), NonLocal(), and ResolveVariable().

+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ ParserFactory

friend class ParserFactory
friend

Definition at line 418 of file scopes.h.

Member Data Documentation

◆ already_resolved_

bool v8::internal::Scope::already_resolved_
protected

Definition at line 489 of file scopes.h.

Referenced by already_resolved().

◆ arguments_

Variable* v8::internal::Scope::arguments_
protected

Definition at line 455 of file scopes.h.

Referenced by AllocateParameterLocals(), arguments(), and SetDefaults().

◆ asm_function_

bool v8::internal::Scope::asm_function_
protected

Definition at line 474 of file scopes.h.

Referenced by asm_function(), DeserializeScopeChain(), PropagateScopeInfo(), and SetDefaults().

◆ asm_module_

bool v8::internal::Scope::asm_module_
protected

◆ ast_value_factory_

AstValueFactory* v8::internal::Scope::ast_value_factory_
private

◆ decls_

ZoneList<Declaration*> v8::internal::Scope::decls_
protected

Definition at line 449 of file scopes.h.

Referenced by AddDeclaration(), CheckConflictingVarDeclarations(), and declarations().

◆ dynamics_

DynamicScopePart* v8::internal::Scope::dynamics_
protected

Definition at line 445 of file scopes.h.

Referenced by NonLocal(), and SetDefaults().

◆ end_position_

int v8::internal::Scope::end_position_
protected

Definition at line 479 of file scopes.h.

Referenced by end_position(), set_end_position(), and SetDefaults().

◆ force_context_allocation_

bool v8::internal::Scope::force_context_allocation_
protected

Definition at line 485 of file scopes.h.

Referenced by ForceContextAllocation(), has_forced_context_allocation(), and SetDefaults().

◆ force_eager_compilation_

bool v8::internal::Scope::force_eager_compilation_
protected

◆ function_

VariableDeclaration* v8::internal::Scope::function_
protected

◆ illegal_redecl_

Expression* v8::internal::Scope::illegal_redecl_
protected

◆ inner_scope_calls_eval_

bool v8::internal::Scope::inner_scope_calls_eval_
protected

Definition at line 483 of file scopes.h.

Referenced by MustAllocate(), MustAllocateInContext(), PropagateScopeInfo(), and SetDefaults().

◆ inner_scopes_

◆ interface_

Interface* v8::internal::Scope::interface_
protected

Definition at line 457 of file scopes.h.

Referenced by AllocateModulesRecursively(), and interface().

◆ internals_

ZoneList<Variable*> v8::internal::Scope::internals_
protected

◆ isolate_

Isolate* const v8::internal::Scope::isolate_
protected

Definition at line 420 of file scopes.h.

Referenced by AllocateNonParameterLocal(), and HasArgumentsParameter().

◆ module_var_

Variable* v8::internal::Scope::module_var_
protected

Definition at line 502 of file scopes.h.

Referenced by AllocateModulesRecursively(), module_var(), and SetDefaults().

◆ num_heap_slots_

int v8::internal::Scope::num_heap_slots_
protected

◆ num_modules_

int v8::internal::Scope::num_modules_
protected

Definition at line 499 of file scopes.h.

Referenced by AllocateModulesRecursively(), AllocateVariables(), num_modules(), and SetDefaults().

◆ num_stack_slots_

int v8::internal::Scope::num_stack_slots_
protected

◆ num_var_or_const_

int v8::internal::Scope::num_var_or_const_
protected

Definition at line 492 of file scopes.h.

Referenced by DeclareLocal(), num_var_or_const(), Scope(), and SetDefaults().

◆ outer_scope_

◆ outer_scope_calls_sloppy_eval_

bool v8::internal::Scope::outer_scope_calls_sloppy_eval_
protected

Definition at line 482 of file scopes.h.

Referenced by outer_scope_calls_sloppy_eval(), PropagateScopeInfo(), and SetDefaults().

◆ params_

ZoneList<Variable*> v8::internal::Scope::params_
protected

◆ receiver_

Variable* v8::internal::Scope::receiver_
protected

Definition at line 451 of file scopes.h.

Referenced by Initialize(), receiver(), and SetDefaults().

◆ scope_calls_eval_

bool v8::internal::Scope::scope_calls_eval_
protected

◆ scope_contains_with_

bool v8::internal::Scope::scope_contains_with_
protected

◆ scope_info_

Handle<ScopeInfo> v8::internal::Scope::scope_info_
protected

Definition at line 505 of file scopes.h.

Referenced by GetScopeInfo(), LookupFunctionVar(), LookupLocal(), Scope(), and SetDefaults().

◆ scope_inside_with_

bool v8::internal::Scope::scope_inside_with_
protected

Definition at line 465 of file scopes.h.

Referenced by HasTrivialOuterContext(), Initialize(), inside_with(), and SetDefaults().

◆ scope_name_

const AstRawString* v8::internal::Scope::scope_name_
protected

Definition at line 430 of file scopes.h.

Referenced by SetDefaults(), and SetScopeName().

◆ scope_type_

ScopeType v8::internal::Scope::scope_type_
protected

◆ start_position_

int v8::internal::Scope::start_position_
protected

Definition at line 478 of file scopes.h.

Referenced by set_start_position(), SetDefaults(), and start_position().

◆ strict_mode_

StrictMode v8::internal::Scope::strict_mode_
protected

◆ temps_

ZoneList<Variable*> v8::internal::Scope::temps_
protected

◆ unresolved_

ZoneList<VariableProxy*> v8::internal::Scope::unresolved_
protected

◆ variables_

◆ zone_

Zone* v8::internal::Scope::zone_
private

Definition at line 624 of file scopes.h.

Referenced by AddInnerScope(), NewUnresolved(), and zone().


The documentation for this class was generated from the following files: