diff options
author | bors-servo <release+servo@mozilla.com> | 2014-05-03 14:25:22 -0400 |
---|---|---|
committer | bors-servo <release+servo@mozilla.com> | 2014-05-03 14:25:22 -0400 |
commit | 731e66ff132e41cdc49bc5324c0e15be19c46ec2 (patch) | |
tree | ccce9b42e8a6c54245e53620082efe0b9840eae1 /src/components/script/dom/virtualmethods.rs | |
parent | 4051a8096d7ba7e7f9c86e76d0b4bffd83e85805 (diff) | |
parent | 91278da9dd55582401154e07f9eea34425a332c2 (diff) | |
download | servo-731e66ff132e41cdc49bc5324c0e15be19c46ec2.tar.gz servo-731e66ff132e41cdc49bc5324c0e15be19c46ec2.zip |
auto merge of #2101 : jdm/servo/newroot_rebase, r=Ms2ger
As described in #1764, this strategy uses the following properties:
* DOM members are `JS<T>` types. These cannot be used with being explicitly rooted, but they are required for compiler-derived trace hooks.
* Methods that take DOM type arguments receive `&[mut] JSRef<T>`. These are rooted value references that are cloneable but cannot escape.
* Methods that return DOM values use `Unrooted<T>`. These are values that may or may not be rooted elsewhere, but callers must root them in order to interact with them in any way. One unsoundness hole exists - `Unrooted` values must be rooted ASAP, or there exists the danger that JSAPI calls could be made that could cause the underlying JS value to be GCed.
* All methods are implemented on `JSRef<T>`, enforcing the requirement that all DOM values are rooted for the duration of a method call (with a few exceptions for layout-related code, which cannot root values and therefore interacts with `JS<T>` and `&T` values - this is safe under the assumption that layout code interacts with DOM nodes that are in the tree, therefore rooted, and does not run concurrently with content code)
Diffstat (limited to 'src/components/script/dom/virtualmethods.rs')
-rw-r--r-- | src/components/script/dom/virtualmethods.rs | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/src/components/script/dom/virtualmethods.rs b/src/components/script/dom/virtualmethods.rs index 85ae37cb032..2b0d9aabfe5 100644 --- a/src/components/script/dom/virtualmethods.rs +++ b/src/components/script/dom/virtualmethods.rs @@ -8,7 +8,7 @@ use dom::bindings::codegen::InheritTypes::HTMLIFrameElementCast; use dom::bindings::codegen::InheritTypes::HTMLImageElementCast; use dom::bindings::codegen::InheritTypes::HTMLObjectElementCast; use dom::bindings::codegen::InheritTypes::HTMLStyleElementCast; -use dom::bindings::js::JS; +use dom::bindings::js::JSRef; use dom::element::Element; use dom::element::{ElementTypeId, HTMLImageElementTypeId}; use dom::element::{HTMLIFrameElementTypeId, HTMLObjectElementTypeId, HTMLStyleElementTypeId}; @@ -17,7 +17,7 @@ use dom::htmliframeelement::HTMLIFrameElement; use dom::htmlimageelement::HTMLImageElement; use dom::htmlobjectelement::HTMLObjectElement; use dom::htmlstyleelement::HTMLStyleElement; -use dom::node::{Node, ElementNodeTypeId}; +use dom::node::{Node, NodeHelpers, ElementNodeTypeId}; use servo_util::str::DOMString; /// Trait to allow DOM nodes to opt-in to overriding (or adding to) common @@ -25,7 +25,7 @@ use servo_util::str::DOMString; pub trait VirtualMethods { /// Returns self as the superclass of the implementation for this trait, /// if any. - fn super_type(&self) -> Option<~VirtualMethods:>; + fn super_type<'a>(&'a mut self) -> Option<&'a mut VirtualMethods:>; /// Called when changing or adding attributes, after the attribute's value /// has been updated. @@ -62,7 +62,7 @@ pub trait VirtualMethods { } /// Called on the parent when a node is added to its child list. - fn child_inserted(&mut self, child: &JS<Node>) { + fn child_inserted(&mut self, child: &JSRef<Node>) { match self.super_type() { Some(ref mut s) => s.child_inserted(child), _ => (), @@ -74,34 +74,34 @@ pub trait VirtualMethods { /// method call on the trait object will invoke the corresponding method on the /// concrete type, propagating up the parent hierarchy unless otherwise /// interrupted. -pub fn vtable_for<'a>(node: &JS<Node>) -> ~VirtualMethods: { - match node.get().type_id { +pub fn vtable_for<'a>(node: &'a mut JSRef<Node>) -> &'a mut VirtualMethods: { + match node.type_id() { ElementNodeTypeId(HTMLImageElementTypeId) => { - let element: JS<HTMLImageElement> = HTMLImageElementCast::to(node).unwrap(); - ~element as ~VirtualMethods: + let element: &mut JSRef<HTMLImageElement> = HTMLImageElementCast::to_mut_ref(node).unwrap(); + element as &mut VirtualMethods: } ElementNodeTypeId(HTMLIFrameElementTypeId) => { - let element: JS<HTMLIFrameElement> = HTMLIFrameElementCast::to(node).unwrap(); - ~element as ~VirtualMethods: + let element: &mut JSRef<HTMLIFrameElement> = HTMLIFrameElementCast::to_mut_ref(node).unwrap(); + element as &mut VirtualMethods: } ElementNodeTypeId(HTMLObjectElementTypeId) => { - let element: JS<HTMLObjectElement> = HTMLObjectElementCast::to(node).unwrap(); - ~element as ~VirtualMethods: + let element: &mut JSRef<HTMLObjectElement> = HTMLObjectElementCast::to_mut_ref(node).unwrap(); + element as &mut VirtualMethods: } ElementNodeTypeId(HTMLStyleElementTypeId) => { - let element: JS<HTMLStyleElement> = HTMLStyleElementCast::to(node).unwrap(); - ~element as ~VirtualMethods: + let element: &mut JSRef<HTMLStyleElement> = HTMLStyleElementCast::to_mut_ref(node).unwrap(); + element as &mut VirtualMethods: } ElementNodeTypeId(ElementTypeId) => { - let element: JS<Element> = ElementCast::to(node).unwrap(); - ~element as ~VirtualMethods: + let element: &mut JSRef<Element> = ElementCast::to_mut_ref(node).unwrap(); + element as &mut VirtualMethods: } ElementNodeTypeId(_) => { - let element: JS<HTMLElement> = HTMLElementCast::to(node).unwrap(); - ~element as ~VirtualMethods: + let element: &mut JSRef<HTMLElement> = HTMLElementCast::to_mut_ref(node).unwrap(); + element as &mut VirtualMethods: } _ => { - ~node.clone() as ~VirtualMethods: + node as &mut VirtualMethods: } } } |