diff options
Diffstat (limited to 'deps/v8/src/scopes.h')
-rw-r--r-- | deps/v8/src/scopes.h | 78 |
1 files changed, 47 insertions, 31 deletions
diff --git a/deps/v8/src/scopes.h b/deps/v8/src/scopes.h index 5e3dc1f065..40863800e4 100644 --- a/deps/v8/src/scopes.h +++ b/deps/v8/src/scopes.h @@ -144,14 +144,15 @@ class Scope: public ZoneObject { // Create a new unresolved variable. VariableProxy* NewUnresolved(AstNodeFactory* factory, const AstRawString* name, + Variable::Kind kind = Variable::NORMAL, int start_position = RelocInfo::kNoPosition, int end_position = RelocInfo::kNoPosition) { // Note that we must not share the unresolved variables with // the same name because they may be removed selectively via // RemoveUnresolved(). DCHECK(!already_resolved()); - VariableProxy* proxy = factory->NewVariableProxy( - name, Variable::NORMAL, start_position, end_position); + VariableProxy* proxy = + factory->NewVariableProxy(name, kind, start_position, end_position); unresolved_.Add(proxy, zone_); return proxy; } @@ -217,9 +218,6 @@ class Scope: public ZoneObject { // Inform the scope that the corresponding code uses "super". void RecordSuperPropertyUsage() { scope_uses_super_property_ = true; } - // Inform the scope that the corresponding code uses "this". - void RecordThisUsage() { scope_uses_this_ = true; } - // Set the language mode flag (unless disabled by a global flag). void SetLanguageMode(LanguageMode language_mode) { language_mode_ = language_mode; @@ -282,13 +280,6 @@ class Scope: public ZoneObject { bool is_block_scope() const { return scope_type_ == BLOCK_SCOPE; } bool is_with_scope() const { return scope_type_ == WITH_SCOPE; } bool is_arrow_scope() const { return scope_type_ == ARROW_SCOPE; } - void tag_as_class_scope() { - DCHECK(is_block_scope()); - block_scope_is_class_scope_ = true; - } - bool is_class_scope() const { - return is_block_scope() && block_scope_is_class_scope_; - } bool is_declaration_scope() const { return is_eval_scope() || is_function_scope() || is_module_scope() || is_script_scope(); @@ -319,14 +310,13 @@ class Scope: public ZoneObject { bool inner_uses_arguments() const { return inner_scope_uses_arguments_; } // Does this scope access "super" property (super.foo). bool uses_super_property() const { return scope_uses_super_property_; } - // Does any inner scope access "super" property. - bool inner_uses_super_property() const { - return inner_scope_uses_super_property_; + + bool NeedsHomeObject() const { + return scope_uses_super_property_ || + (scope_calls_eval_ && (IsConciseMethod(function_kind()) || + IsAccessorFunction(function_kind()) || + IsConstructor(function_kind()))); } - // Does this scope access "this". - bool uses_this() const { return scope_uses_this_; } - // Does any inner scope access "this". - bool inner_uses_this() const { return inner_scope_uses_this_; } const Scope* NearestOuterEvalScope() const { if (is_eval_scope()) return this; @@ -346,7 +336,20 @@ class Scope: public ZoneObject { LanguageMode language_mode() const { return language_mode_; } // The variable corresponding to the 'this' value. - Variable* receiver() { return receiver_; } + Variable* receiver() { + DCHECK(has_this_declaration()); + DCHECK_NOT_NULL(receiver_); + return receiver_; + } + + Variable* LookupThis() { return Lookup(ast_value_factory_->this_string()); } + + // TODO(wingo): Add a GLOBAL_SCOPE scope type which will lexically allocate + // "this" (and no other variable) on the native context. Script scopes then + // will not have a "this" declaration. + bool has_this_declaration() const { + return (is_function_scope() && !is_arrow_scope()) || is_module_scope(); + } // The variable corresponding to the 'new.target' value. Variable* new_target_var() { return new_target_; } @@ -401,6 +404,15 @@ class Scope: public ZoneObject { return arguments_; } + Variable* this_function_var() const { + // This is only used in derived constructors atm. + DCHECK(this_function_ == nullptr || + (is_function_scope() && (IsConstructor(function_kind()) || + IsConciseMethod(function_kind()) || + IsAccessorFunction(function_kind())))); + return this_function_; + } + // Declarations list. ZoneList<Declaration*>* declarations() { return &decls_; } @@ -430,6 +442,7 @@ class Scope: public ZoneObject { // handled separately. void CollectStackAndContextLocals( ZoneList<Variable*>* stack_locals, ZoneList<Variable*>* context_locals, + ZoneList<Variable*>* context_globals, ZoneList<Variable*>* strong_mode_free_variables = nullptr); // Current number of var or const locals. @@ -438,9 +451,11 @@ class Scope: public ZoneObject { // Result of variable allocation. int num_stack_slots() const { return num_stack_slots_; } int num_heap_slots() const { return num_heap_slots_; } + int num_global_slots() const { return num_global_slots_; } int StackLocalCount() const; int ContextLocalCount() const; + int ContextGlobalCount() const; // For script scopes, the number of module literals (including nested ones). int num_modules() const { return num_modules_; } @@ -451,6 +466,9 @@ class Scope: public ZoneObject { // Make sure this scope and all outer scopes are eagerly compiled. void ForceEagerCompilation() { force_eager_compilation_ = true; } + // Determine if we can parse a function literal in this scope lazily. + bool AllowsLazyParsing() const; + // Determine if we can use lazy compilation for this scope. bool AllowsLazyCompilation() const; @@ -460,9 +478,6 @@ class Scope: public ZoneObject { // True if the outer context of this scope is always the native context. bool HasTrivialOuterContext() const; - // True if the outer context allows lazy compilation of this scope. - bool HasLazyCompilableOuterContext() const; - // The number of contexts between this and scope; zero if this == scope. int ContextChainLength(Scope* scope); @@ -503,7 +518,8 @@ class Scope: public ZoneObject { } // Error handling. - void ReportMessage(int start_position, int end_position, const char* message, + void ReportMessage(int start_position, int end_position, + MessageTemplate::Template message, const AstRawString* arg); // --------------------------------------------------------------------------- @@ -524,8 +540,6 @@ class Scope: public ZoneObject { // The scope type. ScopeType scope_type_; - // Some block scopes are tagged as class scopes. - bool block_scope_is_class_scope_; // If the scope is a function scope, this is the function kind. FunctionKind function_kind_; @@ -558,6 +572,8 @@ class Scope: public ZoneObject { Variable* new_target_; // Convenience variable; function scopes only. Variable* arguments_; + // Convenience variable; Subclass constructor only + Variable* this_function_; // Module descriptor; module scopes only. ModuleDescriptor* module_descriptor_; @@ -577,8 +593,6 @@ class Scope: public ZoneObject { bool scope_uses_arguments_; // This scope uses "super" property ('super.foo'). bool scope_uses_super_property_; - // This scope uses "this". - bool scope_uses_this_; // This scope contains an "use asm" annotation. bool asm_module_; // This scope's outer context is an asm module. @@ -593,8 +607,6 @@ class Scope: public ZoneObject { bool outer_scope_calls_sloppy_eval_; bool inner_scope_calls_eval_; bool inner_scope_uses_arguments_; - bool inner_scope_uses_super_property_; - bool inner_scope_uses_this_; bool force_eager_compilation_; bool force_context_allocation_; @@ -608,6 +620,7 @@ class Scope: public ZoneObject { // Computed via AllocateVariables; function, block and catch scopes only. int num_stack_slots_; int num_heap_slots_; + int num_global_slots_; // The number of modules (including nested ones). int num_modules_; @@ -704,8 +717,11 @@ class Scope: public ZoneObject { void AllocateHeapSlot(Variable* var); void AllocateParameterLocals(Isolate* isolate); void AllocateNonParameterLocal(Isolate* isolate, Variable* var); - void AllocateNonParameterLocals(Isolate* isolate); + void AllocateDeclaredGlobal(Isolate* isolate, Variable* var); + void AllocateNonParameterLocalsAndDeclaredGlobals(Isolate* isolate); void AllocateVariablesRecursively(Isolate* isolate); + void AllocateParameter(Variable* var, int index); + void AllocateReceiver(); void AllocateModules(); // Resolve and fill in the allocation information for all variables |