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/characterdata.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/characterdata.rs')
-rw-r--r-- | src/components/script/dom/characterdata.rs | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/src/components/script/dom/characterdata.rs b/src/components/script/dom/characterdata.rs index f85246ee12c..2a41e1fee3b 100644 --- a/src/components/script/dom/characterdata.rs +++ b/src/components/script/dom/characterdata.rs @@ -5,7 +5,7 @@ //! DOM bindings for `CharacterData`. use dom::bindings::codegen::InheritTypes::CharacterDataDerived; -use dom::bindings::js::JS; +use dom::bindings::js::JSRef; use dom::bindings::error::{Fallible, ErrorResult, IndexSize}; use dom::bindings::utils::{Reflectable, Reflector}; use dom::document::Document; @@ -31,44 +31,57 @@ impl CharacterDataDerived for EventTarget { } impl CharacterData { - pub fn new_inherited(id: NodeTypeId, data: DOMString, document: JS<Document>) -> CharacterData { + pub fn new_inherited(id: NodeTypeId, data: DOMString, document: &JSRef<Document>) -> CharacterData { CharacterData { node: Node::new_inherited(id, document), data: data } } +} + +pub trait CharacterDataMethods { + fn Data(&self) -> DOMString; + fn SetData(&mut self, arg: DOMString) -> ErrorResult; + fn Length(&self) -> u32; + fn SubstringData(&self, offset: u32, count: u32) -> Fallible<DOMString>; + fn AppendData(&mut self, arg: DOMString) -> ErrorResult; + fn InsertData(&mut self, _offset: u32, _arg: DOMString) -> ErrorResult; + fn DeleteData(&mut self, _offset: u32, _count: u32) -> ErrorResult; + fn ReplaceData(&mut self, _offset: u32, _count: u32, _arg: DOMString) -> ErrorResult; +} - pub fn Data(&self) -> DOMString { +impl<'a> CharacterDataMethods for JSRef<'a, CharacterData> { + fn Data(&self) -> DOMString { self.data.clone() } - pub fn SetData(&mut self, arg: DOMString) -> ErrorResult { + fn SetData(&mut self, arg: DOMString) -> ErrorResult { self.data = arg; Ok(()) } - pub fn Length(&self) -> u32 { + fn Length(&self) -> u32 { self.data.len() as u32 } - pub fn SubstringData(&self, offset: u32, count: u32) -> Fallible<DOMString> { + fn SubstringData(&self, offset: u32, count: u32) -> Fallible<DOMString> { Ok(self.data.slice(offset as uint, count as uint).to_str()) } - pub fn AppendData(&mut self, arg: DOMString) -> ErrorResult { + fn AppendData(&mut self, arg: DOMString) -> ErrorResult { self.data.push_str(arg); Ok(()) } - pub fn InsertData(&mut self, offset: u32, arg: DOMString) -> ErrorResult { + fn InsertData(&mut self, offset: u32, arg: DOMString) -> ErrorResult { self.ReplaceData(offset, 0, arg) } - pub fn DeleteData(&mut self, offset: u32, count: u32) -> ErrorResult { + fn DeleteData(&mut self, offset: u32, count: u32) -> ErrorResult { self.ReplaceData(offset, count, ~"") } - pub fn ReplaceData(&mut self, offset: u32, count: u32, arg: DOMString) -> ErrorResult { + fn ReplaceData(&mut self, offset: u32, count: u32, arg: DOMString) -> ErrorResult { let length = self.data.len() as u32; if offset > length { return Err(IndexSize); |