aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Resig <jeresig@gmail.com>2009-12-09 21:43:20 -0800
committerJohn Resig <jeresig@gmail.com>2009-12-09 21:43:20 -0800
commit715d1c5a30cc4986018bbf063713f14c34c3e258 (patch)
treec196e50135a2713305b4b922610239e3ee0ff09c
parentf25eedf32a7555f71a246c6f491292ce876c4133 (diff)
downloadjquery-715d1c5a30cc4986018bbf063713f14c34c3e258.tar.gz
jquery-715d1c5a30cc4986018bbf063713f14c34c3e258.zip
Rewrote .merge() (faster and less obtuse now). Fixed #5610.
-rw-r--r--src/core.js25
-rw-r--r--test/unit/core.js6
2 files changed, 16 insertions, 15 deletions
diff --git a/src/core.js b/src/core.js
index 5f1bc3a6b..4c7b07eca 100644
--- a/src/core.js
+++ b/src/core.js
@@ -567,23 +567,20 @@ jQuery.extend({
},
merge: function( first, second ) {
- var pos, i = second.length;
+ var i = first.length, j = 0;
- // We have to get length this way when IE & Opera overwrite the length
- // expando of getElementsByTagName
- if ( i && i.nodeType ) {
- for ( i = 0; second[i]; ++i ) {}
- }
-
- pos = i + first.length;
-
- // Correct length for non Arrays
- first.length = pos;
-
- while ( i ) {
- first[ --pos ] = second[ --i ];
+ if ( typeof second.length === "number" ) {
+ for ( var l = second.length; j < l; j++ ) {
+ first[ i++ ] = second[ j ];
+ }
+ } else {
+ while ( second[j] !== undefined ) {
+ first[ i++ ] = second[ j++ ];
+ }
}
+ first.length = i;
+
return first;
},
diff --git a/test/unit/core.js b/test/unit/core.js
index 252c9f99d..576deb7b9 100644
--- a/test/unit/core.js
+++ b/test/unit/core.js
@@ -711,7 +711,7 @@ test("jQuery.each(Object,Function)", function() {
});
test("jQuery.makeArray", function(){
- expect(15);
+ expect(17);
equals( jQuery.makeArray(jQuery('html>*'))[0].nodeName.toUpperCase(), "HEAD", "Pass makeArray a jQuery object" );
@@ -744,6 +744,10 @@ test("jQuery.makeArray", function(){
equals( jQuery.makeArray(/a/)[0].constructor, RegExp, "Pass makeArray a regex" );
ok( jQuery.makeArray(document.getElementById('form')).length >= 13, "Pass makeArray a form (treat as elements)" );
+
+ // For #5610
+ same( jQuery.makeArray({'length': '0'}), [], "Make sure object is coerced properly.");
+ same( jQuery.makeArray({'length': '5'}), [], "Make sure object is coerced properly.");
});
test("jQuery.isEmptyObject", function(){