diff options
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | components/script/dom/bindings/trace.rs | 7 | ||||
-rw-r--r-- | components/script/dom/crypto.rs | 9 | ||||
-rw-r--r-- | components/script/dom/imagedata.rs | 10 | ||||
-rw-r--r-- | components/script/dom/textdecoder.rs | 10 | ||||
-rw-r--r-- | components/script/dom/vrframedata.rs | 17 | ||||
-rw-r--r-- | components/script/dom/vrpose.rs | 5 | ||||
-rw-r--r-- | components/script/dom/vrstageparameters.rs | 5 | ||||
-rw-r--r-- | components/script/dom/webglrenderingcontext.rs | 39 |
9 files changed, 59 insertions, 45 deletions
diff --git a/Cargo.lock b/Cargo.lock index 90732048742..1f4f778091e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1285,7 +1285,7 @@ dependencies = [ [[package]] name = "js" version = "0.1.4" -source = "git+https://github.com/servo/rust-mozjs#101c6b6b58e0b7c5ed1ef2b6b676a7497f90df2f" +source = "git+https://github.com/servo/rust-mozjs#a633c9888695af02a539ee95451bf6954458f418" dependencies = [ "cmake 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index 4d38b39d333..794ba061f53 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -58,6 +58,7 @@ use js::glue::{CallObjectTracer, CallValueTracer}; use js::jsapi::{GCTraceKindToAscii, Heap, JSObject, JSTracer, TraceKind}; use js::jsval::JSVal; use js::rust::Runtime; +use js::typedarray::{TypedArray, TypedArrayElement}; use msg::constellation_msg::{FrameId, FrameType, PipelineId}; use net_traits::{Metadata, NetworkError, ReferrerPolicy, ResourceThreads}; use net_traits::filemanager_thread::RelativePos; @@ -153,6 +154,12 @@ pub fn trace_object(tracer: *mut JSTracer, description: &str, obj: &Heap<*mut JS } } +unsafe impl<T: TypedArrayElement> JSTraceable for TypedArray<T> { + unsafe fn trace(&self, trc: *mut JSTracer) { + trace_object(trc, "typed array", self.object()); + } +} + unsafe impl<T: JSTraceable> JSTraceable for Rc<T> { unsafe fn trace(&self, trc: *mut JSTracer) { (**self).trace(trc) diff --git a/components/script/dom/crypto.rs b/components/script/dom/crypto.rs index fc71faa660a..7a8685bc251 100644 --- a/components/script/dom/crypto.rs +++ b/components/script/dom/crypto.rs @@ -9,10 +9,11 @@ use dom::bindings::codegen::Bindings::CryptoBinding::CryptoMethods; use dom::bindings::error::{Error, Fallible}; use dom::bindings::js::Root; use dom::bindings::reflector::{Reflector, reflect_dom_object}; +use dom::bindings::trace::RootedTraceableBox; use dom::globalscope::GlobalScope; use dom_struct::dom_struct; -use js::jsapi::{JSContext, JSObject}; -use js::jsapi::Type; +use js::jsapi::{JSContext, JSObject, Type}; +use js::typedarray::ArrayBufferView; use servo_rand::{ServoRng, Rng}; unsafe_no_jsmanaged_fields!(ServoRng); @@ -42,11 +43,11 @@ impl CryptoMethods for Crypto { #[allow(unsafe_code)] // https://dvcs.w3.org/hg/webcrypto-api/raw-file/tip/spec/Overview.html#Crypto-method-getRandomValues unsafe fn GetRandomValues(&self, - _cx: *mut JSContext, + cx: *mut JSContext, input: *mut JSObject) -> Fallible<NonZero<*mut JSObject>> { assert!(!input.is_null()); - typedarray!(in(_cx) let mut array_buffer_view: ArrayBufferView = input); + let mut array_buffer_view = RootedTraceableBox::new(ArrayBufferView::from(cx, input)); let (array_type, mut data) = match array_buffer_view.as_mut() { Ok(x) => (x.get_array_type(), x.as_mut_slice()), Err(_) => { diff --git a/components/script/dom/imagedata.rs b/components/script/dom/imagedata.rs index d3adb0f3f76..7e43286f118 100644 --- a/components/script/dom/imagedata.rs +++ b/components/script/dom/imagedata.rs @@ -8,6 +8,7 @@ use dom::bindings::codegen::Bindings::ImageDataBinding::ImageDataMethods; use dom::bindings::error::{Fallible, Error}; use dom::bindings::js::Root; use dom::bindings::reflector::{Reflector, reflect_dom_object}; +use dom::bindings::trace::RootedTraceableBox; use dom::globalscope::GlobalScope; use dom_struct::dom_struct; use euclid::size::Size2D; @@ -60,9 +61,10 @@ impl ImageData { // checking jsobject type and verifying (height * width * 4 == jsobject.byte_len()) if let Some(jsobject) = opt_jsobject { let cx = global.get_cx(); - typedarray!(in(cx) let array_res: Uint8ClampedArray = jsobject); - let mut array = try!(array_res + let array_res = Uint8ClampedArray::from(cx, jsobject); + let array = try!(array_res .map_err(|_| Error::Type("Argument to Image data is not an Uint8ClampedArray".to_owned()))); + let mut array = RootedTraceableBox::new(array); let byte_len = array.as_slice().len() as u32; if byte_len % 4 != 0 { @@ -131,8 +133,8 @@ impl ImageData { assert!(!self.data.get().is_null()); let cx = Runtime::get(); assert!(!cx.is_null()); - typedarray!(in(cx) let array: Uint8ClampedArray = self.data.get()); - let vec = array.unwrap().as_slice().to_vec(); + let mut array = RootedTraceableBox::new(Uint8ClampedArray::from(cx, self.data.get())); + let vec = array.as_mut().unwrap().as_slice().to_vec(); vec } } diff --git a/components/script/dom/textdecoder.rs b/components/script/dom/textdecoder.rs index e1b1edc1048..5d25e5c9653 100644 --- a/components/script/dom/textdecoder.rs +++ b/components/script/dom/textdecoder.rs @@ -8,11 +8,13 @@ use dom::bindings::error::{Error, Fallible}; use dom::bindings::js::Root; use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::bindings::str::{DOMString, USVString}; +use dom::bindings::trace::RootedTraceableBox; use dom::globalscope::GlobalScope; use dom_struct::dom_struct; use encoding::label::encoding_from_whatwg_label; use encoding::types::{DecoderTrap, EncodingRef}; use js::jsapi::{JSContext, JSObject}; +use js::typedarray::ArrayBufferView; use std::borrow::ToOwned; #[dom_struct] @@ -78,16 +80,16 @@ impl TextDecoderMethods for TextDecoder { #[allow(unsafe_code)] // https://encoding.spec.whatwg.org/#dom-textdecoder-decode - unsafe fn Decode(&self, _cx: *mut JSContext, input: Option<*mut JSObject>) + unsafe fn Decode(&self, cx: *mut JSContext, input: Option<*mut JSObject>) -> Fallible<USVString> { let input = match input { Some(input) => input, None => return Ok(USVString("".to_owned())), }; - typedarray!(in(_cx) let data_res: ArrayBufferView = input); - let mut data = match data_res { - Ok(data) => data, + let mut data_res = RootedTraceableBox::new(ArrayBufferView::from(cx, input)); + let mut data = match *data_res { + Ok(ref mut data) => data, Err(_) => { return Err(Error::Type("Argument to TextDecoder.decode is not an ArrayBufferView".to_owned())); } diff --git a/components/script/dom/vrframedata.rs b/components/script/dom/vrframedata.rs index 5b153a2a43e..663f7cb7526 100644 --- a/components/script/dom/vrframedata.rs +++ b/components/script/dom/vrframedata.rs @@ -9,6 +9,7 @@ use dom::bindings::error::Fallible; use dom::bindings::js::{JS, Root}; use dom::bindings::num::Finite; use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; +use dom::bindings::trace::RootedTraceableBox; use dom::globalscope::GlobalScope; use dom::vrpose::VRPose; use dom::window::Window; @@ -81,20 +82,20 @@ impl VRFrameData { pub fn update(&self, data: &WebVRFrameData) { unsafe { let cx = self.global().get_cx(); - typedarray!(in(cx) let left_proj_array: Float32Array = self.left_proj.get()); - if let Ok(mut array) = left_proj_array { + let mut left_proj_array = RootedTraceableBox::new(Float32Array::from(cx, self.left_proj.get())); + if let Ok(ref mut array) = *left_proj_array { array.update(&data.left_projection_matrix); } - typedarray!(in(cx) let left_view_array: Float32Array = self.left_view.get()); - if let Ok(mut array) = left_view_array { + let mut left_view_array = RootedTraceableBox::new(Float32Array::from(cx, self.left_view.get())); + if let Ok(ref mut array) = *left_view_array { array.update(&data.left_view_matrix); } - typedarray!(in(cx) let right_proj_array: Float32Array = self.right_proj.get()); - if let Ok(mut array) = right_proj_array { + let mut right_proj_array = RootedTraceableBox::new(Float32Array::from(cx, self.right_proj.get())); + if let Ok(ref mut array) = *right_proj_array { array.update(&data.right_projection_matrix); } - typedarray!(in(cx) let right_view_array: Float32Array = self.right_view.get()); - if let Ok(mut array) = right_view_array { + let mut right_view_array = RootedTraceableBox::new(Float32Array::from(cx, self.right_view.get())); + if let Ok(ref mut array) = *right_view_array { array.update(&data.right_view_matrix); } } diff --git a/components/script/dom/vrpose.rs b/components/script/dom/vrpose.rs index 542059ca799..39bb4929f46 100644 --- a/components/script/dom/vrpose.rs +++ b/components/script/dom/vrpose.rs @@ -7,6 +7,7 @@ use dom::bindings::codegen::Bindings::VRPoseBinding; use dom::bindings::codegen::Bindings::VRPoseBinding::VRPoseMethods; use dom::bindings::js::Root; use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; +use dom::bindings::trace::RootedTraceableBox; use dom::globalscope::GlobalScope; use dom_struct::dom_struct; use js::jsapi::{Heap, JSContext, JSObject}; @@ -34,8 +35,8 @@ unsafe fn update_or_create_typed_array(cx: *mut JSContext, if dst.get().is_null() { 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 { + let mut array = RootedTraceableBox::new(Float32Array::from(cx, dst.get())); + if let Ok(ref mut array) = *array { array.update(data); } } diff --git a/components/script/dom/vrstageparameters.rs b/components/script/dom/vrstageparameters.rs index 0bc319466c3..e9d9ad9c29b 100644 --- a/components/script/dom/vrstageparameters.rs +++ b/components/script/dom/vrstageparameters.rs @@ -9,6 +9,7 @@ use dom::bindings::codegen::Bindings::VRStageParametersBinding::VRStageParameter use dom::bindings::js::Root; use dom::bindings::num::Finite; use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; +use dom::bindings::trace::RootedTraceableBox; use dom::globalscope::GlobalScope; use dom_struct::dom_struct; use js::jsapi::{Heap, JSContext, JSObject}; @@ -54,8 +55,8 @@ impl VRStageParameters { pub fn update(&self, parameters: &WebVRStageParameters) { unsafe { let cx = self.global().get_cx(); - typedarray!(in(cx) let array: Float32Array = self.transform.get()); - if let Ok(mut array) = array { + let mut array = RootedTraceableBox::new(Float32Array::from(cx, self.transform.get())); + if let Ok(ref mut array) = *array { array.update(¶meters.sitting_to_standing_transform); } } diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 5261b96d1c5..e03245695db 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -15,6 +15,7 @@ use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, LayoutJS, MutNullableJS, Root}; use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; use dom::bindings::str::DOMString; +use dom::bindings::trace::RootedTraceableBox; use dom::event::{Event, EventBubbles, EventCancelable}; use dom::globalscope::GlobalScope; use dom::htmlcanvaselement::HTMLCanvasElement; @@ -38,9 +39,10 @@ use dom_struct::dom_struct; use euclid::size::Size2D; use ipc_channel::ipc::{self, IpcSender}; use js::conversions::ConversionBehavior; -use js::jsapi::{JSContext, JSObject, Type, Rooted}; +use js::jsapi::{JSContext, JSObject, Type}; use js::jsval::{BooleanValue, DoubleValue, Int32Value, JSVal, NullValue, UndefinedValue}; -use js::typedarray::{TypedArray, TypedArrayElement, Float32, Int32}; +use js::typedarray::{TypedArray, TypedArrayElement, Float32, Int32, Uint8Array}; +use js::typedarray::{Uint16Array, ArrayBuffer, ArrayBufferView}; use net_traits::image::base::PixelFormat; use net_traits::image_cache_thread::ImageResponse; use offscreen_gl_context::{GLContextAttributes, GLLimits}; @@ -512,8 +514,8 @@ impl WebGLRenderingContext { // if it is UNSIGNED_SHORT_5_6_5, UNSIGNED_SHORT_4_4_4_4, // or UNSIGNED_SHORT_5_5_5_1, a Uint16Array must be supplied. // If the types do not match, an INVALID_OPERATION error is generated. - typedarray!(in(cx) let typedarray_u8: Uint8Array = data); - typedarray!(in(cx) let typedarray_u16: Uint16Array = data); + let typedarray_u8 = RootedTraceableBox::new(Uint8Array::from(cx, data)); + let typedarray_u16 = RootedTraceableBox::new(Uint16Array::from(cx, data)); let received_size = if data.is_null() { element_size } else { @@ -779,15 +781,12 @@ unsafe fn typed_array_or_sequence_to_vec<T>(cx: *mut JSContext, sequence_or_abv: *mut JSObject, config: <T::Element as FromJSValConvertible>::Config) -> Result<Vec<T::Element>, Error> - where T: TypedArrayElement, + where T: TypedArrayElement + 'static, T::Element: FromJSValConvertible + Clone, <T::Element as FromJSValConvertible>::Config: Clone, { - // TODO(servo/rust-mozjs#330): replace this with a macro that supports generic types. - let mut typed_array_root = Rooted::new_unrooted(); - let typed_array: Option<TypedArray<T>> = - TypedArray::from(cx, &mut typed_array_root, sequence_or_abv).ok(); - if let Some(mut typed_array) = typed_array { + let mut typed_array = RootedTraceableBox::new(TypedArray::<T>::from(cx, sequence_or_abv).ok()); + if let Some(ref mut typed_array) = *typed_array { return Ok(typed_array.as_slice().to_vec()); } assert!(!sequence_or_abv.is_null()); @@ -807,9 +806,9 @@ unsafe fn typed_array_or_sequence_to_vec<T>(cx: *mut JSContext, unsafe fn fallible_array_buffer_view_to_vec(cx: *mut JSContext, abv: *mut JSObject) -> Result<Vec<u8>, Error> { assert!(!abv.is_null()); - typedarray!(in(cx) let array_buffer_view: ArrayBufferView = abv); - match array_buffer_view { - Ok(mut v) => Ok(v.as_slice().to_vec()), + let mut array_buffer_view = RootedTraceableBox::new(ArrayBufferView::from(cx, abv)); + match *array_buffer_view { + Ok(ref mut v) => Ok(v.as_slice().to_vec()), Err(_) => Err(Error::Type("Not an ArrayBufferView".to_owned())), } } @@ -1194,9 +1193,9 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { return Ok(self.webgl_error(InvalidValue)); } - typedarray!(in(cx) let array_buffer: ArrayBuffer = data); - let data_vec = match array_buffer { - Ok(mut data) => data.as_slice().to_vec(), + let mut array_buffer = RootedTraceableBox::new(ArrayBuffer::from(cx, data)); + let data_vec = match *array_buffer { + Ok(ref mut data) => data.as_slice().to_vec(), Err(_) => try!(fallible_array_buffer_view_to_vec(cx, data)), }; @@ -1262,9 +1261,9 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { return Ok(self.webgl_error(InvalidValue)); } - typedarray!(in(cx) let array_buffer: ArrayBuffer = data); - let data_vec = match array_buffer { - Ok(mut data) => data.as_slice().to_vec(), + let mut array_buffer = RootedTraceableBox::new(ArrayBuffer::from(cx, data)); + let data_vec = match *array_buffer { + Ok(ref mut data) => data.as_slice().to_vec(), Err(_) => try!(fallible_array_buffer_view_to_vec(cx, data)), }; @@ -2080,7 +2079,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { return Ok(self.webgl_error(InvalidValue)); } - typedarray!(in(cx) let mut pixels_data: ArrayBufferView = pixels); + let mut pixels_data = RootedTraceableBox::new(ArrayBufferView::from(cx, pixels)); let (array_type, mut data) = match { pixels_data.as_mut() } { Ok(data) => (data.get_array_type(), data.as_mut_slice()), Err(_) => return Err(Error::Type("Not an ArrayBufferView".to_owned())), |