Skip to content

Commit

Permalink
Update type of MediaMetadata's artwork
Browse files Browse the repository at this point in the history
Fixes w3c#237

Introduce a slot where we store the FrozenArray so that the getter always returns the same object.
Make sure the slot is reset when the setter is called.
  • Loading branch information
youennf committed Sep 27, 2024
1 parent e862d47 commit 71a1d94
Showing 1 changed file with 38 additions and 41 deletions.
79 changes: 38 additions & 41 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ table td, table th {

<pre class="link-defaults">
spec:html; type:element; text:link
spec:webidl; type:interface; text:object
</pre>

<pre class="anchors">
Expand Down Expand Up @@ -1094,9 +1095,10 @@ dictionary MediaMetadataInit {
</p>

<p>
A {{MediaMetadata}} has an associated list of <dfn for="MediaMetadata">artwork
images</dfn>, which is a list of type <a idl>object</a> on the interface
but a list of type {{MediaImage}} internally.
A {{MediaMetadata}} has an associated sequence of <dfn for="MediaMetadata">artwork
images</dfn>, which is a sequence of type {{MediaImage}}.
A {{MediaMetadata}} also has has an associated <dfn for="MediaMetadata">
converted artwork images</dfn> which is initially <code>undefined</code>.
</p>

<p>
Expand Down Expand Up @@ -1141,7 +1143,7 @@ dictionary MediaMetadataInit {
<li>
Run the <a>convert artwork algorithm</a> with <var>init</var>'s
{{MediaMetadataInit/artwork}} as <var>input</var>,
where the <var>input</var> is a list of type {{MediaImage}},
where <var>input</var> is a sequence of type {{MediaImage}},
and set <var>metadata</var>'s <a for="MediaMetadata">artwork images</a>
as the result if it succeeded.
</li>
Expand All @@ -1166,7 +1168,7 @@ dictionary MediaMetadataInit {
</p>

When the <dfn>convert artwork algorithm</dfn> with <var>input</var> parameter is
invoked, where the <var>input</var> is a list of type {{MediaImage}},
invoked, where the <var>input</var> is a sequence of type {{MediaImage}},
the user agent MUST run the following steps:
<ol>
<li>
Expand Down Expand Up @@ -1230,62 +1232,56 @@ the user agent MUST run the following steps:
<p>
The <dfn attribute for="MediaMetadata">artwork</dfn>
attribute reflects the {{MediaMetadata}}'s <a for="MediaMetadata">artwork
images</a>. On getting, it MUST return the result of the following steps:
images</a>. On getting, it MUST run the following steps:
<ol>
<li>
Let <var>frozenArtwork</var> be an empty list of type <a idl>object</a>.
</li>
<li>
For each <var>entry</var> in the {{MediaMetadata}}'s <a
for="MediaMetadata">artwork images</a>, perform the following steps:
If the {{MediaMetadata}}'s <dfn>converted artwork images</dfn> is <code>undefined</code>,
run the following steps:
<ol>
<li>
Let <var>image</var> be a new {{MediaImage}}.
Let <var>frozenArtwork</var> be a Javascript Array value.
</li>
<li>
Set <var>image</var>'s {{MediaImage/src}} to <var>entry</var>'s
{{MediaImage/src}}.
</li>
<li>
Set <var>image</var>'s {{MediaImage/sizes}} to <var>entry</var>'s
{{MediaImage/sizes}}.
</li>
<li>
Set <var>image</var>'s {{MediaImage/type}} to <var>entry</var>'s
{{MediaImage/type}}.
</li>
<li>
Convert <var>image</var> into an <var>object</var>
whose type is <a idl>object</a>.
For each <var>entry</var> in the {{MediaMetadata}}'s <a
for="MediaMetadata">artwork images</a>, perform the following steps:
<ol>
<li>
Convert <var>entry</var> into a Javascript object named <var>image</var>.
</li>
<li>
Perform [=!=] <a abstract-op>SetIntegrityLevel</a>(<var>image</var>,
"<code>frozen</code>"), to prevent accidental mutation by scripts.
</li>
<li>
Push <var>image</var> to <var>frozenArtwork</var>.
</li>
</ol>
</li>
<!-- XXX IDL dictionaries are usually returned by value, so don't need
to be immutable. But FrozenArray reifies the dictionaries to mutable JS
objects accessed by reference, so we explicitly freeze them. It would be
better to do this with IDL primitives instead of JS - see
https://www.w3.org/Bugs/Public/show_bug.cgi?id=29004 -->
<li>
Call {{Object/freeze(O)}} on <var>image</var>, to prevent accidental
mutation by scripts.
Perform [=!=] <a abstract-op>SetIntegrityLevel</a>(<var>frozenArtwork</var>, "<code>frozen</code>").
</li>
<li>
Append the <var>object</var> to <var>frozenArtwork</var>.
Set the {{MediaMetadata}}'s <a>converted artwork images</a> to <var>frozenArtwork</var>.
</li>
</ol>
</li>
<li>
<a>Create a frozen array</a> from <var>frozenArtwork</var>.
Return the {{MediaMetadata}}'s <a>converted artwork images</a>.
</li>
</ol>
On setting, it MUST run the following steps:
<ol>
<li>
Convert the <var>frozenArtwork</var> from a list of type <a idl>object</a>
into a list of type {{MediaImage}}.
Let <var>convertedArtwork</var> be the result of converting
<var>frozenArtwork</var> into a sequence of type {{MediaImage}}.
</li>
<li>
Run <a>convert artwork algorithm</a> with the converted list as
Run <a>convert artwork algorithm</a> with the converted sequence as
<var>input</var>, and set the {{MediaMetadata}}'s
<a for="MediaMetadata">artwork images</a> as the result if it succeeded.
<a for="MediaMetadata">artwork images</a> as the result if it succeeds.
</li>
<li>
Set the {{MediaMetadata}}'s <a>converted artwork images</a> to <code>undefined</code>.
</li>
</ol>
</p>
Expand Down Expand Up @@ -1384,11 +1380,12 @@ dictionary ChapterInformationInit {
</li>
<li>
Let {{ChapterInformationInit/artwork}} be the result of running the
<a>convert artwork algorithm</a>.
<a>convert artwork algorithm</a> with <var>init</var>'s
{{ChapterInformation/artwork}} as <var>input</var>.
</li>
<li>
Set <var>chapterInfo</var>'s <a for="ChapterInformation">artwork
images</a> to the result of [=Create a frozen array|creating a frozen
images</a> be the result of [=Create a frozen array|creating a frozen
array=] from {{ChapterInformationInit/artwork}}.
</li>
<li>
Expand Down

0 comments on commit 71a1d94

Please sign in to comment.