mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-15 23:52:57 +00:00
When inserting a node into a parent, any live DOM ranges that reference the parent may need to be updated. The spec does this by increasing or decreasing the start/end offsets of each live range *before* actually performing the insertion. This caused us to crash with a verification failure, since it was possible to set the range offset to an invalid value (that would go on to immediately become valid after the insertion was finished). This patch fixes the issue by adding special badged helpers on Range for Node to reach into it and increase/decrease the offsets during node insertion. This skips the offset validity check and actually makes our code read slightly more like the spec. Found by Domato :^)
14 lines
611 B
HTML
14 lines
611 B
HTML
<script src="../include.js"></script>
|
|
<script>
|
|
test(() => {
|
|
const h2 = document.querySelector("h2");
|
|
document.getSelection().collapse(h2, 1);
|
|
var h3 = document.createElement("h3");
|
|
h2.insertBefore(h3, h2.firstChild)
|
|
println(document.getSelection().rangeCount);
|
|
printElement(document.getSelection().getRangeAt(0).startContainer);
|
|
println(document.getSelection().getRangeAt(0).startOffset);
|
|
printElement(document.getSelection().getRangeAt(0).endContainer);
|
|
println(document.getSelection().getRangeAt(0).endOffset);
|
|
});
|
|
</script><h2>
|