Skip to content

Commit 5a6987e

Browse files
committed
Use Object.prototype.hasOwnProperty.call() instead of hasOwnProperty() to check for property existence.
See https://eslint.org/docs/rules/no-prototype-builtins for more details.
1 parent a5e7298 commit 5a6987e

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

js/dataTables.checkboxes.js

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767
this.s = {
6868
dt: new DataTable.Api( settings ),
6969
columns: [],
70-
data: [],
71-
dataDisabled: [],
70+
data: {},
71+
dataDisabled: {},
7272
ignoreSelect: false
7373
};
7474

@@ -607,7 +607,10 @@
607607
var isCellSelectable = self.isCellSelectable(colIdx, cellData);
608608

609609
// If checkbox is checked
610-
if(ctx.checkboxes.s.data[colIdx].hasOwnProperty(cellData)){
610+
if(
611+
Object.prototype.hasOwnProperty.call(ctx.checkboxes.s.data, colIdx)
612+
&& Object.prototype.hasOwnProperty.call(ctx.checkboxes.s.data[colIdx], cellData)
613+
) {
611614
// If row selection is enabled
612615
// and checkbox can be checked
613616
if(ctx.aoColumns[colIdx].checkboxes.selectRow && isCellSelectable){
@@ -671,7 +674,10 @@
671674
var cellData = cell.data();
672675

673676
// Determine whether data is in the list
674-
var hasData = self.s.data[colIdx].hasOwnProperty(cellData);
677+
var hasData = (
678+
Object.prototype.hasOwnProperty.call(self.s.data, colIdx)
679+
&& Object.prototype.hasOwnProperty.call(self.s.data[colIdx], cellData)
680+
);
675681

676682
// If state of the checkbox needs to be updated
677683
if(hasData !== ctrl.checked){
@@ -768,7 +774,12 @@
768774
$.each(cellsData, function(index, cellData){
769775
// If checkbox is not disabled
770776
if(self.isCellSelectable(colIdx, cellData)){
771-
if(self.s.data[colIdx].hasOwnProperty(cellData)){ countChecked++; }
777+
if(
778+
Object.prototype.hasOwnProperty.call(self.s.data, colIdx)
779+
&& Object.prototype.hasOwnProperty.call(self.s.data[colIdx], cellData)
780+
) {
781+
countChecked++;
782+
}
772783

773784
// Otherwise, if checkbox is disabled
774785
} else {
@@ -846,7 +857,10 @@
846857
// Count number of selected rows
847858
var countRows = 0;
848859
for (var cellData in ctx.checkboxes.s.data[colIdx]){
849-
if (ctx.checkboxes.s.data[colIdx].hasOwnProperty(cellData)){
860+
if(
861+
Object.prototype.hasOwnProperty.call(ctx.checkboxes.s.data, colIdx)
862+
&& Object.prototype.hasOwnProperty.call(ctx.checkboxes.s.data[colIdx], cellData)
863+
) {
850864
countRows++;
851865
}
852866
}
@@ -884,7 +898,10 @@
884898
var ctx = self.s.ctx;
885899

886900
// If data is in the list of disabled elements
887-
if(ctx.checkboxes.s.dataDisabled[colIdx].hasOwnProperty(cellData)){
901+
if(
902+
Object.prototype.hasOwnProperty.call(ctx.checkboxes.s.dataDisabled, colIdx)
903+
&& Object.prototype.hasOwnProperty.call(ctx.checkboxes.s.dataDisabled[colIdx], cellData)
904+
) {
888905
return false;
889906

890907
// Otherwise, if checkbox can be selected
@@ -1136,7 +1153,10 @@
11361153
// and checkbox can be checked
11371154
if(ctx.aoColumns[colIdx].checkboxes.selectRow){
11381155
// If data is in the list
1139-
if(ctx.checkboxes.s.data[colIdx].hasOwnProperty(cellData)){
1156+
if(
1157+
Object.prototype.hasOwnProperty.call(ctx.checkboxes.s.data, colIdx)
1158+
&& Object.prototype.hasOwnProperty.call(ctx.checkboxes.s.data[colIdx], cellData)
1159+
) {
11401160
// Update selection based on current state:
11411161
// if checkbox is enabled then select row;
11421162
// otherwise, deselect row
@@ -1204,7 +1224,10 @@
12041224
// Enumerate all cells data
12051225
$.each(cellsData, function(index, cellData){
12061226
// If checkbox is checked
1207-
if(ctx.checkboxes.s.data[colIdx].hasOwnProperty(cellData)){
1227+
if(
1228+
Object.prototype.hasOwnProperty.call(ctx.checkboxes.s.data, colIdx)
1229+
&& Object.prototype.hasOwnProperty.call(ctx.checkboxes.s.data[colIdx], cellData)
1230+
) {
12081231
// If checkbox in the cell can be selected
12091232
if(ctx.checkboxes.isCellSelectable(colIdx, cellData)){
12101233
data.push(cellData);

0 commit comments

Comments
 (0)