if ( owner.nodeType ) {
owner[ this.expando ] = value;
- // Otherwise secure it in a non-enumerable, non-writable property
- // configurability must be true to allow the property to be
- // deleted with the delete operator
+ // Otherwise secure it in a non-enumerable property
+ // configurable must be true to allow the property to be
+ // deleted when data is removed
} else {
Object.defineProperty( owner, this.expando, {
value: value,
- writable: true,
configurable: true
} );
}
// Remove the expando if there's no more data
if ( key === undefined || jQuery.isEmptyObject( cache ) ) {
- delete owner[ this.expando ];
+
+ // Support: Chrome <= 35-45+
+ // Webkit & Blink performance suffers when deleting properties
+ // from DOM nodes, so set to undefined instead
+ // https://code.google.com/p/chromium/issues/detail?id=378607
+ if ( owner.nodeType ) {
+ owner[ this.expando ] = undefined;
+ } else {
+ delete owner[ this.expando ];
+ }
}
},
hasData: function( owner ) {
}
}
}
- delete elem[ dataPriv.expando ];
+
+ // Support: Chrome <= 35-45+
+ // Assign undefined instead of using delete, see Data#remove
+ elem[ dataPriv.expando ] = undefined;
}
if ( elem[ dataUser.expando ] ) {
- delete elem[ dataUser.expando ];
+
+ // Support: Chrome <= 35-45+
+ // Assign undefined instead of using delete, see Data#remove
+ elem[ dataUser.expando ] = undefined;
}
}
}
);
QUnit.test( "Check that the expando is removed when there's no more data", function( assert ) {
- assert.expect( 1 );
+ assert.expect( 2 );
var key,
div = jQuery( "<div/>" );
// Make sure the expando is gone
for ( key in div[ 0 ] ) {
+ if ( /^jQuery/.test( key ) ) {
+ assert.strictEqual( div[ 0 ][ key ], undefined, "Expando was not removed when there was no more data" );
+ }
+ }
+});
+
+QUnit.test( "Check that the expando is removed when there's no more data on non-nodes", function( assert ) {
+ assert.expect( 1 );
+
+ var key,
+ obj = jQuery( {key: 42} );
+ obj.data( "some", "data" );
+ assert.equal( obj.data( "some" ), "data", "Data is added" );
+ obj.removeData( "some" );
+
+ // Make sure the expando is gone
+ for ( key in obj[ 0 ] ) {
if ( /^jQuery/.test( key ) ) {
assert.ok( false, "Expando was not removed when there was no more data" );
}
} );
QUnit.test( ".off() removes the expando when there's no more data", function( assert ) {
- assert.expect( 1 );
+ assert.expect( 2 );
var key,
div = jQuery( "<div/>" ).appendTo( "#qunit-fixture" );
// Make sure the expando is gone
for ( key in div[ 0 ] ) {
if ( /^jQuery/.test( key ) ) {
- assert.ok( false, "Expando was not removed when there was no more data" );
+ assert.strictEqual(
+ div[ 0 ][ key ], undefined,
+ "Expando was not removed when there was no more data"
+ );
}
}
} );
} );
QUnit.test( "jQuery.cleanData eliminates all public data", function( assert ) {
- assert.expect( 2 );
+ assert.expect( 3 );
var key,
div = jQuery( "<div/>" );
// Make sure the expando is gone
for ( key in div[ 0 ] ) {
if ( /^jQuery/.test( key ) ) {
- assert.ok( false, "Expando was not removed when there was no more data" );
+ assert.strictEqual( div[ 0 ][ key ], undefined, "Expando was not removed when there was no more data" );
}
}
} );