Skip to content

Commit

Permalink
LibWeb: Add null checks to related navigable collection methods
Browse files Browse the repository at this point in the history
This commit adds a null check to both
`Document::inclusive_ancestor_navigables()` and
`Document::inclusive_descendant_navigables`.

The spec doesn't explicitly mention these null checks, but this change
follows an earlier change made to `Document::ancestor_navigables`.
  • Loading branch information
tcl3 committed Jun 19, 2024
1 parent 8a509a8 commit eb4b318
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Userland/Libraries/LibWeb/DOM/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3049,9 +3049,14 @@ Vector<JS::Handle<HTML::Navigable>> const Document::descendant_navigables() cons
// https://html.spec.whatwg.org/multipage/document-sequences.html#inclusive-descendant-navigables
Vector<JS::Handle<HTML::Navigable>> Document::inclusive_descendant_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 = navigable();
if (!document_node_navigable)
return {};

// 1. Let navigables be « document's node navigable ».
Vector<JS::Handle<HTML::Navigable>> navigables;
navigables.append(*navigable());
navigables.append(*document_node_navigable);

// 2. Extend navigables with document's descendant navigables.
navigables.extend(descendant_navigables());
Expand Down Expand Up @@ -3095,11 +3100,16 @@ Vector<JS::Handle<HTML::Navigable>> const Document::ancestor_navigables() const
// https://html.spec.whatwg.org/multipage/document-sequences.html#inclusive-ancestor-navigables
Vector<JS::Handle<HTML::Navigable>> Document::inclusive_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 = navigable();
if (!document_node_navigable)
return {};

// 1. Let navigables be document's ancestor navigables.
auto navigables = ancestor_navigables();

// 2. Append document's node navigable to navigables.
navigables.append(*navigable());
navigables.append(*document_node_navigable);

// 3. Return navigables.
return navigables;
Expand Down

0 comments on commit eb4b318

Please sign in to comment.