mirror of
https://github.com/servo/servo.git
synced 2025-06-24 09:04:33 +01:00
parent
90ab488d42
commit
ee9bb1f3c6
5 changed files with 55 additions and 3 deletions
|
@ -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();
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
def main(request, response):
|
||||
headers = [("Content-Type", "text/javascript")]
|
||||
body = "test2_token = \"script executed\";"
|
||||
return 200, headers, body
|
|
@ -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>
|
|
@ -0,0 +1,4 @@
|
|||
def main(request, response):
|
||||
headers = [("Content-Type", "text/javascript")]
|
||||
body = "test1_token = \"script executed\";"
|
||||
return 404, headers, body
|
Loading…
Add table
Add a link
Reference in a new issue