LibWeb: Make DOM::Position's node mandatory

We can only construct positions if there's a node involved, which was
already enforced by Position::create() only accepting a GC::Ref.
This commit is contained in:
Jelle Raaijmakers 2025-08-20 11:32:16 +02:00 committed by Tim Ledbetter
commit 51ce46859e
Notes: github-actions[bot] 2025-08-20 11:26:01 +00:00
4 changed files with 10 additions and 14 deletions

View file

@ -1,6 +1,7 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2021, Max Wipfli <mail@maxwipfli.ch>
* Copyright (c) 2025, Jelle Raaijmakers <jelle@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -13,7 +14,7 @@ namespace Web::DOM {
GC_DEFINE_ALLOCATOR(Position);
Position::Position(GC::Ptr<Node> node, unsigned offset)
Position::Position(GC::Ref<Node> node, unsigned offset)
: m_node(node)
, m_offset(offset)
{
@ -27,8 +28,6 @@ void Position::visit_edges(Visitor& visitor)
ErrorOr<String> Position::to_string() const
{
if (!node())
return String::formatted("DOM::Position(nullptr, {})", offset());
return String::formatted("DOM::Position({} ({})), {})", node()->node_name(), node().ptr(), offset());
}