diff options
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/dom/servohtmlparser.rs | 19 | ||||
-rw-r--r-- | components/script/dom/servoxmlparser.rs | 17 | ||||
-rw-r--r-- | components/script/parse/html.rs | 22 |
3 files changed, 19 insertions, 39 deletions
diff --git a/components/script/dom/servohtmlparser.rs b/components/script/dom/servohtmlparser.rs index 6584dbe5cb5..82ed85a9a9c 100644 --- a/components/script/dom/servohtmlparser.rs +++ b/components/script/dom/servohtmlparser.rs @@ -16,13 +16,12 @@ use dom::bindings::trace::JSTraceable; use dom::document::Document; use dom::node::Node; use dom::servoxmlparser::ServoXMLParser; -use dom::text::Text; use dom::window::Window; use encoding::all::UTF_8; use encoding::types::{DecoderTrap, Encoding}; use html5ever::tokenizer; use html5ever::tree_builder; -use html5ever::tree_builder::{NodeOrText, TreeBuilder, TreeBuilderOpts}; +use html5ever::tree_builder::{TreeBuilder, TreeBuilderOpts}; use hyper::header::ContentType; use hyper::mime::{Mime, SubLevel, TopLevel}; use js::jsapi::JSTracer; @@ -36,7 +35,6 @@ use std::cell::UnsafeCell; use std::default::Default; use std::ptr; use url::Url; -use util::str::DOMString; #[must_root] #[derive(JSTraceable, HeapSizeOf)] @@ -45,21 +43,6 @@ pub struct Sink { pub document: JS<Document>, } -impl Sink { - #[allow(unrooted_must_root)] // method is only run at parse time - pub fn get_or_create(&self, child: NodeOrText<JS<Node>>) -> Root<Node> { - match child { - NodeOrText::AppendNode(n) => Root::from_ref(&*n), - NodeOrText::AppendText(t) => { - // FIXME(ajeffrey): convert directly from tendrils to DOMStrings - let s: String = t.into(); - let text = Text::new(DOMString::from(s), &self.document); - Root::upcast(text) - } - } - } -} - /// FragmentContext is used only to pass this group of related values /// into functions. #[derive(Copy, Clone)] diff --git a/components/script/dom/servoxmlparser.rs b/components/script/dom/servoxmlparser.rs index 4f4b4be7d3e..1433e9f49e1 100644 --- a/components/script/dom/servoxmlparser.rs +++ b/components/script/dom/servoxmlparser.rs @@ -11,7 +11,6 @@ use dom::bindings::trace::JSTraceable; use dom::document::Document; use dom::node::Node; use dom::servohtmlparser::ParserRef; -use dom::text::Text; use dom::window::Window; use js::jsapi::JSTracer; use msg::constellation_msg::PipelineId; @@ -19,9 +18,8 @@ use parse::Parser; use script_task::ScriptTask; use std::cell::Cell; use url::Url; -use util::str::DOMString; use xml5ever::tokenizer; -use xml5ever::tree_builder::{self, NodeOrText, XmlTreeBuilder}; +use xml5ever::tree_builder::{self, XmlTreeBuilder}; pub type Tokenizer = tokenizer::XmlTokenizer<XmlTreeBuilder<JS<Node>, Sink>>; @@ -32,19 +30,6 @@ pub struct Sink { pub document: JS<Document>, } -impl Sink { - #[allow(unrooted_must_root)] // method is only run at parse time - pub fn get_or_create(&self, child: NodeOrText<JS<Node>>) -> Root<Node> { - match child { - NodeOrText::AppendNode(n) => Root::from_ref(&*n), - NodeOrText::AppendText(t) => { - let s: String = t.into(); - let text = Text::new(DOMString::from(s), &self.document); - Root::upcast(text) - } - } - } -} #[must_root] #[dom_struct] pub struct ServoXMLParser { 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, |