Skip to content

Commit

Permalink
Finish hooking up XML parser
Browse files Browse the repository at this point in the history
added script integration with xml5ever

Updated test expectations

Removed timeout test expectation

Refactors

application/xhtml+xml is treated as HTML

Updated xml5ever

Updated Text Expectations
  • Loading branch information
cbrewster committed Apr 27, 2016
1 parent 2729864 commit 3389c49
Show file tree
Hide file tree
Showing 29 changed files with 393 additions and 96 deletions.
2 changes: 1 addition & 1 deletion components/script/Cargo.toml
Expand Up @@ -27,7 +27,7 @@ canvas_traits = {path = "../canvas_traits"}
js = {git = "https://github.com/servo/rust-mozjs"}
angle = {git = "https://github.com/emilio/angle", branch = "servo"}
ipc-channel = {git = "https://github.com/servo/ipc-channel"}
xml5ever = {git = "https://github.com/Ygg01/xml5ever", features = ["unstable"]}
xml5ever = {version = "0.1.2", features = ["unstable"]}
gfx_traits = {path = "../gfx_traits"}
webrender_traits = {git = "https://github.com/servo/webrender_traits"}
app_units = {version = "0.2.3", features = ["plugins"]}
Expand Down
2 changes: 2 additions & 0 deletions components/script/dom/servoxmlparser.rs
Expand Up @@ -128,6 +128,8 @@ impl ServoXMLParser {
if !pending_input.is_empty() {
let chunk = pending_input.remove(0);
self.tokenizer.borrow_mut().feed(chunk.into());
} else {
self.tokenizer.borrow_mut().run();
}

// Document parsing is blocked on an external resource.
Expand Down
23 changes: 21 additions & 2 deletions components/script/parse/xml.rs
Expand Up @@ -11,11 +11,13 @@ use dom::comment::Comment;
use dom::document::Document;
use dom::documenttype::DocumentType;
use dom::element::{Element, ElementCreator};
use dom::htmlscriptelement::HTMLScriptElement;
use dom::node::Node;
use dom::processinginstruction::ProcessingInstruction;
use dom::servoxmlparser;
use dom::servoxmlparser::ServoXMLParser;
use dom::text::Text;
use html5ever;
use msg::constellation_msg::PipelineId;
use parse::Parser;
use std::borrow::Cow;
Expand All @@ -24,7 +26,7 @@ use url::Url;
use util::str::DOMString;
use xml5ever::tendril::StrTendril;
use xml5ever::tokenizer::{Attribute, QName};
use xml5ever::tree_builder::{NodeOrText, TreeSink};
use xml5ever::tree_builder::{NextParserState, NodeOrText, TreeSink};

impl<'a> TreeSink for servoxmlparser::Sink {
type Handle = JS<Node>;
Expand Down Expand Up @@ -101,6 +103,24 @@ impl<'a> TreeSink for servoxmlparser::Sink {
doc);
JS::from_ref(pi.upcast())
}

fn mark_script_already_started(&mut self, node: Self::Handle) {
let script = node.downcast::<HTMLScriptElement>();
if let Some(script) = script {
script.mark_already_started();
}
}

fn complete_script(&mut self, node: Self::Handle) -> NextParserState {
let script = node.downcast::<HTMLScriptElement>();
if let Some(script) = script {
return match script.prepare() {
html5ever::tree_builder::NextParserState::Continue => NextParserState::Continue,
html5ever::tree_builder::NextParserState::Suspend => NextParserState::Suspend
};
}
NextParserState::Continue
}
}


Expand All @@ -119,4 +139,3 @@ pub fn parse_xml(document: &Document,
};
parser.parse_chunk(String::from(input));
}

52 changes: 29 additions & 23 deletions components/script/script_thread.rs
Expand Up @@ -1509,23 +1509,22 @@ impl ScriptThread {
headers.get().map(|&LastModified(HttpDate(ref tm))| dom_last_modified(tm))
});

let content_type = match metadata.content_type {
Some(ContentType(Mime(TopLevel::Text, SubLevel::Xml, _))) => {
Some(DOMString::from("text/xml"))
let content_type = metadata.content_type.as_ref().and_then(|&ContentType(ref mimetype)| {
match *mimetype {
Mime(TopLevel::Application, SubLevel::Xml, _) |
Mime(TopLevel::Application, SubLevel::Ext(_), _) |
Mime(TopLevel::Text, SubLevel::Xml, _) |
Mime(TopLevel::Text, SubLevel::Plain, _) => Some(DOMString::from(mimetype.to_string())),
_ => None,
}

Some(ContentType(Mime(TopLevel::Text, SubLevel::Plain, _))) => {
Some(DOMString::from("text/plain"))
}

_ => None
};
});

let loader = DocumentLoader::new_with_thread(self.resource_thread.clone(),
Some(page.pipeline()),
Some(incomplete.url.clone()));

let is_html_document = match metadata.content_type {
Some(ContentType(Mime(TopLevel::Application, SubLevel::Xml, _))) |
Some(ContentType(Mime(TopLevel::Text, SubLevel::Xml, _))) =>
IsHTMLDocument::NonHTMLDocument,
_ => IsHTMLDocument::HTMLDocument,
Expand Down Expand Up @@ -1586,19 +1585,26 @@ impl ScriptThread {

document.set_https_state(metadata.https_state);

match metadata.content_type {
Some(ContentType(Mime(TopLevel::Text, SubLevel::Xml, _))) => {
parse_xml(document.r(),
parse_input,
final_url,
xml::ParseContext::Owner(Some(incomplete.pipeline_id)));
}
_ => {
parse_html(document.r(),
parse_input,
final_url,
ParseContext::Owner(Some(incomplete.pipeline_id)));
}
let is_xml = match metadata.content_type {
Some(ContentType(Mime(TopLevel::Application, SubLevel::Ext(ref sub_level), _)))
if sub_level.ends_with("+xml") => true,

Some(ContentType(Mime(TopLevel::Application, SubLevel::Xml, _))) |
Some(ContentType(Mime(TopLevel::Text, SubLevel::Xml, _))) => true,

_ => false,
};

if is_xml {
parse_xml(document.r(),
parse_input,
final_url,
xml::ParseContext::Owner(Some(incomplete.pipeline_id)));
} else {
parse_html(document.r(),
parse_input,
final_url,
ParseContext::Owner(Some(incomplete.pipeline_id)));
}

if incomplete.is_frozen {
Expand Down
6 changes: 3 additions & 3 deletions components/servo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions ports/cef/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions ports/gonk/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

This file was deleted.

@@ -1,3 +1,17 @@
[Document-getElementsByTagName-xhtml.xhtml]
type: testharness
disabled: xml
[HTML element with uppercase tag name matches in XHTML documents]
expected: FAIL

[Element in non-HTML namespace, prefix, lowercase name]
expected: FAIL

[Element in non-HTML namespace, prefix, uppercase name]
expected: FAIL

[Element in HTML namespace, no prefix, non-ascii characters in name]
expected: FAIL

[Element in HTML namespace, prefix, non-ascii characters in name]
expected: FAIL

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

@@ -1,3 +1,5 @@
[Element-firstElementChild-entity-xhtml.xhtml]
type: testharness
disabled: xml
[Entity References]
expected: FAIL

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

@@ -1,6 +1,5 @@
[Node-isEqualNode-xhtml.xhtml]
type: testharness
expected: TIMEOUT
[isEqualNode should return true when only the internal subsets of DocumentTypes differ.]
expected: NOTRUN
expected: FAIL

0 comments on commit 3389c49

Please sign in to comment.