Produce output of fragment parsing in &mut RootedVec<JS<Node>> argument

This commit is contained in:
Chris Paris 2015-04-01 16:10:43 -10:00
parent 6422f38574
commit f76a137344
2 changed files with 15 additions and 12 deletions

View file

@ -936,16 +936,16 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> {
fn parse_fragment(self, markup: DOMString) -> Fallible<Temporary<DocumentFragment>> { fn parse_fragment(self, markup: DOMString) -> Fallible<Temporary<DocumentFragment>> {
let context_node: JSRef<Node> = NodeCast::from_ref(self); let context_node: JSRef<Node> = NodeCast::from_ref(self);
let context_document = document_from_node(self).root(); let context_document = document_from_node(self).root();
let new_children = let mut new_children: RootedVec<JS<Node>> = RootedVec::new();
if context_document.r().is_html_document() { if context_document.r().is_html_document() {
parse_html_fragment(context_node, markup) parse_html_fragment(context_node, markup, &mut new_children);
} else { } else {
// FIXME: XML case // FIXME: XML case
unimplemented!() unimplemented!();
}; }
let fragment = DocumentFragment::new(context_document.r()).root(); let fragment = DocumentFragment::new(context_document.r()).root();
let fragment_node: JSRef<Node> = NodeCast::from_ref(fragment.r()); let fragment_node: JSRef<Node> = NodeCast::from_ref(fragment.r());
for node in new_children { for node in new_children.iter() {
fragment_node.AppendChild(node.root().r()).unwrap(); fragment_node.AppendChild(node.root().r()).unwrap();
} }
Ok(Temporary::from_rooted(fragment.r())) Ok(Temporary::from_rooted(fragment.r()))

View file

@ -12,6 +12,7 @@ use dom::bindings::codegen::InheritTypes::{DocumentTypeCast, TextCast, CommentCa
use dom::bindings::codegen::InheritTypes::ProcessingInstructionCast; use dom::bindings::codegen::InheritTypes::ProcessingInstructionCast;
use dom::bindings::codegen::InheritTypes::HTMLFormElementDerived; use dom::bindings::codegen::InheritTypes::HTMLFormElementDerived;
use dom::bindings::js::{JS, JSRef, Temporary, OptionalRootable, Root}; use dom::bindings::js::{JS, JSRef, Temporary, OptionalRootable, Root};
use dom::bindings::trace::RootedVec;
use dom::comment::Comment; use dom::comment::Comment;
use dom::document::{Document, DocumentHelpers}; use dom::document::{Document, DocumentHelpers};
use dom::document::{DocumentSource, IsHTMLDocument}; use dom::document::{DocumentSource, IsHTMLDocument};
@ -331,7 +332,9 @@ pub fn parse_html(document: JSRef<Document>,
} }
// https://html.spec.whatwg.org/multipage/syntax.html#parsing-html-fragments // https://html.spec.whatwg.org/multipage/syntax.html#parsing-html-fragments
pub fn parse_html_fragment(context_node: JSRef<Node>, input: DOMString) -> Vec<Temporary<Node>> { pub fn parse_html_fragment(context_node: JSRef<Node>,
input: DOMString,
output: &mut RootedVec<JS<Node>>) {
let window = window_from_node(context_node).root(); let window = window_from_node(context_node).root();
let context_document = document_from_node(context_node).root(); let context_document = document_from_node(context_node).root();
let url = context_document.r().url(); let url = context_document.r().url();
@ -357,7 +360,7 @@ pub fn parse_html_fragment(context_node: JSRef<Node>, input: DOMString) -> Vec<T
// Step 14. // Step 14.
let root_element = document.r().GetDocumentElement().expect("no document element").root(); let root_element = document.r().GetDocumentElement().expect("no document element").root();
let root_node: JSRef<Node> = NodeCast::from_ref(root_element.r()); let root_node: JSRef<Node> = NodeCast::from_ref(root_element.r());
root_node.children() for child in root_node.children() {
.map(|node| Temporary::from_rooted(node)) output.push(JS::from_rooted(child));
.collect() }
} }