Skip to main content

Bug Tracker

Side navigation

#12378 closed bug (invalid)

Opened August 23, 2012 03:58AM UTC

Closed August 23, 2012 01:30PM UTC

$.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
.

Attachments (0)
Change History (5)

Changed August 23, 2012 12:42PM UTC by dmethvin comment:1

owner: → 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?

Changed August 23, 2012 01:06PM UTC by dangerbell comment:2

status: pendingnew

Replying to [comment:1 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.

Changed August 23, 2012 01:07PM UTC by dmethvin comment:3

status: newpending

Great! Which plugin was this?

Changed August 23, 2012 01:23PM UTC by dangerbell comment:4

status: pendingnew

Replying to [comment:3 dmethvin]:

Great! Which plugin was this?

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

Changed August 23, 2012 01:30PM UTC by dmethvin comment:5

resolution: → invalid
status: newclosed

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