Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch: make consumeBody sync #3606

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions lib/web/fetch/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,6 @@ function cloneBody (instance, body) {
}
}

function throwIfAborted (state) {
if (state.aborted) {
throw new DOMException('The operation was aborted.', 'AbortError')
}
}

function bodyMixinMethods (instance) {
const methods = {
blob () {
Expand Down Expand Up @@ -424,16 +418,22 @@ function mixinBody (prototype) {
* @param {(value: unknown) => unknown} convertBytesToJSValue
* @param {Response|Request} instance
*/
async function consumeBody (object, convertBytesToJSValue, instance) {
webidl.brandCheck(object, instance)
function consumeBody (object, convertBytesToJSValue, instance) {
try {
webidl.brandCheck(object, instance)
} catch (e) {
return Promise.reject(e)
}

// 1. If object is unusable, then return a promise rejected
// with a TypeError.
if (bodyUnusable(object)) {
throw new TypeError('Body is unusable: Body has already been read')
return Promise.reject(new TypeError('Body is unusable: Body has already been read'))
}

throwIfAborted(object[kState])
if (object[kState].aborted) {
return Promise.reject(new DOMException('The operation was aborted.', 'AbortError'))
}
Comment on lines 430 to +436
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I thin aborted is a subtype of the object being unusable. Does it have to be a DOMException?


// 2. Let promise be a new promise.
const promise = createDeferredPromise()
Expand Down Expand Up @@ -462,7 +462,7 @@ async function consumeBody (object, convertBytesToJSValue, instance) {

// 6. Otherwise, fully read object’s body given successSteps,
// errorSteps, and object’s relevant global object.
await fullyReadBody(object[kState].body, successSteps, errorSteps)
fullyReadBody(object[kState].body, successSteps, errorSteps)

// 7. Return promise.
return promise.promise
Expand Down
Loading