(data, init = undefined)
| 43 | |
| 44 | // https://fetch.spec.whatwg.org/#dom-response-json |
| 45 | static json (data, init = undefined) { |
| 46 | webidl.argumentLengthCheck(arguments, 1, 'Response.json') |
| 47 | |
| 48 | if (init !== null) { |
| 49 | init = webidl.converters.ResponseInit(init) |
| 50 | } |
| 51 | |
| 52 | // 1. Let bytes the result of running serialize a JavaScript value to JSON bytes on data. |
| 53 | const bytes = textEncoder.encode( |
| 54 | serializeJavascriptValueToJSONString(data) |
| 55 | ) |
| 56 | |
| 57 | // 2. Let body be the result of extracting bytes. |
| 58 | const body = extractBody(bytes) |
| 59 | |
| 60 | // 3. Let responseObject be the result of creating a Response object, given a new response, |
| 61 | // "response", and this’s relevant Realm. |
| 62 | const responseObject = fromInnerResponse(makeResponse({}), 'response') |
| 63 | |
| 64 | // 4. Perform initialize a response given responseObject, init, and (body, "application/json"). |
| 65 | initializeResponse(responseObject, init, { body: body[0], type: 'application/json' }) |
| 66 | |
| 67 | // 5. Return responseObject. |
| 68 | return responseObject |
| 69 | } |
| 70 | |
| 71 | // Creates a redirect Response that redirects to url with status status. |
| 72 | static redirect (url, status = 302) { |
nothing calls this directly
no test coverage detected