W3C home > Mailing lists > Public > public-webapi@w3.org > March 2006

Re: ACTION-87: Selectors API

From: Maciej Stachowiak <mjs@apple.com>
Date: Wed, 22 Mar 2006 14:28:26 -0800
Message-Id: <2A17CC7D-706A-43B2-83C5-03A15899D5EA@apple.com>
Cc: "Web APIs WG (public)" <public-webapi@w3.org>
To: Robin Berjon <robin.berjon@expway.fr>


On Mar 22, 2006, at 2:01 PM, Robin Berjon wrote:

> On Mar 22, 2006, at 20:25, Maciej Stachowiak wrote:
>> On Mar 22, 2006, at 2:30 AM, Anne van Kesteren wrote:
>>>> * IMHO the method should not raise an exception when the  
>>>> selector contains a pseudo-element. It should would return an  
>>>> empty list.
>>>
>>> Given that it per definition only returns Element nodes I don't  
>>> see why it shouldn't raise an exception.
>>
>> I think exceptions should be reserved for actual syntax errors,  
>> not for selectors that can't match an element. I'm sure there are  
>> other ways besides pseudo-elements to make a selector that can't  
>> match anything.
>
> I'm not convinced that an exception is the best way to go, but  
> being able to make the difference between the inability to process  
> the request and the fact that nothing matched could prove important  
> for versioning purposes. For instance say v2 supports the ability  
> to return the first-letter inside an element while v1 doesn't, and  
> I want to write code that tries to do that using selectors in such  
> a way that if the implementation tells me it's impossible I fall  
> back to some hand-coded munging.
>
> If we can't differentiate we'll have to resort to hasFeature().  
> Quite frankly, give me exceptions any day over that :)

I think exception on syntax error would cover this. If you use  
selector features that the implementation doesn't support, you'll get  
a parse error. Pseudo-elements would not be in that category, since  
they are supported but don't match any elements.

Another possibility, however, would be to match any element that is  
at least partially included in the pseudo. For example, document.match 
("em::selection") would give you all <em> elements at least partially  
contained in the selection. I could imagine this being useful for  
some use cases.

And it would let us cleanly reserve exceptions for the case of a  
syntax error in the selector group.

Regards,
Maciej
Received on Wednesday, 22 March 2006 22:28:50 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 8 January 2008 14:18:54 GMT