Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upDo not use borrowed types in the selectors::Element trait. #23463
Conversation
highfive
commented
May 26, 2019
|
Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @asajeffrey (or someone else) soon. |
highfive
commented
May 26, 2019
|
Heads up! This PR modifies the following files:
|
highfive
commented
May 26, 2019
| @@ -58,10 +58,21 @@ pub trait Element: Sized + Clone + Debug { | |||
|
|
|||
| fn is_html_element_in_html_document(&self) -> bool; | |||
|
|
|||
| fn local_name(&self) -> &<Self::Impl as SelectorImpl>::BorrowedLocalName; | |||
| fn local_name_hash(&self) -> u32; | |||
This comment has been minimized.
This comment has been minimized.
RazrFalcon
May 26, 2019
Author
Contributor
This is ugly. I know. We need three methods instead of one now...
This comment has been minimized.
This comment has been minimized.
emilio
May 26, 2019
Member
I think we don't need get_local_name or get_namespace, instead fn local_name and fn namespace should move to TElement (in components/style/dom.rs).
| @@ -226,7 +226,7 @@ impl SelectorMap<Rule> { | |||
| } | |||
| }); | |||
|
|
|||
| if let Some(rules) = self.local_name_hash.get(rule_hash_target.local_name()) { | |||
| if let Some(rules) = self.local_name_hash.get(&rule_hash_target.get_local_name()) { | |||
This comment has been minimized.
This comment has been minimized.
RazrFalcon
May 26, 2019
Author
Contributor
This method invokes clone() now. Which is bad. By I don't know how to fix it.
This comment has been minimized.
This comment has been minimized.
emilio
May 26, 2019
Member
This doesn't need to use selectors::Element. You can move the fn local_name signature to TElement. So selectors doesn't need get_local_name, and this shouldn't need to call clone().
|
Thanks for the patch! Needs some changes, I think it can be simpler. |
| @@ -226,7 +226,7 @@ impl SelectorMap<Rule> { | |||
| } | |||
| }); | |||
|
|
|||
| if let Some(rules) = self.local_name_hash.get(rule_hash_target.local_name()) { | |||
| if let Some(rules) = self.local_name_hash.get(&rule_hash_target.get_local_name()) { | |||
This comment has been minimized.
This comment has been minimized.
emilio
May 26, 2019
Member
This doesn't need to use selectors::Element. You can move the fn local_name signature to TElement. So selectors doesn't need get_local_name, and this shouldn't need to call clone().
| f(element.local_name().get_hash()); | ||
| f(element.namespace().get_hash()); | ||
| f(element.local_name_hash()); | ||
| f(element.namespace_hash()); |
This comment has been minimized.
This comment has been minimized.
emilio
May 26, 2019
Member
Same, this doesn't need to use selectors::Element, and selectors doesn't need Element::namespace_hash.
| @@ -58,10 +58,21 @@ pub trait Element: Sized + Clone + Debug { | |||
|
|
|||
| fn is_html_element_in_html_document(&self) -> bool; | |||
|
|
|||
| fn local_name(&self) -> &<Self::Impl as SelectorImpl>::BorrowedLocalName; | |||
| fn local_name_hash(&self) -> u32; | |||
This comment has been minimized.
This comment has been minimized.
emilio
May 26, 2019
Member
I think we don't need get_local_name or get_namespace, instead fn local_name and fn namespace should move to TElement (in components/style/dom.rs).
| @@ -90,8 +90,7 @@ impl Invalidation { | |||
| // This could look at the quirks mode of the document, instead | |||
| // of testing against both names, but it's probably not worth | |||
| // it. | |||
| let local_name = element.local_name(); | |||
| return *local_name == **name || *local_name == **lower_name; | |||
| return element.has_local_name(name) || element.has_local_name(lower_name); | |||
This comment has been minimized.
This comment has been minimized.
| @@ -42,7 +42,7 @@ pub fn containing_shadow_ignoring_svg_use<E: TElement>( | |||
| loop { | |||
| let host = shadow.host(); | |||
| let host_is_svg_use_element = | |||
| host.is_svg_element() && host.local_name() == &*local_name!("use"); | |||
| host.is_svg_element() && host.has_local_name(&local_name!("use")); | |||
This comment has been minimized.
This comment has been minimized.
|
|
||
| if target.namespace() != candidate.element.namespace() { | ||
| trace!("Miss: Namespace"); | ||
| if !target.is_same_type(&candidate.element) { |
This comment has been minimized.
This comment has been minimized.
emilio
May 26, 2019
Member
This doesn't need to change either, and I'd prefer to keep the two checks to remain separate to see why it fails.
| &self, | ||
| local_name: &<Self::Impl as ::selectors::SelectorImpl>::BorrowedLocalName, | ||
| ) -> bool { | ||
| self.element.has_local_name(local_name) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| @@ -877,6 +877,12 @@ pub trait TElement: | |||
| hints: &mut V, | |||
| ) where | |||
| V: Push<ApplicableDeclarationBlock>; | |||
|
|
|||
| /// Returns element's local name. | |||
| fn local_name(&self) -> &LocalName; | |||
This comment has been minimized.
This comment has been minimized.
emilio
May 26, 2019
Member
This still needs to use the Borrowed* gunk, so that you don't break Firefox.
Also this actually needs to be implemented, right?
This comment has been minimized.
This comment has been minimized.
RazrFalcon
May 26, 2019
Author
Contributor
Not sure what exact type should be used?
Yes. It's used in the code.
|
Finally, I was able to build it locally without any errors. |
|
@emilio ? |
|
Thanks. No problem. |
|
I'm cherry-picking this in the next sync |
|
#23503 includes this commit along with the Firefox changes needed. Thanks a lot for the patch @RazrFalcon! |
…it. r=emilio This cherry-picks servo/servo#23463 with a few fixes for the Gecko build.
Closes servo#22972 Closes servo#23463
…it. r=emilio This cherry-picks servo/servo#23463 with a few fixes for the Gecko build.
style: sync changes from mozilla-central See each individual commit for details. This also cherry-picks #23463 with a few fixes that were needed in Gecko-only code. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23503) <!-- Reviewable:end -->
style: sync changes from mozilla-central See each individual commit for details. This also cherry-picks #23463 with a few fixes that were needed in Gecko-only code. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23503) <!-- Reviewable:end -->
…it. r=emilio This cherry-picks servo/servo#23463 with a few fixes for the Gecko build. UltraBlame original commit: 53a5f4a6e1de21b62be288cac96763aeece78277
…it. r=emilio This cherry-picks servo/servo#23463 with a few fixes for the Gecko build. UltraBlame original commit: 53a5f4a6e1de21b62be288cac96763aeece78277
…it. r=emilio This cherry-picks servo/servo#23463 with a few fixes for the Gecko build. UltraBlame original commit: 53a5f4a6e1de21b62be288cac96763aeece78277
RazrFalcon commentedMay 26, 2019
•
edited
This change allows implementing the
selectors::Elementtrait for types that doesn't support borrowed types, like rc-tree../mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is