Skip to content

Commit

Permalink
Make WebSocket constructor take (DOMString or sequence<DOMString>)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsanders committed Jan 18, 2016
1 parent eb7b930 commit 0bffffd
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 36 deletions.
2 changes: 1 addition & 1 deletion components/script/dom/webidls/WebSocket.webidl
Expand Up @@ -6,7 +6,7 @@

enum BinaryType { "blob", "arraybuffer" };

[Constructor(DOMString url, optional /*(*/DOMString /*or DOMString[])*/ protocols)]
[Constructor(DOMString url, optional (DOMString or sequence<DOMString>) protocols)]
interface WebSocket : EventTarget {
readonly attribute DOMString url;
//ready state
Expand Down
15 changes: 9 additions & 6 deletions components/script/dom/websocket.rs
Expand Up @@ -7,6 +7,7 @@ use dom::bindings::codegen::Bindings::BlobBinding::BlobMethods;
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
use dom::bindings::codegen::Bindings::WebSocketBinding;
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::error::{Error, Fallible};
use dom::bindings::global::GlobalRef;
Expand All @@ -31,7 +32,6 @@ use net_traits::MessageData;
use net_traits::hosts::replace_hosts;
use net_traits::unwrap_websocket_protocol;
use net_traits::{WebSocketCommunicate, WebSocketConnectData, WebSocketDomAction, WebSocketNetworkEvent};
use ref_slice::ref_slice;
use script_thread::ScriptThreadEventCategory::WebSocketEvent;
use script_thread::{CommonScriptMsg, Runnable};
use std::borrow::ToOwned;
Expand Down Expand Up @@ -176,7 +176,7 @@ impl WebSocket {

pub fn Constructor(global: GlobalRef,
url: DOMString,
protocols: Option<DOMString>)
protocols: Option<StringOrStringSequence>)
-> Fallible<Root<WebSocket>> {
// Step 1.
let resource_url = try!(Url::parse(&url).map_err(|_| Error::Syntax));
Expand All @@ -193,9 +193,13 @@ impl WebSocket {
}

// Step 4.
let protocols: &[DOMString] = protocols
.as_ref()
.map_or(&[], |ref string| ref_slice(string));
let protocols = match protocols {
Some(eString(string)) => vec![String::from(string)],
Some(eStringSequence(sequence)) => {
sequence.into_iter().map(String::from).collect()
},
_ => Vec::new(),
};

// Step 5.
for (i, protocol) in protocols.iter().enumerate() {
Expand Down Expand Up @@ -223,7 +227,6 @@ impl WebSocket {
let address = Trusted::new(ws.r(), global.networking_thread_source());

let origin = global.get_url().serialize();
let protocols: Vec<String> = protocols.iter().map(|x| String::from(x.clone())).collect();

let connect_data = WebSocketConnectData {
resource_url: resource_url.clone(),
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions tests/wpt/metadata/websockets/constructor/022.html.ini

This file was deleted.

0 comments on commit 0bffffd

Please sign in to comment.