44 if (p->value ==
NULL) {
47 p->value =
new (
zone())
49 maybe_assigned_flag, interface);
51 return reinterpret_cast<Variable*
>(p->value);
61 return reinterpret_cast<Variable*
>(p->value);
72 : isolate_(zone->isolate()),
73 inner_scopes_(4, zone),
78 unresolved_(16, zone),
80 interface_(FLAG_harmony_modules &&
83 already_resolved_(
false),
84 ast_value_factory_(ast_value_factory),
98 : isolate_(zone->isolate()),
99 inner_scopes_(4, zone),
104 unresolved_(16, zone),
107 already_resolved_(
true),
108 ast_value_factory_(value_factory),
123 : isolate_(zone->isolate()),
124 inner_scopes_(1, zone),
129 unresolved_(0, zone),
132 already_resolved_(
true),
133 ast_value_factory_(value_factory),
200 current_scope = with_scope;
203 for (
Scope* s = innermost_scope; s !=
NULL; s = s->outer_scope()) {
204 s->scope_inside_with_ =
true;
208 current_scope =
new(
zone)
Scope(current_scope,
214 ScopeInfo* scope_info = ScopeInfo::cast(context->
module()->scope_info());
215 current_scope =
new(
zone)
Scope(current_scope,
222 current_scope =
new(
zone)
Scope(current_scope,
231 current_scope =
new(
zone)
Scope(current_scope,
245 if (innermost_scope ==
NULL) innermost_scope = current_scope;
256 return (innermost_scope ==
NULL) ? global_scope : innermost_scope;
281 ? FLAG_print_builtin_scopes
282 : FLAG_print_scopes) {
286 if (FLAG_harmony_modules && FLAG_print_interfaces && top->
is_global_scope()) {
394 &init_flag, &maybe_assigned_flag);
398 if (index < 0)
return NULL;
410 init_flag, maybe_assigned_flag);
424 if (index < 0)
return NULL;
428 VariableProxy* proxy = factory->NewVariableProxy(var);
429 VariableDeclaration* declaration = factory->NewVariableDeclaration(
441 for (
Scope* scope =
this;
443 scope = scope->outer_scope()) {
445 if (var !=
NULL)
return var;
546 int length =
decls_.length();
547 for (
int i = 0;
i < length;
i++) {
549 if (decl->
mode() !=
VAR)
continue;
558 if (other_var !=
NULL && other_var->
mode() !=
VAR) {
594 context_locals->
Add(var,
zone());
600 for (
int i = 0;
i <
temps_.length();
i++) {
605 context_locals->
Add(var,
zone());
608 stack_locals->
Add(var,
zone());
624 int var_count = vars.length();
625 for (
int i = 0;
i < var_count;
i++) {
628 stack_locals->
Add(var,
zone());
630 context_locals->
Add(var,
zone());
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;
679 if (outer ==
NULL)
return true;
689 if (outer ==
NULL)
return true;
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;
719 if (s->is_with_scope() || s->num_heap_slots() > 0) n++;
721 DCHECK(!s->is_catch_scope() || s->num_heap_slots() > 0);
722 DCHECK(!s->is_module_scope() || s->num_heap_slots() > 0);
763 DCHECK(beg_pos >= 0 && end_pos >= 0);
764 if (beg_pos <= position && position < end_pos) {
773 static const char* Header(
ScopeType scope_type) {
774 switch (scope_type) {
788 static void Indent(
int n,
const char* str) {
789 PrintF(
"%*s%s", n,
"", str);
793 static void PrintName(
const AstRawString*
name) {
798 static void PrintLocation(Variable* var) {
799 switch (var->location()) {
803 PrintF(
"parameter[%d]", var->index());
806 PrintF(
"local[%d]", var->index());
809 PrintF(
"context[%d]", var->index());
818 static void PrintVar(
int indent, Variable* var) {
819 if (var->is_used() || !var->IsUnallocated()) {
822 PrintName(var->raw_name());
825 bool comma = !var->IsUnallocated();
826 if (var->has_forced_context_allocation()) {
828 PrintF(
"forced context allocation");
840 static void PrintMap(
int indent, VariableMap*
map) {
841 for (VariableMap::Entry* p =
map->Start(); p !=
NULL; p =
map->Next(p)) {
842 Variable* var =
reinterpret_cast<Variable*
>(p->value);
843 PrintVar(indent, var);
848 void Scope::Print(
int n) {
849 int n0 = (n > 0 ? n : 0);
873 Indent(n1,
"// (local) function name: ");
874 PrintName(
function_->proxy()->raw_name());
880 Indent(n1,
"// scope has trivial outer context\n");
883 Indent(n1,
"// strict mode scope\n");
889 Indent(n1,
"// outer scope calls 'eval' in sloppy context\n");
899 Indent(n1,
"// function var:\n");
903 if (
temps_.length() > 0) {
904 Indent(n1,
"// temporary vars:\n");
905 for (
int i = 0;
i <
temps_.length();
i++) {
911 Indent(n1,
"// internal vars:\n");
918 Indent(n1,
"// local vars:\n");
923 Indent(n1,
"// dynamic vars:\n");
981 *binding_kind =
BOUND;
991 *binding_kind =
BOUND;
1017 if (*binding_kind ==
BOUND) {
1019 }
else if (*binding_kind ==
UNBOUND) {
1028 VariableProxy* proxy,
1034 if (proxy->var() !=
NULL)
return true;
1039 switch (binding_kind) {
1083 info->
script(), proxy->position(), proxy->position());
1085 Factory* factory = isolate->
factory();
1089 factory->NewSyntaxError(
"harmony_const_assign", array);
1090 if (maybe_error.ToHandle(&error)) isolate->
Throw(*error, &location);
1094 if (FLAG_harmony_modules) {
1097 if (FLAG_print_interface_details) {
1105 if (FLAG_print_interfaces) {
1106 PrintF(
"SCOPES TYPE ERROR\n");
1108 proxy->interface()->Print();
1117 info->
script(), proxy->position(), proxy->position());
1119 Factory* factory = isolate->
factory();
1124 factory->NewSyntaxError(
"module_type_error", array);
1125 if (maybe_error.ToHandle(&error)) isolate->
Throw(*error, &location);
1248 bool uses_sloppy_arguments =
false;
1274 for (
int i =
params_.length() - 1;
i >= 0; --
i) {
1315 for (
int i = 0;
i <
temps_.length();
i++) {
1331 int var_count = vars.length();
1332 for (
int i = 0;
i < var_count;
i++) {
virtual void Accept(AstVisitor *v)=0
const unsigned char * raw_data() const
virtual int length() const OVERRIDE
const AstRawString * GetString(Handle< String > literal)
AstNode::IdGen * ast_node_id_gen()
void PrepareForCompilation(Scope *scope)
Scope * global_scope() const
Handle< Script > script() const
AstValueFactory * ast_value_factory() const
FunctionLiteral * function() const
Isolate * isolate() const
VariableMode mode() const
VariableProxy * proxy() const
VariableMap * GetMap(VariableMode mode)
Object * Throw(Object *exception, MessageLocation *location=NULL)
Bootstrapper * bootstrapper()
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)
void Add(const T &element, AllocationPolicy allocator=AllocationPolicy())
void Sort(int(*cmp)(const T *x, const T *y))
static const int kNoPosition
static int ContextSlotIndex(Handle< ScopeInfo > scope_info, Handle< String > name, VariableMode *mode, InitializationFlag *init_flag, MaybeAssignedFlag *maybe_assigned_flag)
static Handle< ScopeInfo > Create(Scope *scope, Zone *zone)
int ContextLocalCount() const
void SetDefaults(ScopeType type, Scope *outer_scope, Handle< ScopeInfo > scope_info)
void AllocateNonParameterLocal(Variable *var)
int num_heap_slots() const
void AllocateHeapSlot(Variable *var)
bool outer_scope_calls_sloppy_eval_
bool contains_with() const
bool is_global_scope() const
bool AllowsLazyCompilationWithoutContext() const
Variable * LookupFunctionVar(const AstRawString *name, AstNodeFactory< AstNullVisitor > *factory)
ZoneList< Variable * > temps_
MUST_USE_RESULT bool AllocateVariables(CompilationInfo *info, AstNodeFactory< AstNullVisitor > *factory)
bool force_eager_compilation_
static bool Analyze(CompilationInfo *info)
Variable * Lookup(const AstRawString *name)
void DeclareFunctionVar(VariableDeclaration *declaration)
const AstRawString * scope_name_
ZoneList< VariableProxy * > unresolved_
void AllocateParameterLocals()
Handle< ScopeInfo > scope_info_
Scope * outer_scope() const
bool HasTrivialOuterContext() const
Variable * DeclareDynamicGlobal(const AstRawString *name)
Variable * DeclareLocal(const AstRawString *name, VariableMode mode, InitializationFlag init_flag, MaybeAssignedFlag maybe_assigned_flag=kNotAssigned, Interface *interface=Interface::NewValue())
void AllocateNonParameterLocals()
Variable * LookupRecursive(VariableProxy *proxy, BindingKind *binding_kind, AstNodeFactory< AstNullVisitor > *factory)
bool HasLazyCompilableOuterContext() const
int ContextChainLength(Scope *scope)
ZoneList< Scope * > inner_scopes_
bool HasTrivialContext() const
void AllocateVariablesRecursively()
Variable * NewInternal(const AstRawString *name)
void AddInnerScope(Scope *inner_scope)
void PropagateScopeInfo(bool outer_scope_calls_sloppy_eval)
ZoneList< Variable * > params_
bool HasIllegalRedeclaration() const
bool is_eval_scope() const
void SetIllegalRedeclaration(Expression *expression)
void CollectStackAndContextLocals(ZoneList< Variable * > *stack_locals, ZoneList< Variable * > *context_locals)
bool is_function_scope() const
ZoneList< Declaration * > decls_
ScopeType scope_type() const
bool AllowsLazyCompilation() const
void AllocateStackSlot(Variable *var)
MUST_USE_RESULT bool ResolveVariable(CompilationInfo *info, VariableProxy *proxy, AstNodeFactory< AstNullVisitor > *factory)
bool MustAllocateInContext(Variable *var)
bool outer_scope_calls_sloppy_eval() const
void VisitIllegalRedeclaration(AstVisitor *visitor)
bool HasArgumentsParameter()
void AllocateModulesRecursively(Scope *host_scope)
void RemoveUnresolved(VariableProxy *var)
Variable * NonLocal(const AstRawString *name, VariableMode mode)
ZoneList< Variable * > internals_
Scope * DeclarationScope()
Variable * arguments() const
Expression * illegal_redecl_
Variable * NewTemporary(const AstRawString *name)
DynamicScopePart * dynamics_
bool inner_scope_calls_eval_
bool is_with_scope() const
bool scope_contains_with_
AstValueFactory * ast_value_factory_
Scope(Scope *outer_scope, ScopeType scope_type, AstValueFactory *value_factory, Zone *zone)
bool is_block_scope() const
Scope * FinalizeBlockScope()
int num_stack_slots() const
StrictMode strict_mode() const
Declaration * CheckConflictingVarDeclarations()
bool has_forced_context_allocation() const
bool MustAllocate(Variable *var)
Variable * DeclareParameter(const AstRawString *name, VariableMode mode)
VariableDeclaration * function_
Interface * interface() const
void RecordWithStatement()
bool force_context_allocation_
Handle< ScopeInfo > GetScopeInfo()
void AddDeclaration(Declaration *declaration)
static Scope * DeserializeScopeChain(Context *context, Scope *global_scope, Zone *zone)
bool is_catch_scope() const
int start_position() const
bool is_module_scope() const
void GetNestedScopeChain(List< Handle< ScopeInfo > > *chain, int statement_position)
MUST_USE_RESULT bool ResolveVariablesRecursively(CompilationInfo *info, AstNodeFactory< AstNullVisitor > *factory)
int StackLocalCount() const
bool is_declaration_scope() const
Variable * LookupLocal(const AstRawString *name)
Entry * Next(Entry *p) const
uint32_t occupancy() const
Entry * Lookup(void *key, uint32_t hash, bool insert, ZoneAllocationPolicy allocator=ZoneAllocationPolicy())
static int Compare(const VarAndOrder *a, const VarAndOrder *b)
VarAndOrder(Variable *var, int order)
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())
Variable * Lookup(const AstRawString *name)
Handle< String > name() const
static const char * Mode2String(VariableMode mode)
void set_maybe_assigned()
VariableMode mode() const
bool is_const_mode() const
Interface * interface() const
bool IsVariable(Handle< String > n) const
void AllocateTo(Location location, int index)
void set_local_if_not_shadowed(Variable *local)
bool has_forced_context_allocation() const
bool IsGlobalObjectProperty() const
bool IsStackLocal() const
const AstRawString * raw_name() const
void ForceContextAllocation()
bool IsContextSlot() const
bool IsUnallocated() const
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
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
enable harmony numeric enable harmony object literal extensions true
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
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)
bool IsLexicalVariableMode(VariableMode mode)
bool IsDeclaredVariableMode(VariableMode mode)
static LifetimePosition Max(LifetimePosition a, LifetimePosition b)
void PrintF(const char *format,...)
Debugger support for the V8 JavaScript engine.