summaryrefslogtreecommitdiff
path: root/deps/v8/src/ast/scopes.h
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/ast/scopes.h')
-rw-r--r--deps/v8/src/ast/scopes.h82
1 files changed, 26 insertions, 56 deletions
diff --git a/deps/v8/src/ast/scopes.h b/deps/v8/src/ast/scopes.h
index 0acff8ac32..c7d88aca11 100644
--- a/deps/v8/src/ast/scopes.h
+++ b/deps/v8/src/ast/scopes.h
@@ -5,6 +5,7 @@
#ifndef V8_AST_SCOPES_H_
#define V8_AST_SCOPES_H_
+#include "src/base/compiler-specific.h"
#include "src/base/hashmap.h"
#include "src/globals.h"
#include "src/objects.h"
@@ -62,7 +63,7 @@ enum class AnalyzeMode { kRegular, kDebugger };
// and ModuleScope. DeclarationScope is used for any scope that hosts 'var'
// declarations. This includes script, module, eval, varblock, and function
// scope. ModuleScope further specializes DeclarationScope.
-class Scope: public ZoneObject {
+class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) {
public:
// ---------------------------------------------------------------------------
// Construction
@@ -95,8 +96,8 @@ class Scope: public ZoneObject {
Scope* outer_scope_;
Scope* top_inner_scope_;
VariableProxy* top_unresolved_;
- int top_local_;
- int top_decl_;
+ ThreadedList<Variable>::Iterator top_local_;
+ ThreadedList<Declaration>::Iterator top_decl_;
};
enum class DeserializationMode { kIncludingVariables, kScopesOnly };
@@ -157,15 +158,14 @@ class Scope: public ZoneObject {
bool* ok);
// Declarations list.
- ZoneList<Declaration*>* declarations() { return &decls_; }
+ ThreadedList<Declaration>* declarations() { return &decls_; }
- ZoneList<Variable*>* locals() { return &locals_; }
+ ThreadedList<Variable>* locals() { return &locals_; }
// Create a new unresolved variable.
VariableProxy* NewUnresolved(AstNodeFactory* factory,
const AstRawString* name,
int start_position = kNoSourcePosition,
- int end_position = kNoSourcePosition,
VariableKind kind = NORMAL_VARIABLE);
void AddUnresolved(VariableProxy* proxy);
@@ -351,7 +351,7 @@ class Scope: public ZoneObject {
// Determine if we can parse a function literal in this scope lazily without
// caring about the unresolved variables within.
- bool AllowsLazyParsingWithoutUnresolvedVariables() const;
+ bool AllowsLazyParsingWithoutUnresolvedVariables(const Scope* outer) const;
// The number of contexts between this and scope; zero if this == scope.
int ContextChainLength(Scope* scope) const;
@@ -374,6 +374,7 @@ class Scope: public ZoneObject {
// the scope for which a function prologue allocates a context) or declaring
// temporaries.
DeclarationScope* GetClosureScope();
+ const DeclarationScope* GetClosureScope() const;
// Find the first (non-arrow) function or script scope. This is where
// 'this' is bound, and what determines the function kind.
@@ -422,8 +423,6 @@ class Scope: public ZoneObject {
void set_is_debug_evaluate_scope() { is_debug_evaluate_scope_ = true; }
bool is_debug_evaluate_scope() const { return is_debug_evaluate_scope_; }
- bool is_lazily_parsed() const { return is_lazily_parsed_; }
-
protected:
explicit Scope(Zone* zone);
@@ -435,29 +434,13 @@ class Scope: public ZoneObject {
Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name,
VariableMode mode, VariableKind kind,
InitializationFlag initialization_flag,
- MaybeAssignedFlag maybe_assigned_flag = kNotAssigned) {
- bool added;
- Variable* var =
- variables_.Declare(zone, scope, name, mode, kind, initialization_flag,
- maybe_assigned_flag, &added);
- if (added) locals_.Add(var, zone);
- return var;
- }
+ MaybeAssignedFlag maybe_assigned_flag = kNotAssigned);
// This method should only be invoked on scopes created during parsing (i.e.,
// not deserialized from a context). Also, since NeedsContext() is only
// returning a valid result after variables are resolved, NeedsScopeInfo()
// should also be invoked after resolution.
- bool NeedsScopeInfo() const {
- DCHECK(!already_resolved_);
- // A lazily parsed scope doesn't contain enough information to create a
- // ScopeInfo from it.
- if (is_lazily_parsed_) return false;
- // The debugger expects all functions to have scope infos.
- // TODO(jochen|yangguo): Remove this requirement.
- if (is_function_scope()) return true;
- return NeedsContext();
- }
+ bool NeedsScopeInfo() const;
Zone* zone_;
@@ -474,13 +457,12 @@ class Scope: public ZoneObject {
VariableMap variables_;
// In case of non-scopeinfo-backed scopes, this contains the variables of the
// map above in order of addition.
- // TODO(verwaest): Thread through Variable.
- ZoneList<Variable*> locals_;
+ ThreadedList<Variable> locals_;
// Unresolved variables referred to from this scope. The proxies themselves
// form a linked list of all unresolved proxies.
VariableProxy* unresolved_;
// Declarations.
- ZoneList<Declaration*> decls_;
+ ThreadedList<Declaration> decls_;
// Serialized scope info support.
Handle<ScopeInfo> scope_info_;
@@ -527,8 +509,6 @@ class Scope: public ZoneObject {
// True if it holds 'var' declarations.
bool is_declaration_scope_ : 1;
- bool is_lazily_parsed_ : 1;
-
// Create a non-local variable with a given name.
// These variables are looked up dynamically at runtime.
Variable* NonLocal(const AstRawString* name, VariableMode mode);
@@ -563,8 +543,10 @@ class Scope: public ZoneObject {
void AllocateNonParameterLocalsAndDeclaredGlobals();
void AllocateVariablesRecursively();
- void AllocateScopeInfosRecursively(Isolate* isolate, AnalyzeMode mode,
+ void AllocateScopeInfosRecursively(Isolate* isolate,
MaybeHandle<ScopeInfo> outer_scope);
+ void AllocateDebuggerScopeInfos(Isolate* isolate,
+ MaybeHandle<ScopeInfo> outer_scope);
// Construct a scope based on the scope info.
Scope(Zone* zone, ScopeType type, Handle<ScopeInfo> scope_info);
@@ -634,6 +616,10 @@ class DeclarationScope : public Scope {
IsClassConstructor(function_kind())));
}
+ bool is_lazily_parsed() const { return is_lazily_parsed_; }
+ bool ShouldEagerCompile() const;
+ void set_should_eager_compile();
+
void SetScriptScopeInfo(Handle<ScopeInfo> scope_info) {
DCHECK(is_script_scope());
DCHECK(scope_info_.is_null());
@@ -704,16 +690,6 @@ class DeclarationScope : public Scope {
return params_[index];
}
- // Returns the default function arity excluding default or rest parameters.
- // This will be used to set the length of the function, by default.
- // Class field initializers use this property to indicate the number of
- // fields being initialized.
- int arity() const { return arity_; }
-
- // Normal code should not need to call this. Class field initializers use this
- // property to indicate the number of fields being initialized.
- void set_arity(int arity) { arity_ = arity; }
-
// Returns the number of formal parameters, excluding a possible rest
// parameter. Examples:
// function foo(a, b) {} ==> 2
@@ -758,12 +734,7 @@ class DeclarationScope : public Scope {
// Adds a local variable in this scope's locals list. This is for adjusting
// the scope of temporaries and do-expression vars when desugaring parameter
// initializers.
- void AddLocal(Variable* var) {
- DCHECK(!already_resolved_);
- // Temporaries are only placed in ClosureScopes.
- DCHECK_EQ(GetClosureScope(), this);
- locals_.Add(var, zone());
- }
+ void AddLocal(Variable* var);
void DeclareSloppyBlockFunction(const AstRawString* name,
SloppyBlockFunctionStatement* statement) {
@@ -796,16 +767,15 @@ class DeclarationScope : public Scope {
// Determine if we can use lazy compilation for this scope.
bool AllowsLazyCompilation() const;
- // Determine if we can use lazy compilation for this scope without a context.
- bool AllowsLazyCompilationWithoutContext() const;
-
// Make sure this closure and all outer closures are eagerly compiled.
void ForceEagerCompilation() {
DCHECK_EQ(this, GetClosureScope());
- for (DeclarationScope* s = this; !s->is_script_scope();
+ DeclarationScope* s;
+ for (s = this; !s->is_script_scope();
s = s->outer_scope()->GetClosureScope()) {
s->force_eager_compilation_ = true;
}
+ s->force_eager_compilation_ = true;
}
#ifdef DEBUG
@@ -848,9 +818,9 @@ class DeclarationScope : public Scope {
bool has_arguments_parameter_ : 1;
// This scope uses "super" property ('super.foo').
bool scope_uses_super_property_ : 1;
+ bool should_eager_compile_ : 1;
+ bool is_lazily_parsed_ : 1;
- // Info about the parameter list of a function.
- int arity_;
// Parameter list in source order.
ZoneList<Variable*> params_;
// Map of function names to lists of functions defined in sloppy blocks
@@ -884,7 +854,7 @@ class ModuleScope final : public DeclarationScope {
return module_descriptor_;
}
- // Set MODULE as VariableLocation for all variables that will live in some
+ // Set MODULE as VariableLocation for all variables that will live in a
// module's export table.
void AllocateModuleVariables();