mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #14718 - dpyro:websocket-typed-arrays, r=jdm
Rewrote websocket array buffer handling to typed array API <!-- Please describe your changes on the following line: -➜ Replaced existing code for handling `BinaryType::Arraybuffer` from `JS_NewArrayBuffer` to `Uint8Array::create`. --- <!-- 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 #14675 (github issue number if applicable). <!-- Either: --> - [X] These changes do not require tests because they replace an existing implementation <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> I am not certain the test suite will adequately verify my implementation as I am not familiar with the architecture. It compiles and passes the current tests. <!-- 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/14718) <!-- Reviewable:end -->
This commit is contained in:
commit
0f600db3ae
1 changed files with 9 additions and 9 deletions
|
@ -25,10 +25,9 @@ use dom::urlhelper::UrlHelper;
|
|||
use hyper;
|
||||
use hyper_serde::Serde;
|
||||
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
|
||||
use js::jsapi::{JS_GetArrayBufferData, JS_NewArrayBuffer};
|
||||
use js::jsapi::JSAutoCompartment;
|
||||
use js::jsval::UndefinedValue;
|
||||
use libc::{uint32_t, uint8_t};
|
||||
use js::typedarray::ArrayBuffer;
|
||||
use net_traits::{WebSocketCommunicate, WebSocketConnectData, WebSocketDomAction, WebSocketNetworkEvent};
|
||||
use net_traits::CookieSource::HTTP;
|
||||
use net_traits::CoreResourceMsg::{SetCookiesForUrl, WebsocketConnect};
|
||||
|
@ -608,13 +607,14 @@ impl Runnable for MessageReceivedTask {
|
|||
blob.to_jsval(cx, message.handle_mut());
|
||||
}
|
||||
BinaryType::Arraybuffer => {
|
||||
let len = data.len() as uint32_t;
|
||||
let buf = JS_NewArrayBuffer(cx, len);
|
||||
let mut is_shared = false;
|
||||
let buf_data: *mut uint8_t = JS_GetArrayBufferData(buf, &mut is_shared, ptr::null());
|
||||
assert!(!is_shared);
|
||||
ptr::copy_nonoverlapping(data.as_ptr(), buf_data, len as usize);
|
||||
buf.to_jsval(cx, message.handle_mut());
|
||||
rooted!(in(cx) let mut array_buffer = ptr::null_mut());
|
||||
assert!(ArrayBuffer::create(cx,
|
||||
data.len() as u32,
|
||||
Some(data.as_slice()),
|
||||
array_buffer.handle_mut())
|
||||
.is_ok());
|
||||
|
||||
(*array_buffer).to_jsval(cx, message.handle_mut());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue