From 97f4dfc089edfac9acbdc4bc5cdd92b8af645ab3 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 20 May 2012 20:38:32 -0400 Subject: [PATCH] Add comment explaining JavaScript engine's arguments.length limit and add shim file to underscore.html. Former-commit-id: ace6dae609cab05b86ddc60a7f8c980447da2bdc --- lodash.js | 23 ++++++++++++++++++----- test/underscore.html | 1 + 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lodash.js b/lodash.js index c2d1f71d1..7f7b37407 100644 --- a/lodash.js +++ b/lodash.js @@ -12,12 +12,26 @@ var freeExports = typeof exports == 'object' && exports && (typeof global == 'object' && global && global == global.global && (window = global), exports); - /** Used to detect the JavaScript engine's argument length limit */ - var argsLimit = Math.pow(2, 32) - 1; + /** + * Used to detect the JavaScript engine's argument length limit. + * + * The initial value of `argsLimit` is low enough not to cause uncatchable + * errors in Java and avoid locking up older browsers like Safari 3. + * + * Some engines have a limit on the number of arguments functions can accept + * before clipping the argument length or throwing an error. + * https://bugs.webkit.org/show_bug.cgi?id=80797 + * + * For example Firefox's limits have been observed to be at least: + * Firefox 2 - 35,535 + * Firefox 3.6 - 16,777,215 + * Firefox 4-7 - 523,264 + * Firefox >= 8 - Throws error + */ + var argsLimit = 5e4; try { - // skip test if running in Java to avoid uncatchable error - window.environment && environment['java.home'] || (function() { + (function() { argsLimit = arguments.length; }).apply(null, Array(argsLimit)); } catch(e) { } @@ -1298,7 +1312,6 @@ if (array[0] === +array[0] && length <= argsLimit) { // some JavaScript engines have a limit on the number of arguments functions // can accept before clipping the argument length or throwing an error - // https://bugs.webkit.org/show_bug.cgi?id=80797 try { return Math.max.apply(Math, array); } catch(e) { } diff --git a/test/underscore.html b/test/underscore.html index f8535f0e1..09a4209ea 100644 --- a/test/underscore.html +++ b/test/underscore.html @@ -18,6 +18,7 @@
+