From: Colin Snover Date: Thu, 23 Dec 2010 00:31:33 +0000 (-0600) Subject: Don't use for-in loops on Arrays. Fixes #7817. Thanks to dmethvin. X-Git-Url: http://git.asbjorn.biz/?p=jquery.git;a=commitdiff_plain;h=82ac384b494258e17e2856ee2259475ecb0174ca;hp=-c Don't use for-in loops on Arrays. Fixes #7817. Thanks to dmethvin. Conflicts: src/manipulation.js --- 82ac384b494258e17e2856ee2259475ecb0174ca diff --combined src/manipulation.js index 3b9aa14,9d70a7b..5f4b15d --- a/src/manipulation.js +++ b/src/manipulation.js @@@ -370,18 -370,14 +370,18 @@@ function root( elem, cur ) } function cloneCopyEvent(orig, ret) { - var node = 0; - - ret.each(function() { - if ( this.nodeType !== 1 || this.nodeName !== (orig[node] && orig[node].nodeName) ) { + ret.each(function (nodeIndex) { + if ( this.nodeType !== 1 || !jQuery.hasData(orig[nodeIndex]) ) { return; } - var oldData = jQuery.data( orig[node++] ), + // XXX remove for 1.5 RC or merge back in if there is actually a reason for this check that has been + // unexposed by unit tests + if ( this.nodeName !== (orig[nodeIndex] && orig[nodeIndex].nodeName) ) { + throw "Cloned data mismatch"; + } + + var oldData = jQuery.data( orig[nodeIndex] ), curData = jQuery.data( this, oldData ), events = oldData && oldData.events; @@@ -390,8 -386,8 +390,8 @@@ curData.events = {}; for ( var type in events ) { - for ( var handler in events[ type ] ) { - jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data ); + for ( var i = 0, l = events[ type ].length; i < l; i++ ) { + jQuery.event.add( this, type, events[ type ][ i ], events[ type ][ i ].data ); } } } diff --combined test/unit/manipulation.js index ba57a6f,cbc0b77..da16354 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@@ -1,5 -1,8 +1,8 @@@ module("manipulation"); + // Ensure that an extended Array prototype doesn't break jQuery + Array.prototype.arrayProtoFn = function(arg) { throw("arrayProtoFn should not be called"); }; + var bareObj = function(value) { return value; }; var functionReturningObj = function(value) { return (function() { return value; }); }; @@@ -51,7 -54,7 +54,7 @@@ test("text(Function) with incoming valu }); var testWrap = function(val) { - expect(18); + expect(19); var defaultText = 'Try them out:' var result = jQuery('#first').wrap(val( '
' )).text(); equals( defaultText, result, 'Check for wrapping of on-the-fly html' ); @@@ -80,20 -83,10 +83,20 @@@ equals( jQuery("#nonnodes > i").text(), j.text(), "Check node,textnode,comment wraps doesn't hurt text" ); // Try wrapping a disconnected node + var cacheLength = 0; + for (var i in jQuery.cache) { + cacheLength++; + } + j = jQuery("