Skip to content

isArrayLike no longer fails gracefully for null and undefined from 1.11.1 to 1.11.3 #2267

@ScottLNorvell

Description

@ScottLNorvell

in 1.11.1, isArrayLike looks like this:

function isArraylike( obj ) {
    var length = obj.length,
        type = jQuery.type( obj );

    if ( type === "function" || jQuery.isWindow( obj ) ) {
        return false;
    }

    if ( obj.nodeType === 1 && length ) {
        return true;
    }

    return type === "array" || length === 0 ||
        typeof length === "number" && length > 0 && ( length - 1 ) in obj;
}

in 1.11.3, it looks like this:

function isArraylike( obj ) {

    // Support: iOS 8.2 (not reproducible in simulator)
    // `in` check used to prevent JIT error (gh-2145)
    // hasOwn isn't used here due to false negatives
    // regarding Nodelist length in IE
    var length = "length" in obj && obj.length,
        type = jQuery.type( obj );

    if ( type === "function" || jQuery.isWindow( obj ) ) {
        return false;
    }

    if ( obj.nodeType === 1 && length ) {
        return true;
    }

    return type === "array" || length === 0 ||
        typeof length === "number" && length > 0 && ( length - 1 ) in obj;
}

"length" in obj produces the error TypeError: Cannot use 'in' operator to search for 'length' in 6 when obj === 6. Similarly when obj is a undefined or null. This causes, specifically $.each to fail when you accidentally put in a numerical value for obj. Not sure if this is an issue, but in 1.11.1, nothing failed when obj was accidentally a number. This caused some tests to fail that we've fixed. Thought I'd mention it.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions