LibWeb: Don't leak entire realm after parsing CSS @supports rule

Before this change, every CSS @supports rule would keep the containing
JS realm alive via a JS::Handle. This led to a GC reference cycle and
the whole realm leaked.

Since we only need the realm at construction time, we can take it as a
parameter instead, and stop storing it.
This commit is contained in:
Andreas Kling 2024-04-04 12:44:43 +02:00
commit b2a099e647
Notes: sideshowbarker 2024-07-17 07:31:31 +09:00
3 changed files with 27 additions and 29 deletions

View file

@ -178,7 +178,7 @@ RefPtr<Supports> Parser::parse_a_supports(TokenStream<T>& tokens)
auto maybe_condition = parse_supports_condition(token_stream);
token_stream.skip_whitespace();
if (maybe_condition && !token_stream.has_next_token())
return Supports::create(maybe_condition.release_nonnull());
return Supports::create(m_context.realm(), maybe_condition.release_nonnull());
return {};
}
@ -303,7 +303,7 @@ Optional<Supports::Feature> Parser::parse_supports_feature(TokenStream<Component
if (auto declaration = consume_a_declaration(block_tokens); declaration.has_value()) {
transaction.commit();
return Supports::Feature {
Supports::Declaration { declaration->to_string(), JS::make_handle(m_context.realm()) }
Supports::Declaration { declaration->to_string() }
};
}
}
@ -316,7 +316,7 @@ Optional<Supports::Feature> Parser::parse_supports_feature(TokenStream<Component
builder.append(item.to_string());
transaction.commit();
return Supports::Feature {
Supports::Selector { builder.to_string().release_value_but_fixme_should_propagate_errors(), JS::make_handle(m_context.realm()) }
Supports::Selector { builder.to_string().release_value_but_fixme_should_propagate_errors() }
};
}