commit afbde9b7af8bdfbe8e0bda8c43170190310105f8
parent 15ee536019d871203b3959f6d3a5b3b412faeafc
Author: Cosmin Sabou <csabou@mozilla.com>
Date: Sat, 6 Dec 2025 22:03:41 +0200
Revert "Bug 2004005 - CSS Highlight API: Don't add invalid static ranges to Selection. r=smaug" for causing build bustages on Selection.cpp
This reverts commit 15ee536019d871203b3959f6d3a5b3b412faeafc.
Diffstat:
2 files changed, 1 insertion(+), 26 deletions(-)
diff --git a/dom/base/Selection.cpp b/dom/base/Selection.cpp
@@ -1293,6 +1293,7 @@ nsresult Selection::StyledRanges::AddRangeAndIgnoreOverlaps(
MOZ_ASSERT(mSelection.mSelectionType == SelectionType::eHighlight);
if (aRange->IsStaticRange() && !aRange->AsStaticRange()->IsValid()) {
mInvalidStaticRanges.AppendElement(StyledRange(aRange));
+ aRange->RegisterSelection(MOZ_KnownLive(mSelection));
return NS_OK;
}
@@ -1643,9 +1644,6 @@ void Selection::StyledRanges::ReorderRangesIfNecessary() {
MOZ_ASSERT(iter->mRange->IsStaticRange());
if (iter->mRange->AsStaticRange()->IsValid()) {
mRanges.AppendElement(*iter);
- if (!iter->mRange->IsInSelection(mSelection)) {
- iter->mRange->RegisterSelection(MOZ_KnownLive(mSelection));
- }
iter = mInvalidStaticRanges.RemoveElementAt(iter);
} else {
++iter;
diff --git a/testing/web-platform/tests/css/css-highlight-api/Highlight-invalid-static-range-crash.html b/testing/web-platform/tests/css/css-highlight-api/Highlight-invalid-static-range-crash.html
@@ -1,23 +0,0 @@
-<!DOCTYPE html>
-
-<body onload="boom()">
- <p id="A"></p>
- <p id="B"></p>
-</body>
-
-<script>
-function boom() {
- let highlight0 = new Highlight();
-
- let range = new StaticRange({
- endContainer: document.getElementById("A"),
- startOffset: 1,
- startContainer: document.getElementById("B"),
- endOffset: 1,
- });
- CSS.highlights.set("highlight0", highlight0);
-
- document.getElementById("A").remove();
- highlight0.add(range);
-}
-</script>