diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2018-03-25 14:07:15 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-25 14:07:15 -0400 |
commit | 36a41722b6b93be6e500b4fc0debfa9b5d2ac7bf (patch) | |
tree | 45609c6714bc0bd0f484bd7c3268a4f88d5a8080 /components/script/dom/websocket.rs | |
parent | 3ce3f39383c8217a30b15d27f3121f96bbe0014d (diff) | |
parent | bff887c5a6d5d1077922db7071fc4246ad8acc22 (diff) | |
download | servo-36a41722b6b93be6e500b4fc0debfa9b5d2ac7bf.tar.gz servo-36a41722b6b93be6e500b4fc0debfa9b5d2ac7bf.zip |
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 -->
Diffstat (limited to 'components/script/dom/websocket.rs')
-rw-r--r-- | components/script/dom/websocket.rs | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/components/script/dom/websocket.rs b/components/script/dom/websocket.rs index 6acb82c863c..c072f4bb010 100644 --- a/components/script/dom/websocket.rs +++ b/components/script/dom/websocket.rs @@ -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 { |