Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Fix duplicate root html #510

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Unmuddle document node and root node

  • Loading branch information
jjjjw committed Jun 9, 2013
commit 59432ba08cdfd6bc7fdb6d992a6097238d6e06f2
@@ -40,7 +40,7 @@ type JSResult = ~[~[u8]];

enum CSSMessage {
CSSTaskNewFile(StylesheetProvenance),
CSSTaskExit
CSSTaskExit
}

enum JSMessage {
@@ -231,13 +231,15 @@ pub fn parse_html(url: Url,

let url2 = url.clone(), url3 = url.clone();

// Build the root node.
let root = ~HTMLHtmlElement { parent: Element::new(HTMLHtmlElementTypeId, ~"html") };
let root = unsafe { Node::as_abstract_node(root) };
debug!("created new node");
// Build the the document node.
// TODO(jj): Since this node is a formality, we should use a different element type
// for clarity.
let doc_node = ~HTMLHtmlElement { parent: Element::new(HTMLHtmlElementTypeId, ~"html") };
let doc_node = unsafe { Node::as_abstract_node(doc_node) };
debug!("created document node");
let mut parser = hubbub::Parser("UTF-8", false);
debug!("created parser");
parser.set_document_node(root.to_hubbub_node());
parser.set_document_node(doc_node.to_hubbub_node());
parser.enable_scripting(true);

// Performs various actions necessary after appending has taken place. Currently, this
@@ -429,10 +431,22 @@ pub fn parse_html(url: Url,
css_chan.send(CSSTaskExit);
js_chan.send(JSTaskExit);

let html_el = get_root_html_node(&doc_node);

HtmlParserResult {
root: root,
root: html_el,
style_port: stylesheet_port,
js_port: js_result_port,
}
}

fn get_root_html_node(doc_node: &AbstractNode<ScriptView>) -> AbstractNode<ScriptView> {
// We need to look at the children of the document node to find the root html node of the document.
// This is a Hubbub approach that looks odd when combined with our usage.
for doc_node.each_child |kid| {
if kid.is_element() && kid.type_id() == ElementNodeTypeId(HTMLHtmlElementTypeId) {
return kid;
}
}
fail!("The document tree has no root html element!")
}
@@ -336,6 +336,7 @@ impl ScriptContext {
let document = Document(root_node, Some(window));

// Tie the root into the document.
// FIXME(jj): Remove this code? The document is created with a root node.
do root_node.with_mut_base |base| {
base.add_to_doc(document)
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.