Skip to content

Commit 95fb798

Browse files
jbedardtimmywil
authored andcommitted
Data: avoid Object.defineProperties for nodes
Closes gh-1668 Fixes gh-1728 Ref gh-1734 Ref gh-1428
1 parent 2380028 commit 95fb798

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/data/Data.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,20 @@ Data.prototype = {
2929
return 0;
3030
}
3131

32-
var descriptor = {},
33-
// Check if the owner object already has a cache key
34-
unlock = owner[ this.expando ];
32+
// Check if the owner object already has a cache key
33+
var unlock = owner[ this.expando ];
3534

3635
// If not, create one
3736
if ( !unlock ) {
3837
unlock = Data.uid++;
3938

40-
// Secure it in a non-enumerable, non-writable property
41-
try {
42-
descriptor[ this.expando ] = { value: unlock };
43-
Object.defineProperties( owner, descriptor );
44-
45-
// Support: Android<4
46-
// Fallback to a less secure definition
47-
} catch ( e ) {
48-
descriptor[ this.expando ] = unlock;
49-
jQuery.extend( owner, descriptor );
39+
// If it is a node unlikely to be stringify-ed or looped over
40+
// use plain assignment
41+
if ( owner.nodeType ) {
42+
owner[ this.expando ] = unlock;
43+
// Otherwise secure it in a non-enumerable, non-writable property
44+
} else {
45+
Object.defineProperty( owner, this.expando, { value: unlock } );
5046
}
5147
}
5248

0 commit comments

Comments
 (0)