Skip to content

Commit

Permalink
Guard against exceptions when clearing safeChildNodes.
Browse files Browse the repository at this point in the history
Supplements #11356 and fixes unit test failures in FF 3.6.
  • Loading branch information
rwaldron authored and dmethvin committed Mar 6, 2012
1 parent e529d91 commit 619f0d9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,10 +727,14 @@ jQuery.extend({
// to avoid hoarding elements. Fixes #11356
if ( div ) {
div.parentNode.removeChild( div );
remove = safeChildNodes[ safeChildNodes.length - 1 ];

if ( remove && remove.parentNode ) {
remove.parentNode.removeChild( remove );
// Guard against -1 index exceptions in FF3.6
if ( safeChildNodes.length > 0 ) {
remove = safeChildNodes[ safeChildNodes.length - 1 ];

if ( remove && remove.parentNode ) {
remove.parentNode.removeChild( remove );
}
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions test/unit/manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -1740,3 +1740,15 @@ test("jQuery.fragments cache expectations", function() {

equal( fragmentCacheSize(), 12, "12 entries exist in jQuery.fragments, 2" );
});

test("Guard against exceptions when clearing safeChildNodes", function() {
expect( 1 );

var div;

try {
div = jQuery("<div/><hr/><code/><b/>");
} catch(e) {}

ok( div && div.jquery, "Created nodes safely, guarded against exceptions on safeChildNodes[ -1 ]" );
});

0 comments on commit 619f0d9

Please sign in to comment.