Bug 1632722 - IO.read hits 'too many arguments' r=remote-protocol-reviewers,jgraham

Differential Revision: https://phabricator.services.mozilla.com/D86262
This commit is contained in:
Maja Frydrychowicz 2020-08-07 09:08:01 +00:00
parent f5b18fe910
commit e9022983f1

View File

@ -101,8 +101,17 @@ class IO extends Domain {
const bytes = await stream.read(chunkSize);
// Each UCS2 character has an upper byte of 0 and a lower byte matching
// the binary data
const data = btoa(String.fromCharCode.apply(null, bytes));
// the binary data. Using a loop here prevents us from hitting the browser's
// internal `arguments.length` limit.
const ARGS_MAX = 262144;
const stringData = [];
for (let i = 0; i < bytes.length; i += ARGS_MAX) {
let argsChunk = Math.min(bytes.length, i + ARGS_MAX);
stringData.push(
String.fromCharCode.apply(null, bytes.slice(i, argsChunk))
);
}
const data = btoa(stringData.join(""));
return {
data,