diff options
author | Rick Waldron <waldron.rick@gmail.com> | 2013-04-01 12:48:30 -0400 |
---|---|---|
committer | Rick Waldron <waldron.rick@gmail.com> | 2013-04-01 12:48:30 -0400 |
commit | 332a490573bbbd9e7df1381bde8f590240cb8679 (patch) | |
tree | a5b0e46fb4a25f41a146bb9e50ce0f4240588904 /src/data.js | |
parent | 1f530e286755416369f4452d20f5ab6bb175451d (diff) | |
download | jquery-332a490573bbbd9e7df1381bde8f590240cb8679.tar.gz jquery-332a490573bbbd9e7df1381bde8f590240cb8679.zip |
Avoid side-effects when calling jQuery.hasData
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
Diffstat (limited to 'src/data.js')
-rw-r--r-- | src/data.js | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/data.js b/src/data.js index 585d78b20..189de6259 100644 --- a/src/data.js +++ b/src/data.js @@ -21,11 +21,17 @@ function Data() { 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++; @@ -158,7 +164,7 @@ Data.prototype = { }, hasData: function( owner ) { return !jQuery.isEmptyObject( - this.cache[ this.key( owner ) ] + this.cache[ this.key( owner, { readonly: true }) ] || {} ); }, discard: function( owner ) { |