aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/html/hubbub_html_parser.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/script/html/hubbub_html_parser.rs')
-rw-r--r--src/components/script/html/hubbub_html_parser.rs24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs
index fac27f299b1..c7629958d33 100644
--- a/src/components/script/html/hubbub_html_parser.rs
+++ b/src/components/script/html/hubbub_html_parser.rs
@@ -17,10 +17,10 @@ use html::cssparse::{StylesheetProvenance, UrlProvenance, spawn_css_parser};
use script_task::Page;
use hubbub::hubbub;
-use hubbub::hubbub::{NullNs, XLinkNs, XmlNs, XmlNsNs};
+use hubbub::hubbub::{NullNs, HtmlNs, MathMlNs, SvgNs, XLinkNs, XmlNs, XmlNsNs};
use servo_net::resource_task::{Load, LoadData, Payload, Done, ResourceTask, load_whole_resource};
use servo_util::namespace;
-use servo_util::namespace::Null;
+use servo_util::namespace::{Namespace, Null};
use servo_util::str::{DOMString, HTML_SPACE_CHARACTERS};
use servo_util::task::spawn_named;
use servo_util::url::parse_url;
@@ -158,7 +158,11 @@ fn js_script_listener(to_parent: Sender<HtmlDiscoveryMessage>,
// Silly macros to handle constructing DOM nodes. This produces bad code and should be optimized
// via atomization (issue #85).
-pub fn build_element_from_tag(tag: DOMString, document: &JSRef<Document>) -> Temporary<Element> {
+pub fn build_element_from_tag(tag: DOMString, ns: Namespace, document: &JSRef<Document>) -> Temporary<Element> {
+ if ns != namespace::HTML {
+ return Element::new(tag, ns, None, document);
+ }
+
// TODO (Issue #85): use atoms
handle_element!(document, tag, "a", HTMLAnchorElement);
handle_element!(document, tag, "abbr", HTMLElement);
@@ -369,7 +373,13 @@ pub fn parse_html(page: &Page,
// NOTE: tmp vars are workaround for lifetime issues. Both required.
let tmp_borrow = doc_cell.borrow();
let tmp = &*tmp_borrow;
- let mut element: Root<Element> = build_element_from_tag(tag.name.clone(), *tmp).root();
+ let namespace = match tag.ns {
+ HtmlNs => namespace::HTML,
+ MathMlNs => namespace::MathML,
+ SvgNs => namespace::SVG,
+ ns => fail!("Not expecting namespace {:?}", ns),
+ };
+ let mut element: Root<Element> = build_element_from_tag(tag.name.clone(), namespace, *tmp).root();
debug!("-- attach attrs");
for attr in tag.attributes.iter() {
@@ -496,17 +506,17 @@ pub fn parse_html(page: &Page,
js_chan2.send(JSTaskNewFile(new_url));
}
None => {
- let mut data = vec!();
+ let mut data = String::new();
let scriptnode: &JSRef<Node> = NodeCast::from_ref(script);
debug!("iterating over children {:?}", scriptnode.first_child());
for child in scriptnode.children() {
debug!("child = {:?}", child);
let text: &JSRef<Text> = TextCast::to_ref(&child).unwrap();
- data.push(text.deref().characterdata.data.to_str()); // FIXME: Bad copy.
+ data.push_str(text.deref().characterdata.data.deref().borrow().as_slice());
}
debug!("script data = {:?}", data);
- js_chan2.send(JSTaskNewInlineScript(data.concat(), url3.clone()));
+ js_chan2.send(JSTaskNewInlineScript(data, url3.clone()));
}
}
}