LibWeb: Ensure we're not creating invalid ranges

Our Ranges should maintain the invariant that their offsets are always
within range of 0..length (inclusive) of their respective containers.

Note that we cannot maintain this in AbstractRange, which is the base
for StaticRange and can still have invalid offsets.
This commit is contained in:
Jelle Raaijmakers 2025-05-14 15:41:32 +02:00 committed by Tim Ledbetter
commit cac1d49d21
Notes: github-actions[bot] 2025-05-15 10:45:34 +00:00

View file

@ -68,6 +68,9 @@ Range::Range(Document& document)
Range::Range(GC::Ref<Node> start_container, WebIDL::UnsignedLong start_offset, GC::Ref<Node> end_container, WebIDL::UnsignedLong end_offset)
: AbstractRange(start_container, start_offset, end_container, end_offset)
{
VERIFY(start_offset <= start_container->length());
VERIFY(end_offset <= end_container->length());
live_ranges().set(this);
}