Bug 16587 - Implement the W3C Selectors API
: Implement the W3C Selectors API
Status: RESOLVED FIXED
Product: WebKit
Classification: Unclassified
Component: HTML DOM
: 528+ (Nightly build)
: Macintosh Mac OS X 10.5
: P2 Normal
Assigned To: Nobody
http://dscoder.com/deansqueryselector...
:
Depends on:
Blocks: 16234
  Show dependency treegraph
 
Reported: 2007-12-23 13:21 PST by David Smith
Modified: 2007-12-31 18:21 PST (History)
3 users (show)

See Also:


Attachments
In-progress patch (12.88 KB, patch)
2007-12-23 13:24 PST, David Smith
no flags Details | Formatted Diff | Diff
another in-progress patch (adds StaticNodeList) (53.54 KB, patch)
2007-12-23 15:25 PST, Sam Weinig
no flags Details | Formatted Diff | Diff
more fun (54.63 KB, patch)
2007-12-23 22:36 PST, Sam Weinig
no flags Details | Formatted Diff | Diff
Stop leaking a bunch of CSS stuff every query (55.36 KB, patch)
2007-12-24 13:33 PST, David Smith
no flags Details | Formatted Diff | Diff
Much much faster (55.16 KB, patch)
2007-12-24 17:41 PST, David Smith
no flags Details | Formatted Diff | Diff
Fixes selectors with commas (55.49 KB, patch)
2007-12-24 18:44 PST, David Smith
no flags Details | Formatted Diff | Diff
Updated (58.92 KB, patch)
2007-12-24 19:23 PST, David Smith
no flags Details | Formatted Diff | Diff
Handle null and undefined according to the spec (59.23 KB, patch)
2007-12-24 22:31 PST, David Smith
no flags Details | Formatted Diff | Diff
Now with tests :) (86.56 KB, patch)
2007-12-25 13:34 PST, David Smith
oliver: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Smith 2007-12-23 13:21:04 PST
http://www.w3.org/TR/selectors-api/

Would be very handy for authors.
Comment 1 David Smith 2007-12-23 13:24:25 PST
Created attachment 18074 [details]
In-progress patch

There are quite a few issues with this patch, so I'm not requesting review yet. It leaks memory, uses NodeList instead of StaticNodeList, and doesn't implement the functions other than querySelectorAll. Other than that it appears to work nicely, though :)
Comment 2 Sam Weinig 2007-12-23 15:25:57 PST
Created attachment 18079 [details]
another in-progress patch (adds StaticNodeList)
Comment 3 Sam Weinig 2007-12-23 22:36:31 PST
Created attachment 18088 [details]
more fun
Comment 4 David Smith 2007-12-24 11:18:54 PST
Adding a link to a version of Dean Edward's tests for his cssQuery function modified to tolerate exceptions and use querySelector/querySelectorAll instead of cssQuery. With the latest patch we pass for all selectors WebKit supports.
Comment 5 David Smith 2007-12-24 13:33:14 PST
Created attachment 18095 [details]
Stop leaking a bunch of CSS stuff every query
Comment 6 David Smith 2007-12-24 17:41:40 PST
Created attachment 18097 [details]
Much much faster

Benchmarking + Sharking + Weinig making good suggestions == Speedy
Comment 7 David Smith 2007-12-24 18:44:50 PST
Created attachment 18098 [details]
Fixes selectors with commas

Previously things like a, b { } would fail, since we weren't checking all the selectors. There are now no test failures on the slickspeed test, except those due to webkit not supporting the relevant selector.
Comment 8 David Smith 2007-12-24 19:23:01 PST
Created attachment 18100 [details]
Updated

Fixed comma selectors for querySelector as well as querySelectorAll, made a tiny optimization, and added a changelog.
Comment 9 David Smith 2007-12-24 22:31:25 PST
Created attachment 18103 [details]
Handle null and undefined according to the spec

This also makes it so that if you put in syntactically valid CSS that is not a selector, it throws a syntax error as it should (for example: "@font-face").
Comment 10 David Smith 2007-12-25 00:44:27 PST
Ken Ferry points out that although the CSS spec does define an empty selector as invalid, it's possibly a reasonable interpretation to say that null/undefined are just not selectors at all, valid or invalid. I think we should probably get this clarified. I'm also not convinced that throwing is the best behavior for the spec to dictate in this situation, but that's another matter.
Comment 11 David Smith 2007-12-25 13:34:25 PST
Created attachment 18113 [details]
Now with tests :)

I think this is ready for review.
Comment 12 Oliver Hunt 2007-12-25 16:40:03 PST
Comment on attachment 18113 [details]
Now with tests :)

With the various formatting fixes i mentioned in irc
Comment 13 David Smith 2007-12-25 16:55:05 PST
Landed in r28981