jquery core: fixed makeArray to recognize the window (has length)
authorAriel Flesler <aflesler@gmail.com>
Fri, 25 Apr 2008 03:48:07 +0000 (03:48 +0000)
committerAriel Flesler <aflesler@gmail.com>
Fri, 25 Apr 2008 03:48:07 +0000 (03:48 +0000)
test runner: updated the tests for makeArray

src/core.js
test/unit/core.js

index 66efc18..c5fb865 100644 (file)
@@ -1114,13 +1114,15 @@ jQuery.extend({
        makeArray: function( array ) {
                var ret = [];
 
-               if( array != undefined )
-                       //strings and functions also have 'length'
-                       if( array.length != undefined && !array.split && !array.call )
-                               for( var i = array.length; i; )
+               if( array != undefined ){
+                       var i = array.length;
+                       //the window, strings and functions also have 'length'
+                       if( i != undefined && typeof array == 'object' && array != window )
+                               while( i )
                                        ret[--i] = array[i];
                        else
                                ret[0] = array;
+               }
 
                return ret;
        },
index b79b8cb..8cd1aee 100644 (file)
@@ -1563,7 +1563,7 @@ test("contents()", function() {
 });
 
 test("$.makeArray", function(){
-       expect(11);
+       expect(13);
        
        equals( $.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" );
 
@@ -1577,14 +1577,18 @@ test("$.makeArray", function(){
 
        equals( $.makeArray( "foo" )[0], "foo", "Pass makeArray a string" );
 
-       equals( typeof $.makeArray( true )[0], "boolean", "Pass makeArray a boolean" );
+       equals( $.makeArray( true )[0].constructor, Boolean, "Pass makeArray a boolean" );
 
        equals( $.makeArray( document.createElement("div") )[0].nodeName, "DIV", "Pass makeArray a single node" );
 
        equals( $.makeArray( {length:2, 0:"a", 1:"b"} ).join(""), "ab", "Pass makeArray an array like map (with length)" );
 
-       equals( $.makeArray( document.documentElement.childNodes ).slice(0,1)[0].nodeName, "HEAD", "Pass makeArray a childNodeson array" );
+       equals( $.makeArray( document.documentElement.childNodes ).slice(0,1)[0].nodeName, "HEAD", "Pass makeArray a childNodes array" );
 
-       //function (tricky, they have length)
-       equals( $.makeArray( function(){ return 1;} )[0](), 1, "Pass makeArray a function" );   
+       //function, is tricky as it has length
+       equals( $.makeArray( function(){ return 1;} )[0](), 1, "Pass makeArray a function" );
+       //window, also has length
+       equals( $.makeArray(window)[0], window, "Pass makeArray the window" );
+       
+       equals( $.makeArray(/a/)[0].constructor, RegExp, "Pass makeArray a regex" );
 });
\ No newline at end of file