]> source.dussan.org Git - jquery.git/commitdiff
Make sure that empty nodelists continue to map properly. Fixes #8993.
authorJohn Resig <jeresig@gmail.com>
Mon, 2 May 2011 17:25:53 +0000 (13:25 -0400)
committerJohn Resig <jeresig@gmail.com>
Mon, 2 May 2011 17:25:53 +0000 (13:25 -0400)
src/core.js
test/unit/core.js

index 6ab06e15b322a0d9f4f12c46d5d0d1df25dc56aa..7eb0e0b110cc0f1aef007e42fba4ca5d4a0b9088 100644 (file)
@@ -720,7 +720,7 @@ jQuery.extend({
                        i = 0,
                        length = elems.length,
                        // jquery objects are treated as arrays
-                       isArray = elems instanceof jQuery || length !== undefined && typeof length === "number" && ( ( length > 0 && elems[ 0 ] && elems[ length -1 ] ) || jQuery.isArray( elems ) ) ;
+                       isArray = elems instanceof jQuery || length !== undefined && typeof length === "number" && ( ( length > 0 && elems[ 0 ] && elems[ length -1 ] ) || length === 0 || jQuery.isArray( elems ) ) ;
 
                // Go through the array, translating each of the items to their
                if ( isArray ) {
index 7690756d916ea3dda216e51d40f446a52d53a60e..75d3e0e2c138ebffb9e0be3f3830a6e75fdaeaa9 100644 (file)
@@ -653,7 +653,7 @@ test("first()/last()", function() {
 });
 
 test("map()", function() {
-       expect(7);
+       expect(8);
 
        same(
                jQuery("#ap").map(function(){
@@ -694,6 +694,12 @@ test("map()", function() {
        });
        equals( mapped.length, scripts.length, "Map an array(-like) to a hash" );
 
+       var nonsense = document.getElementsByTagName("asdf");
+       var mapped = jQuery.map( nonsense, function( v, k ){
+               return v;
+       });
+       equals( mapped.length, nonsense.length, "Map an empty array(-like) to a hash" );
+
        var flat = jQuery.map( Array(4), function( v, k ){
                return k % 2 ? k : [k,k,k];//try mixing array and regular returns
        });