Skip to content
Permalink
Browse files

Update js.

Fixes #15553.
  • Loading branch information
Ms2ger committed Feb 15, 2017
1 parent 9702d69 commit 67c572af37ac6dd170414b3dfc34dfdf21da8015

Some generated files are not rendered by default. Learn more.

@@ -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;
@@ -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()));

@@ -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;
@@ -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());
}

@@ -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]
@@ -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())
}
@@ -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;

@@ -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
@@ -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;

@@ -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());
}

@@ -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;

@@ -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 {
@@ -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]
@@ -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());
}

@@ -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};
@@ -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());

0 comments on commit 67c572a

Please sign in to comment.
You can’t perform that action at this time.