@@ -110,58 +110,38 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) {
110
110
111
111
class Snapshot final {
112
112
public:
113
- Snapshot ()
114
- : outer_scope_and_calls_eval_(nullptr , false ),
115
- top_unresolved_ (),
116
- top_local_() {
117
- DCHECK (IsCleared ());
118
- }
119
113
inline explicit Snapshot (Scope* scope);
120
114
121
115
// Disallow copy and move.
122
116
Snapshot (const Snapshot&) = delete ;
123
117
Snapshot (Snapshot&&) = delete ;
124
118
125
119
~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 ;
131
123
}
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 ;
138
126
}
139
127
}
140
128
141
129
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
- }
155
130
156
131
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_;
162
134
Scope* top_inner_scope_;
163
135
UnresolvedList::Iterator top_unresolved_;
164
136
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_;
165
145
};
166
146
167
147
enum class DeserializationMode { kIncludingVariables , kScopesOnly };
@@ -907,8 +887,8 @@ class V8_EXPORT_PRIVATE DeclarationScope : public Scope {
907
887
void RecordDeclarationScopeEvalCall () {
908
888
calls_eval_ = true ;
909
889
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 ())) ;
912
892
913
893
// Sloppy eval in script scopes can only introduce global variables anyway,
914
894
// so we don't care that it calls sloppy eval.
@@ -942,7 +922,6 @@ class V8_EXPORT_PRIVATE DeclarationScope : public Scope {
942
922
}
943
923
944
924
sloppy_eval_can_extend_vars_ = true ;
945
- num_heap_slots_ = Context::MIN_CONTEXT_EXTENDED_SLOTS;
946
925
}
947
926
948
927
bool sloppy_eval_can_extend_vars () const {
@@ -1367,7 +1346,9 @@ class V8_EXPORT_PRIVATE DeclarationScope : public Scope {
1367
1346
1368
1347
void Scope::RecordEvalCall () {
1369
1348
calls_eval_ = true ;
1370
- GetDeclarationScope ()->RecordDeclarationScopeEvalCall ();
1349
+ if (is_sloppy (language_mode ())) {
1350
+ GetDeclarationScope ()->RecordDeclarationScopeEvalCall ();
1351
+ }
1371
1352
RecordInnerScopeEvalCall ();
1372
1353
// The eval contents might access "super" (if it's inside a function that
1373
1354
// binds super).
@@ -1380,14 +1361,18 @@ void Scope::RecordEvalCall() {
1380
1361
}
1381
1362
1382
1363
Scope::Snapshot::Snapshot (Scope* scope)
1383
- : outer_scope_and_calls_eval_(scope, scope->calls_eval_),
1364
+ : outer_scope_(scope),
1365
+ declaration_scope_ (scope->GetDeclarationScope ()),
1384
1366
top_inner_scope_(scope->inner_scope_),
1385
1367
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 ;
1391
1376
}
1392
1377
1393
1378
class ModuleScope final : public DeclarationScope {
0 commit comments