Data.uid = 1;
Data.prototype = {
- key: function( owner ) {
+ key: function( owner, options ) {
var descriptor = {},
// Check if the owner object already has a cache key
unlock = owner[ this.expando ];
+ // `readonly` calls from hasData, on owners with no key
+ // should not create new/empty cache records
+ if ( !unlock && (options && options.readonly) ) {
+ return null;
+ }
+
// If not, create one
if ( !unlock ) {
unlock = Data.uid++;
},
hasData: function( owner ) {
return !jQuery.isEmptyObject(
- this.cache[ this.key( owner ) ]
+ this.cache[ this.key( owner, { readonly: true }) ] || {}
);
},
discard: function( owner ) {
);
});
+test( "jQuery.hasData no side effects", function() {
+ expect(1);
+ var obj = {};
+
+ jQuery.hasData( obj );
+
+ equal( Object.getOwnPropertyNames( obj ).length, 0,
+ "No data expandos where added when calling jQuery.hasData(o)"
+ );
+});
+
function dataTests (elem) {
var oldCacheLength, dataObj, internalDataObj, expected, actual;