mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 18:07:49 +00:00
Add comment explaining JavaScript engine's arguments.length limit and add shim file to underscore.html.
Former-commit-id: ace6dae609cab05b86ddc60a7f8c980447da2bdc
This commit is contained in:
23
lodash.js
23
lodash.js
@@ -12,12 +12,26 @@
|
|||||||
var freeExports = typeof exports == 'object' && exports &&
|
var freeExports = typeof exports == 'object' && exports &&
|
||||||
(typeof global == 'object' && global && global == global.global && (window = global), 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 {
|
try {
|
||||||
// skip test if running in Java to avoid uncatchable error
|
(function() {
|
||||||
window.environment && environment['java.home'] || (function() {
|
|
||||||
argsLimit = arguments.length;
|
argsLimit = arguments.length;
|
||||||
}).apply(null, Array(argsLimit));
|
}).apply(null, Array(argsLimit));
|
||||||
} catch(e) { }
|
} catch(e) { }
|
||||||
@@ -1298,7 +1312,6 @@
|
|||||||
if (array[0] === +array[0] && length <= argsLimit) {
|
if (array[0] === +array[0] && length <= argsLimit) {
|
||||||
// some JavaScript engines have a limit on the number of arguments functions
|
// some JavaScript engines have a limit on the number of arguments functions
|
||||||
// can accept before clipping the argument length or throwing an error
|
// can accept before clipping the argument length 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) { }
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
<div id="id2"></div>
|
<div id="id2"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<script src="../vendor/backbone/test/vendor/json2.js"></script>
|
||||||
<script src="../vendor/underscore/test/vendor/jquery.js"></script>
|
<script src="../vendor/underscore/test/vendor/jquery.js"></script>
|
||||||
<script src="../vendor/underscore/test/vendor/qunit.js"></script>
|
<script src="../vendor/underscore/test/vendor/qunit.js"></script>
|
||||||
<script src="../vendor/underscore/test/vendor/jslitmus.js"></script>
|
<script src="../vendor/underscore/test/vendor/jslitmus.js"></script>
|
||||||
|
|||||||
Reference in New Issue
Block a user