mirror of
https://github.com/servo/servo.git
synced 2025-06-11 01:50:10 +00:00
Implement a basic WebSocket interface.
This commit is contained in:
parent
10f8fe0067
commit
b1d6041420
6 changed files with 79 additions and 36 deletions
|
@ -38,6 +38,7 @@ pub enum ListenerPhase {
|
||||||
#[jstraceable]
|
#[jstraceable]
|
||||||
pub enum EventTargetTypeId {
|
pub enum EventTargetTypeId {
|
||||||
NodeTargetTypeId(NodeTypeId),
|
NodeTargetTypeId(NodeTypeId),
|
||||||
|
WebSocketTypeId,
|
||||||
WindowTypeId,
|
WindowTypeId,
|
||||||
WorkerTypeId,
|
WorkerTypeId,
|
||||||
WorkerGlobalScopeTypeId(WorkerGlobalScopeId),
|
WorkerGlobalScopeTypeId(WorkerGlobalScopeId),
|
||||||
|
|
27
components/script/dom/webidls/WebSocket.webidl
Normal file
27
components/script/dom/webidls/WebSocket.webidl
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
[Constructor(DOMString url)]
|
||||||
|
interface WebSocket : EventTarget {
|
||||||
|
readonly attribute DOMString url;
|
||||||
|
//attribute DOMString port;
|
||||||
|
//attribute DOMString host;
|
||||||
|
//ready state
|
||||||
|
const unsigned short CONNECTING = 0;
|
||||||
|
const unsigned short OPEN = 1;
|
||||||
|
const unsigned short CLOSING = 2;
|
||||||
|
const unsigned short CLOSED = 3;
|
||||||
|
//readonly attribute unsigned short readyState;
|
||||||
|
//readonly attribute unsigned long bufferedAmount;
|
||||||
|
//networking
|
||||||
|
//attribute EventHandler onopen;
|
||||||
|
//attribute EventHandler onerror;
|
||||||
|
//attribute EventHandler onclose;
|
||||||
|
//readonly attribute DOMString extensions;
|
||||||
|
//readonly attribute DOMString protocol;
|
||||||
|
//void send(USVString data);
|
||||||
|
//void send(Blob data);
|
||||||
|
//void send(ArrayBuffer data);
|
||||||
|
//void send(ArrayBufferView data);
|
||||||
|
};
|
49
components/script/dom/websocket.rs
Normal file
49
components/script/dom/websocket.rs
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use dom::bindings::codegen::Bindings::WebSocketBinding;
|
||||||
|
use dom::bindings::codegen::Bindings::WebSocketBinding::WebSocketMethods;
|
||||||
|
use dom::bindings::error::Fallible;
|
||||||
|
use dom::bindings::global::GlobalRef;
|
||||||
|
use dom::bindings::js::{Temporary, JSRef};
|
||||||
|
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||||
|
use dom::eventtarget::{EventTarget, WebSocketTypeId};
|
||||||
|
use servo_util::str::DOMString;
|
||||||
|
|
||||||
|
#[dom_struct]
|
||||||
|
pub struct WebSocket {
|
||||||
|
eventtarget: EventTarget,
|
||||||
|
url: DOMString
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WebSocket {
|
||||||
|
pub fn new_inherited(url: DOMString) -> WebSocket {
|
||||||
|
WebSocket {
|
||||||
|
eventtarget: EventTarget::new_inherited(WebSocketTypeId),
|
||||||
|
url: url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new(global: &GlobalRef, url: DOMString) -> Temporary<WebSocket> {
|
||||||
|
reflect_dom_object(box WebSocket::new_inherited(url),
|
||||||
|
global,
|
||||||
|
WebSocketBinding::Wrap)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn Constructor(global: &GlobalRef, url: DOMString) -> Fallible<Temporary<WebSocket>> {
|
||||||
|
Ok(WebSocket::new(global, url))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Reflectable for WebSocket {
|
||||||
|
fn reflector<'a>(&'a self) -> &'a Reflector {
|
||||||
|
self.eventtarget.reflector()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> WebSocketMethods for JSRef<'a, WebSocket> {
|
||||||
|
fn Url(self) -> DOMString {
|
||||||
|
self.url.clone()
|
||||||
|
}
|
||||||
|
}
|
|
@ -203,6 +203,7 @@ pub mod dom {
|
||||||
pub mod urlsearchparams;
|
pub mod urlsearchparams;
|
||||||
pub mod validitystate;
|
pub mod validitystate;
|
||||||
pub mod virtualmethods;
|
pub mod virtualmethods;
|
||||||
|
pub mod websocket;
|
||||||
pub mod window;
|
pub mod window;
|
||||||
pub mod worker;
|
pub mod worker;
|
||||||
pub mod workerglobalscope;
|
pub mod workerglobalscope;
|
||||||
|
|
|
@ -164,6 +164,7 @@ var interfaceNamesInGlobalScope = [
|
||||||
"UIEvent",
|
"UIEvent",
|
||||||
"URLSearchParams",
|
"URLSearchParams",
|
||||||
"ValidityState",
|
"ValidityState",
|
||||||
|
"WebSocket",
|
||||||
"Window",
|
"Window",
|
||||||
"Worker",
|
"Worker",
|
||||||
"WorkerGlobalScope", // #2823
|
"WorkerGlobalScope", // #2823
|
||||||
|
|
|
@ -9228,45 +9228,9 @@
|
||||||
[EventSource interface: operation close()]
|
[EventSource interface: operation close()]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[WebSocket interface: existence and properties of interface object]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[WebSocket interface object length]
|
[WebSocket interface object length]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[WebSocket interface: existence and properties of interface prototype object]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[WebSocket interface: existence and properties of interface prototype object\'s "constructor" property]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[WebSocket interface: attribute url]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[WebSocket interface: constant CONNECTING on interface object]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[WebSocket interface: constant CONNECTING on interface prototype object]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[WebSocket interface: constant OPEN on interface object]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[WebSocket interface: constant OPEN on interface prototype object]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[WebSocket interface: constant CLOSING on interface object]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[WebSocket interface: constant CLOSING on interface prototype object]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[WebSocket interface: constant CLOSED on interface object]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[WebSocket interface: constant CLOSED on interface prototype object]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[WebSocket interface: attribute readyState]
|
[WebSocket interface: attribute readyState]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue