diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index 63c65bc9fd8..ea34398e39e 100644 --- a/src/components/script/html/hubbub_html_parser.rs +++ b/src/components/script/html/hubbub_html_parser.rs @@ -23,7 +23,7 @@ use servo_net::resource_task::{Load, LoadData, Payload, Done, ResourceTask, load use servo_util::atom::Atom; use servo_util::namespace; use servo_util::namespace::{Namespace, Null}; -use servo_util::str::{DOMString, HTML_SPACE_CHARACTERS}; +use servo_util::str::{DOMString, HTML_SPACE_CHARACTERS, StaticStringVec}; use servo_util::task::spawn_named; use std::ascii::StrAsciiExt; use std::mem; @@ -291,6 +291,57 @@ pub fn build_element_from_tag(tag: DOMString, ns: Namespace, document: &JSRef) -> bool { + match script.get_attribute(Null, "type").root().map(|s| s.Value()) { + Some(ref s) if s.is_empty() => { + // type attr exists, but empty means js + debug!("script type empty, inferring js"); + true + }, + Some(ref s) => { + debug!("script type={:s}", *s); + SCRIPT_JS_MIMES.contains(&s.as_slice().trim_chars(HTML_SPACE_CHARACTERS)) + }, + None => { + debug!("no script type"); + match script.get_attribute(Null, "language").root().map(|s| s.Value()) { + Some(ref s) if s.is_empty() => { + debug!("script language empty, inferring js"); + true + }, + Some(ref s) => { + debug!("script language={:s}", *s); + SCRIPT_JS_MIMES.contains(&"text/".to_string().append(s.as_slice()).as_slice()) + }, + None => { + debug!("no script type or language, inferring js"); + true + } + } + } + } +} + pub fn parse_html(page: &Page, document: &JSRef, url: Url, @@ -494,6 +545,11 @@ pub fn parse_html(page: &Page, complete_script: |script| { unsafe { let script: &JSRef = &*from_hubbub_node(script).root(); + + if !is_javascript(script) { + return; + } + match script.get_attribute(Null, "src").root() { Some(src) => { debug!("found script: {:s}", src.deref().Value()); diff --git a/src/test/content/harness.js b/src/test/content/harness.js index 7bd118a9dff..7dafac00b6e 100644 --- a/src/test/content/harness.js +++ b/src/test/content/harness.js @@ -3,12 +3,20 @@ function _oneline(x) { return (i == -1) ? x : (x.slice(0, i) + "..."); } +var _expectations = 0; +var _tests = 0; +function expect(num) { + _expectations = num; +} + function _fail(s, m) { + _tests++; // string split to avoid problems with tests that end up printing the value of window._fail. window.alert(_oneline("TEST-UNEXPECTED" + "-FAIL | " + s + ": " + m)); } function _pass(s, m) { + _tests++; window.alert(_oneline("TEST-PASS | " + s + ": " + m)); } @@ -67,6 +75,9 @@ function check_disabled_selector(elem, disabled) { var _test_complete = false; var _test_timeout = 10000; //10 seconds function finish() { + if (_expectations > _tests) { + _fail('expected ' + _expectations + ' tests, fullfilled ' + _tests); + } _test_complete = true; window.close(); } diff --git a/src/test/content/test_script_type.html b/src/test/content/test_script_type.html new file mode 100644 index 00000000000..e034b9013a9 --- /dev/null +++ b/src/test/content/test_script_type.html @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +