Skip to content

Commit

Permalink
Data: use removeAttribute in cleanData to bypass Chrome bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard authored and timmywil committed Dec 10, 2014
1 parent 57652ee commit 9d1d90e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/data.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ function internalRemoveData( elem, name, pvt ) {
/* jshint eqeqeq: true */ /* jshint eqeqeq: true */
delete cache[ id ]; delete cache[ id ];


// When all else fails, null // When all else fails, undefined
} else { } else {
cache[ id ] = null; cache[ id ] = undefined;
} }
} }


Expand Down
15 changes: 6 additions & 9 deletions src/data/support.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ define([
(function() { (function() {
var div = document.createElement( "div" ); var div = document.createElement( "div" );


// Execute the test only if not already executed in another module. // Support: IE<9
if (support.deleteExpando == null) { support.deleteExpando = true;
// Support: IE<9 try {
support.deleteExpando = true; delete div.test;
try { } catch ( e ) {
delete div.test; support.deleteExpando = false;
} catch ( e ) {
support.deleteExpando = false;
}
} }


// Null elements to avoid leaks in IE. // Null elements to avoid leaks in IE.
Expand Down
19 changes: 10 additions & 9 deletions src/manipulation.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ jQuery.extend({
i = 0, i = 0,
internalKey = jQuery.expando, internalKey = jQuery.expando,
cache = jQuery.cache, cache = jQuery.cache,
deleteExpando = support.deleteExpando, attributes = support.attributes,
special = jQuery.event.special; special = jQuery.event.special;


for ( ; (elem = elems[i]) != null; i++ ) { for ( ; (elem = elems[i]) != null; i++ ) {
Expand All @@ -394,17 +394,18 @@ jQuery.extend({


delete cache[ id ]; delete cache[ id ];


// IE does not allow us to delete expando properties from nodes, // Support: IE<9
// nor does it have a removeAttribute function on Document nodes; // IE does not allow us to delete expando properties from nodes
// we must handle all of these cases // IE creates expando attributes along with the property
if ( deleteExpando ) { // IE does not have a removeAttribute function on Document nodes
delete elem[ internalKey ]; if ( !attributes && typeof elem.removeAttribute !== "undefined" ) {

} else if ( typeof elem.removeAttribute !== "undefined" ) {
elem.removeAttribute( internalKey ); elem.removeAttribute( internalKey );


// Webkit & Blink performance suffers when deleting properties
// from DOM nodes, so set to undefined instead
// https://code.google.com/p/chromium/issues/detail?id=378607
} else { } else {
elem[ internalKey ] = null; elem[ internalKey ] = undefined;
} }


deletedIds.push( id ); deletedIds.push( id );
Expand Down
18 changes: 7 additions & 11 deletions src/manipulation/support.js
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,7 @@
define([ define([
"../core",
"../var/support" "../var/support"
], function( support ) { ], function( jQuery, support ) {


(function() { (function() {
var div = document.createElement( "div" ), var div = document.createElement( "div" ),
Expand Down Expand Up @@ -38,16 +39,11 @@ define([
// Cloned elements keep attachEvent handlers, we use addEventListener on IE9+ // Cloned elements keep attachEvent handlers, we use addEventListener on IE9+
support.noCloneEvent = !!div.addEventListener; support.noCloneEvent = !!div.addEventListener;


// Execute the test only if not already executed in another module. // Support: IE<9
if (support.deleteExpando == null) { // Since attributes and properties are the same in IE,
// Support: IE<9 // cleanData must set properties to undefined rather than use removeAttribute
support.deleteExpando = true; div[ jQuery.expando ] = 1;
try { support.attributes = !div.getAttribute( jQuery.expando );
delete div.test;
} catch ( e ) {
support.deleteExpando = false;
}
}
})(); })();


return support; return support;
Expand Down
12 changes: 2 additions & 10 deletions test/unit/data.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -100,18 +100,10 @@ test("jQuery.data(document)", 25, function() {
}); });


test("Expando cleanup", 4, function() { test("Expando cleanup", 4, function() {
var expected, actual, var div = document.createElement("div");
div = document.createElement("div");


function assertExpandoAbsent(message) { function assertExpandoAbsent(message) {
if (jQuery.support.deleteExpando) { strictEqual( div[ jQuery.expando ], undefined, message );
expected = false;
actual = jQuery.expando in div;
} else {
expected = null;
actual = div[ jQuery.expando ];
}
equal( actual, expected, message );
} }


assertExpandoAbsent("There is no expando on new elements"); assertExpandoAbsent("There is no expando on new elements");
Expand Down
10 changes: 10 additions & 0 deletions test/unit/support.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
// Android browser on Android >= 4.4). // Android browser on Android >= 4.4).
expected = { expected = {
"ajax": true, "ajax": true,
"attributes": true,
"boxSizingReliable": true, "boxSizingReliable": true,
"changeBubbles": true, "changeBubbles": true,
"checkClone": true, "checkClone": true,
Expand Down Expand Up @@ -103,6 +104,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
} else if ( /(msie 10\.0|trident\/7\.0)/i.test( userAgent ) ) { } else if ( /(msie 10\.0|trident\/7\.0)/i.test( userAgent ) ) {
expected = { expected = {
"ajax": true, "ajax": true,
"attributes": true,
"boxSizingReliable": false, "boxSizingReliable": false,
"changeBubbles": true, "changeBubbles": true,
"checkClone": true, "checkClone": true,
Expand Down Expand Up @@ -133,6 +135,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
} else if ( /msie 9\.0/i.test( userAgent ) ) { } else if ( /msie 9\.0/i.test( userAgent ) ) {
expected = { expected = {
"ajax": true, "ajax": true,
"attributes": true,
"boxSizingReliable": false, "boxSizingReliable": false,
"changeBubbles": true, "changeBubbles": true,
"checkClone": true, "checkClone": true,
Expand Down Expand Up @@ -163,6 +166,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
} else if ( /msie 8\.0/i.test( userAgent ) ) { } else if ( /msie 8\.0/i.test( userAgent ) ) {
expected = { expected = {
"ajax": true, "ajax": true,
"attributes": false,
"boxSizingReliable": false, "boxSizingReliable": false,
"changeBubbles": false, "changeBubbles": false,
"checkClone": true, "checkClone": true,
Expand Down Expand Up @@ -193,6 +197,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
} else if ( /(6|7)\.0(\.\d+|) safari/i.test( userAgent ) ) { } else if ( /(6|7)\.0(\.\d+|) safari/i.test( userAgent ) ) {
expected = { expected = {
"ajax": true, "ajax": true,
"attributes": true,
"boxSizingReliable": true, "boxSizingReliable": true,
"changeBubbles": true, "changeBubbles": true,
"checkClone": true, "checkClone": true,
Expand Down Expand Up @@ -223,6 +228,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
} else if ( /8.0(\.\d+|) safari/i.test( userAgent ) ) { } else if ( /8.0(\.\d+|) safari/i.test( userAgent ) ) {
expected = { expected = {
"ajax": true, "ajax": true,
"attributes": true,
"boxSizingReliable": true, "boxSizingReliable": true,
"changeBubbles": true, "changeBubbles": true,
"checkClone": true, "checkClone": true,
Expand Down Expand Up @@ -253,6 +259,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
} else if ( /firefox/i.test( userAgent ) ) { } else if ( /firefox/i.test( userAgent ) ) {
expected = { expected = {
"ajax": true, "ajax": true,
"attributes": true,
"boxSizingReliable": true, "boxSizingReliable": true,
"changeBubbles": true, "changeBubbles": true,
"checkClone": true, "checkClone": true,
Expand Down Expand Up @@ -283,6 +290,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
} else if ( /iphone os/i.test( userAgent ) ) { } else if ( /iphone os/i.test( userAgent ) ) {
expected = { expected = {
"ajax": true, "ajax": true,
"attributes": true,
"boxSizingReliable": true, "boxSizingReliable": true,
"changeBubbles": true, "changeBubbles": true,
"checkClone": true, "checkClone": true,
Expand Down Expand Up @@ -313,6 +321,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
} else if ( /android 4\.[0-3]/i.test( userAgent ) ) { } else if ( /android 4\.[0-3]/i.test( userAgent ) ) {
expected = { expected = {
"ajax": true, "ajax": true,
"attributes": true,
"boxSizingReliable": true, "boxSizingReliable": true,
"changeBubbles": true, "changeBubbles": true,
"checkClone": false, "checkClone": false,
Expand Down Expand Up @@ -343,6 +352,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
} else if ( /android 2\.3/i.test( userAgent ) ) { } else if ( /android 2\.3/i.test( userAgent ) ) {
expected = { expected = {
"ajax": true, "ajax": true,
"attributes": true,
"boxSizingReliable": true, "boxSizingReliable": true,
"changeBubbles": true, "changeBubbles": true,
"checkClone": true, "checkClone": true,
Expand Down

0 comments on commit 9d1d90e

Please sign in to comment.