mirror of
https://github.com/servo/servo.git
synced 2025-07-31 11:10:22 +01:00
WebSocket constructor should not panic
Make an early return when the WebSocket connection fails in the constructor. Also let the WebSocket connection to be closed when the connection could not be established. Fixes #6082.
This commit is contained in:
parent
4435e6f42a
commit
7781f331d3
15 changed files with 48 additions and 28 deletions
|
@ -141,7 +141,16 @@ impl WebSocket {
|
|||
|
||||
// TODO Client::connect does not conform to RFC 6455
|
||||
// see https://github.com/cyderize/rust-websocket/issues/38
|
||||
let request = Client::connect(parsed_url).unwrap();
|
||||
let request = match Client::connect(parsed_url) {
|
||||
Ok(request) => request,
|
||||
Err(_) => {
|
||||
let global_root = ws_root.global.root();
|
||||
let address = Trusted::new(global_root.r().get_cx(), ws_root, global_root.r().script_chan().clone());
|
||||
let task = box WebSocketTaskHandler::new(address, WebSocketTask::Close);
|
||||
global_root.r().script_chan().send(ScriptMsg::RunnableMsg(task)).unwrap();
|
||||
return Ok(Temporary::from_rooted(ws_root));
|
||||
}
|
||||
};
|
||||
let response = request.send().unwrap();
|
||||
response.validate().unwrap();
|
||||
ws_root.ready_state.set(WebSocketRequestState::Open);
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
[progress.html]
|
||||
type: testharness
|
||||
expected: TIMEOUT
|
||||
[W3C WebSocket API - Create WebSocket - Pass a URL with a non ws/wss scheme - SYNTAX_ERR is thrown]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
[Create-Secure-blocked-port.htm]
|
||||
type: testharness
|
||||
expected: CRASH
|
||||
[W3C WebSocket API - Create Secure WebSocket - Pass a URL with a blocked port - SECURITY_ERR should be thrown]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
[008.html]
|
||||
type: testharness
|
||||
expected: CRASH
|
|
@ -1,3 +0,0 @@
|
|||
[017.html]
|
||||
type: testharness
|
||||
expected: CRASH
|
|
@ -1,3 +1,5 @@
|
|||
[021.html]
|
||||
type: testharness
|
||||
expected: CRASH
|
||||
[WebSockets: Same sub protocol twice]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
[bufferedAmount-defineProperty-getter.html]
|
||||
type: testharness
|
||||
expected: CRASH
|
|
@ -1,3 +0,0 @@
|
|||
[bufferedAmount-defineProperty-setter.html]
|
||||
type: testharness
|
||||
expected: CRASH
|
|
@ -1,3 +1,6 @@
|
|||
[020.html]
|
||||
type: testharness
|
||||
expected: CRASH
|
||||
expected: TIMEOUT
|
||||
[WebSockets: error events]
|
||||
expected: TIMEOUT
|
||||
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
[004.html]
|
||||
type: testharness
|
||||
expected: CRASH
|
|
@ -1,3 +0,0 @@
|
|||
[005.html]
|
||||
type: testharness
|
||||
expected: CRASH
|
|
@ -1,3 +0,0 @@
|
|||
[005.html]
|
||||
type: testharness
|
||||
expected: CRASH
|
|
@ -1,3 +0,0 @@
|
|||
[006.html]
|
||||
type: testharness
|
||||
expected: CRASH
|
|
@ -539,6 +539,12 @@
|
|||
"url": "/_mozilla/mozilla/union.html"
|
||||
}
|
||||
],
|
||||
"mozilla/websocket_connection_fail.html": [
|
||||
{
|
||||
"path": "mozilla/websocket_connection_fail.html",
|
||||
"url": "/_mozilla/mozilla/websocket_connection_fail.html"
|
||||
}
|
||||
],
|
||||
"mozilla/window.html": [
|
||||
{
|
||||
"path": "mozilla/window.html",
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
<html>
|
||||
<head>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
async_test(function() {
|
||||
var onclose = 0;
|
||||
var ws = new WebSocket("ws://wrong_url");
|
||||
|
||||
ws.onclose = this.step_func_done(function(ev) {
|
||||
onclose++;
|
||||
assert_equals(onclose, 1);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue