aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/attr.rs
diff options
context:
space:
mode:
authorbors-servo <release+servo@mozilla.com>2014-05-03 14:25:22 -0400
committerbors-servo <release+servo@mozilla.com>2014-05-03 14:25:22 -0400
commit731e66ff132e41cdc49bc5324c0e15be19c46ec2 (patch)
treeccce9b42e8a6c54245e53620082efe0b9840eae1 /src/components/script/dom/attr.rs
parent4051a8096d7ba7e7f9c86e76d0b4bffd83e85805 (diff)
parent91278da9dd55582401154e07f9eea34425a332c2 (diff)
downloadservo-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/attr.rs')
-rw-r--r--src/components/script/dom/attr.rs40
1 files changed, 25 insertions, 15 deletions
diff --git a/src/components/script/dom/attr.rs b/src/components/script/dom/attr.rs
index 0ca2fb2889e..4822de7eb07 100644
--- a/src/components/script/dom/attr.rs
+++ b/src/components/script/dom/attr.rs
@@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::AttrBinding;
use dom::bindings::codegen::InheritTypes::NodeCast;
-use dom::bindings::js::JS;
+use dom::bindings::js::{JS, JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::element::Element;
use dom::node::Node;
@@ -45,7 +45,7 @@ impl Reflectable for Attr {
impl Attr {
fn new_inherited(local_name: DOMString, value: DOMString,
name: DOMString, namespace: Namespace,
- prefix: Option<DOMString>, owner: JS<Element>) -> Attr {
+ prefix: Option<DOMString>, owner: &JSRef<Element>) -> Attr {
Attr {
reflector_: Reflector::new(),
local_name: local_name,
@@ -53,25 +53,26 @@ impl Attr {
name: name, //TODO: Intern attribute names
namespace: namespace,
prefix: prefix,
- owner: owner,
+ owner: owner.unrooted(),
}
}
- pub fn new(window: &JS<Window>, local_name: DOMString, value: DOMString,
+ pub fn new(window: &JSRef<Window>, local_name: DOMString, value: DOMString,
name: DOMString, namespace: Namespace,
- prefix: Option<DOMString>, owner: JS<Element>) -> JS<Attr> {
+ prefix: Option<DOMString>, owner: &JSRef<Element>) -> Temporary<Attr> {
let attr = Attr::new_inherited(local_name, value, name, namespace, prefix, owner);
reflect_dom_object(~attr, window, AttrBinding::Wrap)
}
pub fn set_value(&mut self, set_type: AttrSettingType, value: DOMString) {
- let node: JS<Node> = NodeCast::from(&self.owner);
+ let mut owner = self.owner.root();
+ let node: &mut JSRef<Node> = NodeCast::from_mut_ref(&mut *owner);
let namespace_is_null = self.namespace == namespace::Null;
match set_type {
ReplacedAttr => {
if namespace_is_null {
- vtable_for(&node).before_remove_attr(self.local_name.clone(), self.value.clone());
+ vtable_for(node).before_remove_attr(self.local_name.clone(), self.value.clone());
}
}
FirstSetAttr => {}
@@ -80,7 +81,7 @@ impl Attr {
self.value = value;
if namespace_is_null {
- vtable_for(&node).after_set_attr(self.local_name.clone(), self.value.clone());
+ vtable_for(node).after_set_attr(self.local_name.clone(), self.value.clone());
}
}
@@ -89,31 +90,40 @@ impl Attr {
}
}
-impl Attr {
- pub fn LocalName(&self) -> DOMString {
+pub trait AttrMethods {
+ fn LocalName(&self) -> DOMString;
+ fn Value(&self) -> DOMString;
+ fn SetValue(&mut self, value: DOMString);
+ fn Name(&self) -> DOMString;
+ fn GetNamespaceURI(&self) -> Option<DOMString>;
+ fn GetPrefix(&self) -> Option<DOMString>;
+}
+
+impl<'a> AttrMethods for JSRef<'a, Attr> {
+ fn LocalName(&self) -> DOMString {
self.local_name.clone()
}
- pub fn Value(&self) -> DOMString {
+ fn Value(&self) -> DOMString {
self.value.clone()
}
- pub fn SetValue(&mut self, value: DOMString) {
+ fn SetValue(&mut self, value: DOMString) {
self.set_value(ReplacedAttr, value);
}
- pub fn Name(&self) -> DOMString {
+ fn Name(&self) -> DOMString {
self.name.clone()
}
- pub fn GetNamespaceURI(&self) -> Option<DOMString> {
+ fn GetNamespaceURI(&self) -> Option<DOMString> {
match self.namespace.to_str() {
"" => None,
url => Some(url.to_owned()),
}
}
- pub fn GetPrefix(&self) -> Option<DOMString> {
+ fn GetPrefix(&self) -> Option<DOMString> {
self.prefix.clone()
}
}