Re: [whatwg/fetch] Add `Response.json` static method (PR #1392)

@annevk commented on this pull request.

Mostly nits and request for a follow-up. Shared algorithm looks rather good! Thanks.

> +<p>A <dfn export id=concept-body-with-type>body with type</dfn> is a
+<a for=/>tuple</a> that consists of a
+<dfn export for="body with type" id=concept-body-with-type-body>body</dfn> (a <a for=/>body</a>) and
+<dfn export for="body with type" id=concept-body-with-type-type>type</dfn> (a <a for=/>header value</a>).

Drop the explicit IDs here. For new stuff we want whatever Bikeshed comes up with generally.

> @@ -7434,11 +7446,8 @@ enum ResponseType { "basic", "cors", "default", "error", "opaque", "opaqueredire
  <li><p>Return <var>responseObject</var>.
 </ol>
 
-<hr>
-
-<p>The
-<dfn constructor for=Response id=dom-response lt="Response(body, init)"><code>new Response(<var>body</var>, <var>init</var>)</code></dfn>
-constructor steps are:
+<p>To <dfn>initialize a response</dfn>, given a {{Response}} <var>response</var>, {{ResponseInit}}
+<var>init</var>, and an optional <a for/>body with type</a> <var>body</var>, run these steps:

```suggestion
<var>init</var>, and an optional <a for=/>body with type</a> <var>body</var>, run these steps:
```

>     <a for=response>header list</a>.
-  </ol>
+</ol>

I think there's a missing closing tag here as we're going from 3 spaces to 0 too quickly.

> +
+<p>The
+<dfn constructor for=Response id=dom-response lt="Response(body, init)"><code>new Response(<var>body</var>, <var>init</var>)</code></dfn>
+constructor steps are:
+
+<ol>
+ <li><p>Set <a>this</a>'s <a for=Response>response</a> to a new <a for=/>response</a>.
+
+ <li><p>Set <a>this</a>'s <a for=Response>headers</a> to a <a for=/>new</a> {{Headers}} object with
+ <a>this</a>'s <a>relevant Realm</a>, whose <a for=Headers>header list</a> is <a>this</a>'s
+ <a for=Response>response</a>'s <a for=response>header list</a> and <a for=Headers>guard</a> is
+ "<code>response</code>".
+
+ <li><p>Let <var>bodyWithType</var> be null.
+
+ <li><p>If <var>body</var> is non-null, then let <var>bodyWithType</var> be the result of

```suggestion
 <li><p>If <var>body</var> is non-null, then set <var>bodyWithType</var> to the result of
```

> +<p>The
+<dfn constructor for=Response id=dom-response lt="Response(body, init)"><code>new Response(<var>body</var>, <var>init</var>)</code></dfn>
+constructor steps are:
+
+<ol>
+ <li><p>Set <a>this</a>'s <a for=Response>response</a> to a new <a for=/>response</a>.
+
+ <li><p>Set <a>this</a>'s <a for=Response>headers</a> to a <a for=/>new</a> {{Headers}} object with
+ <a>this</a>'s <a>relevant Realm</a>, whose <a for=Headers>header list</a> is <a>this</a>'s
+ <a for=Response>response</a>'s <a for=response>header list</a> and <a for=Headers>guard</a> is
+ "<code>response</code>".
+
+ <li><p>Let <var>bodyWithType</var> be null.
+
+ <li><p>If <var>body</var> is non-null, then let <var>bodyWithType</var> be the result of
+ <a for=BodyInit>extracting</a> <var>body</var>.

We should have a follow-up on using "body with type" throughout so this doesn't stay as shaky as it is here.

> +<dfn method for=Response><code>json(<var>data</var>, <var>init</var>)</code></dfn> method steps
+are:
+
+<ol>
+ <li><p>Let <var>bytes</var> the result of running <a>serialize a JavaScript value to JSON bytes</a>
+ on <var>data</var>.
+
+ <li><p>Let <var>body</var> be the result of <a for=BodyInit>extracting</a> <var>bytes</var>.
+
+ <li><p>Let <var>responseObject</var> be the result of <a for=Response>creating</a> a {{Response}}
+ object, given a new <a for=/>response</a>, "<code>response</code>", and <a>this</a>'s
+ <a>relevant Realm</a>.
+
+ <li><p>Perform <a>initialize a response</a> given <var>responseObject</var>, <var>init</var>, and
+ (body, <code>"application/json;charset=utf-8"</code>).
+</ol>

You need to return _responseObject_.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/pull/1392#pullrequestreview-905745084
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/fetch/pull/1392/review/905745084@github.com>

Received on Thursday, 10 March 2022 12:23:40 UTC