mirror of
https://github.com/servo/servo.git
synced 2025-06-21 15:49:04 +01:00
Make CharacterData store a ~str rather than a DOMString, because its data can never be null.
This commit is contained in:
parent
9073329737
commit
efff6be86c
2 changed files with 16 additions and 15 deletions
|
@ -111,6 +111,14 @@ impl DOMString {
|
|||
null_string => &'a "",
|
||||
}
|
||||
}
|
||||
|
||||
// XXX This is temporary until issue #875 is fixed.
|
||||
pub fn unwrap(&self) -> ~str {
|
||||
match self {
|
||||
&str(ref s) => s.clone(),
|
||||
&null_string => fail!("Cannot unwrap a null string.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct rust_box<T> {
|
||||
|
|
|
@ -4,49 +4,42 @@
|
|||
|
||||
//! DOM bindings for `CharacterData`.
|
||||
|
||||
use dom::bindings::utils::{DOMString, null_string, str, ErrorResult};
|
||||
use dom::bindings::utils::{DOMString, str, ErrorResult};
|
||||
use dom::bindings::utils::{BindingObject, CacheableWrapper, WrapperCache};
|
||||
use dom::node::{Node, NodeTypeId, ScriptView};
|
||||
use js::jsapi::{JSObject, JSContext};
|
||||
|
||||
pub struct CharacterData {
|
||||
parent: Node<ScriptView>,
|
||||
data: DOMString
|
||||
data: ~str
|
||||
}
|
||||
|
||||
impl CharacterData {
|
||||
pub fn new(id: NodeTypeId, data: ~str) -> CharacterData {
|
||||
CharacterData {
|
||||
parent: Node::new(id),
|
||||
data: str(data)
|
||||
data: data
|
||||
}
|
||||
}
|
||||
|
||||
pub fn Data(&self) -> DOMString {
|
||||
self.data.clone()
|
||||
str(self.data.clone())
|
||||
}
|
||||
|
||||
pub fn SetData(&mut self, arg: &DOMString, _rv: &mut ErrorResult) {
|
||||
self.data = (*arg).clone();
|
||||
self.data = arg.unwrap();
|
||||
}
|
||||
|
||||
pub fn Length(&self) -> u32 {
|
||||
match self.data {
|
||||
str(ref s) => s.len() as u32,
|
||||
null_string => 0
|
||||
}
|
||||
self.data.len() as u32
|
||||
}
|
||||
|
||||
pub fn SubstringData(&self, offset: u32, count: u32, _rv: &mut ErrorResult) -> DOMString {
|
||||
match self.data {
|
||||
str(ref s) => str(s.slice(offset as uint, count as uint).to_str()),
|
||||
null_string => null_string
|
||||
}
|
||||
str(self.data.slice(offset as uint, count as uint).to_str())
|
||||
}
|
||||
|
||||
pub fn AppendData(&mut self, arg: &DOMString, _rv: &mut ErrorResult) {
|
||||
let s = self.data.to_str();
|
||||
self.data = str(s.append(arg.to_str()));
|
||||
self.data.push_str(arg.unwrap());
|
||||
}
|
||||
|
||||
pub fn InsertData(&mut self, _offset: u32, _arg: &DOMString, _rv: &mut ErrorResult) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue