Skip to content

Commit

Permalink
Bug 1632722 - IO.read hits 'too many arguments' r=remote-protocol-rev…
Browse files Browse the repository at this point in the history
…iewers,jgraham

Differential Revision: https://phabricator.services.mozilla.com/D86262
  • Loading branch information
mjzffr committed Aug 7, 2020
1 parent 07d67dc commit fbce182
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions remote/domains/parent/IO.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit fbce182

Please sign in to comment.