@@ -110,58 +110,38 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) {
110110
111111 class Snapshot final {
112112 public:
113- Snapshot ()
114- : outer_scope_and_calls_eval_(nullptr , false ),
115- top_unresolved_ (),
116- top_local_() {
117- DCHECK (IsCleared ());
118- }
119113 inline explicit Snapshot (Scope* scope);
120114
121115 // Disallow copy and move.
122116 Snapshot (const Snapshot&) = delete ;
123117 Snapshot (Snapshot&&) = delete ;
124118
125119 ~Snapshot () {
126- // If we're still active, there was no arrow function. In that case outer
127- // calls eval if it already called eval before this snapshot started, or
128- // if the code during the snapshot called eval.
129- if (!IsCleared () && outer_scope_and_calls_eval_.GetPayload ()) {
130- RestoreEvalFlag ();
120+ // Restore eval flags from before the scope was active.
121+ if (sloppy_eval_can_extend_vars_) {
122+ declaration_scope_->sloppy_eval_can_extend_vars_ = true ;
131123 }
132- }
133-
134- void RestoreEvalFlag () {
135- if (outer_scope_and_calls_eval_.GetPayload ()) {
136- // This recreates both calls_eval and sloppy_eval_can_extend_vars.
137- outer_scope_and_calls_eval_.GetPointer ()->RecordEvalCall ();
124+ if (calls_eval_) {
125+ outer_scope_->calls_eval_ = true ;
138126 }
139127 }
140128
141129 void Reparent (DeclarationScope* new_parent);
142- bool IsCleared () const {
143- return outer_scope_and_calls_eval_.GetPointer () == nullptr ;
144- }
145-
146- void Clear () {
147- outer_scope_and_calls_eval_.SetPointer (nullptr );
148- #ifdef DEBUG
149- outer_scope_and_calls_eval_.SetPayload (false );
150- top_inner_scope_ = nullptr ;
151- top_local_ = base::ThreadedList<Variable>::Iterator ();
152- top_unresolved_ = UnresolvedList::Iterator ();
153- #endif
154- }
155130
156131 private:
157- // During tracking calls_eval caches whether the outer scope called eval.
158- // Upon move assignment we store whether the new inner scope calls eval into
159- // the move target calls_eval bit, and restore calls eval on the outer
160- // scope.
161- base::PointerWithPayload<Scope, bool , 1 > outer_scope_and_calls_eval_;
132+ Scope* outer_scope_;
133+ Scope* declaration_scope_;
162134 Scope* top_inner_scope_;
163135 UnresolvedList::Iterator top_unresolved_;
164136 base::ThreadedList<Variable>::Iterator top_local_;
137+ // While the scope is active, the scope caches the flag values for
138+ // outer_scope_ / declaration_scope_ they can be used to know what happened
139+ // while parsing the arrow head. If this turns out to be an arrow head, new
140+ // values on the respective scopes will be cleared and moved to the inner
141+ // scope. Otherwise the cached flags will be merged with the flags from the
142+ // arrow head.
143+ bool calls_eval_;
144+ bool sloppy_eval_can_extend_vars_;
165145 };
166146
167147 enum class DeserializationMode { kIncludingVariables , kScopesOnly };
@@ -907,8 +887,8 @@ class V8_EXPORT_PRIVATE DeclarationScope : public Scope {
907887 void RecordDeclarationScopeEvalCall () {
908888 calls_eval_ = true ;
909889
910- // If this isn't a sloppy eval, we don't care about it .
911- if ( language_mode () != LanguageMode:: kSloppy ) return ;
890+ // The caller already checked whether we're in sloppy mode .
891+ CHECK ( is_sloppy ( language_mode ())) ;
912892
913893 // Sloppy eval in script scopes can only introduce global variables anyway,
914894 // so we don't care that it calls sloppy eval.
@@ -942,7 +922,6 @@ class V8_EXPORT_PRIVATE DeclarationScope : public Scope {
942922 }
943923
944924 sloppy_eval_can_extend_vars_ = true ;
945- num_heap_slots_ = Context::MIN_CONTEXT_EXTENDED_SLOTS;
946925 }
947926
948927 bool sloppy_eval_can_extend_vars () const {
@@ -1367,7 +1346,9 @@ class V8_EXPORT_PRIVATE DeclarationScope : public Scope {
13671346
13681347void Scope::RecordEvalCall () {
13691348 calls_eval_ = true ;
1370- GetDeclarationScope ()->RecordDeclarationScopeEvalCall ();
1349+ if (is_sloppy (language_mode ())) {
1350+ GetDeclarationScope ()->RecordDeclarationScopeEvalCall ();
1351+ }
13711352 RecordInnerScopeEvalCall ();
13721353 // The eval contents might access "super" (if it's inside a function that
13731354 // binds super).
@@ -1380,14 +1361,18 @@ void Scope::RecordEvalCall() {
13801361}
13811362
13821363Scope::Snapshot::Snapshot (Scope* scope)
1383- : outer_scope_and_calls_eval_(scope, scope->calls_eval_),
1364+ : outer_scope_(scope),
1365+ declaration_scope_ (scope->GetDeclarationScope ()),
13841366 top_inner_scope_(scope->inner_scope_),
13851367 top_unresolved_(scope->unresolved_list_.end()),
1386- top_local_(scope->GetClosureScope ()->locals_.end()) {
1387- // Reset in order to record eval calls during this Snapshot's lifetime.
1388- outer_scope_and_calls_eval_.GetPointer ()->calls_eval_ = false ;
1389- outer_scope_and_calls_eval_.GetPointer ()->sloppy_eval_can_extend_vars_ =
1390- false ;
1368+ top_local_(scope->GetClosureScope ()->locals_.end()),
1369+ calls_eval_(outer_scope_->calls_eval_),
1370+ sloppy_eval_can_extend_vars_(
1371+ declaration_scope_->sloppy_eval_can_extend_vars_) {
1372+ // Reset in order to record (sloppy) eval calls during this Snapshot's
1373+ // lifetime.
1374+ outer_scope_->calls_eval_ = false ;
1375+ declaration_scope_->sloppy_eval_can_extend_vars_ = false ;
13911376}
13921377
13931378class ModuleScope final : public DeclarationScope {
0 commit comments