Bug Tracker

Opened 7 years ago

Closed 7 years ago

#12378 closed bug (invalid)

$.unique goes into an infinite loop in IE8 (slow script warning).

Reported by: dangerbell Owned by: dangerbell
Priority: undecided Milestone: None
Component: unfiled Version: 1.8.0
Keywords: Cc:
Blocked by: Blocking:

Description

http://jsfiddle.net/QAWyd/2/

The above jsFiddle will trigger a slow script warning in IE8 (but not Chrome, I haven't checked other IEs).

It seems to be the condition in the for loop of Sizzle.uniqueSort.

for ( ; (elem = results[i]); i++ ) {
  if ( elem === results[ i - 1 ] ) {
    results.splice( i--, 1 );
  }
}

In Chrome when results[i] accesses an element that's been removed with splice it returns undefined. But in IE8 it seems that it can still access the element and assigns it to elem. So the condition always ends up being true. Array indexes that are outside the original array's length return undefined and results.length returns the correct size. I have no idea why IE would do this.

The loop from jQuery 1.7.2 works properly because it's checking results.length.

Change History (5)

comment:1 Changed 7 years ago by dmethvin

Owner: set to dangerbell
Status: newpending

The documentation says:

This function only works on plain JavaScript arrays of DOM elements, and is chiefly used internally by jQuery. -- http://api.jquery.com/jQuery.unique/

You're passing it a jQuery object. Did you notice the documentation?

comment:2 in reply to:  1 Changed 7 years ago by dangerbell

Status: pendingnew

Replying to dmethvin:

The documentation says:

This function only works on plain JavaScript arrays of DOM elements, and is chiefly used internally by jQuery. -- http://api.jquery.com/jQuery.unique/

You're passing it a jQuery object. Did you notice the documentation?

Oh. Yep, it works if you pass it a regular array. I guess I'll go report this as a bug in the plugin I was using. Thanks.

comment:3 Changed 7 years ago by dmethvin

Status: newpending

Great! Which plugin was this?

comment:4 in reply to:  3 Changed 7 years ago by dangerbell

Status: pendingnew

Replying to dmethvin:

Great! Which plugin was this?

jqBootstrapValidation: http://reactiveraven.github.com/jqBootstrapValidation/

comment:5 Changed 7 years ago by dmethvin

Resolution: invalid
Status: newclosed

I'll file a bug on their issue tracker, thanks!

Note: See TracTickets for help on using tickets.