]> source.dussan.org Git - jquery.git/commitdiff
Data: updates to element[expando] cache
authorRick Waldron <waldron.rick@gmail.com>
Thu, 5 Mar 2015 19:56:54 +0000 (14:56 -0500)
committerRick Waldron <waldron.rick@gmail.com>
Thu, 5 Mar 2015 19:56:54 +0000 (14:56 -0500)
  - removes descriptor allocation
  - restore simplified cache creation
  - adds early return from remove call where no data exists
  - use Object.defineProperty
  - remove unnecessary code path

Closes gh-2119

src/data/Data.js

index ec108e06217d3111703ce8187d91a43546d5289a..4584734305455de99ace17ac7b3b6ad1e1c86b67 100644 (file)
@@ -14,34 +14,23 @@ Data.accepts = jQuery.acceptData;
 Data.prototype = {
 
        register: function( owner, initial ) {
-               var descriptor = {},
-                       value = initial || {};
-
-               try {
-                       // If it is a node unlikely to be stringify-ed or looped over
-                       // use plain assignment
-                       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
-                       } else {
-                               descriptor[ this.expando ] = {
-                                       value: value,
-                                       writable: true,
-                                       configurable: true
-                               };
-                               Object.defineProperties( owner, descriptor );
-                       }
+               var value = initial || {};
 
-               // Support: Android < 4
-               // Fallback to a less secure definition
-               } catch ( e ) {
-                       descriptor[ this.expando ] = value;
-                       jQuery.extend( owner, descriptor );
-               }
+               // If it is a node unlikely to be stringify-ed or looped over
+               // use plain assignment
+               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
+               } else {
+                       Object.defineProperty( owner, this.expando, {
+                               value: value,
+                               writable: true,
+                               configurable: true
+                       });
+               }
                return owner[ this.expando ];
        },
        cache: function( owner, initial ) {
@@ -73,15 +62,9 @@ Data.prototype = {
 
                // Handle: [ owner, { properties } ] args
                } else {
-                       // Fresh assignments by object are shallow copied
-                       if ( jQuery.isEmptyObject( cache ) ) {
-
-                               jQuery.extend( cache, data );
-                       // Otherwise, copy the properties one-by-one to the cache object
-                       } else {
-                               for ( prop in data ) {
-                                       cache[ prop ] = data[ prop ];
-                               }
+                       // Copy the properties one-by-one to the cache object
+                       for ( prop in data ) {
+                               cache[ prop ] = data[ prop ];
                        }
                }
                return cache;
@@ -128,7 +111,11 @@ Data.prototype = {
        },
        remove: function( owner, key ) {
                var i, name, camel,
-                       cache = this.cache( owner );
+                       cache = owner[ this.expando ];
+
+               if ( cache === undefined ) {
+                       return;
+               }
 
                if ( key === undefined ) {
                        this.register( owner );