diff options
5 files changed, 55 insertions, 3 deletions
diff --git a/components/script/dom/htmlscriptelement.rs b/components/script/dom/htmlscriptelement.rs index 3a609a0977f..efe5fe54535 100644 --- a/components/script/dom/htmlscriptelement.rs +++ b/components/script/dom/htmlscriptelement.rs @@ -28,6 +28,7 @@ use dom::window::ScriptHelpers; use encoding::label::encoding_from_whatwg_label; use encoding::types::{DecoderTrap, Encoding, EncodingRef}; use html5ever::tree_builder::NextParserState; +use hyper::http::RawStatus; use ipc_channel::ipc; use ipc_channel::router::ROUTER; use js::jsapi::RootedValue; @@ -136,20 +137,35 @@ struct ScriptContext { metadata: Option<Metadata>, /// The initial URL requested. url: Url, + /// Indicates whether the request failed, and why + status: Result<(), String> } impl AsyncResponseListener for ScriptContext { fn headers_available(&mut self, metadata: Metadata) { + let status_code = match metadata.status { + Some(RawStatus(c, _)) => c, + _ => 0 + }; + + self.status = match status_code { + 0 => Err("No http status code received".to_owned()), + 200...299 => Ok(()), // HTTP ok status codes + _ => Err(format!("HTTP error code {}", status_code)) + }; + self.metadata = Some(metadata); } fn data_available(&mut self, payload: Vec<u8>) { - let mut payload = payload; - self.data.append(&mut payload); + if self.status.is_ok() { + let mut payload = payload; + self.data.append(&mut payload); + } } fn response_complete(&mut self, status: Result<(), String>) { - let load = status.map(|_| { + let load = status.and(self.status.clone()).map(|_| { let data = mem::replace(&mut self.data, vec!()); let metadata = self.metadata.take().unwrap(); (metadata, data) @@ -292,6 +308,7 @@ impl HTMLScriptElement { data: vec!(), metadata: None, url: url.clone(), + status: Ok(()) })); let (action_sender, action_receiver) = ipc::channel().unwrap(); diff --git a/tests/wpt/metadata/MANIFEST.json b/tests/wpt/metadata/MANIFEST.json index f238e4d90e9..2c18cb3f8ee 100644 --- a/tests/wpt/metadata/MANIFEST.json +++ b/tests/wpt/metadata/MANIFEST.json @@ -40150,6 +40150,14 @@ "url": "/webvtt/rendering/cues-with-video/processing-model/too_many_cues_wrapped.html" } ] + }, + "testharness": { + "html/semantics/scripting-1/the-script-element/script-not-found-not-executed.html": [ + { + "path": "html/semantics/scripting-1/the-script-element/script-not-found-not-executed.html", + "url": "/html/semantics/scripting-1/the-script-element/script-not-found-not-executed.html" + } + ] } }, "reftest_nodes": { diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/script-not-found-not-executed-2.py b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/script-not-found-not-executed-2.py new file mode 100644 index 00000000000..53caed7c043 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/script-not-found-not-executed-2.py @@ -0,0 +1,4 @@ +def main(request, response): + headers = [("Content-Type", "text/javascript")] + body = "test2_token = \"script executed\";" + return 200, headers, body diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/script-not-found-not-executed.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/script-not-found-not-executed.html new file mode 100644 index 00000000000..44ad30b018a --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/script-not-found-not-executed.html @@ -0,0 +1,19 @@ +<!doctype html> +<meta charset="utf-8"> +<title></title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script>var test1_token = "script not executed";</script> +<script src="script-not-found-not-executed.py"></script> +<script> +test(function(){ + assert_equals(test1_token, "script not executed"); +}, "Script that 404"); +</script> +<script>var test2_token = "script not executed";</script> +<script src="script-not-found-not-executed-2.py"></script> +<script> +test(function(){ + assert_equals(test2_token, "script executed"); +}, "Script that does not 404"); +</script> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/script-not-found-not-executed.py b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/script-not-found-not-executed.py new file mode 100644 index 00000000000..7722bd3f231 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/script-not-found-not-executed.py @@ -0,0 +1,4 @@ +def main(request, response): + headers = [("Content-Type", "text/javascript")] + body = "test1_token = \"script executed\";" + return 404, headers, body |