diff options
author | Ahmed.S.ElAfifi <ahmed.s.elafifi@gmail.com> | 2019-08-19 10:04:01 +0200 |
---|---|---|
committer | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2019-09-25 01:38:21 +0200 |
commit | 9df4f1de12728b44a4b0f91748f12421008d9079 (patch) | |
tree | a8864c22790c5045db115c789af5dfecebeb6a02 /test/unit/core.js | |
parent | aa6344baf87145ffc807a527d9c1fb03c96b1948 (diff) | |
download | jquery-9df4f1de12728b44a4b0f91748f12421008d9079.tar.gz jquery-9df4f1de12728b44a4b0f91748f12421008d9079.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.
Fixes gh-4320
Closes gh-4459
Diffstat (limited to 'test/unit/core.js')
-rw-r--r-- | test/unit/core.js | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/test/unit/core.js b/test/unit/core.js index be09163ac..bc5d2fc25 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -681,7 +681,7 @@ QUnit.test( "map()", function( assert ) { } ); QUnit.test( "jQuery.map", function( assert ) { - assert.expect( 25 ); + assert.expect( 28 ); var i, label, result, callback; @@ -781,6 +781,23 @@ 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 11+, Edge 18+ + // 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 ) { |