mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Detect the argument length limit instead of using a fixed limit.
Former-commit-id: 24875b0f67c7c92a37c315d3e8a33f23b5372119
This commit is contained in:
23
lodash.js
23
lodash.js
@@ -8,6 +8,13 @@
|
|||||||
;(function(window, undefined) {
|
;(function(window, undefined) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
/** Used to detect the JavaScript engine's argument length limit */
|
||||||
|
var argsLimit = Math.pow(2, 32) - 1;
|
||||||
|
|
||||||
|
try {
|
||||||
|
(function() { argsLimit = arguments.length; }).apply(null, Array(argsLimit));
|
||||||
|
} catch(e) { }
|
||||||
|
|
||||||
/** Used to escape characters in templates */
|
/** Used to escape characters in templates */
|
||||||
var escapes = {
|
var escapes = {
|
||||||
'\\': '\\',
|
'\\': '\\',
|
||||||
@@ -1263,11 +1270,11 @@
|
|||||||
result = computed;
|
result = computed;
|
||||||
|
|
||||||
if (!callback) {
|
if (!callback) {
|
||||||
// assume an array of numbers
|
// fast path for arrays of numbers
|
||||||
if (array[0] === +array[0] && length < 25000) {
|
if (array[0] === +array[0] && length < argsLimit) {
|
||||||
// some browsers, like Chrome and Firefox, have a limit on the number of
|
// some JavaScript engines have a limit on the number of arguments functions
|
||||||
// arguments a function is allowed to accept before clipping the arguments
|
// can accept before clipping the argument length or throwing an error
|
||||||
// or throwing an error
|
// https://bugs.webkit.org/show_bug.cgi?id=80797
|
||||||
try {
|
try {
|
||||||
return Math.max.apply(Math, array);
|
return Math.max.apply(Math, array);
|
||||||
} catch(e) { }
|
} catch(e) { }
|
||||||
@@ -1314,11 +1321,7 @@
|
|||||||
result = computed;
|
result = computed;
|
||||||
|
|
||||||
if (!callback) {
|
if (!callback) {
|
||||||
// assume an array of numbers
|
if (array[0] === +array[0] && length < argsLimit) {
|
||||||
if (array[0] === +array[0] && length < 25000) {
|
|
||||||
// some browsers, like Chrome and Firefox, have a limit on the number of
|
|
||||||
// arguments a function is allowed to accept before clipping the arguments
|
|
||||||
// or throwing an error
|
|
||||||
try {
|
try {
|
||||||
return Math.min.apply(Math, array);
|
return Math.min.apply(Math, array);
|
||||||
} catch(e) { }
|
} catch(e) { }
|
||||||
|
|||||||
Reference in New Issue
Block a user