From 916d0253b3e949f908259de12e387f91275731c0 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 4 Sep 2013 21:38:35 +0200 Subject: [PATCH] Issue #561 - Execute inline JS. This follows the approach of external scripts in executing tests all together after parsing finishes. --- .../script/html/hubbub_html_parser.rs | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index d8e75e81b34..c4ac7db18ef 100644 --- a/src/components/script/html/hubbub_html_parser.rs +++ b/src/components/script/html/hubbub_html_parser.rs @@ -86,6 +86,7 @@ enum CSSMessage { enum JSMessage { JSTaskNewFile(Url), + JSTaskNewInlineScript(~str, Url), JSTaskExit } @@ -193,6 +194,9 @@ fn js_script_listener(to_parent: SharedChan, result_vec.push(JSFile { data: bytes.unwrap(), url: url_clone }); } } + JSTaskNewInlineScript(data, url) => { + result_vec.push(JSFile { data: data.into_bytes(), url: url }); + } JSTaskExit => { break; } @@ -511,15 +515,27 @@ pub fn parse_html(cx: *JSContext, url: Url, js_chan: SharedChan) { unsafe { - let script: AbstractNode = NodeWrapping::from_hubbub_node(script); - do script.with_imm_element |script| { + let scriptnode: AbstractNode = NodeWrapping::from_hubbub_node(script); + do scriptnode.with_imm_element |script| { match script.get_attr("src") { Some(src) => { debug!("found script: %s", src); let new_url = make_url(src.to_str(), Some(url.clone())); js_chan.send(JSTaskNewFile(new_url)); } - None => {} + None => { + let mut data = ~[]; + debug!("iterating over children %?", scriptnode.first_child()); + for child in scriptnode.children() { + debug!("child = %?", child); + do child.with_imm_text() |text| { + data.push(text.parent.data.to_str()); // FIXME: Bad copy. + } + } + + debug!("data = %?", data); + js_chan.send(JSTaskNewInlineScript(data.concat(), url.clone())); + } } } }