@@ -112,58 +112,38 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) {
112
112
113
113
class Snapshot final {
114
114
public:
115
- Snapshot ()
116
- : outer_scope_and_calls_eval_(nullptr , false ),
117
- top_unresolved_ (),
118
- top_local_() {
119
- DCHECK (IsCleared ());
120
- }
121
115
inline explicit Snapshot (Scope* scope);
122
116
123
117
// Disallow copy and move.
124
118
Snapshot (const Snapshot&) = delete ;
125
119
Snapshot (Snapshot&&) = delete ;
126
120
127
121
~Snapshot () {
128
- // If we're still active, there was no arrow function. In that case outer
129
- // calls eval if it already called eval before this snapshot started, or
130
- // if the code during the snapshot called eval.
131
- if (!IsCleared () && outer_scope_and_calls_eval_.GetPayload ()) {
132
- RestoreEvalFlag ();
122
+ // Restore eval flags from before the scope was active.
123
+ if (sloppy_eval_can_extend_vars_) {
124
+ declaration_scope_->sloppy_eval_can_extend_vars_ = true ;
133
125
}
134
- }
135
-
136
- void RestoreEvalFlag () {
137
- if (outer_scope_and_calls_eval_.GetPayload ()) {
138
- // This recreates both calls_eval and sloppy_eval_can_extend_vars.
139
- outer_scope_and_calls_eval_.GetPointer ()->RecordEvalCall ();
126
+ if (calls_eval_) {
127
+ outer_scope_->calls_eval_ = true ;
140
128
}
141
129
}
142
130
143
131
void Reparent (DeclarationScope* new_parent);
144
- bool IsCleared () const {
145
- return outer_scope_and_calls_eval_.GetPointer () == nullptr ;
146
- }
147
-
148
- void Clear () {
149
- outer_scope_and_calls_eval_.SetPointer (nullptr );
150
- #ifdef DEBUG
151
- outer_scope_and_calls_eval_.SetPayload (false );
152
- top_inner_scope_ = nullptr ;
153
- top_local_ = base::ThreadedList<Variable>::Iterator ();
154
- top_unresolved_ = UnresolvedList::Iterator ();
155
- #endif
156
- }
157
132
158
133
private:
159
- // During tracking calls_eval caches whether the outer scope called eval.
160
- // Upon move assignment we store whether the new inner scope calls eval into
161
- // the move target calls_eval bit, and restore calls eval on the outer
162
- // scope.
163
- base::PointerWithPayload<Scope, bool , 1 > outer_scope_and_calls_eval_;
134
+ Scope* outer_scope_;
135
+ Scope* declaration_scope_;
164
136
Scope* top_inner_scope_;
165
137
UnresolvedList::Iterator top_unresolved_;
166
138
base::ThreadedList<Variable>::Iterator top_local_;
139
+ // While the scope is active, the scope caches the flag values for
140
+ // outer_scope_ / declaration_scope_ they can be used to know what happened
141
+ // while parsing the arrow head. If this turns out to be an arrow head, new
142
+ // values on the respective scopes will be cleared and moved to the inner
143
+ // scope. Otherwise the cached flags will be merged with the flags from the
144
+ // arrow head.
145
+ bool calls_eval_;
146
+ bool sloppy_eval_can_extend_vars_;
167
147
};
168
148
169
149
enum class DeserializationMode { kIncludingVariables , kScopesOnly };
@@ -909,8 +889,8 @@ class V8_EXPORT_PRIVATE DeclarationScope : public Scope {
909
889
void RecordDeclarationScopeEvalCall () {
910
890
calls_eval_ = true ;
911
891
912
- // If this isn't a sloppy eval, we don't care about it .
913
- if ( language_mode () != LanguageMode:: kSloppy ) return ;
892
+ // The caller already checked whether we're in sloppy mode .
893
+ CHECK ( is_sloppy ( language_mode ())) ;
914
894
915
895
// Sloppy eval in script scopes can only introduce global variables anyway,
916
896
// so we don't care that it calls sloppy eval.
@@ -944,7 +924,6 @@ class V8_EXPORT_PRIVATE DeclarationScope : public Scope {
944
924
}
945
925
946
926
sloppy_eval_can_extend_vars_ = true ;
947
- num_heap_slots_ = Context::MIN_CONTEXT_EXTENDED_SLOTS;
948
927
}
949
928
950
929
bool sloppy_eval_can_extend_vars () const {
@@ -1369,7 +1348,9 @@ class V8_EXPORT_PRIVATE DeclarationScope : public Scope {
1369
1348
1370
1349
void Scope::RecordEvalCall () {
1371
1350
calls_eval_ = true ;
1372
- GetDeclarationScope ()->RecordDeclarationScopeEvalCall ();
1351
+ if (is_sloppy (language_mode ())) {
1352
+ GetDeclarationScope ()->RecordDeclarationScopeEvalCall ();
1353
+ }
1373
1354
RecordInnerScopeEvalCall ();
1374
1355
// The eval contents might access "super" (if it's inside a function that
1375
1356
// binds super).
@@ -1382,14 +1363,18 @@ void Scope::RecordEvalCall() {
1382
1363
}
1383
1364
1384
1365
Scope::Snapshot::Snapshot (Scope* scope)
1385
- : outer_scope_and_calls_eval_(scope, scope->calls_eval_),
1366
+ : outer_scope_(scope),
1367
+ declaration_scope_ (scope->GetDeclarationScope ()),
1386
1368
top_inner_scope_(scope->inner_scope_),
1387
1369
top_unresolved_(scope->unresolved_list_.end()),
1388
- top_local_(scope->GetClosureScope ()->locals_.end()) {
1389
- // Reset in order to record eval calls during this Snapshot's lifetime.
1390
- outer_scope_and_calls_eval_.GetPointer ()->calls_eval_ = false ;
1391
- outer_scope_and_calls_eval_.GetPointer ()->sloppy_eval_can_extend_vars_ =
1392
- false ;
1370
+ top_local_(scope->GetClosureScope ()->locals_.end()),
1371
+ calls_eval_(outer_scope_->calls_eval_),
1372
+ sloppy_eval_can_extend_vars_(
1373
+ declaration_scope_->sloppy_eval_can_extend_vars_) {
1374
+ // Reset in order to record (sloppy) eval calls during this Snapshot's
1375
+ // lifetime.
1376
+ outer_scope_->calls_eval_ = false ;
1377
+ declaration_scope_->sloppy_eval_can_extend_vars_ = false ;
1393
1378
}
1394
1379
1395
1380
class ModuleScope final : public DeclarationScope {
0 commit comments