52 static bool Match(
void* key1,
void* key2) {
53 String* name1 = *
reinterpret_cast<String**
>(key1);
54 String* name2 = *
reinterpret_cast<String**
>(key2);
57 return name1 == name2;
77 if (p->value ==
NULL) {
88 return reinterpret_cast<Variable*
>(p->value);
96 ASSERT(*reinterpret_cast<String**>(p->key) == *name);
98 return reinterpret_cast<Variable*
>(p->value);
108 : isolate_(
Isolate::Current()),
109 inner_scopes_(4, zone),
113 unresolved_(16, zone),
115 interface_(FLAG_harmony_modules &&
118 already_resolved_(
false),
131 : isolate_(
Isolate::Current()),
132 inner_scopes_(4, zone),
136 unresolved_(16, zone),
139 already_resolved_(
true),
141 SetDefaults(type,
NULL, scope_info);
148 AddInnerScope(inner_scope);
152 Scope::Scope(Scope* inner_scope, Handle<String> catch_variable_name, Zone* zone)
153 : isolate_(Isolate::Current()),
154 inner_scopes_(1, zone),
158 unresolved_(0, zone),
161 already_resolved_(
true),
164 AddInnerScope(inner_scope);
179 Handle<ScopeInfo> scope_info) {
203 if (!scope_info.is_null()) {
216 while (!context->IsNativeContext()) {
222 current_scope = with_scope;
224 contains_with =
true;
225 for (
Scope* s = innermost_scope; s !=
NULL; s = s->outer_scope()) {
230 current_scope =
new(
zone)
Scope(current_scope,
236 current_scope =
new(
zone)
Scope(current_scope,
242 current_scope =
new(
zone)
Scope(current_scope,
248 current_scope =
new(
zone)
Scope(current_scope,
259 if (innermost_scope ==
NULL) innermost_scope = current_scope;
263 contains_with =
false;
268 global_scope->AddInnerScope(current_scope);
270 return (innermost_scope ==
NULL) ? global_scope : innermost_scope;
295 ? FLAG_print_builtin_scopes
296 : FLAG_print_scopes) {
300 if (FLAG_harmony_modules && FLAG_print_interfaces && top->
is_global_scope()) {
306 if (FLAG_harmony_scoping) {
314 Factory* factory = isolate->factory();
318 isolate->Throw(*result, &location);
418 int index =
scope_info_->ContextSlotIndex(*name, &mode, &init_flag);
422 if (index < 0)
return NULL;
443 int index =
scope_info_->FunctionContextSlotIndex(*name, &mode);
444 if (index < 0)
return NULL;
446 this, name, mode,
true ,
450 factory->NewVariableDeclaration(proxy, mode,
this);
461 for (
Scope* scope =
this;
463 scope = scope->outer_scope()) {
464 Variable* var = scope->LocalLookup(name);
465 if (var !=
NULL)
return var;
552 int length =
decls_.length();
553 for (
int i = 0; i < length; i++) {
555 if (decl->
mode() !=
VAR)
continue;
564 if (other_var !=
NULL && other_var->
mode() !=
VAR) {
590 if (proxy !=
NULL)
return proxy;
602 int order()
const {
return order_; }
604 return a->order_ - b->order_;
619 for (
int i = 0; i <
temps_.length(); i++) {
623 stack_locals->
Add(var,
zone());
639 int var_count = vars.length();
640 for (
int i = 0; i < var_count; i++) {
643 stack_locals->
Add(var,
zone());
645 context_locals->
Add(var,
zone());
656 outer_scope_calls_non_strict_eval =
683 for (
const Scope* scope =
this; scope !=
NULL; scope = scope->outer_scope_) {
684 if (scope->is_eval_scope())
return false;
685 if (scope->scope_inside_with_)
return false;
686 if (scope->num_heap_slots_ > 0)
return false;
694 if (outer ==
NULL)
return true;
704 if (outer ==
NULL)
return true;
713 bool found_non_trivial_declarations =
false;
714 for (
const Scope* scope = outer; scope !=
NULL; scope = scope->outer_scope_) {
715 if (scope->is_eval_scope())
return false;
716 if (scope->is_with_scope() && !found_non_trivial_declarations)
return false;
717 if (scope->is_declaration_scope() && scope->num_heap_slots() > 0) {
718 found_non_trivial_declarations =
true;
739 if (s->num_heap_slots() > 0) n++;
771 ASSERT(beg_pos >= 0 && end_pos >= 0);
772 if (beg_pos <= position && position < end_pos) {
781 static const char* Header(
ScopeType type) {
796 static void Indent(
int n,
const char* str) {
797 PrintF(
"%*s%s", n,
"", str);
801 static void PrintName(Handle<String> name) {
807 static void PrintLocation(Variable* var) {
808 switch (var->location()) {
812 PrintF(
"parameter[%d]", var->index());
815 PrintF(
"local[%d]", var->index());
818 PrintF(
"context[%d]", var->index());
827 static void PrintVar(
int indent, Variable* var) {
828 if (var->is_used() || !var->IsUnallocated()) {
831 PrintName(var->name());
834 if (var->has_forced_context_allocation()) {
835 if (!var->IsUnallocated())
PrintF(
", ");
836 PrintF(
"forced context allocation");
843 static void PrintMap(
int indent, VariableMap* map) {
844 for (VariableMap::Entry* p = map->Start(); p !=
NULL; p = map->Next(p)) {
845 Variable* var =
reinterpret_cast<Variable*
>(p->value);
846 PrintVar(indent, var);
852 int n0 = (n > 0 ? n : 0);
856 Indent(n0, Header(
type_));
865 for (
int i = 0; i <
params_.length(); i++) {
876 Indent(n1,
"// (local) function name: ");
883 Indent(n1,
"// scope has trivial outer context\n");
889 Indent(n1,
"// strict mode scope\n");
892 Indent(n1,
"// extended mode scope\n");
899 Indent(n1,
"// outer scope calls 'eval' in non-strict context\n");
908 Indent(n1,
"// function var\n");
913 Indent(n1,
"// temporary vars\n");
914 for (
int i = 0; i <
temps_.length(); i++) {
918 Indent(n1,
"// local vars\n");
921 Indent(n1,
"// dynamic vars\n");
973 *binding_kind =
BOUND;
983 *binding_kind =
BOUND;
1007 if (*binding_kind ==
BOUND) {
1009 }
else if (*binding_kind ==
UNBOUND) {
1024 if (proxy->
var() !=
NULL)
return true;
1029 switch (binding_kind) {
1070 if (FLAG_harmony_modules) {
1073 if (FLAG_print_interface_details)
1074 PrintF(
"# Resolve %s:\n", var->
name()->ToAsciiArray());
1079 if (FLAG_print_interfaces) {
1080 PrintF(
"SCOPES TYPE ERROR\n");
1093 Isolate* isolate = Isolate::Current();
1094 Factory* factory = isolate->factory();
1099 isolate->Throw(*result, &location);
1129 if (outer_scope_calls_non_strict_eval) {
1153 if ((var->
is_this() || var->
name()->length() > 0) &&
1188 for (
int i = 0; i <
params_.length(); i++) {
1189 if (
params_[i]->name().is_identical_to(
1213 bool uses_nonstrict_arguments =
false;
1239 for (
int i =
params_.length() - 1; i >= 0; --i) {
1242 if (uses_nonstrict_arguments) {
1280 for (
int i = 0; i <
temps_.length(); i++) {
1294 int var_count = vars.length();
1295 for (
int i = 0; i < var_count; i++) {
1371 context->set_module(*instance);
1400 !it.
done(); it.Advance()) {
1401 if (it.interface()->IsModule()) {
1405 instance, it.name(), value, ro_attr,
kStrictMode);
1413 ASSERT(!(result.is_null() || result->IsUndefined()));
bool is_global_scope() const
void AllocateTo(Location location, int index)
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if expose natives in global object expose gc extension number of stack frames to capture disable builtin natives files print a stack trace if an assertion failure occurs use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations prepare for turning on always opt minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions automatically set the debug break flag when debugger commands are in the queue always cause a debug break before aborting maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print more details following each garbage collection print amount of external allocated memory after each time it is adjusted flush code that we expect not to use again before full gc do incremental marking steps track object counts and memory usage use caching Perform compaction on every full GC Never perform compaction on full GC testing only Compact code space on full incremental collections Default seed for initializing random allows verbose printing trace parsing and preparsing Check icache flushes in ARM and MIPS simulator Stack alingment in bytes in print stack trace when throwing exceptions randomize hashes to avoid predictable hash Fixed seed to use to hash property activate a timer that switches between V8 threads testing_bool_flag float flag Seed used for threading test randomness A filename with extra code to be included in the Print usage including on console Map counters to a file Enable debugger compile events enable GDBJIT interface(disables compacting GC)") DEFINE_bool(gdbjit_full
Scope * DeclarationScope()
bool scope_contains_with_
static Handle< Object > SetProperty(Handle< JSReceiver > object, Handle< String > key, Handle< Object > value, PropertyAttributes attributes, StrictModeFlag strict_mode)
Declaration * CheckConflictingVarDeclarations()
Handle< Context > NewModuleContext(Handle< ScopeInfo > scope_info)
void PrintF(const char *format,...)
void ForceContextAllocation()
static String * cast(Object *obj)
Handle< ScopeInfo > GetScopeInfo()
void SetScope(Scope *scope)
ZoneList< Scope * > inner_scopes_
bool force_eager_compilation_
VarAndOrder(Variable *var, int order)
void CollectStackAndContextLocals(ZoneList< Variable * > *stack_locals, ZoneList< Variable * > *context_locals)
bool outer_scope_calls_non_strict_eval() const
Scope * FinalizeBlockScope()
Handle< JSArray > NewJSArray(int capacity, ElementsKind elements_kind=TERMINAL_FAST_ELEMENTS_KIND, PretenureFlag pretenure=NOT_TENURED)
Handle< Script > script() const
static bool Analyze(CompilationInfo *info)
Scope * outer_scope() const
bool HasIllegalRedeclaration() const
bool is_identical_to(const Handle< T > other) const
ZoneList< VariableProxy * > unresolved_
Expression * illegal_redecl_
void set_local_if_not_shadowed(Variable *local)
bool is_classic_mode() const
Bootstrapper * bootstrapper()
Handle< String > scope_name_
void DeclareParameter(Handle< String > name, VariableMode mode)
Handle< Object > SetAccessor(Handle< JSObject > obj, Handle< AccessorInfo > info)
VariableProxy * CheckAssignmentToConst()
bool HasTrivialContext() const
#define ASSERT(condition)
v8::Handle< v8::Value > Print(const v8::Arguments &args)
Variable * NewTemporary(Handle< String > name)
MUST_USE_RESULT MaybeObject * PreventExtensions()
bool is_const_mode() const
Interface * interface() const
VariableMap * GetMap(VariableMode mode)
VariableDeclaration * function_
Variable * LookupRecursive(Handle< String > name, BindingKind *binding_kind, AstNodeFactory< AstNullVisitor > *factory)
LanguageMode language_mode_
Handle< String > name() const
bool outer_scope_calls_non_strict_eval_
void Unify(Interface *that, Zone *zone, bool *ok)
bool is_block_scope() const
Handle< Object > NewSyntaxError(const char *type, Handle< JSArray > args)
Handle< String > name() const
static Handle< ScopeInfo > Create(Scope *scope, Zone *zone)
bool MustAllocateInContext(Variable *var)
ZoneList< Declaration * > decls_
Handle< ScopeInfo > scope_info_
void MakeSingleton(Handle< JSModule > instance, bool *ok)
int ContextChainLength(Scope *scope)
static ScopeInfo * cast(Object *object)
bool HasTrivialOuterContext() const
Iterator iterator() const
bool AllowsLazyCompilation() const
void DeclareFunctionVar(VariableDeclaration *declaration)
void AllocateNonParameterLocal(Variable *var)
static int Compare(const VarAndOrder *a, const VarAndOrder *b)
void AllocateModules(CompilationInfo *info)
int start_position() const
Variable * DeclareLocal(Handle< String > name, VariableMode mode, InitializationFlag init_flag, Interface *interface=Interface::NewValue())
VariableProxy * proxy() const
void AllocateVariablesRecursively()
VariableMode mode() const
bool is_eval_scope() const
bool HasArgumentsParameter()
Variable * arguments() const
int num_stack_slots() const
bool has_forced_context_allocation() const
void GetNestedScopeChain(List< Handle< ScopeInfo > > *chain, int statement_position)
void AllocateHeapSlot(Variable *var)
uint32_t occupancy() const
bool PropagateScopeInfo(bool outer_scope_calls_non_strict_eval)
bool calls_non_strict_eval()
FunctionLiteral * function() const
void PrintMap(map< string, string > *m)
bool is_declaration_scope() const
bool HasLazyCompilableOuterContext() const
bool inner_scope_calls_eval_
Entry * Lookup(void *key, uint32_t hash, bool insert, ZoneAllocationPolicyallocator=ZoneAllocationPolicy())
void AllocateStackSlot(Variable *var)
bool IsLexicalVariableMode(VariableMode mode)
Scope * global_scope() const
bool IsContextSlot() const
static MUST_USE_RESULT Handle< Object > SetElement(Handle< JSObject > object, uint32_t index, Handle< Object > value, PropertyAttributes attr, StrictModeFlag strict_mode, SetPropertyMode set_mode=SET_PROPERTY)
static const char * Mode2String(VariableMode mode)
bool MustAllocate(Variable *var)
Variable * LocalLookup(Handle< String > name)
bool IsVariable(Handle< String > n) const
bool IsDeclaredVariableMode(VariableMode mode)
activate correct semantics for inheriting readonliness false
bool IsStackLocal() const
ZoneList< Variable * > params_
static Handle< AccessorInfo > MakeModuleExport(Handle< String > name, int index, PropertyAttributes attributes)
Interface * interface() const
void AllocateParameterLocals()
int StackLocalCount() const
void AddDeclaration(Declaration *declaration)
int num_heap_slots() const
void VisitIllegalRedeclaration(AstVisitor *visitor)
bool is_with_scope() const
void AllocateNonParameterLocals()
ZoneList< Variable * > temps_
bool contains_with() const
bool AllowsLazyCompilationWithoutContext() const
Handle< JSModule > NewJSModule(Handle< Context > context, Handle< ScopeInfo > scope_info)
void LinkModules(CompilationInfo *info)
bool IsUnallocated() const
Variable * DeclareDynamicGlobal(Handle< String > name)
Handle< JSModule > Instance()
int ContextLocalCount() const
Variable * Lookup(Handle< String > name)
void BindTo(Variable *var)
void set_is_used(bool flag)
MUST_USE_RESULT bool AllocateVariables(CompilationInfo *info, AstNodeFactory< AstNullVisitor > *factory)
Variable * NonLocal(Handle< String > name, VariableMode mode)
bool IsGlobalObjectProperty() const
Interface * interface() const
void Add(const T &element, AllocationPolicy allocator=AllocationPolicy())
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if NULL
MUST_USE_RESULT bool ResolveVariable(CompilationInfo *info, VariableProxy *proxy, AstNodeFactory< AstNullVisitor > *factory)
LanguageMode language_mode() const
DynamicScopePart * dynamics_
bool is_function_scope() const
Variable * Lookup(Handle< String > name)
virtual void Accept(AstVisitor *v)=0
VariableMode mode() const
Variable * Declare(Scope *scope, Handle< String > name, VariableMode mode, bool is_valid_lhs, Variable::Kind kind, InitializationFlag initialization_flag, Interface *interface=Interface::NewValue())
void RecordWithStatement()
bool is_module_scope() const
bool is_catch_scope() const
bool is_extended_mode() const
static Scope * DeserializeScopeChain(Context *context, Scope *global_scope, Zone *zone)
Scope(Scope *outer_scope, ScopeType type, Zone *zone)
void RemoveUnresolved(VariableProxy *var)
Entry * Next(Entry *p) const
Variable * LookupFunctionVar(Handle< String > name, AstNodeFactory< AstNullVisitor > *factory)
MUST_USE_RESULT bool ResolveVariablesRecursively(CompilationInfo *info, AstNodeFactory< AstNullVisitor > *factory)
void SetIllegalRedeclaration(Expression *expression)