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 upIntroduce VirtualMethods::attribute_mutated() #7452
Conversation
|
Amended because of #7412. |
|
I'm not keen on the debug_assert changes since we only run tests in release mode right now. |
|
@jdm Will remove commit. |
|
I like this refactoring. I'd also like to get @Ms2ger's opinion. |
|
Will try to finish reviewing today. |
|
I hope it won't be too much trouble to match my comments and the code; I reviewed most of it on a train. pub fn get_attribute(&self, namespace: &Namespace, local_name: &Atom) -> Option<Root<Attr>> {
let mut attributes = RootedVec::new();
self.get_attributes(local_name, &mut attributes);
- attributes.r().iter()
+ attributes.r().
+ iter()Not an improvement. (Fixed in another commit? Please fix that.) + };
+ // https://github.com/rust-lang/rust/issues/21114
+ is_jsUgh. + self.attrs.borrow().iter().map(|attr| attr.root())Can we create a method that returns that iterator? + attr.namespace() == namespace && attr.local_name() == local_nameThe local_name check is much more likely to fail, so check it first.
I think you mean "e.g." ("for example") rather than "i.e." ("that is"). + pub fn uint(&self) -> Option<u32> {With the helper traits gone, it's no longer a pain to document these. + mem::swap(&mut *self.value.borrow_mut(), &mut value);Feels more like a - self.do_set_attribute(qname.local, value, name, qname.ns, prefix, |_| false)
+ let in_empty_ns = qname.ns == ns!("");
+ let attr = Attr::new(&window, qname.local, value, name, qname.ns, prefix, Some(self));
+ self.attrs.borrow_mut().push(JS::from_rooted(&attr));I kinda liked having a single place where we pushed into - pub fn do_set_attribute<F>(&self,
+ fn set_first_matching_attribute<F>(&self,Reviewing tends to be easier if you split renames into their own commit. + find: F)
+ where F: Fn(&Attr)
+ -> bool { find: F)
where F: Fn(&Attr) -> bool
{Your formatting is extremely confusing. I thought you'd managed to stick a + if let Some(attr) = attr {
+ attr.set_value(value, self);
+ } else {Seems like a case for let attr = (*self.attrs.borrow())[idx].root();
- if attr.r().namespace() == &ns!("") {
- vtable_for(&NodeCast::from_ref(self)).before_remove_attr(attr.r());
- }
-
self.attrs.borrow_mut().remove(idx);let attr = self.attrs.borrow_mut().remove(idx);- &atom!("style") => {
+ &atom!(style) => {Did that really need to pollute this commit? + static FORWARDED_EVENTS: &'static [&'static str] =
+ &["onfocus", "onload", "onscroll", "onafterprint", "onbeforeprint",Followup: this should use atoms. (And I already found two other pre-existing bugs in this code, yay!) + if *attr.local_name() == atom!(disabled) {
+ let node = NodeCast::from_ref(self);
+ match mutation {
+ AttributeMutation::Set(Some(_)) => {}I guess this is correct, but now I want a test for this case. + let children = node.children().filter(|node| {
+ if found_legend {
+ true
+ } else if node.is_htmllegendelement() {
+ found_legend = true;I tend to prefer using those methods only with pure closures, but I guess this is fine. - _ => ()
+ _ => {},I prefer + if attr.local_name() == &atom!(data) && mutation != AttributeMutation::Removed {
+ self.process_data_url();
}Please keep the + if attr.local_name() == &atom!(disabled) {
+ let options = NodeCast::from_ref(self).children().filter(|child| {
+ child.is_htmloptionelement()
+ });Ditto. Also elsewhere. Why pass the |
There are no other examples of such a use, but I will reword it. |
I find |
|
Review status: 0 of 31 files reviewed at latest revision, 18 unresolved discussions, all commit checks successful. components/script/dom/attr.rs, line 92 [r4] (raw file):
Will do. components/script/dom/element.rs, line 829 [r3] (raw file):
Will make a private one. components/script/dom/element.rs, line 830 [r3] (raw file):
Will do. components/script/dom/element.rs, line 833 [r2] (raw file):
This is not in one of my commits. components/script/dom/element.rs, line 912 [r4] (raw file):
I guess I could make a push_new_attr() method that calls Attr::new(), pushes it and handles the virtual method. components/script/dom/element.rs, line 1457 [r4] (raw file):
This is quite the nit, I didn't even expected those would be on the same indent level, and most lines around it changed anyway. Do I really need to address this? components/script/dom/htmlbodyelement.rs, line 141 [r4] (raw file):
Will file. components/script/dom/htmlbuttonelement.rs, line 143 [r4] (raw file):
Will write one. components/script/dom/htmlfieldsetelement.rs, line 93 [r4] (raw file): components/script/dom/htmlfieldsetelement.rs, line 109 [r4] (raw file):
components/script/dom/htmlfontelement.rs, line 65 [r4] (raw file): components/script/dom/htmliframeelement.rs, line 384 [r4] (raw file):
components/script/dom/htmlimageelement.rs, line 305 [r4] (raw file): components/script/dom/htmlobjectelement.rs, line 106 [r4] (raw file):
Will do. components/script/dom/htmloptionelement.rs, line 136 [r4] (raw file): components/script/dom/htmlscriptelement.rs, line 537 [r4] (raw file): components/script/dom/htmltablerowelement.rs, line 67 [r4] (raw file): components/script/dom/htmltablesectionelement.rs, line 66 [r4] (raw file): Comments from the review on Reviewable.io |
Introduce VirtualMethods::attribute_mutated() <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7452) <!-- Reviewable:end -->
|
|
|
|
Failed rebase, probably, I had ran these tests before. :( Will look at. |
This replaces before_remove_attr(), after_remove_attr() and after_set_attr(). The virtual method takes the mutated attribute and an AttributeMutation value to disambiguate between "attribute is changed", "attribute is added" and "attribute is removed". In the case of "attribute is changed", the mutation value contains a reference to the old value of the mutated attribute, which is used to unregister outdated named elements when the "id" attribute is changed on an element. This greatly simplifies the handling of attributes, which in many cases don't have any specific behaviour whether they are removed or changed or added. It also fixes a few bugs where things were put in before_remove_attr() instead of after_remove_attr() (e.g. when removing an href attribute from a base element). A few helper functions in Element were also renamed and made private.
|
I had broken HTMLOptGroup. I added a line in the associated test to better improve it. |
|
@bors-servo r+ r=jdm r=Ms2ger |
|
|
|
|
|
|
Introduce VirtualMethods::attribute_mutated() <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7452) <!-- Reviewable:end -->
|
|
nox commentedAug 30, 2015