]> source.dussan.org Git - jquery.git/commitdiff
Data: avoid Object.defineProperties for nodes
authorJason Bedard <jason+github@jbedard.ca>
Fri, 26 Sep 2014 15:55:48 +0000 (08:55 -0700)
committerTimmy Willison <timmywillisn@gmail.com>
Wed, 4 Mar 2015 19:32:24 +0000 (14:32 -0500)
Closes gh-1668
Fixes gh-1728
Ref gh-1734
Ref gh-1428

src/data/Data.js

index 85afd64f54b4427fe5cdc65c2edaf8f96fa6a1d9..7b9ec5b54ee9e9cbf1dec4e6f9c9e5b3caf9914e 100644 (file)
@@ -29,24 +29,20 @@ Data.prototype = {
                        return 0;
                }
 
-               var descriptor = {},
-                       // Check if the owner object already has a cache key
-                       unlock = owner[ this.expando ];
+               // Check if the owner object already has a cache key
+               var unlock = owner[ this.expando ];
 
                // If not, create one
                if ( !unlock ) {
                        unlock = Data.uid++;
 
-                       // Secure it in a non-enumerable, non-writable property
-                       try {
-                               descriptor[ this.expando ] = { value: unlock };
-                               Object.defineProperties( owner, descriptor );
-
-                       // Support: Android<4
-                       // Fallback to a less secure definition
-                       } catch ( e ) {
-                               descriptor[ this.expando ] = unlock;
-                               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 ] = unlock;
+                       // Otherwise secure it in a non-enumerable, non-writable property
+                       } else {
+                               Object.defineProperty( owner, this.expando, { value: unlock } );
                        }
                }