Skip to content

Commit

Permalink
Directly append children to output node in parse_html_fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwu committed Jul 15, 2015
1 parent b6b9508 commit 2752d33
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
12 changes: 3 additions & 9 deletions components/script/dom/node.rs
Expand Up @@ -1023,20 +1023,14 @@ impl<'a> NodeHelpers for &'a Node {
fn parse_fragment(self, markup: DOMString) -> Fallible<Root<DocumentFragment>> {
let context_node: &Node = NodeCast::from_ref(self);
let context_document = document_from_node(self);
let mut new_children: RootedVec<JS<Node>> = RootedVec::new();
let fragment = DocumentFragment::new(context_document.r());
if context_document.r().is_html_document() {
parse_html_fragment(context_node, markup, &mut new_children);
let fragment_node = NodeCast::from_ref(fragment.r());
parse_html_fragment(context_node, markup, fragment_node);
} else {
// FIXME: XML case
unimplemented!();
}
let fragment = DocumentFragment::new(context_document.r());
{
let fragment_node = NodeCast::from_ref(fragment.r());
for node in new_children.iter() {
fragment_node.AppendChild(node.root().r()).unwrap();
}
}
Ok(fragment)
}
}
Expand Down
5 changes: 2 additions & 3 deletions components/script/parse/html.rs
Expand Up @@ -14,7 +14,6 @@ use dom::bindings::codegen::InheritTypes::{HTMLFormElementDerived, NodeCast};
use dom::bindings::codegen::InheritTypes::ProcessingInstructionCast;
use dom::bindings::js::{JS, Root};
use dom::bindings::js::{RootedReference};
use dom::bindings::trace::RootedVec;
use dom::characterdata::{CharacterDataHelpers, CharacterDataTypeId};
use dom::comment::Comment;
use dom::document::{Document, DocumentHelpers};
Expand Down Expand Up @@ -284,7 +283,7 @@ pub fn parse_html(document: &Document,
// https://html.spec.whatwg.org/multipage/#parsing-html-fragments
pub fn parse_html_fragment(context_node: &Node,
input: DOMString,
output: &mut RootedVec<JS<Node>>) {
output: &Node) {
let window = window_from_node(context_node);
let context_document = document_from_node(context_node);
let context_document = context_document.r();
Expand Down Expand Up @@ -314,6 +313,6 @@ pub fn parse_html_fragment(context_node: &Node,
let root_element = document.r().GetDocumentElement().expect("no document element");
let root_node = NodeCast::from_ref(root_element.r());
for child in root_node.children() {
output.push(JS::from_rooted(&child));
output.AppendChild(child.r()).unwrap();
}
}

0 comments on commit 2752d33

Please sign in to comment.