fix RangeError on chrome71 (#150)

Fixes the following error: RangeError: Too many arguments in function call (only 65534 allowed)
The argument limit seems to have become lower in chrome 72...
This commit is contained in:
Jake 2018-11-29 08:24:02 -08:00 committed by Vitaly Puzrin
parent 0124206d64
commit 0e865a5cea

View file

@ -83,8 +83,10 @@ exports.string2buf = function (str) {
// Helper (used in 2 places) // Helper (used in 2 places)
function buf2binstring(buf, len) { function buf2binstring(buf, len) {
// use fallback for big arrays to avoid stack overflow // On Chrome, the arguments in a function call that are allowed is `65534`.
if (len < 65537) { // If the length of the buffer is smaller than that, we can use this optimization,
// otherwise we will take a slower path.
if (len < 65534) {
if ((buf.subarray && STR_APPLY_UIA_OK) || (!buf.subarray && STR_APPLY_OK)) { if ((buf.subarray && STR_APPLY_UIA_OK) || (!buf.subarray && STR_APPLY_OK)) {
return String.fromCharCode.apply(null, utils.shrinkBuf(buf, len)); return String.fromCharCode.apply(null, utils.shrinkBuf(buf, len));
} }