diff options
author | Ms2ger <Ms2ger@gmail.com> | 2015-12-11 09:40:17 -0500 |
---|---|---|
committer | Ms2ger <Ms2ger@gmail.com> | 2015-12-11 09:40:17 -0500 |
commit | 14acf1616e46a7e312d6398f3c7e1c3e83ad1f31 (patch) | |
tree | 23e3fbe1fb693e7083ef27da7076bbdf33a28ee6 /components/script/parse/html.rs | |
parent | 4e73a30b0072dcf93bd8faa18f6ed89b7b2ad245 (diff) | |
download | servo-14acf1616e46a7e312d6398f3c7e1c3e83ad1f31.tar.gz servo-14acf1616e46a7e312d6398f3c7e1c3e83ad1f31.zip |
Avoid some rooting in parsing.
Diffstat (limited to 'components/script/parse/html.rs')
-rw-r--r-- | components/script/parse/html.rs | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/components/script/parse/html.rs b/components/script/parse/html.rs index 6c4bf205239..8804010d4ba 100644 --- a/components/script/parse/html.rs +++ b/components/script/parse/html.rs @@ -24,6 +24,7 @@ use dom::node::{document_from_node, window_from_node}; use dom::processinginstruction::ProcessingInstruction; use dom::servohtmlparser; use dom::servohtmlparser::{FragmentContext, ServoHTMLParser}; +use dom::text::Text; use encoding::types::Encoding; use html5ever::Attribute; use html5ever::serialize::TraversalScope; @@ -39,6 +40,20 @@ use tendril::StrTendril; use url::Url; use util::str::DOMString; +fn insert(parent: &Node, reference_child: Option<&Node>, child: NodeOrText<JS<Node>>) { + match child { + NodeOrText::AppendNode(n) => { + assert!(parent.InsertBefore(&n, reference_child).is_ok()); + }, + NodeOrText::AppendText(t) => { + // FIXME(ajeffrey): convert directly from tendrils to DOMStrings + let s: String = t.into(); + let text = Text::new(DOMString::from(s), &parent.owner_doc()); + assert!(parent.InsertBefore(text.upcast(), reference_child).is_ok()); + } + } +} + impl<'a> TreeSink for servohtmlparser::Sink { type Handle = JS<Node>; @@ -91,8 +106,7 @@ impl<'a> TreeSink for servohtmlparser::Sink { None => return Err(new_node), }; - let child = self.get_or_create(new_node); - assert!(parent.InsertBefore(child.r(), Some(&*sibling)).is_ok()); + insert(&parent, Some(&*sibling), new_node); Ok(()) } @@ -105,10 +119,8 @@ impl<'a> TreeSink for servohtmlparser::Sink { } fn append(&mut self, parent: JS<Node>, child: NodeOrText<JS<Node>>) { - let child = self.get_or_create(child); - // FIXME(#3701): Use a simpler algorithm and merge adjacent text nodes - assert!(parent.AppendChild(child.r()).is_ok()); + insert(&parent, None, child); } fn append_doctype_to_document(&mut self, name: StrTendril, public_id: StrTendril, |