From b5457f7910b867b4bbd98ddd69b95b7623ef4ff9 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 9 Sep 2013 12:16:38 +0200 Subject: [PATCH] Introduce a createText function. --- src/components/script/dom/document.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index d84f2427f8d..60d611f3fde 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -331,10 +331,7 @@ impl Document { for title_child in child.children() { child.remove_child(title_child); } - let new_text = unsafe { - Node::as_abstract_node(cx, @Text::new(title.to_str())) - }; - child.add_child(new_text); + child.add_child(self.createText(title.to_str())); break; } if !has_title { @@ -344,10 +341,7 @@ impl Document { let new_title = unsafe { Node::as_abstract_node(cx, new_title) }; - let new_text = unsafe { - Node::as_abstract_node(cx, @Text::new(title.to_str())) - }; - new_title.add_child(new_text); + new_title.add_child(self.createText(title.to_str())); node.add_child(new_title); } break; @@ -443,6 +437,13 @@ impl Document { self.createHTMLCollection(|elem| elem.get_attr("name").is_some() && eq_slice(elem.get_attr("name").unwrap(), name.to_str())) } + + pub fn createText(&self, data: ~str) -> AbstractNode { + let (_scope, cx) = self.get_scope_and_cx(); + unsafe { + Node::as_abstract_node(cx, @Text::new(data)) + } + } pub fn createHTMLCollection(&self, callback: &fn(elem: &Element) -> bool) -> @mut HTMLCollection { let mut elements = ~[];