Index: src/ast/scopes.h |
diff --git a/src/ast/scopes.h b/src/ast/scopes.h |
index ea37890c5e4875406996b0a5916141fc2459fc82..162c9003019934c5c90060afc38f4ff4528566c7 100644 |
--- a/src/ast/scopes.h |
+++ b/src/ast/scopes.h |
@@ -680,6 +680,11 @@ class DeclarationScope : public Scope { |
// calls sloppy eval. |
Variable* DeclareFunctionVar(const AstRawString* name); |
+ // Declare some special internal variables which must be accessible to |
+ // Ignition without ScopeInfo. |
+ Variable* DeclareGeneratorObjectVar(const AstRawString* name); |
+ Variable* DeclarePromiseVar(const AstRawString* name); |
+ |
// Declare a parameter in this scope. When there are duplicated |
// parameters the rightmost one 'wins'. However, the implementation |
// expects all parameters to be declared and from left to right. |
@@ -718,6 +723,17 @@ class DeclarationScope : public Scope { |
return function_; |
} |
+ Variable* generator_object_var() const { |
+ DCHECK(is_function_scope() || is_module_scope()); |
+ return GetRareVariable(RareVariable::kGeneratorObject); |
+ } |
+ |
+ Variable* promise_var() const { |
+ DCHECK(is_function_scope()); |
+ DCHECK(IsAsyncFunction(function_kind_)); |
+ return GetRareVariable(RareVariable::kPromise); |
+ } |
+ |
// Parameters. The left-most parameter has index 0. |
// Only valid for function and module scopes. |
Variable* parameter(int index) const { |
@@ -758,12 +774,14 @@ class DeclarationScope : public Scope { |
} |
Variable* this_function_var() const { |
+ Variable* this_function = GetRareVariable(RareVariable::kThisFunction); |
+ |
// This is only used in derived constructors atm. |
- DCHECK(this_function_ == nullptr || |
+ DCHECK(this_function == nullptr || |
(is_function_scope() && (IsClassConstructor(function_kind()) || |
IsConciseMethod(function_kind()) || |
IsAccessorFunction(function_kind())))); |
- return this_function_; |
+ return this_function; |
} |
// Adds a local variable in this scope's locals list. This is for adjusting |
@@ -872,8 +890,50 @@ class DeclarationScope : public Scope { |
Variable* new_target_; |
// Convenience variable; function scopes only. |
Variable* arguments_; |
- // Convenience variable; Subclass constructor only |
- Variable* this_function_; |
+ |
+ struct RareData : public ZoneObject { |
+ void* operator new(size_t size, Zone* zone) { return zone->New(size); } |
+ |
+ // Convenience variable; Subclass constructor only |
+ Variable* this_function = nullptr; |
+ |
+ // Generator object, if any; generator function scopes and module scopes |
+ // only. |
+ Variable* generator_object = nullptr; |
+ // Promise, if any; async function scopes only. |
+ Variable* promise = nullptr; |
+ }; |
+ |
+ enum class RareVariable { |
+ kThisFunction = offsetof(RareData, this_function), |
+ kGeneratorObject = offsetof(RareData, generator_object), |
+ kPromise = offsetof(RareData, promise) |
+ }; |
+ |
+ V8_INLINE RareData* EnsureRareData() { |
+ if (rare_data_ == nullptr) { |
+ rare_data_ = new (zone_) RareData; |
+ } |
+ return rare_data_; |
+ } |
+ |
+ V8_INLINE Variable* GetRareVariable(RareVariable id) const { |
+ if (rare_data_ == nullptr) return nullptr; |
+ return *reinterpret_cast<Variable**>( |
+ reinterpret_cast<uint8_t*>(rare_data_) + static_cast<ptrdiff_t>(id)); |
+ } |
+ |
+ // Set `var` to null if it's non-null and Predicate (Variable*) -> bool |
+ // returns true. |
+ template <typename Predicate> |
+ V8_INLINE void NullifyRareVariableIf(RareVariable id, Predicate predicate) { |
+ if (V8_LIKELY(rare_data_ == nullptr)) return; |
+ Variable** var = reinterpret_cast<Variable**>( |
+ reinterpret_cast<uint8_t*>(rare_data_) + static_cast<ptrdiff_t>(id)); |
+ if (*var && predicate(*var)) *var = nullptr; |
+ } |
+ |
+ RareData* rare_data_ = nullptr; |
}; |
class ModuleScope final : public DeclarationScope { |