From 0e865a5cea266a3ee18995d03e814494d9b4b934 Mon Sep 17 00:00:00 2001 From: Jake Date: Thu, 29 Nov 2018 08:24:02 -0800 Subject: [PATCH] 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... --- lib/utils/strings.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/utils/strings.js b/lib/utils/strings.js index 313c27b..b07a732 100644 --- a/lib/utils/strings.js +++ b/lib/utils/strings.js @@ -83,8 +83,10 @@ exports.string2buf = function (str) { // Helper (used in 2 places) function buf2binstring(buf, len) { - // use fallback for big arrays to avoid stack overflow - if (len < 65537) { + // On Chrome, the arguments in a function call that are allowed is `65534`. + // 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)) { return String.fromCharCode.apply(null, utils.shrinkBuf(buf, len)); }