mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Auto merge of #9360 - jsanders:accept-protocols-sequence, r=KiChjang
Accept WebSocket protocols as string or sequence Fixes #9053 <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9360) <!-- Reviewable:end -->
This commit is contained in:
commit
03a0b73538
6 changed files with 10 additions and 36 deletions
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
enum BinaryType { "blob", "arraybuffer" };
|
enum BinaryType { "blob", "arraybuffer" };
|
||||||
|
|
||||||
[Constructor(DOMString url, optional /*(*/DOMString /*or DOMString[])*/ protocols)]
|
[Constructor(DOMString url, optional (DOMString or sequence<DOMString>) protocols)]
|
||||||
interface WebSocket : EventTarget {
|
interface WebSocket : EventTarget {
|
||||||
readonly attribute DOMString url;
|
readonly attribute DOMString url;
|
||||||
//ready state
|
//ready state
|
||||||
|
|
|
@ -7,6 +7,7 @@ use dom::bindings::codegen::Bindings::BlobBinding::BlobMethods;
|
||||||
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
||||||
use dom::bindings::codegen::Bindings::WebSocketBinding;
|
use dom::bindings::codegen::Bindings::WebSocketBinding;
|
||||||
use dom::bindings::codegen::Bindings::WebSocketBinding::{BinaryType, WebSocketMethods};
|
use dom::bindings::codegen::Bindings::WebSocketBinding::{BinaryType, WebSocketMethods};
|
||||||
|
use dom::bindings::codegen::UnionTypes::StringOrStringSequence::{self, eString, eStringSequence};
|
||||||
use dom::bindings::conversions::{ToJSValConvertible};
|
use dom::bindings::conversions::{ToJSValConvertible};
|
||||||
use dom::bindings::error::{Error, Fallible};
|
use dom::bindings::error::{Error, Fallible};
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
|
@ -31,7 +32,6 @@ use net_traits::MessageData;
|
||||||
use net_traits::hosts::replace_hosts;
|
use net_traits::hosts::replace_hosts;
|
||||||
use net_traits::unwrap_websocket_protocol;
|
use net_traits::unwrap_websocket_protocol;
|
||||||
use net_traits::{WebSocketCommunicate, WebSocketConnectData, WebSocketDomAction, WebSocketNetworkEvent};
|
use net_traits::{WebSocketCommunicate, WebSocketConnectData, WebSocketDomAction, WebSocketNetworkEvent};
|
||||||
use ref_slice::ref_slice;
|
|
||||||
use script_thread::ScriptThreadEventCategory::WebSocketEvent;
|
use script_thread::ScriptThreadEventCategory::WebSocketEvent;
|
||||||
use script_thread::{CommonScriptMsg, Runnable};
|
use script_thread::{CommonScriptMsg, Runnable};
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
|
@ -176,7 +176,7 @@ impl WebSocket {
|
||||||
|
|
||||||
pub fn Constructor(global: GlobalRef,
|
pub fn Constructor(global: GlobalRef,
|
||||||
url: DOMString,
|
url: DOMString,
|
||||||
protocols: Option<DOMString>)
|
protocols: Option<StringOrStringSequence>)
|
||||||
-> Fallible<Root<WebSocket>> {
|
-> Fallible<Root<WebSocket>> {
|
||||||
// Step 1.
|
// Step 1.
|
||||||
let resource_url = try!(Url::parse(&url).map_err(|_| Error::Syntax));
|
let resource_url = try!(Url::parse(&url).map_err(|_| Error::Syntax));
|
||||||
|
@ -193,9 +193,13 @@ impl WebSocket {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 4.
|
// Step 4.
|
||||||
let protocols: &[DOMString] = protocols
|
let protocols = match protocols {
|
||||||
.as_ref()
|
Some(eString(string)) => vec![String::from(string)],
|
||||||
.map_or(&[], |ref string| ref_slice(string));
|
Some(eStringSequence(sequence)) => {
|
||||||
|
sequence.into_iter().map(String::from).collect()
|
||||||
|
},
|
||||||
|
_ => Vec::new(),
|
||||||
|
};
|
||||||
|
|
||||||
// Step 5.
|
// Step 5.
|
||||||
for (i, protocol) in protocols.iter().enumerate() {
|
for (i, protocol) in protocols.iter().enumerate() {
|
||||||
|
@ -223,7 +227,6 @@ impl WebSocket {
|
||||||
let address = Trusted::new(ws.r(), global.networking_thread_source());
|
let address = Trusted::new(ws.r(), global.networking_thread_source());
|
||||||
|
|
||||||
let origin = global.get_url().serialize();
|
let origin = global.get_url().serialize();
|
||||||
let protocols: Vec<String> = protocols.iter().map(|x| String::from(x.clone())).collect();
|
|
||||||
|
|
||||||
let connect_data = WebSocketConnectData {
|
let connect_data = WebSocketConnectData {
|
||||||
resource_url: resource_url.clone(),
|
resource_url: resource_url.clone(),
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
[Create-Secure-valid-url-array-protocols.htm]
|
|
||||||
type: testharness
|
|
||||||
expected: TIMEOUT
|
|
||||||
[W3C WebSocket API - Create Secure WebSocket - Pass a valid URL and array of protocol strings - Connection should be opened]
|
|
||||||
expected: NOTRUN
|
|
||||||
|
|
||||||
[W3C WebSocket API - Create Secure WebSocket - Pass a valid URL and array of protocol strings - Connection should be closed]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[Create-protocols-repeated.htm]
|
|
||||||
type: testharness
|
|
||||||
[W3C WebSocket API - Create WebSocket - Pass a valid URL and an array of protocol strings with repeated values - SYNTAX_ERR is thrown]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
[Create-valid-url-array-protocols.htm]
|
|
||||||
type: testharness
|
|
||||||
expected: TIMEOUT
|
|
||||||
[W3C WebSocket API - Create WebSocket - Pass a valid URL and array of protocol strings - Connection should be opened]
|
|
||||||
expected: NOTRUN
|
|
||||||
|
|
||||||
[W3C WebSocket API - Create WebSocket - Pass a valid URL and array of protocol strings - Connection should be closed]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
[022.html]
|
|
||||||
type: testharness
|
|
||||||
expected: TIMEOUT
|
|
||||||
[WebSockets: protocol array]
|
|
||||||
expected: TIMEOUT
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue