Auto merge of #20426 - christianpoveda:issue_20347, r=jdm

Websockets send typed arrays now

<!-- Please describe your changes on the following line: -->

r? jdm

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #20347 (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20426)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-03-25 14:07:15 -04:00 committed by GitHub
commit 36a41722b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 32 additions and 90 deletions

View file

@ -30,6 +30,6 @@ interface WebSocket : EventTarget {
attribute BinaryType binaryType;
[Throws] void send(USVString data);
[Throws] void send(Blob data);
//void send(ArrayBuffer data);
//void send(ArrayBufferView data);
[Throws] void send(ArrayBuffer data);
[Throws] void send(ArrayBufferView data);
};

View file

@ -24,7 +24,8 @@ use dom_struct::dom_struct;
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use js::jsapi::{JSAutoCompartment, JSObject};
use js::jsval::UndefinedValue;
use js::typedarray::{ArrayBuffer, CreateWith};
use js::rust::CustomAutoRooterGuard;
use js::typedarray::{ArrayBuffer, ArrayBufferView, CreateWith};
use net_traits::{CoreResourceMsg, FetchChannels};
use net_traits::{WebSocketDomAction, WebSocketNetworkEvent};
use net_traits::MessageData;
@ -350,6 +351,34 @@ impl WebSocketMethods for WebSocket {
Ok(())
}
// https://html.spec.whatwg.org/multipage/#dom-websocket-send
fn Send__(&self, array: CustomAutoRooterGuard<ArrayBuffer>) -> ErrorResult {
let bytes = array.to_vec();
let data_byte_len = bytes.len();
let send_data = self.send_impl(data_byte_len as u64)?;
if send_data {
let mut other_sender = self.sender.borrow_mut();
let my_sender = other_sender.as_mut().unwrap();
let _ = my_sender.send(WebSocketDomAction::SendMessage(MessageData::Binary(bytes)));
}
Ok(())
}
// https://html.spec.whatwg.org/multipage/#dom-websocket-send
fn Send___(&self, array: CustomAutoRooterGuard<ArrayBufferView>) -> ErrorResult {
let bytes = array.to_vec();
let data_byte_len = bytes.len();
let send_data = self.send_impl(data_byte_len as u64)?;
if send_data {
let mut other_sender = self.sender.borrow_mut();
let my_sender = other_sender.as_mut().unwrap();
let _ = my_sender.send(WebSocketDomAction::SendMessage(MessageData::Binary(bytes)));
}
Ok(())
}
// https://html.spec.whatwg.org/multipage/#dom-websocket-close
fn Close(&self, code: Option<u16>, reason: Option<USVString>) -> ErrorResult {
if let Some(code) = code {

View file

@ -1,9 +0,0 @@
[Secure-Send-binary-arraybufferview-float32.htm]
type: testharness
expected: TIMEOUT
[W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Float32Array - Message should be received]
expected: FAIL
[W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Float32Array - Connection should be closed]
expected: NOTRUN

View file

@ -1,12 +0,0 @@
[Send-binary-65K-arraybuffer.htm]
type: testharness
expected: TIMEOUT
[W3C WebSocket API - Send 65K binary data on a WebSocket - ArrayBuffer - Connection should be opened]
expected: FAIL
[W3C WebSocket API - Send 65K binary data on a WebSocket - ArrayBuffer - Message should be received]
expected: FAIL
[W3C WebSocket API - Send 65K binary data on a WebSocket - ArrayBuffer - Connection should be closed]
expected: NOTRUN

View file

@ -1,12 +0,0 @@
[Send-binary-arraybuffer.htm]
type: testharness
expected: TIMEOUT
[W3C WebSocket API - Send binary data on a WebSocket - ArrayBuffer - Connection should be opened]
expected: FAIL
[W3C WebSocket API - Send binary data on a WebSocket - ArrayBuffer - Message should be received]
expected: FAIL
[W3C WebSocket API - Send binary data on a WebSocket - ArrayBuffer - Connection should be closed]
expected: NOTRUN

View file

@ -1,9 +0,0 @@
[Send-binary-arraybufferview-int16-offset.htm]
type: testharness
expected: TIMEOUT
[W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Int16Array with offset - Message should be received]
expected: FAIL
[W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Int16Array with offset - Connection should be closed]
expected: NOTRUN

View file

@ -1,9 +0,0 @@
[Send-binary-arraybufferview-int8.htm]
type: testharness
expected: TIMEOUT
[W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Int8Array - Message should be received]
expected: FAIL
[W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Int8Array - Connection should be closed]
expected: NOTRUN

View file

@ -1,9 +1,3 @@
[001.html]
type: testharness
[WebSockets: Send/Receive blob, blob size less than network array buffer]
expected: FAIL
[001.html?wss]
type: testharness
expected: TIMEOUT

View file

@ -1,9 +1,3 @@
[002.html]
type: testharness
[WebSockets: Send/Receive blob, blob size greater than network array buffer]
expected: FAIL
[002.html?wss]
type: testharness
[WebSockets: Send/Receive blob, blob size greater than network array buffer]

View file

@ -1,9 +1,3 @@
[004.html]
type: testharness
[WebSockets: Send/Receive ArrayBuffer, size greater than network array buffer]
expected: FAIL
[004.html?wss]
type: testharness
[WebSockets: Send/Receive ArrayBuffer, size greater than network array buffer]

View file

@ -1,9 +1,3 @@
[005.html]
type: testharness
[WebSockets: Send/Receive ArrayBuffer, size less than network array buffer]
expected: FAIL
[005.html?wss]
type: testharness
expected: TIMEOUT

View file

@ -1,9 +1,3 @@
[bufferedAmount-arraybuffer.html]
type: testharness
[WebSockets: bufferedAmount for ArrayBuffer]
expected: FAIL
[bufferedAmount-arraybuffer.html?wss]
type: testharness
expected: TIMEOUT

View file

@ -1,9 +1,3 @@
[bufferedAmount-blob.html]
type: testharness
[WebSockets: bufferedAmount for blob]
expected: FAIL
[bufferedAmount-blob.html?wss]
type: testharness
expected: TIMEOUT