aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/core.js
diff options
context:
space:
mode:
authorAhmed.S.ElAfifi <ahmed.s.elafifi@gmail.com>2019-08-19 10:04:01 +0200
committerMichał Gołębiowski-Owczarek <m.goleb@gmail.com>2019-09-25 17:49:32 +0200
commit2f666c1daba43d26d77d9500db09d528bf66fac8 (patch)
treec03612d12f7e81acbfbccd16884ac0b390219f7b /test/unit/core.js
parent78ff24dd4b7c18d3c72cfbfe871a8cd3cbf3caee (diff)
downloadjquery-2f666c1daba43d26d77d9500db09d528bf66fac8.tar.gz
jquery-2f666c1daba43d26d77d9500db09d528bf66fac8.zip
Core: Use Array.prototype.flat where supported
Calling `Array.prototype.concat.apply( [], inputArray )` to flatten `inputArray` crashes for large arrays; using `Array.prototype.flat` avoids these issues in browsers that support it. In case it's necessary to support these large arrays even in older browsers, a polyfill for `Array.prototype.flat` can be loaded. This is already being done by many applications. (cherry picked from 9df4f1de12728b44a4b0f91748f12421008d9079) Fixes gh-4320 Closes gh-4459
Diffstat (limited to 'test/unit/core.js')
-rw-r--r--test/unit/core.js20
1 files changed, 19 insertions, 1 deletions
diff --git a/test/unit/core.js b/test/unit/core.js
index b8e556b85..c3deef1f7 100644
--- a/test/unit/core.js
+++ b/test/unit/core.js
@@ -703,7 +703,7 @@ QUnit.test( "map()", function( assert ) {
} );
QUnit.test( "jQuery.map", function( assert ) {
- assert.expect( 25 );
+ assert.expect( 28 );
var i, label, result, callback;
@@ -803,6 +803,24 @@ QUnit.test( "jQuery.map", function( assert ) {
return k % 2 ? k : [ k, k, k ];
} );
assert.equal( result.join( "" ), "00012223", "Array results flattened (#2616)" );
+
+ result = jQuery.map( [ [ [ 1, 2 ], 3 ], 4 ], function( v, k ) {
+ return v;
+ } );
+ assert.equal( result.length, 3, "Array flatten only one level down" );
+ assert.ok( Array.isArray( result[ 0 ] ), "Array flatten only one level down" );
+
+ // Support: IE 9 - 11+, Edge 18+, Android Browser 4.0 - 4.3 only, iOS 7 - 11 only,
+ // Safari 11 only, Firefox <= 61 only
+ // Skip the test in browsers without Array#flat.
+ if ( Array.prototype.flat ) {
+ result = jQuery.map( Array( 300000 ), function( v, k ) {
+ return k;
+ } );
+ assert.equal( result.length, 300000, "Able to map 300000 records without any problems (#4320)" );
+ } else {
+ assert.ok( "skip", "Array#flat doesn't supported on all browsers" );
+ }
} );
QUnit.test( "jQuery.merge()", function( assert ) {