mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Remove global field from WebSocket
This commit is contained in:
parent
25814021ea
commit
fbe9107614
1 changed files with 7 additions and 10 deletions
|
@ -9,7 +9,7 @@ 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::conversions::{ToJSValConvertible};
|
use dom::bindings::conversions::{ToJSValConvertible};
|
||||||
use dom::bindings::error::{Error, Fallible};
|
use dom::bindings::error::{Error, Fallible};
|
||||||
use dom::bindings::global::{GlobalField, GlobalRef};
|
use dom::bindings::global::{GlobalRef, global_root_from_reflector};
|
||||||
use dom::bindings::inheritance::Castable;
|
use dom::bindings::inheritance::Castable;
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
use dom::bindings::refcounted::Trusted;
|
use dom::bindings::refcounted::Trusted;
|
||||||
|
@ -136,7 +136,6 @@ mod close_code {
|
||||||
pub struct WebSocket {
|
pub struct WebSocket {
|
||||||
eventtarget: EventTarget,
|
eventtarget: EventTarget,
|
||||||
url: Url,
|
url: Url,
|
||||||
global: GlobalField,
|
|
||||||
ready_state: Cell<WebSocketRequestState>,
|
ready_state: Cell<WebSocketRequestState>,
|
||||||
buffered_amount: Cell<u64>,
|
buffered_amount: Cell<u64>,
|
||||||
clearing_buffer: Cell<bool>, //Flag to tell if there is a running thread to clear buffered_amount
|
clearing_buffer: Cell<bool>, //Flag to tell if there is a running thread to clear buffered_amount
|
||||||
|
@ -152,11 +151,10 @@ pub struct WebSocket {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WebSocket {
|
impl WebSocket {
|
||||||
fn new_inherited(global: GlobalRef, url: Url) -> WebSocket {
|
fn new_inherited(url: Url) -> WebSocket {
|
||||||
WebSocket {
|
WebSocket {
|
||||||
eventtarget: EventTarget::new_inherited(),
|
eventtarget: EventTarget::new_inherited(),
|
||||||
url: url,
|
url: url,
|
||||||
global: GlobalField::from_rooted(&global),
|
|
||||||
ready_state: Cell::new(WebSocketRequestState::Connecting),
|
ready_state: Cell::new(WebSocketRequestState::Connecting),
|
||||||
buffered_amount: Cell::new(0),
|
buffered_amount: Cell::new(0),
|
||||||
clearing_buffer: Cell::new(false),
|
clearing_buffer: Cell::new(false),
|
||||||
|
@ -169,11 +167,10 @@ impl WebSocket {
|
||||||
binary_type: Cell::new(BinaryType::Blob),
|
binary_type: Cell::new(BinaryType::Blob),
|
||||||
protocol: DOMRefCell::new("".to_owned()),
|
protocol: DOMRefCell::new("".to_owned()),
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new(global: GlobalRef, url: Url) -> Root<WebSocket> {
|
fn new(global: GlobalRef, url: Url) -> Root<WebSocket> {
|
||||||
reflect_dom_object(box WebSocket::new_inherited(global, url),
|
reflect_dom_object(box WebSocket::new_inherited(url),
|
||||||
global, WebSocketBinding::Wrap)
|
global, WebSocketBinding::Wrap)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,7 +292,7 @@ impl WebSocket {
|
||||||
WebSocketRequestState::Closing | WebSocketRequestState::Closed => true,
|
WebSocketRequestState::Closing | WebSocketRequestState::Closed => true,
|
||||||
};
|
};
|
||||||
|
|
||||||
let global = self.global.root();
|
let global = global_root_from_reflector(self);
|
||||||
let chan = global.r().networking_thread_source();
|
let chan = global.r().networking_thread_source();
|
||||||
let address = Trusted::new(self, chan.clone());
|
let address = Trusted::new(self, chan.clone());
|
||||||
|
|
||||||
|
@ -463,7 +460,7 @@ struct ConnectionEstablishedTask {
|
||||||
impl Runnable for ConnectionEstablishedTask {
|
impl Runnable for ConnectionEstablishedTask {
|
||||||
fn handler(self: Box<Self>) {
|
fn handler(self: Box<Self>) {
|
||||||
let ws = self.addr.root();
|
let ws = self.addr.root();
|
||||||
let global = ws.global.root();
|
let global = global_root_from_reflector(ws.r());
|
||||||
|
|
||||||
// Step 1: Protocols.
|
// Step 1: Protocols.
|
||||||
if !self.protocols.is_empty() && self.headers.get::<WebSocketProtocol>().is_none() {
|
if !self.protocols.is_empty() && self.headers.get::<WebSocketProtocol>().is_none() {
|
||||||
|
@ -522,7 +519,7 @@ impl Runnable for CloseTask {
|
||||||
fn handler(self: Box<Self>) {
|
fn handler(self: Box<Self>) {
|
||||||
let ws = self.addr.root();
|
let ws = self.addr.root();
|
||||||
let ws = ws.r();
|
let ws = ws.r();
|
||||||
let global = ws.global.root();
|
let global = global_root_from_reflector(ws);
|
||||||
ws.ready_state.set(WebSocketRequestState::Closed);
|
ws.ready_state.set(WebSocketRequestState::Closed);
|
||||||
//If failed or full, fire error event
|
//If failed or full, fire error event
|
||||||
if ws.failed.get() || ws.full.get() {
|
if ws.failed.get() || ws.full.get() {
|
||||||
|
@ -568,7 +565,7 @@ impl Runnable for MessageReceivedTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 2-5.
|
// Step 2-5.
|
||||||
let global = ws.global.root();
|
let global = global_root_from_reflector(ws.r());
|
||||||
// global.get_cx() returns a valid `JSContext` pointer, so this is safe.
|
// global.get_cx() returns a valid `JSContext` pointer, so this is safe.
|
||||||
unsafe {
|
unsafe {
|
||||||
let cx = global.r().get_cx();
|
let cx = global.r().get_cx();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue