diff --git a/js/fetch.ts b/js/fetch.ts index b1cd8f4aad4b4a..d5f01b87071130 100644 --- a/js/fetch.ts +++ b/js/fetch.ts @@ -237,6 +237,10 @@ class Body implements domTypes.Body, domTypes.ReadableStream, io.ReadCloser { tee(): [domTypes.ReadableStream, domTypes.ReadableStream] { return notImplemented(); } + + [Symbol.asyncIterator](): AsyncIterableIterator { + return io.toAsyncIterator(this); + } } export class Response implements domTypes.Response { diff --git a/js/fetch_test.ts b/js/fetch_test.ts index b93f7845a05b84..032727dbc0f1c4 100644 --- a/js/fetch_test.ts +++ b/js/fetch_test.ts @@ -33,6 +33,17 @@ testPerm({ net: true }, async function fetchBlob(): Promise { assertEquals(blob.size, Number(headers.get("Content-Length"))); }); +testPerm({ net: true }, async function fetchAsyncIterator(): Promise { + const response = await fetch("http://localhost:4545/package.json"); + const headers = response.headers; + let total = 0; + for await (const chunk of response.body) { + total += chunk.length; + } + + assertEquals(total, Number(headers.get("Content-Length"))); +}); + testPerm({ net: true }, async function responseClone(): Promise { const response = await fetch("http://localhost:4545/package.json"); const response1 = response.clone();