mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Fix up the virtual method unsoundness.
This commit is contained in:
parent
895e9ee37f
commit
46a33b4b38
4 changed files with 26 additions and 24 deletions
|
@ -65,8 +65,8 @@ impl Attr {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_value(&mut self, set_type: AttrSettingType, value: DOMString) {
|
pub fn set_value(&mut self, set_type: AttrSettingType, value: DOMString) {
|
||||||
let owner = self.owner.root();
|
let mut owner = self.owner.root();
|
||||||
let node: &JSRef<Node> = NodeCast::from_ref(&*owner);
|
let node: &mut JSRef<Node> = NodeCast::from_mut_ref(&mut *owner);
|
||||||
let namespace_is_null = self.namespace == namespace::Null;
|
let namespace_is_null = self.namespace == namespace::Null;
|
||||||
|
|
||||||
match set_type {
|
match set_type {
|
||||||
|
|
|
@ -301,13 +301,14 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
||||||
None => (),
|
None => (),
|
||||||
Some(idx) => {
|
Some(idx) => {
|
||||||
{
|
{
|
||||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
let node: &mut JSRef<Node> = NodeCast::from_mut_ref(self);
|
||||||
node.wait_until_safe_to_modify_dom();
|
node.wait_until_safe_to_modify_dom();
|
||||||
}
|
}
|
||||||
|
|
||||||
if namespace == namespace::Null {
|
if namespace == namespace::Null {
|
||||||
let removed_raw_value = self.get().attrs.get(idx).root().Value();
|
let removed_raw_value = self.get().attrs.get(idx).root().Value();
|
||||||
vtable_for(NodeCast::from_ref(self)).before_remove_attr(local_name.clone(), removed_raw_value);
|
vtable_for(NodeCast::from_mut_ref(self))
|
||||||
|
.before_remove_attr(local_name.clone(), removed_raw_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.get_mut().attrs.remove(idx);
|
self.get_mut().attrs.remove(idx);
|
||||||
|
|
|
@ -244,24 +244,25 @@ impl<'a> PrivateNodeHelpers for JSRef<'a, Node> {
|
||||||
let document = document_from_node(self).root();
|
let document = document_from_node(self).root();
|
||||||
|
|
||||||
if self.is_in_doc() {
|
if self.is_in_doc() {
|
||||||
for node in self.traverse_preorder() {
|
for mut node in self.traverse_preorder() {
|
||||||
vtable_for(&node).bind_to_tree();
|
vtable_for(&mut node).bind_to_tree();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.parent_node().root().map(|parent| vtable_for(&*parent).child_inserted(self));
|
let mut parent = self.parent_node().root();
|
||||||
|
parent.as_mut().map(|parent| vtable_for(&mut **parent).child_inserted(self));
|
||||||
|
|
||||||
document.deref().content_changed();
|
document.deref().content_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://dom.spec.whatwg.org/#node-is-removed
|
// http://spec.whatwg.org/#node-is-removed
|
||||||
fn node_removed(&self) {
|
fn node_removed(&self) {
|
||||||
assert!(self.parent_node().is_none());
|
assert!(self.parent_node().is_none());
|
||||||
let document = document_from_node(self).root();
|
let document = document_from_node(self).root();
|
||||||
|
|
||||||
for node in self.traverse_preorder() {
|
for mut node in self.traverse_preorder() {
|
||||||
// XXX how about if the node wasn't in the tree in the first place?
|
// XXX how about if the node wasn't in the tree in the first place?
|
||||||
vtable_for(&node).unbind_from_tree();
|
vtable_for(&mut node).unbind_from_tree();
|
||||||
}
|
}
|
||||||
|
|
||||||
document.deref().content_changed();
|
document.deref().content_changed();
|
||||||
|
|
|
@ -74,34 +74,34 @@ pub trait VirtualMethods {
|
||||||
/// method call on the trait object will invoke the corresponding method on the
|
/// method call on the trait object will invoke the corresponding method on the
|
||||||
/// concrete type, propagating up the parent hierarchy unless otherwise
|
/// concrete type, propagating up the parent hierarchy unless otherwise
|
||||||
/// interrupted.
|
/// interrupted.
|
||||||
pub fn vtable_for<'a>(node: &JSRef<Node>) -> ~VirtualMethods: {
|
pub fn vtable_for<'a>(node: &'a mut JSRef<Node>) -> &'a mut VirtualMethods: {
|
||||||
match node.get().type_id {
|
match node.get().type_id {
|
||||||
ElementNodeTypeId(HTMLImageElementTypeId) => {
|
ElementNodeTypeId(HTMLImageElementTypeId) => {
|
||||||
let element: &JSRef<HTMLImageElement> = HTMLImageElementCast::to_ref(node).unwrap();
|
let element: &mut JSRef<HTMLImageElement> = HTMLImageElementCast::to_mut_ref(node).unwrap();
|
||||||
~element.clone() as ~VirtualMethods:
|
element as &mut VirtualMethods:
|
||||||
}
|
}
|
||||||
ElementNodeTypeId(HTMLIFrameElementTypeId) => {
|
ElementNodeTypeId(HTMLIFrameElementTypeId) => {
|
||||||
let element: &JSRef<HTMLIFrameElement> = HTMLIFrameElementCast::to_ref(node).unwrap();
|
let element: &mut JSRef<HTMLIFrameElement> = HTMLIFrameElementCast::to_mut_ref(node).unwrap();
|
||||||
~element.clone() as ~VirtualMethods:
|
element as &mut VirtualMethods:
|
||||||
}
|
}
|
||||||
ElementNodeTypeId(HTMLObjectElementTypeId) => {
|
ElementNodeTypeId(HTMLObjectElementTypeId) => {
|
||||||
let element: &JSRef<HTMLObjectElement> = HTMLObjectElementCast::to_ref(node).unwrap();
|
let element: &mut JSRef<HTMLObjectElement> = HTMLObjectElementCast::to_mut_ref(node).unwrap();
|
||||||
~element.clone() as ~VirtualMethods:
|
element as &mut VirtualMethods:
|
||||||
}
|
}
|
||||||
ElementNodeTypeId(HTMLStyleElementTypeId) => {
|
ElementNodeTypeId(HTMLStyleElementTypeId) => {
|
||||||
let element: &JSRef<HTMLStyleElement> = HTMLStyleElementCast::to_ref(node).unwrap();
|
let element: &mut JSRef<HTMLStyleElement> = HTMLStyleElementCast::to_mut_ref(node).unwrap();
|
||||||
~element.clone() as ~VirtualMethods:
|
element as &mut VirtualMethods:
|
||||||
}
|
}
|
||||||
ElementNodeTypeId(ElementTypeId) => {
|
ElementNodeTypeId(ElementTypeId) => {
|
||||||
let element: &JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
let element: &mut JSRef<Element> = ElementCast::to_mut_ref(node).unwrap();
|
||||||
~element.clone() as ~VirtualMethods:
|
element as &mut VirtualMethods:
|
||||||
}
|
}
|
||||||
ElementNodeTypeId(_) => {
|
ElementNodeTypeId(_) => {
|
||||||
let element: &JSRef<HTMLElement> = HTMLElementCast::to_ref(node).unwrap();
|
let element: &mut JSRef<HTMLElement> = HTMLElementCast::to_mut_ref(node).unwrap();
|
||||||
~element.clone() as ~VirtualMethods:
|
element as &mut VirtualMethods:
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
~node.clone() as ~VirtualMethods:
|
node as &mut VirtualMethods:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue