rmultiDash = /([A-Z])/g;
function Data() {
- this.cache = {};
+ // Support: Android < 4,
+ // Old WebKit does not have Object.preventExtensions/freeze method, return new empty object instead
+ Object.defineProperty( this.cache = {}, 0, {
+ get: function() {
+ return {};
+ }
+ });
+
this.expando = jQuery.expando + Math.random();
}
Data.prototype = {
key: function( owner ) {
+ // We can accept data for non-element nodes in modern browsers, but we should not, see #8335.
+ // Always return key for "freezed" object for such cases
+ if ( !this.accept( owner ) ) {
+ return 0;
+ }
+
+
var descriptor = {},
// Check if the owner object already has a cache key
unlock = owner[ this.expando ];
}
}
},
+ accept: function( owner ) {
+ // Do not set data on non-element because it will not be cleared (#8335).
+ return owner.nodeType ? owner.nodeType === 1 || owner.nodeType === 9 : true;
+ },
hasData: function( owner ) {
return !jQuery.isEmptyObject(
this.cache[ owner[ this.expando ] ] || {}
jQuery.extend({
- // This is no longer relevant to jQuery core, but must remain
- // supported for the sake of jQuery 1.9.x API surface compatibility.
- acceptData: function() {
- return true;
- },
+ acceptData: data_user.accept,
hasData: function( elem ) {
return data_user.hasData( elem ) || data_priv.hasData( elem );
dataTests( flash );
});
-test("jQuery.data(comment)", 25, function() {
- dataTests( document.createComment("") );
-});
-
-test("jQuery.data(text)", 25, function() {
- dataTests( document.createTextNode("") );
-});
-
test(".data()", function() {
expect(5);
ok( false, e.message );
}
});
+
+test("jQuery.acceptData", 6, function() {
+ ok( jQuery.acceptData( document ), "document" );
+ ok( jQuery.acceptData( document.documentElement ), "documentElement" );
+ ok( jQuery.acceptData( {} ), "object" );
+
+ ok( !jQuery.acceptData( document.createComment("") ), "comment" );
+ ok( !jQuery.acceptData( document.createTextNode("") ), "text" );
+ ok( !jQuery.acceptData( document.createDocumentFragment() ), "documentFragment" );
+});
+
+test("Check proper data removal of non-element descendants nodes (#8335)", 1, function() {
+ var div = jQuery("<div>text</div>"),
+ text = div.contents();
+
+ text.data( "test", "test" ); // This should be a noop.
+ div.remove();
+
+ ok( !text.data("test"), "Be sure data is not stored in non-element" );
+});