Skip to content

Commit

Permalink
424f4b49816899f53e79cd4b19711583d3f4ec97 Fix: API instances created w…
Browse files Browse the repository at this point in the history
…ith a large data set could cause an overflow error in Chrome. This was particularly evident in Buttons file exports.

https://datatables.net/forums/discussion/79078
https://datatables.net/forums/discussion/79186

Sync to source repo @424f4b49816899f53e79cd4b19711583d3f4ec97
  • Loading branch information
dtbuild committed Aug 22, 2024
1 parent 12bcac3 commit d10f0d8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion datatables.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
],
"src-repo": "http://github.com/DataTables/DataTablesSrc",
"last-tag": "2.1.4",
"last-sync": "5b950ca5f428ed25491b662aaab12b8368cadc40"
"last-sync": "424f4b49816899f53e79cd4b19711583d3f4ec97"
}
14 changes: 12 additions & 2 deletions js/dataTables.js
Original file line number Diff line number Diff line change
Expand Up @@ -6782,6 +6782,7 @@
return new _Api( context, data );
}

var i;
var settings = [];
var ctxSettings = function ( o ) {
var a = _toSettings( o );
Expand All @@ -6791,7 +6792,7 @@
};

if ( Array.isArray( context ) ) {
for ( var i=0, ien=context.length ; i<ien ; i++ ) {
for ( i=0 ; i<context.length ; i++ ) {
ctxSettings( context[i] );
}
}
Expand All @@ -6806,7 +6807,16 @@

// Initial data
if ( data ) {
this.push.apply(this, data);
// Chrome can throw a max stack error if apply is called with
// too large an array, but apply is faster.
if (data.length < 10000) {
this.push.apply(this, data);
}
else {
for (i=0 ; i<data.length ; i++) {
this.push(data[i]);
}
}
}

// selector
Expand Down
2 changes: 1 addition & 1 deletion js/dataTables.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dataTables.min.mjs

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions js/dataTables.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6729,6 +6729,7 @@ _Api = function ( context, data )
return new _Api( context, data );
}

var i;
var settings = [];
var ctxSettings = function ( o ) {
var a = _toSettings( o );
Expand All @@ -6738,7 +6739,7 @@ _Api = function ( context, data )
};

if ( Array.isArray( context ) ) {
for ( var i=0, ien=context.length ; i<ien ; i++ ) {
for ( i=0 ; i<context.length ; i++ ) {
ctxSettings( context[i] );
}
}
Expand All @@ -6753,7 +6754,16 @@ _Api = function ( context, data )

// Initial data
if ( data ) {
this.push.apply(this, data);
// Chrome can throw a max stack error if apply is called with
// too large an array, but apply is faster.
if (data.length < 10000) {
this.push.apply(this, data);
}
else {
for (i=0 ; i<data.length ; i++) {
this.push(data[i]);
}
}
}

// selector
Expand Down

0 comments on commit d10f0d8

Please sign in to comment.