Commit 6c449fd5 authored by John Resig's avatar John Resig

Make sure that empty nodelists continue to map properly. Fixes #8993.

parent 86aa764f
...@@ -720,7 +720,7 @@ jQuery.extend({ ...@@ -720,7 +720,7 @@ jQuery.extend({
i = 0, i = 0,
length = elems.length, length = elems.length,
// jquery objects are treated as arrays // 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 // Go through the array, translating each of the items to their
if ( isArray ) { if ( isArray ) {
......
...@@ -653,7 +653,7 @@ test("first()/last()", function() { ...@@ -653,7 +653,7 @@ test("first()/last()", function() {
}); });
test("map()", function() { test("map()", function() {
expect(7); expect(8);
same( same(
jQuery("#ap").map(function(){ jQuery("#ap").map(function(){
...@@ -694,6 +694,12 @@ test("map()", function() { ...@@ -694,6 +694,12 @@ test("map()", function() {
}); });
equals( mapped.length, scripts.length, "Map an array(-like) to a hash" ); 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 ){ var flat = jQuery.map( Array(4), function( v, k ){
return k % 2 ? k : [k,k,k];//try mixing array and regular returns return k % 2 ? k : [k,k,k];//try mixing array and regular returns
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment