Skip to content

Commit 5452c92

Browse files
committed
Data: avoid using delete on DOM nodes
1 parent 9adfad1 commit 5452c92

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

src/data/Data.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,11 @@ Data.prototype = {
147147

148148
// Remove the expando if there's no more data
149149
if ( key === undefined || jQuery.isEmptyObject( cache ) ) {
150-
delete owner[ this.expando ];
150+
// Support: Chrome <=35 - 45
151+
// Webkit & Blink performance suffers when deleting properties
152+
// from DOM nodes, so set to undefined instead
153+
// https://code.google.com/p/chromium/issues/detail?id=378607
154+
owner[ this.expando ] = undefined;
151155
}
152156
},
153157
hasData: function( owner ) {

src/manipulation.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,14 @@ jQuery.extend({
283283
}
284284
}
285285
}
286-
delete elem[ dataPriv.expando ];
286+
// Support: Chrome <=35 - 45
287+
// Assign undefined instead of using delete, see Data#remove
288+
elem[ dataPriv.expando ] = undefined;
287289
}
288290
if ( elem[ dataUser.expando ] ) {
289-
delete elem[ dataUser.expando ];
291+
// Support: Chrome <=35 - 45
292+
// Assign undefined instead of using delete, see Data#remove
293+
elem[ dataUser.expando ] = undefined;
290294
}
291295
}
292296
}

test/unit/data.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ testIframeWithCallback( "enumerate data attrs on body (#14894)", "data/dataAttrs
859859
});
860860

861861
test( "Check that the expando is removed when there's no more data", function() {
862-
expect( 1 );
862+
expect( 2 );
863863

864864
var key,
865865
div = jQuery( "<div/>" );
@@ -870,7 +870,7 @@ test( "Check that the expando is removed when there's no more data", function()
870870
// Make sure the expando is gone
871871
for ( key in div[ 0 ] ) {
872872
if ( /^jQuery/.test( key ) ) {
873-
ok( false, "Expando was not removed when there was no more data" );
873+
strictEqual( div[ 0 ][ key ], undefined, "Expando was not removed when there was no more data" );
874874
}
875875
}
876876
});

test/unit/manipulation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,7 +2089,7 @@ test( "jQuery.cleanData eliminates all private data (gh-2127)", function() {
20892089
});
20902090

20912091
test( "jQuery.cleanData eliminates all public data", function() {
2092-
expect( 2 );
2092+
expect( 3 );
20932093

20942094
var key,
20952095
div = jQuery( "<div/>" );
@@ -2103,7 +2103,7 @@ test( "jQuery.cleanData eliminates all public data", function() {
21032103
// Make sure the expando is gone
21042104
for ( key in div[ 0 ] ) {
21052105
if ( /^jQuery/.test( key ) ) {
2106-
ok( false, "Expando was not removed when there was no more data" );
2106+
strictEqual( div[ 0 ][ key ], undefined, "Expando was not removed when there was no more data" );
21072107
}
21082108
}
21092109
});

0 commit comments

Comments
 (0)