LibWeb: Don't try to set selection with anchor/focus in different roots

If the anchor and focus nodes are not within the same document, we can't
use them for a selection range.

Found by Domato.
This commit is contained in:
Andreas Kling 2024-07-19 16:39:34 +02:00 committed by Andreas Kling
parent 4e0edd42b9
commit 416c478876
Notes: github-actions[bot] 2024-07-20 07:31:52 +00:00
3 changed files with 13 additions and 1 deletions

View File

@ -0,0 +1 @@
PASS (Didn't crash)

View File

@ -0,0 +1,11 @@
<body>
<script src="include.js"></script>
<script>
test(() => {
let newDoc = document.implementation.createHTMLDocument("foo");
let newDocP = newDoc.createElement("p");
let selection = window.getSelection();
selection.setBaseAndExtent(document.body, 0, newDocP, 0);
println("PASS (Didn't crash)");
});
</script>

View File

@ -307,7 +307,7 @@ WebIDL::ExceptionOr<void> Selection::set_base_and_extent(JS::NonnullGCPtr<DOM::N
return WebIDL::IndexSizeError::create(realm(), "Focus offset points outside of the focus node"_fly_string);
// 2. If document associated with this is not a shadow-including inclusive ancestor of anchorNode or focusNode, abort these steps.
if (!(m_document->is_shadow_including_inclusive_ancestor_of(anchor_node) || m_document->is_shadow_including_inclusive_ancestor_of(focus_node)))
if (!m_document->is_shadow_including_inclusive_ancestor_of(anchor_node) || !m_document->is_shadow_including_inclusive_ancestor_of(focus_node))
return {};
// 3. Let anchor be the boundary point (anchorNode, anchorOffset) and let focus be the boundary point (focusNode, focusOffset).