Skip to main content

Bug Tracker

Side navigation

#5380 closed bug (fixed)

Opened October 15, 2009 12:13AM UTC

Closed November 10, 2009 12:40AM UTC

jQuery tests fail because on Chrome of V8 sorting optimization (patch)

Reported by: antonkovalyov Owned by: john
Priority: critical Milestone: 1.4
Component: selector Version: 1.3.2
Keywords: Cc:
Blocked by: Blocking:
Description

In [6617] some tests fail (see below) in Google Chrome (4.0.221.8). That happens because the underlying engine, V8, uses some sort of sorting optimization where it does not call user-defined comparison function for duplicate objects.

[document, document].sort(cmp); // cmp will never be called
[document, window].sort(cmp); // cmp will be called once

jQuery uses a special flag, hasDuplicate, to eliminate an unnecessary loop if there are no duplicates in the collection. While this approach works perfectly well in the majority of browsers, it fails in Chrome (and, I believe, other V8-based browsers, if any) due to reasons described above.

My patch checks the engine for such kind of optimizations and discards the hasDuplicate value if necessary.

All tests pass in Safari (Mac; 4.0.3), Chrome (Mac; 4.0.221.8) and Firefox (Mac; 3.5.3).

P. S. List of failed test before patch:

16.13: Pass an array

16.14: Check duplicated elements

16.15: Check duplicated elements using the window

69.3: Check for parent and self

70.5: Check for unique results from siblings

72.5: Check for unique results from parent

73.5: Check for unique results from parents

83.1: Check for wrapping of on-the-fly.html

Attachments (1)
Change History (1)

Changed November 10, 2009 12:40AM UTC by john comment:1

milestone: → 1.4
resolution: → fixed
status: newclosed
version: → 1.3.2

Made some tweaks to the patch and landed it - good catch and thanks for the patch!

http://github.com/jeresig/sizzle/commit/23e6fb14d83961fdf4487ac3958296caeada82a9