Skip to content

Commit a93f9f8

Browse files
sanketjannevk
authored andcommitted
Add StaticRange constructor
Tests: web-platform-tests/wpt#18619. Closes #590.
1 parent a257369 commit a93f9f8

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

dom.bs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7553,6 +7553,15 @@ Necessarily, a <a>live range</a> might itself be modified as part of the mutatio
75537553
{{Node/normalize()}} method, and the <a>replace data</a> and <a lt="split a Text node">split</a>
75547554
algorithms for the hairy details.
75557555

7556+
<p>Updating <a>live ranges</a> in response to <a>node tree</a> mutations can be expensive. For every
7557+
<a>node tree</a> change, all affected {{Range}} objects need to be updated. Even if the application
7558+
is uninterested in some <a>live ranges</a>, it still has to pay the cost of keeping them up-to-date
7559+
when a mutation occurs.
7560+
7561+
<p>A {{StaticRange}} object is a lightweight <a>range</a> that does not update when the
7562+
<a>node tree</a> mutates. It is therefore not subject to the same maintenance cost as
7563+
<a>live ranges</a>.
7564+
75567565

75577566
<h3 id=boundary-points>Boundary points</h3>
75587567

@@ -7673,13 +7682,41 @@ false otherwise.
76737682
<h3 id=interface-staticrange>Interface {{StaticRange}}</h3>
76747683

76757684
<pre class=idl>
7676-
[Exposed=Window]
7685+
dictionary StaticRangeInit {
7686+
required Node startContainer;
7687+
required unsigned long startOffset;
7688+
required Node endContainer;
7689+
required unsigned long endOffset;
7690+
};
7691+
7692+
[Constructor(StaticRangeInit init),
7693+
Exposed=Window]
76777694
interface StaticRange : AbstractRange {
76787695
};
76797696
</pre>
76807697

7681-
<p class=note>A future version of the {{StaticRange}} interface will provide a non-throwing
7682-
constructor.
7698+
<dl class=domintro>
7699+
<dt><code><var>staticRange</var> = new <a constructor lt="StaticRange(init)">StaticRange</a>(init)</code>
7700+
<dd><p>Returns a new <a>range</a> object that does not update when the <a>node tree</a> mutates.
7701+
</dl>
7702+
7703+
<p>The <dfn constructor for=StaticRange><code>StaticRange(<var>init</var>)</code></dfn> constructor,
7704+
when invoked, must run these steps:
7705+
7706+
<ol>
7707+
<li><p>If <var>init</var>'s {{StaticRangeInit/startContainer}} or {{StaticRangeInit/endContainer}}
7708+
is a {{DocumentType}} or {{Attr}} <a for=/>node</a>, then <a>throw</a> an
7709+
"{{InvalidNodeTypeError!!exception}}" {{DOMException}}.
7710+
7711+
<li><p>Let <var>staticRange</var> be a new {{StaticRange}} object.
7712+
7713+
<li><p>Set <var>staticRange</var>'s <a for=range>start</a> to (<var>init</var>'s
7714+
{{StaticRangeInit/startContainer}}, <var>init</var>'s {{StaticRangeInit/startOffset}}) and
7715+
<a for=range>end</a> to (<var>init</var>'s {{StaticRangeInit/endContainer}}, <var>init</var>'s
7716+
{{StaticRangeInit/endOffset}}).
7717+
7718+
<li><p>Return <var>staticRange</var>.
7719+
</ol>
76837720

76847721

76857722
<h3 id=interface-range>Interface {{Range}}</h3>
@@ -10100,6 +10137,7 @@ Ryosuke Niwa,
1010010137
Sam Dutton,
1010110138
Sam Sneddon,
1010210139
Samuel Giles,
10140+
Sanket Joshi,
1010310141
Sebastian Mayr,
1010410142
Seo Sanghyeon,
1010510143
Sergey G. Grekhov,

0 commit comments

Comments
 (0)