Closed Bug 1815802 Opened 1 year ago Closed 1 year ago

Assertion failure if `Selection::AddRangeJS` is called twice with same range instance

Categories

(Core :: DOM: Selection, defect, P2)

defect

Tracking

()

RESOLVED FIXED
111 Branch
Tracking Status
firefox111 --- fixed

People

(Reporter: masayuki, Assigned: masayuki)

References

Details

Attachments

(1 file)

(In reply to Emilio Cobos Álvarez (:emilio) from comment #10)

So that does seem like either an editor bug or a missing check in Selection::AddRange. It's separate from the crash in comment 0 so I'll land the fix without the crashtest for now. Masayuki do you have cycles to look at that? It seems we end up with a range registered with the editor selection, but where JS can access it, so JS calling document.getSelection().addRange(d) asserts.

(In reply to Emilio Cobos Álvarez (:emilio) from comment #11)

Reduced test-case for that:

<!doctype html>
<html contenteditable>
<button style="background-color: #000; color: #fff">Browse</button>
<script>
  let d = new Range()
  let f = document.getSelection()
  f.addRange(d)
  d.setStart(document.querySelector("button"), 0);
  f.addRange(d)
</script>

(In reply to Emilio Cobos Álvarez (:emilio) from comment #12)

Created attachment 9316599 [details]
Bug 1812194 - Crashtest. r=masayuki

This suffers from the bug mentioned in comment 11 and thus crashes in
debug builds, so should be landed probably in another bug.

Depends on D169085

(In reply to Masayuki Nakano [:masayuki] (he/him)(JST, +0900) from comment #15)

Yeah, it must be a bug of DOM Selection. I don't know how it should be handled (whether the new range is added with cloning or just ignored), but anyway, it should be fixed.

There is no spec about multiple range support.
https://www.w3.org/TR/selection-api/#dom-selection-addrange

Therefore, I think that we don't need to handle it in the case.

Selection stores given ranges directly if and only if it's possible.
Therefore, adding a range which is already in the array of Selection ranges
needs to do nothing.

Pushed by masayuki@d-toybox.com:
https://hg.mozilla.org/integration/autoland/rev/ef922a0f7990
Make `Selection::AddRangeJS` do nothing if adding range instance belongs to the `Selection` r=jjaschke
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 111 Branch
Regressions: 1840700
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: