mirror of
https://github.com/denoland/deno.git
synced 2025-01-09 15:48:16 -05:00
fix(cli/body): Maximum call stack size exceeded error (#6537)
This commit is contained in:
parent
1c12098e4a
commit
89ebe2079b
2 changed files with 25 additions and 2 deletions
|
@ -35,7 +35,7 @@ function validateBodyType(owner: Body, bodySource: BodyInit | null): boolean {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function concatenate(...arrays: Uint8Array[]): ArrayBuffer {
|
function concatenate(arrays: Uint8Array[]): ArrayBuffer {
|
||||||
let totalLength = 0;
|
let totalLength = 0;
|
||||||
for (const arr of arrays) {
|
for (const arr of arrays) {
|
||||||
totalLength += arr.length;
|
totalLength += arr.length;
|
||||||
|
@ -73,7 +73,7 @@ async function bufferFromStream(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return concatenate(...parts);
|
return concatenate(parts);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const BodyUsedError =
|
export const BodyUsedError =
|
||||||
|
|
|
@ -79,3 +79,26 @@ unitTest({ perms: {} }, async function bodyURLSearchParams(): Promise<void> {
|
||||||
const text = await body.text();
|
const text = await body.text();
|
||||||
assertEquals(text, "hello=world");
|
assertEquals(text, "hello=world");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
unitTest(async function bodyArrayBufferMultipleParts(): Promise<void> {
|
||||||
|
const parts: Uint8Array[] = [];
|
||||||
|
let size = 0;
|
||||||
|
for (let i = 0; i <= 150000; i++) {
|
||||||
|
const part = new Uint8Array([1]);
|
||||||
|
parts.push(part);
|
||||||
|
size += part.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
let offset = 0;
|
||||||
|
const stream = new ReadableStream({
|
||||||
|
pull(controller): void {
|
||||||
|
// parts.shift() takes forever: https://github.com/denoland/deno/issues/5259
|
||||||
|
const chunk = parts[offset++];
|
||||||
|
if (!chunk) return controller.close();
|
||||||
|
controller.enqueue(chunk);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const body = buildBody(stream);
|
||||||
|
assertEquals((await body.arrayBuffer()).byteLength, size);
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue