LibWeb: Add null check in Document::ancestor_navigables()

The spec doesn't explicitly forbid calling this when the document
doesn't have a node navigable, so let's handle that situation gracefully
by just returning an empty list of ancestors.

I hit this VERIFY somewhere on the web, but I don't know how to
reproduce it.
This commit is contained in:
Andreas Kling 2024-06-07 19:34:53 +02:00
commit b118c99c27
Notes: sideshowbarker 2024-07-17 00:47:29 +09:00

View file

@ -3063,9 +3063,13 @@ Vector<JS::Handle<HTML::Navigable>> Document::inclusive_descendant_navigables()
// https://html.spec.whatwg.org/multipage/document-sequences.html#ancestor-navigables
Vector<JS::Handle<HTML::Navigable>> Document::ancestor_navigables()
{
// NOTE: This isn't in the spec, but if we don't have a navigable, we can't have ancestors either.
auto document_node_navigable = this->navigable();
if (!document_node_navigable)
return {};
// 1. Let navigable be document's node navigable's parent.
VERIFY(navigable());
auto navigable = this->navigable()->parent();
auto navigable = document_node_navigable->parent();
// 2. Let ancestors be an empty list.
Vector<JS::Handle<HTML::Navigable>> ancestors;