Skip to content

Commit e1344af

Browse files
committed
LibJS: Move ExecutionContext::context_owner to rare data
This is only used by ExecutionContexts owned by an HTML::ESO.
1 parent d234e9e commit e1344af

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

Libraries/LibJS/Runtime/ExecutionContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ void ExecutionContext::visit_edges(Cell::Visitor& visitor)
144144
visitor.visit(variable_environment);
145145
visitor.visit(lexical_environment);
146146
visitor.visit(private_environment);
147-
visitor.visit(context_owner);
148147
visitor.visit(cached_source_range);
149148
visitor.visit(m_rare_data);
150149
if (this_value.has_value())
@@ -161,6 +160,7 @@ void ExecutionContext::visit_edges(Cell::Visitor& visitor)
161160
void ExecutionContextRareData::visit_edges(Cell::Visitor& visitor)
162161
{
163162
Base::visit_edges(visitor);
163+
visitor.visit(context_owner);
164164
for (auto& context : unwind_contexts) {
165165
visitor.visit(context.lexical_environment);
166166
}
@@ -170,7 +170,7 @@ void ExecutionContextRareData::visit_edges(Cell::Visitor& visitor)
170170
GC::Ref<ExecutionContextRareData> ExecutionContext::ensure_rare_data()
171171
{
172172
if (!m_rare_data) {
173-
m_rare_data = executable->heap().allocate<ExecutionContextRareData>();
173+
m_rare_data = GC::Heap::the().allocate<ExecutionContextRareData>();
174174
}
175175
return *m_rare_data;
176176
}

Libraries/LibJS/Runtime/ExecutionContext.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class CachedSourceRange final : public GC::Cell {
3636
Variant<UnrealizedSourceRange, SourceRange> source_range;
3737
};
3838

39-
class ExecutionContextRareData final : public GC::Cell {
39+
class JS_API ExecutionContextRareData final : public GC::Cell {
4040
GC_CELL(ExecutionContextRareData, GC::Cell);
4141
GC_DECLARE_ALLOCATOR(ExecutionContextRareData);
4242

@@ -45,6 +45,9 @@ class ExecutionContextRareData final : public GC::Cell {
4545
Vector<Optional<size_t>> previously_scheduled_jumps;
4646
Vector<GC::Ptr<Environment>> saved_lexical_environments;
4747

48+
// Non-standard: This points at something that owns this ExecutionContext, in case it needs to be protected from GC.
49+
GC::Ptr<Cell> context_owner;
50+
4851
private:
4952
virtual void visit_edges(Cell::Visitor&) override;
5053
};
@@ -82,9 +85,6 @@ struct JS_API ExecutionContext {
8285
Span<Value> registers_and_constants_and_locals_arguments;
8386
ReadonlySpan<Utf16FlyString> identifier_table;
8487

85-
// Non-standard: This points at something that owns this ExecutionContext, in case it needs to be protected from GC.
86-
GC::Ptr<Cell> context_owner;
87-
8888
u32 program_counter { 0 };
8989

9090
// https://html.spec.whatwg.org/multipage/webappapis.html#skip-when-determining-incumbent-counter

Libraries/LibWeb/HTML/Scripting/Environments.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void Environment::visit_edges(Cell::Visitor& visitor)
3838
EnvironmentSettingsObject::EnvironmentSettingsObject(NonnullOwnPtr<JS::ExecutionContext> realm_execution_context)
3939
: m_realm_execution_context(move(realm_execution_context))
4040
{
41-
m_realm_execution_context->context_owner = this;
41+
m_realm_execution_context->ensure_rare_data()->context_owner = this;
4242

4343
// Register with the responsible event loop so we can perform step 4 of "perform a microtask checkpoint".
4444
responsible_event_loop().register_environment_settings_object({}, *this);

0 commit comments

Comments
 (0)