Re: [whatwg/dom] querySelector/All can accidentally return the scoping element (#263)

Finally this will be clarified, @annevk some times ago (~2014) I pointed to you via e-mail the same strange behaviour:

```
And have small question about selectors API. We have method
element.matches(): so I try test it on Firefox (suppose that
mozMatchesSelector will be the same as matches):

alert(document.body.mozMatchesSelector(":scope"))          // true
alert(document.body.mozMatchesSelector("html :scope"))  // true

and it looks like correct. But why this return null or empty collection:

alert(document.body.querySelector(":scope"))          // null
alert(document.body.querySelectorAll(":scope"))  // empty NodeList

When I read the DOM I see very similar description for this method:

"The querySelectorAll(selectors) method must return the static result
of running evaluate a selectors string selectors against the context
object."
"The matches(selectors) method must return true if the context object
is in the result of running evaluate a selectors string selectors
against the context object, and false otherwise."

and I can't determine why this is happening when read this
description. They use the same algorithm and pass the same context
object (so "running evaluate a selectors string selectors against the
context object" should return the same list). But matches() select
scoping root (return true for :scope) and
querySelector/querySelectorAll not.

In DOM for algorithm "evaluate a selectors string selectors against a
node" step 3 we have:
3. Return the result of match a selector s against node's root using
scoping root node. [SELECTORS].

So scoping root is node (context object) and from Selectors Level 4:

scope-filtered selectors
    With this method of scoping, a selector matches if the subject of
the selector is within the scope, even if other components of the
selector are outside the scope. (A scoping element is considered to be
in scope.)  <<< last in parentheses is important.

Of course this happend for all selector, not only :scope pseud-class:

alert(document.body.mozMatchesSelector("body"))          // true
alert(document.body.querySelectorAll("body"))          // empty NodeList

So descriptions in new DOM for this methods is not precisely or I did
not understand them completely?
``` 

Now I see that at that time I make more description: "I see that SELECTORS was changed and DOM was upgrade, but still sth is missing. I have some problem to add topic in mailing list for Selector, so I will try write all to you, especially if I considering only some DOM methods...." << unfortunately this new text never send to you (still don't know why), but here I again tuch this "scope-filtered selectors" question.

Regardless of this, @tabatkins can you add to SELECTORS4 spec. some real small example showing difference beetwen scope-contained selectors and scope-filtered selectors because he terminology of this specification is difficult at first contact?



---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/263#issuecomment-223807634

Received on Sunday, 5 June 2016 11:21:06 UTC