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/documentfragment.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/documentfragment.rs')
-rw-r--r-- | src/components/script/dom/documentfragment.rs | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/src/components/script/dom/documentfragment.rs b/src/components/script/dom/documentfragment.rs index 7346a5a98ef..25f2c3c1d69 100644 --- a/src/components/script/dom/documentfragment.rs +++ b/src/components/script/dom/documentfragment.rs @@ -4,13 +4,13 @@ use dom::bindings::codegen::InheritTypes::{DocumentFragmentDerived, NodeCast}; use dom::bindings::codegen::BindingDeclarations::DocumentFragmentBinding; -use dom::bindings::js::JS; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::Fallible; use dom::document::Document; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::htmlcollection::HTMLCollection; -use dom::node::{DocumentFragmentNodeTypeId, Node}; -use dom::window::Window; +use dom::node::{DocumentFragmentNodeTypeId, Node, window_from_node}; +use dom::window::{Window, WindowMethods}; #[deriving(Encodable)] pub struct DocumentFragment { @@ -28,28 +28,32 @@ impl DocumentFragmentDerived for EventTarget { impl DocumentFragment { /// Creates a new DocumentFragment. - pub fn new_inherited(document: JS<Document>) -> DocumentFragment { + pub fn new_inherited(document: &JSRef<Document>) -> DocumentFragment { DocumentFragment { node: Node::new_inherited(DocumentFragmentNodeTypeId, document), } } - pub fn new(document: &JS<Document>) -> JS<DocumentFragment> { - let node = DocumentFragment::new_inherited(document.clone()); + pub fn new(document: &JSRef<Document>) -> Temporary<DocumentFragment> { + let node = DocumentFragment::new_inherited(document); Node::reflect_node(~node, document, DocumentFragmentBinding::Wrap) } -} -impl DocumentFragment { - pub fn Constructor(owner: &JS<Window>) -> Fallible<JS<DocumentFragment>> { - Ok(DocumentFragment::new(&owner.get().Document())) + pub fn Constructor(owner: &JSRef<Window>) -> Fallible<Temporary<DocumentFragment>> { + let document = owner.Document(); + let document = document.root(); + + Ok(DocumentFragment::new(&document.root_ref())) } } -impl DocumentFragment { - pub fn Children(&self, abstract_self: &JS<DocumentFragment>) -> JS<HTMLCollection> { - let doc = self.node.owner_doc(); - let doc = doc.get(); - HTMLCollection::children(&doc.window, &NodeCast::from(abstract_self)) +pub trait DocumentFragmentMethods { + fn Children(&self) -> Temporary<HTMLCollection>; +} + +impl<'a> DocumentFragmentMethods for JSRef<'a, DocumentFragment> { + fn Children(&self) -> Temporary<HTMLCollection> { + let window = window_from_node(self).root(); + HTMLCollection::children(&window.root_ref(), NodeCast::from_ref(self)) } } |