Skip to content

Commit 9363c6d

Browse files
Collapse range before mutations in deleteContents() and extractContents()
Move the step that sets the range's start and end to (newNode, newOffset) from after DOM mutations to before them, in both the deleteContents() and extract algorithms. The pre-computed collapse target can become invalid if script runs during the remove operation (via "removing steps" hooks) and modifies the DOM. By collapsing the range before mutations, the DOM's built-in live range maintenance mechanisms (live range pre-remove steps and replace data range adjustments) automatically keep the range valid through all subsequent operations. Fixes #1446.
1 parent 3a80353 commit 9363c6d

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

dom.bs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9280,6 +9280,9 @@ method steps are:
92809280
point.
92819281
</ol>
92829282

9283+
<li><p>Set <a>this</a>'s <a for=range>start</a> and <a for=range>end</a> to
9284+
(<var>newNode</var>, <var>newOffset</var>).
9285+
92839286
<li><p>If <var>originalStartNode</var> is a {{CharacterData}} <a for=/>node</a>, then
92849287
<a>replace data</a> of <var>originalStartNode</var> with <var>originalStartOffset</var>,
92859288
<var>originalStartNode</var>'s <a for=Node>length</a> &minus; <var>originalStartOffset</var>, and
@@ -9291,9 +9294,6 @@ method steps are:
92919294
<li><p>If <var>originalEndNode</var> is a {{CharacterData}} <a for=/>node</a>, then
92929295
<a>replace data</a> of <var>originalEndNode</var> with 0, <var>originalEndOffset</var>, and
92939296
the empty string.
9294-
9295-
<li><p>Set <a for=range>start</a> and <a for=range>end</a> to
9296-
(<var>newNode</var>, <var>newOffset</var>).
92979297
</ol>
92989298
</div>
92999299

@@ -9411,8 +9411,8 @@ method steps are:
94119411
point.
94129412
</ol>
94139413

9414-
<!-- Now we start with mutations, so we can't refer to this anymore unless we carefully consider
9415-
how it will have mutated. -->
9414+
<li><p>Set <var>range</var>'s <a for=range>start</a> and <a for=range>end</a> to
9415+
(<var>newNode</var>, <var>newOffset</var>).
94169416

94179417
<li>
94189418
<p>If <var>firstPartiallyContainedChild</var> is a {{CharacterData}} <a for=/>node</a>:
@@ -9495,9 +9495,6 @@ method steps are:
94959495
<li><p><a>Append</a> <var>subfragment</var> to <var>clone</var>.
94969496
</ol>
94979497

9498-
<li><p>Set <var>range</var>'s <a for=range>start</a> and <a for=range>end</a> to
9499-
(<var>newNode</var>, <var>newOffset</var>).
9500-
95019498
<li><p>Return <var>fragment</var>.
95029499
</ol>
95039500
</div>
@@ -11281,6 +11278,7 @@ Simon Pieters,
1128111278
Simon Wülker,
1128211279
Stef Busking,
1128311280
Steve Byrne,
11281+
Steven Obiajulu,
1128411282
Stig Halvorsen,
1128511283
Tab Atkins,
1128611284
Takashi Sakamoto,

0 commit comments

Comments
 (0)