Skip to content

Commit

Permalink
Update js.
Browse files Browse the repository at this point in the history
Fixes #15553.
  • Loading branch information
Ms2ger committed Feb 15, 2017
1 parent 9702d69 commit 67c572a
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions components/script/dom/filereader.rs
Expand Up @@ -27,7 +27,7 @@ use js::jsapi::Heap;
use js::jsapi::JSAutoCompartment;
use js::jsapi::JSContext;
use js::jsval::{self, JSVal};
use js::typedarray::ArrayBuffer;
use js::typedarray::{ArrayBuffer, CreateWith};
use rustc_serialize::base64::{CharacterSet, Config, Newline, ToBase64};
use script_thread::RunnableWrapper;
use servo_atoms::Atom;
Expand Down Expand Up @@ -269,7 +269,7 @@ impl FileReader {
cx: *mut JSContext, _: ReadMetaData, bytes: &[u8]) {
unsafe {
rooted!(in(cx) let mut array_buffer = ptr::null_mut());
assert!(ArrayBuffer::create(cx, bytes.len() as u32, Some(bytes), array_buffer.handle_mut()).is_ok());
assert!(ArrayBuffer::create(cx, CreateWith::Slice(bytes), array_buffer.handle_mut()).is_ok());

*result.borrow_mut() = Some(FileReaderResult::ArrayBuffer(Heap::default()));

Expand Down
15 changes: 11 additions & 4 deletions components/script/dom/imagedata.rs
Expand Up @@ -11,7 +11,7 @@ use dom::globalscope::GlobalScope;
use euclid::size::Size2D;
use js::jsapi::{Heap, JSContext, JSObject};
use js::rust::Runtime;
use js::typedarray::Uint8ClampedArray;
use js::typedarray::{Uint8ClampedArray, CreateWith};
use std::default::Default;
use std::ptr;
use std::vec::Vec;
Expand All @@ -26,19 +26,26 @@ pub struct ImageData {

impl ImageData {
#[allow(unsafe_code)]
pub fn new(global: &GlobalScope, width: u32, height: u32, data: Option<Vec<u8>>) -> Root<ImageData> {
pub fn new(global: &GlobalScope, width: u32, height: u32, mut data: Option<Vec<u8>>) -> Root<ImageData> {
let imagedata = box ImageData {
reflector_: Reflector::new(),
width: width,
height: height,
data: Heap::default(),
};
let len = width * height * 4;

unsafe {
let cx = global.get_cx();
rooted!(in (cx) let mut js_object = ptr::null_mut());
let data = data.as_ref().map(|d| &d[..]);
Uint8ClampedArray::create(cx, width * height * 4, data, js_object.handle_mut()).unwrap();
let data = match data {
Some(ref mut d) => {
d.resize(len as usize, 0);
CreateWith::Slice(&d[..])
},
None => CreateWith::Length(len),
};
Uint8ClampedArray::create(cx, data, js_object.handle_mut()).unwrap();
(*imagedata).data.set(js_object.get());
}

Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/textencoder.rs
Expand Up @@ -14,7 +14,7 @@ use encoding::EncoderTrap;
use encoding::Encoding;
use encoding::all::UTF_8;
use js::jsapi::{JSContext, JSObject};
use js::typedarray::Uint8Array;
use js::typedarray::{Uint8Array, CreateWith};
use std::ptr;

#[dom_struct]
Expand Down Expand Up @@ -53,7 +53,7 @@ impl TextEncoderMethods for TextEncoder {
let encoded = UTF_8.encode(&input.0, EncoderTrap::Strict).unwrap();

rooted!(in(cx) let mut js_object = ptr::null_mut());
assert!(Uint8Array::create(cx, encoded.len() as u32, Some(encoded.as_slice()), js_object.handle_mut()).is_ok());
assert!(Uint8Array::create(cx, CreateWith::Slice(&encoded), js_object.handle_mut()).is_ok());

NonZero::new(js_object.get())
}
Expand Down
5 changes: 2 additions & 3 deletions components/script/dom/vreyeparameters.rs
Expand Up @@ -11,7 +11,7 @@ use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::globalscope::GlobalScope;
use dom::vrfieldofview::VRFieldOfView;
use js::jsapi::{Heap, JSContext, JSObject};
use js::typedarray::Float32Array;
use js::typedarray::{Float32Array, CreateWith};
use std::default::Default;
use webvr_traits::WebVREyeParameters;

Expand Down Expand Up @@ -40,8 +40,7 @@ impl VREyeParameters {

unsafe {
let _ = Float32Array::create(global.get_cx(),
result.parameters.borrow().offset.len() as u32,
Some(&result.parameters.borrow().offset),
CreateWith::Slice(&result.parameters.borrow().offset),
result.offset.handle_mut());
}
result
Expand Down
10 changes: 5 additions & 5 deletions components/script/dom/vrframedata.rs
Expand Up @@ -13,7 +13,7 @@ use dom::globalscope::GlobalScope;
use dom::vrpose::VRPose;
use dom::window::Window;
use js::jsapi::{Heap, JSContext, JSObject};
use js::typedarray::Float32Array;
use js::typedarray::{Float32Array, CreateWith};
use std::cell::Cell;
use webvr_traits::WebVRFrameData;

Expand Down Expand Up @@ -56,13 +56,13 @@ impl VRFrameData {

unsafe {
let ref framedata = *root;
let _ = Float32Array::create(global.get_cx(), matrix.len() as u32, Some(&matrix),
let _ = Float32Array::create(global.get_cx(), CreateWith::Slice(&matrix),
framedata.left_proj.handle_mut());
let _ = Float32Array::create(global.get_cx(), matrix.len() as u32, Some(&matrix),
let _ = Float32Array::create(global.get_cx(), CreateWith::Slice(&matrix),
framedata.left_view.handle_mut());
let _ = Float32Array::create(global.get_cx(), matrix.len() as u32, Some(&matrix),
let _ = Float32Array::create(global.get_cx(), CreateWith::Slice(&matrix),
framedata.right_proj.handle_mut());
let _ = Float32Array::create(global.get_cx(), matrix.len() as u32, Some(&matrix),
let _ = Float32Array::create(global.get_cx(), CreateWith::Slice(&matrix),
framedata.right_view.handle_mut());
}

Expand Down
6 changes: 3 additions & 3 deletions components/script/dom/vrpose.rs
Expand Up @@ -10,7 +10,7 @@ use dom::bindings::js::Root;
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
use dom::globalscope::GlobalScope;
use js::jsapi::{Heap, JSContext, JSObject};
use js::typedarray::Float32Array;
use js::typedarray::{Float32Array, CreateWith};
use std::ptr;
use webvr_traits::webvr;

Expand All @@ -31,9 +31,9 @@ unsafe fn update_or_create_typed_array(cx: *mut JSContext,
dst: &DOMRefCell<Heap<*mut JSObject>>) {
let dst = dst.borrow();
match src {
Some(ref data) => {
Some(data) => {
if dst.get().is_null() {
let _ = Float32Array::create(cx, data.len() as u32, src, dst.handle_mut());
let _ = Float32Array::create(cx, CreateWith::Slice(data), dst.handle_mut());
} else {
typedarray!(in(cx) let array: Float32Array = dst.get());
if let Ok(mut array) = array {
Expand Down
6 changes: 3 additions & 3 deletions components/script/dom/vrstageparameters.rs
Expand Up @@ -11,7 +11,7 @@ use dom::bindings::num::Finite;
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
use dom::globalscope::GlobalScope;
use js::jsapi::{Heap, JSContext, JSObject};
use js::typedarray::Float32Array;
use js::typedarray::{Float32Array, CreateWith};
use webvr_traits::WebVRStageParameters;

#[dom_struct]
Expand All @@ -33,10 +33,10 @@ impl VRStageParameters {
parameters: DOMRefCell::new(parameters),
transform: Heap::default()
};
// XXX unsound!
unsafe {
let _ = Float32Array::create(global.get_cx(),
stage.parameters.borrow().sitting_to_standing_transform.len() as u32,
Some(&stage.parameters.borrow().sitting_to_standing_transform),
CreateWith::Slice(&stage.parameters.borrow().sitting_to_standing_transform),
stage.transform.handle_mut());
}

Expand Down
5 changes: 2 additions & 3 deletions components/script/dom/websocket.rs
Expand Up @@ -27,7 +27,7 @@ use hyper_serde::Serde;
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use js::jsapi::JSAutoCompartment;
use js::jsval::UndefinedValue;
use js::typedarray::ArrayBuffer;
use js::typedarray::{ArrayBuffer, CreateWith};
use net_traits::{WebSocketCommunicate, WebSocketConnectData, WebSocketDomAction, WebSocketNetworkEvent};
use net_traits::CookieSource::HTTP;
use net_traits::CoreResourceMsg::{SetCookiesForUrl, WebsocketConnect};
Expand Down Expand Up @@ -609,8 +609,7 @@ impl Runnable for MessageReceivedTask {
BinaryType::Arraybuffer => {
rooted!(in(cx) let mut array_buffer = ptr::null_mut());
assert!(ArrayBuffer::create(cx,
data.len() as u32,
Some(data.as_slice()),
CreateWith::Slice(&data),
array_buffer.handle_mut())
.is_ok());

Expand Down

0 comments on commit 67c572a

Please sign in to comment.