Commit 68a2004c authored by kochi@chromium.org's avatar kochi@chromium.org

Revert of document.querySelector[All]() should check selector context...

Revert of document.querySelector[All]() should check selector context (patchset #6 id:100001 of https://codereview.chromium.org/1245933002/ )

Reason for revert:
This seems to have caused a significant perf
regression.  Reverting.

BUG=526742

Original issue's description:
> document.querySelector[All]() should check selector context
> 
> Blink failed to check whether the left-most matched selector ends up
> in Document TreeScope.
> The check was only enabled for querySelector*() is called on
> a regular element, not on document.
> 
> This issue can be exposed by passing "::shadow" or "/deep/"
> which pierces shadow boundary and the selector can
> incorrectly match inside shadow.
> 
> BUG=511486
> TEST=fast/dom/shadow/querySelector-with-shadow-all-and-shadow-deep.html
> 
> Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=201461

TBR=esprehn@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=511486

Review URL: https://codereview.chromium.org/1329523002

git-svn-id: svn://svn.chromium.org/blink/trunk@201514 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 2ac08266
...@@ -50,10 +50,6 @@ PASS fooHost.querySelectorAll("::shadow span").length is 3 ...@@ -50,10 +50,6 @@ PASS fooHost.querySelectorAll("::shadow span").length is 3
PASS fooHost.querySelectorAll("::shadow span")[0].id is "not-top" PASS fooHost.querySelectorAll("::shadow span")[0].id is "not-top"
PASS fooHost.querySelectorAll("::shadow span")[1].id is "top" PASS fooHost.querySelectorAll("::shadow span")[1].id is "top"
PASS fooHost.querySelectorAll("::shadow span")[2].id is "inner-host" PASS fooHost.querySelectorAll("::shadow span")[2].id is "inner-host"
PASS document.querySelectorAll("::shadow span").length is 3
PASS document.querySelectorAll("::shadow span")[0].id is "not-top"
PASS document.querySelectorAll("::shadow span")[1].id is "top"
PASS document.querySelectorAll("::shadow span")[2].id is "inner-host"
PASS successfullyParsed is true PASS successfullyParsed is true
TEST COMPLETE TEST COMPLETE
......
...@@ -82,10 +82,4 @@ shouldBe('fooHost.querySelectorAll("::shadow span").length', '3'); ...@@ -82,10 +82,4 @@ shouldBe('fooHost.querySelectorAll("::shadow span").length', '3');
shouldBe('fooHost.querySelectorAll("::shadow span")[0].id', '"not-top"'); shouldBe('fooHost.querySelectorAll("::shadow span")[0].id', '"not-top"');
shouldBe('fooHost.querySelectorAll("::shadow span")[1].id', '"top"'); shouldBe('fooHost.querySelectorAll("::shadow span")[1].id', '"top"');
shouldBe('fooHost.querySelectorAll("::shadow span")[2].id', '"inner-host"'); shouldBe('fooHost.querySelectorAll("::shadow span")[2].id', '"inner-host"');
// crbug.com/511486
shouldBe('document.querySelectorAll("::shadow span").length', '3');
shouldBe('document.querySelectorAll("::shadow span")[0].id', '"not-top"');
shouldBe('document.querySelectorAll("::shadow span")[1].id', '"top"');
shouldBe('document.querySelectorAll("::shadow span")[2].id', '"inner-host"');
</script> </script>
...@@ -960,9 +960,9 @@ bool SelectorChecker::checkPseudoClass(const SelectorCheckingContext& context, M ...@@ -960,9 +960,9 @@ bool SelectorChecker::checkPseudoClass(const SelectorCheckingContext& context, M
case CSSSelector::PseudoScope: case CSSSelector::PseudoScope:
if (m_mode == SharingRules) if (m_mode == SharingRules)
return true; return true;
if (context.scope == element.document()) if (context.scope)
return element == element.document().documentElement(); return context.scope == element;
return context.scope == element; return element == element.document().documentElement();
case CSSSelector::PseudoUnresolved: case CSSSelector::PseudoUnresolved:
return element.isUnresolvedCustomElement(); return element.isUnresolvedCustomElement();
case CSSSelector::PseudoHost: case CSSSelector::PseudoHost:
...@@ -1050,6 +1050,8 @@ bool SelectorChecker::checkPseudoHost(const SelectorCheckingContext& context, Ma ...@@ -1050,6 +1050,8 @@ bool SelectorChecker::checkPseudoHost(const SelectorCheckingContext& context, Ma
if (m_mode == SharingRules) if (m_mode == SharingRules)
return true; return true;
// :host only matches a shadow host when :host is in a shadow tree of the shadow host. // :host only matches a shadow host when :host is in a shadow tree of the shadow host.
if (!context.scope)
return false;
const ContainerNode* shadowHost = context.scope->shadowHost(); const ContainerNode* shadowHost = context.scope->shadowHost();
if (!shadowHost || shadowHost != element) if (!shadowHost || shadowHost != element)
return false; return false;
......
...@@ -122,8 +122,9 @@ inline bool SelectorDataList::selectorMatches(const CSSSelector& selector, Eleme ...@@ -122,8 +122,9 @@ inline bool SelectorDataList::selectorMatches(const CSSSelector& selector, Eleme
SelectorChecker selectorChecker(SelectorChecker::QueryingRules); SelectorChecker selectorChecker(SelectorChecker::QueryingRules);
SelectorChecker::SelectorCheckingContext selectorCheckingContext(&element, SelectorChecker::VisitedMatchDisabled); SelectorChecker::SelectorCheckingContext selectorCheckingContext(&element, SelectorChecker::VisitedMatchDisabled);
selectorCheckingContext.selector = &selector; selectorCheckingContext.selector = &selector;
selectorCheckingContext.scope = &rootNode; selectorCheckingContext.scope = !rootNode.isDocumentNode() ? &rootNode : nullptr;
selectorCheckingContext.scopeContainsLastMatchedElement = true; if (selectorCheckingContext.scope)
selectorCheckingContext.scopeContainsLastMatchedElement = true;
return selectorChecker.match(selectorCheckingContext); return selectorChecker.match(selectorCheckingContext);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment