Skip to content

Commit d28a66a

Browse files
authored
Fix toBlob() and convertToBlob()
In particular: * Neither method dealt properly with "serialization of a the bitmap as a file" returning null. * Neither method clearly indicated what had to happen synchronously (bitmap copy) and asynchronously (converting to a file). * toBlob() did not indicate the Realm of the new Blob object. * toBlob() invoked IDL's callback concept incorrectly. * convertToBlob() was weird with in parallel and queue a task. * convertToBlob() did not list a task source. Fixes #3386.
1 parent b7c21b1 commit d28a66a

File tree

1 file changed

+59
-31
lines changed

1 file changed

+59
-31
lines changed

source

Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -59599,31 +59599,43 @@ callback <dfn>BlobCallback</dfn> = void (<span>Blob</span>? blob);</pre>
5959959599
<var>quality</var>)</code></dfn> method, when invoked, must run these steps:</p>
5960059600

5960159601
<ol>
59602-
59603-
<!--ADD-TOPIC:Security-->
5960459602
<li><p>If this <code>canvas</code> element's bitmap's <span
5960559603
data-x="concept-canvas-origin-clean">origin-clean</span> flag is set to false, then throw a
59606-
<span>"<code>SecurityError</code>"</span> <code>DOMException</code>.</p>
59607-
<!--REMOVE-TOPIC:Security-->
59604+
<span>"<code>SecurityError</code>"</span> <code>DOMException</code>.</p></li>
59605+
59606+
<li><p>Let <var>result</var> be null.</p></li>
59607+
59608+
<li><p>If this <code>canvas</code> element's bitmap has pixels (i.e., neither its horizontal
59609+
dimension nor its vertical dimension is zero), then set <var>result</var> to a copy of this
59610+
<code>canvas</code> element's bitmap.
5960859611

5960959612
<li>
59610-
<p>If this <code>canvas</code> element's bitmap has no pixels (i.e. either its horizontal
59611-
dimension or its vertical dimension is zero) then let <var>result</var> be null.</p>
59613+
<p>Run these steps <span>in parallel</span>:</p>
5961259614

59613-
<p>Otherwise, let <var>result</var> be a <code>Blob</code> object representing <span data-x="a
59614-
serialization of the bitmap as a file">a serialization of this <code>canvas</code> element's
59615-
bitmap as a file</span>, passing <var>type</var> and <var>quality</var> if they were given. <ref
59616-
spec=FILEAPI></p>
59617-
</li>
59615+
<ol>
59616+
<li><p>If <var>result</var> is non-null, then set <var>result</var> to <span data-x="a
59617+
serialization of the bitmap as a file">a serialization of <var>result</var> as a file</span>,
59618+
with <var>type</var> and <var>quality</var> if they were given.</p></li>
5961859619

59619-
<li><p>Return, but continue running these steps <span>in parallel</span>.</p></li>
59620+
<li>
59621+
<p><span>Queue a task</span> to run these steps:</p>
5962059622

59621-
<li><p><span>Queue a task</span> to <span data-x="es-invoking-callback-functions">invoke</span>
59622-
the <code>BlobCallback</code> <var>callback</var> with <var>result</var> as its argument. The
59623-
<span>task source</span> for this task is the
59624-
<!--en-GB--><dfn id="canvas-blob-serialisation-task-source">canvas blob serialization task
59625-
source</dfn>.</p></li>
59623+
<ol>
59624+
<li><p>If <var>result</var> is non-null, then set <var>result</var> to a new
59625+
<code>Blob</code> object, created in the <span data-x="concept-relevant-realm">relevant
59626+
Realm</span> of this <code>canvas</code> element, representing <var>result</var>. <ref
59627+
spec=FILEAPI></p></li>
5962659628

59629+
<li><p><span data-x="es-invoking-callback-functions">Invoke</span> <var>callback</var> with
59630+
« <var>result</var> ».</p></li>
59631+
</ol>
59632+
59633+
<p>The <span>task source</span> for this task is the
59634+
<!--en-GB--><dfn id="canvas-blob-serialisation-task-source">canvas blob serialization task
59635+
source</dfn>.</p>
59636+
</li>
59637+
</ol>
59638+
</li>
5962759639
</ol>
5962859640

5962959641
<p>The <dfn><code
@@ -65286,28 +65298,44 @@ interface <dfn>OffscreenCanvas</dfn> : <span>EventTarget</span> {
6528665298
promise rejected with a <span>"<code>SecurityError</code>"</span> <code>DOMException</code>.</p>
6528765299

6528865300
<li><p>If this <code>OffscreenCanvas</code> object's <span
65289-
data-x="offscreencanvas-bitmap">bitmap</span> has no pixels (i.e. either its
65301+
data-x="offscreencanvas-bitmap">bitmap</span> has no pixels (i.e., either its
6529065302
horizontal dimension or its vertical dimension is zero) then return a promise rejected with an
6529165303
<span>"<code>IndexSizeError</code>"</span> <code>DOMException</code>.</p></li>
6529265304

65305+
<li><p>Let <var>bitmap</var> be a copy of this <code>OffscreenCanvas</code> object's <span
65306+
data-x="offscreencanvas-bitmap">bitmap</span>.</p></li>
65307+
6529365308
<li><p>Let <var>result</var> be a new promise object.</p></li>
6529465309

65295-
<li><p>Return <var>result</var>, and <span>queue a task</span> to run the remaining steps
65296-
<span>in parallel</span>.</p></li>
65310+
<li>
65311+
<p>Run these steps <span>in parallel</span>:</p>
65312+
65313+
<ol>
65314+
<li><p>Let <var>file</var> be <span data-x="a serialization of the bitmap as a file">a
65315+
serialization of <var>bitmap</var> as a file</span>, with <var>options</var>'s <dfn><code
65316+
data-x="image-encode-options-type">type</code></dfn> and <dfn><code
65317+
data-x="image-encode-options-quality">quality</code></dfn>.</p></li>
65318+
65319+
<li>
65320+
<p><span>Queue a task</span> to run these steps:</p>
6529765321

65298-
<li><p>Let <var>blob</var> be a <code>Blob</code> object, created in the <span
65299-
data-x="concept-relevant-realm">relevant Realm</span> of this <code>OffscreenCanvas</code>
65300-
object, representing <span data-x="a serialization of the bitmap as a file">a serialization of
65301-
this <code>OffscreenCanvas</code> object's <span data-x="offscreencanvas-bitmap">bitmap</span> as
65302-
a file</span>, passing the values of the <dfn><code
65303-
data-x="image-encode-options-type">type</code></dfn> and <dfn><code
65304-
data-x="image-encode-options-quality">quality</code></dfn> fields of <var>options</var>, if
65305-
<var>options</var> was specified. <ref spec=FILEAPI></p></li>
65322+
<ol>
65323+
<li><p>If <var>file</var> is null, then reject <var>result</var> with an
65324+
<span>"<code>EncodingError</code>"</span> <code>DOMException</code>.</p></li>
6530665325

65307-
<li><p>If <var>blob</var> is null, then reject <var>result</var> with an
65308-
<span>"<code>EncodingError</code>"</span> <code>DOMException</code>.</p></li>
65326+
<li><p>Otherwise, resolve <var>result</var> with a new <code>Blob</code> object, created in
65327+
the <span data-x="concept-relevant-realm">relevant Realm</span> of this
65328+
<code>OffscreenCanvas</code> object, representing <var>file</var>. <ref
65329+
spec=FILEAPI></p></li>
65330+
</ol>
6530965331

65310-
<li><p>Otherwise, resolve <var>result</var> with <var>blob</var>.</p></li>
65332+
<p>The <span>task source</span> for this task is the <span>canvas blob serialization task
65333+
source</span>.</p>
65334+
</li>
65335+
</ol>
65336+
</li>
65337+
65338+
<li><p>Return <var>result</var>.</p></li>
6531165339
</ol>
6531265340

6531365341
<p>The <dfn><code

0 commit comments

Comments
 (0)