Skip to content

Commit

Permalink
Add bytes() method to Body mixin
Browse files Browse the repository at this point in the history
Returns a Uint8Array as opposed to requiring users to get an ArrayBuffer and wrap it.

Tests: web-platform-tests/wpt#46198.

Fixes #1732.
  • Loading branch information
bakkot committed May 14, 2024
1 parent 5d9d67b commit 1085f4f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions fetch.bs
Original file line number Diff line number Diff line change
Expand Up @@ -7162,6 +7162,7 @@ interface mixin Body {
readonly attribute boolean bodyUsed;
[NewObject] Promise<ArrayBuffer> arrayBuffer();
[NewObject] Promise<Blob> blob();
[NewObject] Promise<Uint8Array> bytes();
[NewObject] Promise<FormData> formData();
[NewObject] Promise<any> json();
[NewObject] Promise<USVString> text();
Expand Down Expand Up @@ -7195,6 +7196,9 @@ due course.
<dt><code><var>requestOrResponse</var> . <a method for=Body>blob</a>()</code>
<dd><p>Returns a promise fulfilled with <var>requestOrResponse</var>'s body as {{Blob}}.

<dt><code><var>requestOrResponse</var> . <a method for=Body>bytes</a>()</code>
<dd><p>Returns a promise fulfilled with <var>requestOrResponse</var>'s body as {{Uint8Array}}.

<dt><code><var>requestOrResponse</var> . <a method for=Body>formData</a>()</code>
<dd><p>Returns a promise fulfilled with <var>requestOrResponse</var>'s body as {{FormData}}.

Expand Down Expand Up @@ -7290,6 +7294,15 @@ and whose {{Blob/type}} attribute is the result of <a for=Body>get the MIME type
<!-- This is wrong. It should really set an underlying concept to this. -->
</div>

<div algorithm>
<p>The <dfn method for=Body><code>bytes()</code></dfn> method steps are to return the result
of running <a for=Body>consume body</a> with <a>this</a> and the following step given a
<a for=/>byte sequence</a> <var>bytes</var>: return the result of [=ArrayBufferView/create|creating=] a
{{Uint8Array}} from <var>bytes</var> in <a>this</a>'s <a>relevant realm</a>.

<p class="note">The above method can reject with a {{RangeError}}.
</div>

<div algorithm>
<p>The <dfn method for=Body><code>formData()</code></dfn> method steps are to return the result of
running <a for=Body>consume body</a> with <a>this</a> and the following steps given a
Expand Down

0 comments on commit 1085f4f

Please sign in to comment.