Bug Tracker

Changeset 5318

Show
Ignore:
Timestamp:
04/25/08 03:48:07 (7 months ago)
Author:
aflesler
Message:

jquery core: fixed makeArray to recognize the window (has length)
test runner: updated the tests for makeArray

Location:
trunk/jquery
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/jquery/src/core.js

    r5317 r5318  
    11151115        var ret = []; 
    11161116 
    1117         if( array != undefined ) 
    1118             //strings and functions also have 'length' 
    1119             if( array.length != undefined && !array.split && !array.call ) 
    1120                 for( var i = array.length; i; ) 
     1117        if( array != undefined ){ 
     1118            var i = array.length; 
     1119            //the window, strings and functions also have 'length' 
     1120            if( i != undefined && typeof array == 'object' && array != window ) 
     1121                while( i ) 
    11211122                    ret[--i] = array[i]; 
    11221123            else 
    11231124                ret[0] = array; 
     1125        } 
    11241126 
    11251127        return ret; 
  • trunk/jquery/test/unit/core.js

    r5314 r5318  
    15641564 
    15651565test("$.makeArray", function(){ 
    1566     expect(11); 
     1566    expect(13); 
    15671567     
    15681568    equals( $.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" ); 
     
    15781578    equals( $.makeArray( "foo" )[0], "foo", "Pass makeArray a string" ); 
    15791579 
    1580     equals( typeof $.makeArray( true )[0], "boolean", "Pass makeArray a boolean" ); 
     1580    equals( $.makeArray( true )[0].constructor, Boolean, "Pass makeArray a boolean" ); 
    15811581 
    15821582    equals( $.makeArray( document.createElement("div") )[0].nodeName, "DIV", "Pass makeArray a single node" ); 
     
    15841584    equals( $.makeArray( {length:2, 0:"a", 1:"b"} ).join(""), "ab", "Pass makeArray an array like map (with length)" ); 
    15851585 
    1586     equals( $.makeArray( document.documentElement.childNodes ).slice(0,1)[0].nodeName, "HEAD", "Pass makeArray a childNodeson array" ); 
    1587  
    1588     //function (tricky, they have length) 
    1589     equals( $.makeArray( function(){ return 1;} )[0](), 1, "Pass makeArray a function" );    
    1590 }); 
     1586    equals( $.makeArray( document.documentElement.childNodes ).slice(0,1)[0].nodeName, "HEAD", "Pass makeArray a childNodes array" ); 
     1587 
     1588    //function, is tricky as it has length 
     1589    equals( $.makeArray( function(){ return 1;} )[0](), 1, "Pass makeArray a function" ); 
     1590    //window, also has length 
     1591    equals( $.makeArray(window)[0], window, "Pass makeArray the window" ); 
     1592     
     1593    equals( $.makeArray(/a/)[0].constructor, RegExp, "Pass makeArray a regex" ); 
     1594});