Auto merge of #6641 - michaelwu:direct-output, r=Ms2ger

Directly append children to output node in parse_html_fragment



<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6641)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-07-16 07:21:06 -06:00
commit 9534e8143f
2 changed files with 5 additions and 12 deletions

View file

@ -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)
}
}

View file

@ -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};
@ -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();
@ -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();
}
}