mirror of
https://github.com/jquery/jquery.git
synced 2025-01-10 18:24:24 +00:00
Fixes #13815: Ensure each element has its own private data object - Tests by @rwldrn
This commit is contained in:
parent
3a6194076b
commit
55e319aa52
@ -90,13 +90,9 @@ Data.prototype = {
|
||||
|
||||
// Handle: [ owner, { properties } ] args
|
||||
} else {
|
||||
// Support an expectation from the old data system where plain
|
||||
// objects used to initialize would be set to the cache by
|
||||
// reference, instead of having properties and values copied.
|
||||
// Note, this will kill the connection between
|
||||
// "this.cache[ unlock ]" and "cache"
|
||||
// Fresh assignments by object are shallow copied
|
||||
if ( jQuery.isEmptyObject( cache ) ) {
|
||||
this.cache[ unlock ] = data;
|
||||
jQuery.extend( this.cache[ unlock ], data );
|
||||
// Otherwise, copy the properties one-by-one to the cache object
|
||||
} else {
|
||||
for ( prop in data ) {
|
||||
@ -104,6 +100,7 @@ Data.prototype = {
|
||||
}
|
||||
}
|
||||
}
|
||||
return cache;
|
||||
},
|
||||
get: function( owner, key ) {
|
||||
// Either a valid cache is found, or will be created.
|
||||
|
@ -527,11 +527,9 @@ function cloneCopyEvent( src, dest ) {
|
||||
// 1. Copy private data: events, handlers, etc.
|
||||
if ( data_priv.hasData( src ) ) {
|
||||
pdataOld = data_priv.access( src );
|
||||
pdataCur = jQuery.extend( {}, pdataOld );
|
||||
pdataCur = data_priv.set( dest, pdataOld );
|
||||
events = pdataOld.events;
|
||||
|
||||
data_priv.set( dest, pdataCur );
|
||||
|
||||
if ( events ) {
|
||||
delete pdataCur.handle;
|
||||
pdataCur.events = {};
|
||||
|
@ -244,6 +244,18 @@ test("jQuery(plain Object).data(String, Object).data(String)", function() {
|
||||
deepEqual( $obj[0], { exists: true }, "removeData does not clear the object" );
|
||||
});
|
||||
|
||||
test(".data(object) does not retain references. #13815", function() {
|
||||
expect( 2 );
|
||||
|
||||
var $divs = jQuery("<div></div><div></div>").appendTo("#qunit-fixture");
|
||||
|
||||
$divs.data({ "type": "foo" });
|
||||
$divs.eq( 0 ).data( "type", "bar" );
|
||||
|
||||
equal( $divs.eq( 0 ).data("type"), "bar", "Correct updated value" );
|
||||
equal( $divs.eq( 1 ).data("type"), "foo", "Original value retained" );
|
||||
});
|
||||
|
||||
test("data-* attributes", function() {
|
||||
expect(40);
|
||||
var prop, i, l, metadata, elem,
|
||||
|
Loading…
Reference in New Issue
Block a user