Bug Tracker

Opened 10 years ago

Closed 10 years ago

#5380 closed bug (fixed)

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

  1. 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)

selector.js.patch (684 bytes) - added by antonkovalyov 10 years ago.

Download all attachments as: .zip

Change History (2)

Changed 10 years ago by antonkovalyov

Attachment: selector.js.patch added

comment:1 Changed 10 years ago by john

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

Note: See TracTickets for help on using tickets.