Skip to content

Commit 00a80ff

Browse files
committed
Editorial: Make "parse a srcset attribute" return an ordered set
Also use Infra Standard control flow and data structures in nearby algorithms. Fixes whatwg#2877.
1 parent 5f59b7a commit 00a80ff

File tree

1 file changed

+82
-87
lines changed

1 file changed

+82
-87
lines changed

source

Lines changed: 82 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -25711,11 +25711,9 @@ interface <dfn>HTMLImageElement</dfn> : <span>HTMLElement</span> {
2571125711

2571225712
<dd>
2571325713

25714-
<!--CLEANUP-->
25715-
<p>Returns a new <code>img</code> element, with the <code
25716-
data-x="attr-dim-width">width</code> and <code
25717-
data-x="attr-dim-height">height</code> attributes set to the values
25718-
passed in the relevant arguments, if applicable.</p>
25714+
<p>Returns a new <code>img</code> element, with the <code data-x="attr-dim-width">width</code>
25715+
and <code data-x="attr-dim-height">height</code> attributes set to the values passed in the
25716+
relevant arguments, if applicable.</p>
2571925717

2572025718
</dd>
2572125719

@@ -26836,8 +26834,8 @@ was an English &lt;a href="/wiki/Music_hall">music hall&lt;/a> singer, ...</pre>
2683626834

2683726835
<p>An <code>img</code> element is associated with a <span>source set</span>.</p>
2683826836

26839-
<p>A <dfn>source set</dfn> is an ordered set of zero or more <span data-x="image source">image sources</span>
26840-
and a <span>source size</span>.</p>
26837+
<p>A <dfn>source set</dfn> has an <span data-x="set">ordered set</span> of zero or more <span
26838+
data-x="image source">image sources</span> and a <span>source size</span>.</p>
2684126839

2684226840
<p>An <dfn>image source</dfn> is a <span>URL</span>, and optionally either a <span>pixel density
2684326841
descriptor</span>, or a <span>width descriptor</span>.</p>
@@ -27469,22 +27467,20 @@ was an English &lt;a href="/wiki/Music_hall">music hall&lt;/a> singer, ...</pre>
2746927467

2747027468
<li><p><span>Update the source set</span> for <var>el</var>.</p></li>
2747127469

27472-
<li><p>If <var>el</var>'s <span>source set</span> is empty,
27473-
return null as the URL and undefined as the pixel density and abort these steps.</p></li>
27470+
<li><p>If <var>el</var>'s <span>source set</span> is empty, then return null as the URL and
27471+
undefined as the pixel density.</p></li>
2747427472

27475-
<li><p>Otherwise, take <var>el</var>'s <span>source set</span>
27476-
and let it be <var>source set</var>.</p></li>
27473+
<li><p>Let <var>sourceSet</var> be <var>el</var>'s <span>source set</span>.</p></li>
2747727474

2747827475
<li><p>If an entry <var>b</var> in <var>source set</var> has the same associated <span>pixel
2747927476
density descriptor</span> as an earlier entry <var>a</var> in <var>source set</var>, then remove
2748027477
entry <var>b</var>. Repeat this step until none of the entries in <var>source set</var> have the
2748127478
same associated <span>pixel density descriptor</span> as an earlier entry.</p></li>
2748227479

27483-
<li><p>In a user agent-specific manner,
27484-
choose one <span>image source</span> from <var>source set</var>.
27485-
Let this be <var>selected source</var>.</p></li>
27480+
<li><p>In a user agent-specific manner, choose one <span>image source</span> from
27481+
<var>sourceSet</var>. Let this be <var>selectedSource</var>.</p></li>
2748627482

27487-
<li><p>Return <var>selected source</var> and its associated pixel density.</p></li>
27483+
<li><p>Return <var>selectedSource</var> and its associated pixel density.</p></li>
2748827484

2748927485
</ol>
2749027486

@@ -27496,11 +27492,14 @@ was an English &lt;a href="/wiki/Music_hall">music hall&lt;/a> singer, ...</pre>
2749627492

2749727493
<ol>
2749827494

27499-
<li><p>Set <var>el</var>'s <span>source set</span> to an empty <span>source set</span>.</p></li>
27495+
<li><p>Let <var>sourceSet</var> be a new empty <span>source set</span>.
27496+
27497+
<li><p>Set <var>el</var>'s <span>source set</span> to <var>sourceSet</var>.</p></li>
2750027498

27501-
<li><p>If <var>el</var> has a parent node and that is a <code>picture</code> element,
27502-
let <var>elements</var> be an array containing <var>el</var>'s parent node's child elements, retaining relative order.
27503-
Otherwise, let <var>elements</var> be array containing only <var>el</var>.</p></li>
27499+
<li><p>If <var>el</var> has a parent node and that is a <code>picture</code> element, let
27500+
<var>elements</var> be a <span>list</span> containing <var>el</var>'s parent node's child
27501+
elements, retaining relative order. Otherwise, let <var>elements</var> be a <span>list</span>
27502+
containing only <var>el</var>.</p></li>
2750427503

2750527504
<li><p>If <var>el</var> has a <code data-x="attr-dim-width">width</code> attribute, and parsing
2750627505
that attribute's value using the <span>rules for parsing dimension values</span> doesn't generate
@@ -27509,8 +27508,7 @@ was an English &lt;a href="/wiki/Music_hall">music hall&lt;/a> singer, ...</pre>
2750927508

2751027509
<li>
2751127510

27512-
<p>Iterate through <var>elements</var>,
27513-
doing the following for each item <var>child</var>:</p>
27511+
<p><span data-x="list iterate">For each</span> <var>child</var> in <var>elements</var>:</p>
2751427512

2751527513
<ol>
2751627514

@@ -27521,59 +27519,55 @@ was an English &lt;a href="/wiki/Music_hall">music hall&lt;/a> singer, ...</pre>
2752127519
<ol>
2752227520

2752327521
<li><p>If <var>child</var> has a <code data-x="attr-img-srcset">srcset</code> attribute,
27524-
<span data-x="parse a srcset attribute">parse <var>child</var>'s srcset attribute</span>
27525-
and let the returned <span>source set</span> be <var>source set</var>.
27526-
Otherwise, let <var>source set</var> be an empty <span>source set</span>.</p></li>
27522+
<span data-x="parse a srcset attribute">parse <var>child</var>'s srcset attribute</span> and
27523+
set <var>sourceSet</var>'s <span data-x="image source">image sources</span> to the returned
27524+
<span data-x="set">ordered set</span>.</p></li>
2752727525

2752827526
<li><p><span data-x="parse a sizes attribute">Parse <var>child</var>'s sizes
27529-
attribute</span> with the fallback width <var>width</var>, and let <var>source set</var>'s
27530-
<span>source size</span> be the returned value.</p></li>
27527+
attribute</span> with the fallback width <var>width</var>, and set <var>sourceSet</var>'s
27528+
<span>source size</span> to the returned value.</p></li>
2753127529

27532-
<li><p>If <var>child</var> has a <code data-x="attr-img-src">src</code> attribute
27533-
whose value is not the empty string
27534-
and <var>source set</var> does not contain an
27535-
<span>image source</span> with a <span>pixel density descriptor</span> value of 1,
27536-
and no <span>image source</span> with a <span>width descriptor</span>,
27537-
append <var>child</var>'s <code data-x="attr-img-src">src</code> attribute value to <var>source set</var>.</p></li>
27530+
<li><p>If <var>child</var> has a <code data-x="attr-img-src">src</code> attribute whose value
27531+
is not the empty string and <var>sourceSet</var> does not contain an <span>image
27532+
source</span> with a <span>pixel density descriptor</span> value of 1, and no <span>image
27533+
source</span> with a <span>width descriptor</span>, append <var>child</var>'s <code
27534+
data-x="attr-img-src">src</code> attribute value to <var>sourceSet</var>.</p></li>
2753827535

2753927536
<li><p><span>Normalize the source densities</span> of <var>source set</var>.</p></li>
2754027537

27541-
<li><p>Let <var>el</var>'s <span>source set</span> be <var>source set</var>.</p></li>
27542-
27543-
<li><p>Abort this algorithm.</p></li>
27538+
<li><p>Return.</p></li>
2754427539

2754527540
</ol>
2754627541

2754727542
</li>
2754827543

27549-
<li><p>If <var>child</var> is not a <code>source</code> element, continue to the next child.
27550-
Otherwise, <var>child</var> is a <code>source</code> element.</p></li>
27544+
<li><p>If <var>child</var> is not a <code>source</code> element, then continue. Otherwise,
27545+
<var>child</var> is a <code>source</code> element.</p></li>
2755127546

2755227547
<li><p>If <var>child</var> does not have a <code data-x="attr-source-srcset">srcset</code>
27553-
attribute, continue to the next child.</p></li>
27548+
attribute, then continue.</p></li>
2755427549

27555-
<li><p><span data-x="parse a srcset attribute">Parse <var>child</var>'s srcset attribute</span> and
27556-
let the returned <span>source set</span> be <var>source set</var>.</p></li>
27550+
<li><p><span data-x="parse a srcset attribute">Parse <var>child</var>'s srcset attribute</span>
27551+
and set <var>sourceSet</var>'s <span data-x="image source">image sources</span> to the returned
27552+
<span data-x="set">ordered set</span>.</p></li>
2755727553

27558-
<li><p>If <var>source set</var> has zero <span data-x="image source">image sources</span>,
27559-
continue to the next child.</p></li>
27554+
<li><p>If <var>sourceSet</var> has zero <span data-x="image source">image sources</span>,
27555+
then continue.</p></li>
2756027556

2756127557
<li><p>If <var>child</var> has a <code data-x="attr-source-media">media</code> attribute, and
27562-
its value does not <span data-x="matches the environment">match the environment</span>,
27563-
continue to the next child.</p></li>
27558+
its value does not <span data-x="matches the environment">match the environment</span>, then
27559+
continue.</p></li>
2756427560

2756527561
<li><p><span data-x="parse a sizes attribute">Parse <var>child</var>'s sizes attribute</span>
27566-
with the fallback width <var>width</var>, and let <var>source set</var>'s <span>source
27567-
size</span> be the returned value.</p></li>
27562+
with the fallback width <var>width</var>, and set <var>sourceSet</var>'s <span>source
27563+
size</span> to the returned value.</p></li>
2756827564

2756927565
<li><p>If <var>child</var> has a <code data-x="attr-source-type">type</code> attribute, and its
27570-
value is an unknown or unsupported <span>MIME type</span>, continue to the next child.</p></li>
27571-
27572-
<li><p><span>Normalize the source densities</span> of <var>source set</var>.</p></li>
27566+
value is an unknown or unsupported <span>MIME type</span>, then continue.</p></li>
2757327567

27574-
<li><p>Let <var>el</var>'s <span>source set</span> be <var>source set</var>.</p></li>
27568+
<li><p><span>Normalize the source densities</span> of <var>sourceSet</var>.</p></li>
2757527569

27576-
<li><p>Abort this algorithm.</p></li>
27570+
<li><p>Return.</p></li>
2757727571

2757827572
</ol>
2757927573

@@ -27600,20 +27594,20 @@ was an English &lt;a href="/wiki/Music_hall">music hall&lt;/a> singer, ...</pre>
2760027594
<li><p>Let <var>position</var> be a pointer into <var>input</var>,
2760127595
initially pointing at the start of the string.</p></li>
2760227596

27603-
<li><p>Let <var>candidates</var> be an initially empty <span>source set</span>.</p></li>
27597+
<li><p>Let <var>candidates</var> be an empty <span data-x="set">ordered set</span>.</p></li>
2760427598

2760527599
<li><p><i>Splitting loop</i>: <span>Collect a sequence of code points</span> that are <span>ASCII
2760627600
whitespace</span> or U+002C COMMA characters from <var>input</var> given <var>position</var>. If
2760727601
any U+002C COMMA characters were collected, that is a <span
2760827602
data-x="concept-microsyntax-parse-error">parse error</span>.</p></li>
2760927603

27610-
<li><p>If <var>position</var> is past the end of <var>input</var>,
27611-
return <var>candidates</var> and abort these steps.</p></li>
27604+
<li><p>If <var>position</var> is past the end of <var>input</var>, return
27605+
<var>candidates</var>.</p></li>
2761227606

2761327607
<li><p><span>Collect a sequence of code points</span> that are not <span>ASCII whitespace</span>
2761427608
from <var>input</var> given <var>position</var>, and let that be <var>url</var>.</p></li>
2761527609

27616-
<li><p>Let <var>descriptors</var> be a new empty list.</p></li>
27610+
<li><p>Let <var>descriptors</var> be a new empty <span>list</span>.</p></li>
2761727611

2761827612
<li>
2761927613

@@ -27634,7 +27628,7 @@ was an English &lt;a href="/wiki/Music_hall">music hall&lt;/a> singer, ...</pre>
2763427628
<li><p><i>Descriptor tokenizer</i>: <span>Skip ASCII whitespace</span> within <var>input</var>
2763527629
given <var>position</var>.</p></li>
2763627630

27637-
<li><p>Let <var>current descriptor</var> be the empty string.</p></li>
27631+
<li><p>Let <var>currentDescriptor</var> be the empty string.</p></li>
2763827632

2763927633
<li><p>Let <var>state</var> be <i>in descriptor</i>.</p></li>
2764027634

@@ -27657,32 +27651,32 @@ was an English &lt;a href="/wiki/Music_hall">music hall&lt;/a> singer, ...</pre>
2765727651

2765827652
<dt><span>ASCII whitespace</span></dt>
2765927653

27660-
<dd><p>If <var>current descriptor</var> is not empty,
27661-
append <var>current descriptor</var> to <var>descriptors</var>
27662-
and let <var>current descriptor</var> be the empty string.
27663-
Set <var>state</var> to <i>after descriptor</i>.</p></dd>
27654+
<dd><p>If <var>currentDescriptor</var> is not empty, <span data-x="list
27655+
append">append</span> <var>currentDescriptor</var> to <var>descriptors</var> and set
27656+
<var>currentDescriptor</var> to the empty string. Set <var>state</var> to <i>after
27657+
descriptor</i>.</p></dd>
2766427658

2766527659
<dt>U+002C COMMA (,)</dt>
2766627660

27667-
<dd><p>Advance <var>position</var> to the next character in <var>input</var>.
27668-
If <var>current descriptor</var> is not empty,
27669-
append <var>current descriptor</var> to <var>descriptors</var>.
27670-
Jump to the step labeled <i>descriptor parser</i>.</p></dd>
27661+
<dd><p>Advance <var>position</var> to the next character in <var>input</var>. If
27662+
<var>currentDescriptor</var> is not empty, <span data-x="list append">append</span>
27663+
<var>currentDescriptor</var> to <var>descriptors</var>. Jump to the step labeled
27664+
<i>descriptor parser</i>.</p></dd>
2767127665

2767227666
<dt>U+0028 LEFT PARENTHESIS (()</dt>
2767327667

27674-
<dd><p>Append <var>c</var> to <var>current descriptor</var>.
27668+
<dd><p>Append <var>c</var> to <var>currentDescriptor</var>.
2767527669
Set <var>state</var> to <i>in parens</i>.</p></dd>
2767627670

2767727671
<dt>EOF</dt>
2767827672

27679-
<dd><p>If <var>current descriptor</var> is not empty,
27680-
append <var>current descriptor</var> to <var>descriptors</var>.
27681-
Jump to the step labeled <i>descriptor parser</i>.</p></dd>
27673+
<dd><p>If <var>currentDescriptor</var> is not empty, then <span data-x="list
27674+
append">append</span> <var>currentDescriptor</var> to <var>descriptors</var>. Jump to the
27675+
step labeled <i>descriptor parser</i>.</p></dd>
2768227676

2768327677
<dt>Anything else</dt>
2768427678

27685-
<dd><p>Append <var>c</var> to <var>current descriptor</var>.</p></dd>
27679+
<dd><p>Append <var>c</var> to <var>currentDescriptor</var>.</p></dd>
2768627680

2768727681
</dl>
2768827682

@@ -27698,17 +27692,17 @@ was an English &lt;a href="/wiki/Music_hall">music hall&lt;/a> singer, ...</pre>
2769827692

2769927693
<dt>U+0029 RIGHT PARENTHESIS ())</dt>
2770027694

27701-
<dd><p>Append <var>c</var> to <var>current descriptor</var>.
27695+
<dd><p>Append <var>c</var> to <var>currentDescriptor</var>.
2770227696
Set <var>state</var> to <i>in descriptor</i>.</p></dd>
2770327697

2770427698
<dt>EOF</dt>
2770527699

27706-
<dd><p>Append <var>current descriptor</var> to <var>descriptors</var>.
27707-
Jump to the step labeled <i>descriptor parser</i>.</p></dd>
27700+
<dd><p><span data-x="list append">Append</span> <var>currentDescriptor</var> to
27701+
<var>descriptors</var>. Jump to the step labeled <i>descriptor parser</i>.</p></dd>
2770827702

2770927703
<dt>Anything else</dt>
2771027704

27711-
<dd><p>Append <var>c</var> to <var>current descriptor</var>.</p></dd>
27705+
<dd><p>Append <var>c</var> to <var>currentDescriptor</var>.</p></dd>
2771227706

2771327707
</dl>
2771427708

@@ -27940,37 +27934,38 @@ was an English &lt;a href="/wiki/Music_hall">music hall&lt;/a> singer, ...</pre>
2794027934
set</span> gives every <span>image source</span> a <span>pixel density descriptor</span>.</p>
2794127935

2794227936
<p>When asked to <!--en-GB--><dfn id="normalise-the-source-densities">normalize the source
27943-
densities</dfn> of a <span>source set</span> <var>source set</var>, the user agent must do the
27937+
densities</dfn> of a <span>source set</span> <var>sourceSet</var>, the user agent must do the
2794427938
following:</p>
2794527939

2794627940
<ol>
2794727941

27948-
<li><p>Let <var>source size</var> be <var>source set</var>'s <span>source size</span>.</p></li>
27942+
<li><p>Let <var>sourceSize</var> be <var>sourceSet</var>'s <span>source size</span>.</p></li>
2794927943

2795027944
<li>
2795127945

27952-
<p>For each <span>image source</span> in <var>source set</var>:</p>
27946+
<p><span data-x="list iterate">For each</span> <span>image source</span> <var>imageSource</var>
27947+
in <var>sourceSet</var>:</p>
2795327948

2795427949
<ol>
2795527950

27956-
<li><p>If the <span>image source</span> has a <span>pixel density descriptor</span>, continue to the next
27957-
<span>image source</span>.</p></li>
27951+
<li><p>If <var>imageSource</var> has a <span>pixel density descriptor</span>, then
27952+
continue.</p></li>
2795827953

2795927954
<li>
2796027955

27961-
<p>Otherwise, if the <span>image source</span> has a <span>width descriptor</span>, replace the <span>width
27962-
descriptor</span> with a <span>pixel density descriptor</span> with a <span data-x="pixel density descriptor
27963-
value">value</span> of the <span>width descriptor value</span> divided by the <span>source size</span> and a unit
27964-
of <code data-x="">x</code>.</p>
27956+
<p>Otherwise, if <var>imageSource</var> has a <span>width descriptor</span>, then replace the
27957+
<span>width descriptor</span> with a <span>pixel density descriptor</span> with a <span
27958+
data-x="pixel density descriptor value">value</span> of the <span>width descriptor
27959+
value</span> divided by the <span>source size</span> and a unit of <code
27960+
data-x="">x</code>.</p>
2796527961

27966-
<p class="note">If the <span>source size</span> is zero,
27967-
the density would be infinity,
27968-
which results in the <span>intrinsic dimensions</span> being zero by zero.</p>
27962+
<p class="note">If the <span>source size</span> is zero, the density would be infinity, which
27963+
results in the <span>intrinsic dimensions</span> being zero by zero.</p>
2796927964

2797027965
</li>
2797127966

27972-
<li><p>Otherwise, give the <span>image source</span> a <span>pixel density descriptor</span> of <code
27973-
data-x="">1x</code>.</p></li>
27967+
<li><p>Otherwise, give <var>imageSource</var> a <span>pixel density descriptor</span> of
27968+
<code data-x="">1x</code>.</p></li>
2797427969

2797527970
</ol>
2797627971

0 commit comments

Comments
 (0)