Don't use for-in loops on Arrays. Fixes #7817. Thanks to dmethvin.
authorColin Snover <github.com@zetafleet.com>
Thu, 23 Dec 2010 00:31:33 +0000 (18:31 -0600)
committerColin Snover <github.com@zetafleet.com>
Thu, 23 Dec 2010 00:32:33 +0000 (18:32 -0600)
Conflicts:
src/manipulation.js

1  2 
src/manipulation.js
test/unit/manipulation.js

diff --combined 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;
  
                        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 );
                                }
                        }
                }
@@@ -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( '<div class="red"><span></span></div>' )).text();
        equals( defaultText, result, 'Check for wrapping of on-the-fly html' );
        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("<label/>").wrap(val( "<li/>" ));
        equals( j[0].nodeName.toUpperCase(), "LABEL", "Element is a label" );
        equals( j[0].parentNode.nodeName.toUpperCase(), "LI", "Element has been wrapped" );
  
 +      for (i in jQuery.cache) {
 +              cacheLength--;
 +      }
 +      equals(cacheLength, 0, "No memory leak in jQuery.cache (bug #7165)");
 +
        // Wrap an element containing a text node
        j = jQuery("<span/>").wrap("<div>test</div>");
        equals( j[0].previousSibling.nodeType, 3, "Make sure the previous node is a text element" );
@@@ -866,7 -859,7 +869,7 @@@ test("replaceAll(String|Element|Array&l
  });
  
  test("clone()", function() {
 -      expect(36);
 +      expect(37);
        equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' );
        var clone = jQuery('#yahoo').clone();
        equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' );
        equals( clone.html(), div.html(), "Element contents cloned" );
        equals( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
  
 -      div = jQuery("<div/>").data({ a: true, b: true });
 -      div = div.clone(true);
 -      equals( div.data("a"), true, "Data cloned." );
 -      equals( div.data("b"), true, "Data cloned." );
 +      div = jQuery("<div/>").data({ a: true });
 +      var div2 = div.clone(true);
 +      equals( div2.data("a"), true, "Data cloned." );
 +      div2.data("a", false);
 +      equals( div2.data("a"), false, "Ensure cloned element data object was correctly modified" );
 +      equals( div.data("a"), true, "Ensure cloned element data object is copied, not referenced" );
  
        var form = document.createElement("form");
        form.action = "/test/";