diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/components/main/layout/wrapper.rs | 6 | ||||
-rw-r--r-- | src/components/script/dom/characterdata.rs | 47 | ||||
-rw-r--r-- | src/components/script/dom/document.rs | 2 | ||||
-rw-r--r-- | src/components/script/dom/htmlserializer.rs | 12 | ||||
-rw-r--r-- | src/components/script/dom/node.rs | 18 | ||||
-rw-r--r-- | src/components/script/html/hubbub_html_parser.rs | 6 |
6 files changed, 46 insertions, 45 deletions
diff --git a/src/components/main/layout/wrapper.rs b/src/components/main/layout/wrapper.rs index cabf046a17d..73dd2483a71 100644 --- a/src/components/main/layout/wrapper.rs +++ b/src/components/main/layout/wrapper.rs @@ -188,7 +188,7 @@ impl<'ln> TLayoutNode for LayoutNode<'ln> { fail!("not text!") } let text: JS<Text> = self.get_jsmanaged().transmute_copy(); - (*text.unsafe_get()).characterdata.data.to_str() + (*text.unsafe_get()).characterdata.data.deref().borrow().clone() } } } @@ -494,7 +494,7 @@ impl<'ln> TLayoutNode for ThreadSafeLayoutNode<'ln> { fail!("not text!") } let text: JS<Text> = self.get_jsmanaged().transmute_copy(); - (*text.unsafe_get()).characterdata.data.to_str() + (*text.unsafe_get()).characterdata.data.deref().borrow().clone() } } } @@ -636,7 +636,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> { Some(TextNodeTypeId) => { unsafe { let text: JS<Text> = self.get_jsmanaged().transmute_copy(); - if !is_whitespace((*text.unsafe_get()).characterdata.data.as_slice()) { + if !is_whitespace((*text.unsafe_get()).characterdata.data.deref().borrow().as_slice()) { return false } diff --git a/src/components/script/dom/characterdata.rs b/src/components/script/dom/characterdata.rs index c4fe6700a3a..309c4de1cd5 100644 --- a/src/components/script/dom/characterdata.rs +++ b/src/components/script/dom/characterdata.rs @@ -5,18 +5,21 @@ //! DOM bindings for `CharacterData`. use dom::bindings::codegen::InheritTypes::{CharacterDataDerived, NodeCast}; -use dom::bindings::js::JSRef; use dom::bindings::error::{Fallible, ErrorResult, IndexSize}; +use dom::bindings::js::JSRef; +use dom::bindings::trace::Untraceable; use dom::bindings::utils::{Reflectable, Reflector}; use dom::document::Document; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::node::{CommentNodeTypeId, Node, NodeTypeId, TextNodeTypeId, ProcessingInstructionNodeTypeId, NodeHelpers}; use servo_util::str::DOMString; +use std::cell::RefCell; + #[deriving(Encodable)] pub struct CharacterData { pub node: Node, - pub data: DOMString, + pub data: Untraceable<RefCell<DOMString>>, } impl CharacterDataDerived for EventTarget { @@ -34,56 +37,56 @@ impl CharacterData { pub fn new_inherited(id: NodeTypeId, data: DOMString, document: &JSRef<Document>) -> CharacterData { CharacterData { node: Node::new_inherited(id, document), - data: data + data: Untraceable::new(RefCell::new(data)), } } } pub trait CharacterDataMethods { fn Data(&self) -> DOMString; - fn SetData(&mut self, arg: DOMString) -> ErrorResult; + fn SetData(&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; + fn AppendData(&self, arg: DOMString) -> ErrorResult; + fn InsertData(&self, _offset: u32, _arg: DOMString) -> ErrorResult; + fn DeleteData(&self, _offset: u32, _count: u32) -> ErrorResult; + fn ReplaceData(&self, _offset: u32, _count: u32, _arg: DOMString) -> ErrorResult; fn Remove(&self); } impl<'a> CharacterDataMethods for JSRef<'a, CharacterData> { fn Data(&self) -> DOMString { - self.data.clone() + self.data.deref().borrow().clone() } - fn SetData(&mut self, arg: DOMString) -> ErrorResult { - self.data = arg; + fn SetData(&self, arg: DOMString) -> ErrorResult { + *self.data.deref().borrow_mut() = arg; Ok(()) } fn Length(&self) -> u32 { - self.data.len() as u32 + self.data.deref().borrow().len() as u32 } fn SubstringData(&self, offset: u32, count: u32) -> Fallible<DOMString> { - Ok(self.data.as_slice().slice(offset as uint, count as uint).to_str()) + Ok(self.data.deref().borrow().as_slice().slice(offset as uint, count as uint).to_string()) } - fn AppendData(&mut self, arg: DOMString) -> ErrorResult { - self.data.push_str(arg.as_slice()); + fn AppendData(&self, arg: DOMString) -> ErrorResult { + self.data.deref().borrow_mut().push_str(arg.as_slice()); Ok(()) } - fn InsertData(&mut self, offset: u32, arg: DOMString) -> ErrorResult { + fn InsertData(&self, offset: u32, arg: DOMString) -> ErrorResult { self.ReplaceData(offset, 0, arg) } - fn DeleteData(&mut self, offset: u32, count: u32) -> ErrorResult { + fn DeleteData(&self, offset: u32, count: u32) -> ErrorResult { self.ReplaceData(offset, count, "".to_string()) } - fn ReplaceData(&mut self, offset: u32, count: u32, arg: DOMString) -> ErrorResult { - let length = self.data.len() as u32; + fn ReplaceData(&self, offset: u32, count: u32, arg: DOMString) -> ErrorResult { + let length = self.data.deref().borrow().len() as u32; if offset > length { return Err(IndexSize); } @@ -92,10 +95,10 @@ impl<'a> CharacterDataMethods for JSRef<'a, CharacterData> { } else { count }; - let mut data = self.data.as_slice().slice(0, offset as uint).to_string(); + let mut data = self.data.deref().borrow().as_slice().slice(0, offset as uint).to_string(); data.push_str(arg.as_slice()); - data.push_str(self.data.as_slice().slice((offset + count) as uint, length as uint)); - self.data = data.into_owned(); + data.push_str(self.data.deref().borrow().as_slice().slice((offset + count) as uint, length as uint)); + *self.data.deref().borrow_mut() = data.into_owned(); // FIXME: Once we have `Range`, we should implement step7 to step11 Ok(()) } diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index d28dc78ea55..87ca5c6c4c1 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -567,7 +567,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { for child in title_elem.children() { if child.is_text() { let text: &JSRef<Text> = TextCast::to_ref(&child).unwrap(); - title.push_str(text.deref().characterdata.data.as_slice()); + title.push_str(text.deref().characterdata.data.deref().borrow().as_slice()); } } }); diff --git a/src/components/script/dom/htmlserializer.rs b/src/components/script/dom/htmlserializer.rs index a1c6d709a47..bb0364672d0 100644 --- a/src/components/script/dom/htmlserializer.rs +++ b/src/components/script/dom/htmlserializer.rs @@ -67,7 +67,7 @@ pub fn serialize(iterator: &mut NodeIterator) -> String { fn serialize_comment(comment: &JSRef<Comment>, html: &mut String) { html.push_str("<!--"); - html.push_str(comment.deref().characterdata.data.as_slice()); + html.push_str(comment.deref().characterdata.data.deref().borrow().as_slice()); html.push_str("-->"); } @@ -80,11 +80,11 @@ fn serialize_text(text: &JSRef<Text>, html: &mut String) { "style" | "script" | "xmp" | "iframe" | "noembed" | "noframes" | "plaintext" | "noscript" if elem.deref().namespace == namespace::HTML - => html.push_str(text.deref().characterdata.data.as_slice()), - _ => escape(text.deref().characterdata.data.as_slice(), false, html) + => html.push_str(text.deref().characterdata.data.deref().borrow().as_slice()), + _ => escape(text.deref().characterdata.data.deref().borrow().as_slice(), false, html) } } - _ => escape(text.deref().characterdata.data.as_slice(), false, html) + _ => escape(text.deref().characterdata.data.deref().borrow().as_slice(), false, html) } } @@ -93,7 +93,7 @@ fn serialize_processing_instruction(processing_instruction: &JSRef<ProcessingIns html.push_str("<?"); html.push_str(processing_instruction.deref().target.as_slice()); html.push_char(' '); - html.push_str(processing_instruction.deref().characterdata.data.as_slice()); + html.push_str(processing_instruction.deref().characterdata.data.deref().borrow().as_slice()); html.push_str("?>"); } @@ -118,7 +118,7 @@ fn serialize_elem(elem: &JSRef<Element>, open_elements: &mut Vec<String>, html: match node.first_child().map(|child| child.root()) { Some(ref child) if child.is_text() => { let text: &JSRef<CharacterData> = CharacterDataCast::to_ref(&**child).unwrap(); - if text.deref().data.len() > 0 && text.deref().data.as_slice().char_at(0) == '\n' { + if text.deref().data.deref().borrow().len() > 0 && text.deref().data.deref().borrow().as_slice().char_at(0) == '\n' { html.push_char('\x0A'); } }, diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index 4a021abd582..323ae5a1c14 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -1235,7 +1235,7 @@ impl Node { CommentNodeTypeId => { let comment: &JSRef<Comment> = CommentCast::to_ref(node).unwrap(); let comment = comment.deref(); - let comment = Comment::new(comment.characterdata.data.clone(), &*document); + let comment = Comment::new(comment.characterdata.data.deref().borrow().clone(), &*document); NodeCast::from_temporary(comment) }, DocumentNodeTypeId => { @@ -1259,14 +1259,14 @@ impl Node { TextNodeTypeId => { let text: &JSRef<Text> = TextCast::to_ref(node).unwrap(); let text = text.deref(); - let text = Text::new(text.characterdata.data.clone(), &*document); + let text = Text::new(text.characterdata.data.deref().borrow().clone(), &*document); NodeCast::from_temporary(text) }, ProcessingInstructionNodeTypeId => { let pi: &JSRef<ProcessingInstruction> = ProcessingInstructionCast::to_ref(node).unwrap(); let pi = pi.deref(); let pi = ProcessingInstruction::new(pi.target.clone(), - pi.characterdata.data.clone(), &*document); + pi.characterdata.data.deref().borrow().clone(), &*document); NodeCast::from_temporary(pi) }, }.root(); @@ -1514,7 +1514,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { for node in self.traverse_preorder() { if node.is_text() { let text: &JSRef<Text> = TextCast::to_ref(&node).unwrap(); - content.push_str(text.deref().characterdata.data.as_slice()); + content.push_str(text.deref().characterdata.data.deref().borrow().as_slice()); } } Some(content.into_owned()) @@ -1555,10 +1555,8 @@ impl<'a> NodeMethods for JSRef<'a, Node> { ProcessingInstructionNodeTypeId => { self.wait_until_safe_to_modify_dom(); - { - let characterdata: &mut JSRef<CharacterData> = CharacterDataCast::to_mut_ref(self).unwrap(); - characterdata.deref_mut().data = value; - } + let characterdata: &JSRef<CharacterData> = CharacterDataCast::to_ref(self).unwrap(); + *characterdata.data.deref().borrow_mut() = value; // Notify the document that the content of this node is different let document = self.owner_doc().root(); @@ -1772,12 +1770,12 @@ impl<'a> NodeMethods for JSRef<'a, Node> { let pi: &JSRef<ProcessingInstruction> = ProcessingInstructionCast::to_ref(node).unwrap(); let other_pi: &JSRef<ProcessingInstruction> = ProcessingInstructionCast::to_ref(other).unwrap(); (pi.deref().target == other_pi.deref().target) && - (pi.deref().characterdata.data == other_pi.deref().characterdata.data) + (*pi.deref().characterdata.data.deref().borrow() == *other_pi.deref().characterdata.data.deref().borrow()) } fn is_equal_characterdata(node: &JSRef<Node>, other: &JSRef<Node>) -> bool { let characterdata: &JSRef<CharacterData> = CharacterDataCast::to_ref(node).unwrap(); let other_characterdata: &JSRef<CharacterData> = CharacterDataCast::to_ref(other).unwrap(); - characterdata.deref().data == other_characterdata.deref().data + *characterdata.deref().data.deref().borrow() == *other_characterdata.deref().data.deref().borrow() } fn is_equal_element_attrs(node: &JSRef<Node>, other: &JSRef<Node>) -> bool { let element: &JSRef<Element> = ElementCast::to_ref(node).unwrap(); diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index 23247341325..c7629958d33 100644 --- a/src/components/script/html/hubbub_html_parser.rs +++ b/src/components/script/html/hubbub_html_parser.rs @@ -506,17 +506,17 @@ pub fn parse_html(page: &Page, js_chan2.send(JSTaskNewFile(new_url)); } None => { - let mut data = vec!(); + let mut data = String::new(); let scriptnode: &JSRef<Node> = NodeCast::from_ref(script); debug!("iterating over children {:?}", scriptnode.first_child()); for child in scriptnode.children() { debug!("child = {:?}", child); let text: &JSRef<Text> = TextCast::to_ref(&child).unwrap(); - data.push(text.deref().characterdata.data.to_str()); // FIXME: Bad copy. + data.push_str(text.deref().characterdata.data.deref().borrow().as_slice()); } debug!("script data = {:?}", data); - js_chan2.send(JSTaskNewInlineScript(data.concat(), url3.clone())); + js_chan2.send(JSTaskNewInlineScript(data, url3.clone())); } } } |