Skip to content

Commit 9d5e68c

Browse files
committed
fetch: make consumeBody sync
1 parent aec609b commit 9d5e68c

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

lib/web/fetch/body.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,6 @@ function cloneBody (body) {
320320
}
321321
}
322322

323-
function throwIfAborted (state) {
324-
if (state.aborted) {
325-
throw new DOMException('The operation was aborted.', 'AbortError')
326-
}
327-
}
328-
329323
function bodyMixinMethods (instance, getInternalState) {
330324
const methods = {
331325
blob () {
@@ -443,19 +437,21 @@ function mixinBody (prototype, getInternalState) {
443437
* @param {any} instance
444438
* @param {(target: any) => any} getInternalState
445439
*/
446-
async function consumeBody (object, convertBytesToJSValue, instance, getInternalState) {
440+
function consumeBody (object, convertBytesToJSValue, instance, getInternalState) {
447441
webidl.brandCheck(object, instance)
448442

449443
const state = getInternalState(object)
450444

445+
if (state.aborted) {
446+
return Promise.reject(new DOMException('The operation was aborted.', 'AbortError'))
447+
}
448+
451449
// 1. If object is unusable, then return a promise rejected
452450
// with a TypeError.
453451
if (bodyUnusable(state)) {
454-
throw new TypeError('Body is unusable: Body has already been read')
452+
return Promise.reject(new TypeError('Body is unusable: Body has already been read'))
455453
}
456454

457-
throwIfAborted(state)
458-
459455
// 2. Let promise be a new promise.
460456
const promise = createDeferredPromise()
461457

0 commit comments

Comments
 (0)