@@ -15,6 +15,7 @@ use dom::bindings::inheritance::Castable;
15
15
use dom:: bindings:: js:: { JS , LayoutJS , MutNullableJS , Root } ;
16
16
use dom:: bindings:: reflector:: { DomObject , Reflector , reflect_dom_object} ;
17
17
use dom:: bindings:: str:: DOMString ;
18
+ use dom:: bindings:: trace:: RootedTraceableBox ;
18
19
use dom:: event:: { Event , EventBubbles , EventCancelable } ;
19
20
use dom:: globalscope:: GlobalScope ;
20
21
use dom:: htmlcanvaselement:: HTMLCanvasElement ;
@@ -38,9 +39,9 @@ use dom_struct::dom_struct;
38
39
use euclid:: size:: Size2D ;
39
40
use ipc_channel:: ipc:: { self , IpcSender } ;
40
41
use js:: conversions:: ConversionBehavior ;
41
- use js:: jsapi:: { JSContext , JSObject , Type , Rooted } ;
42
+ use js:: jsapi:: { JSContext , JSObject , Type } ;
42
43
use js:: jsval:: { BooleanValue , DoubleValue , Int32Value , JSVal , NullValue , UndefinedValue } ;
43
- use js:: typedarray:: { TypedArray , TypedArrayElement , Float32 , Int32 } ;
44
+ use js:: typedarray:: { TypedArray , TypedArrayElement , Float32 , Int32 , Uint8Array , Uint16Array , ArrayBufferView } ;
44
45
use net_traits:: image:: base:: PixelFormat ;
45
46
use net_traits:: image_cache_thread:: ImageResponse ;
46
47
use offscreen_gl_context:: { GLContextAttributes , GLLimits } ;
@@ -512,8 +513,8 @@ impl WebGLRenderingContext {
512
513
// if it is UNSIGNED_SHORT_5_6_5, UNSIGNED_SHORT_4_4_4_4,
513
514
// or UNSIGNED_SHORT_5_5_5_1, a Uint16Array must be supplied.
514
515
// If the types do not match, an INVALID_OPERATION error is generated.
515
- typedarray ! ( in ( cx ) let typedarray_u8: Uint8Array = data) ;
516
- typedarray ! ( in ( cx ) let typedarray_u16: Uint16Array = data) ;
516
+ let typedarray_u8 = RootedTraceableBox :: new ( Uint8Array :: from ( cx , data) ) ;
517
+ let typedarray_u16 = RootedTraceableBox :: new ( Uint16Array :: from ( cx , data) ) ;
517
518
let received_size = if data. is_null ( ) {
518
519
element_size
519
520
} else {
@@ -779,15 +780,12 @@ unsafe fn typed_array_or_sequence_to_vec<T>(cx: *mut JSContext,
779
780
sequence_or_abv : * mut JSObject ,
780
781
config : <T :: Element as FromJSValConvertible >:: Config )
781
782
-> Result < Vec < T :: Element > , Error >
782
- where T : TypedArrayElement ,
783
+ where T : TypedArrayElement + ' static ,
783
784
T :: Element : FromJSValConvertible + Clone ,
784
785
<T :: Element as FromJSValConvertible >:: Config : Clone ,
785
786
{
786
- // TODO(servo/rust-mozjs#330): replace this with a macro that supports generic types.
787
- let mut typed_array_root = Rooted :: new_unrooted ( ) ;
788
- let typed_array: Option < TypedArray < T > > =
789
- TypedArray :: from ( cx, & mut typed_array_root, sequence_or_abv) . ok ( ) ;
790
- if let Some ( mut typed_array) = typed_array {
787
+ let mut typed_array = RootedTraceableBox :: new ( TypedArray :: < T > :: from ( cx, sequence_or_abv) . ok ( ) ) ;
788
+ if let Some ( ref mut typed_array) = * typed_array {
791
789
return Ok ( typed_array. as_slice ( ) . to_vec ( ) ) ;
792
790
}
793
791
assert ! ( !sequence_or_abv. is_null( ) ) ;
@@ -807,9 +805,9 @@ unsafe fn typed_array_or_sequence_to_vec<T>(cx: *mut JSContext,
807
805
unsafe fn fallible_array_buffer_view_to_vec ( cx : * mut JSContext , abv : * mut JSObject ) -> Result < Vec < u8 > , Error >
808
806
{
809
807
assert ! ( !abv. is_null( ) ) ;
810
- typedarray ! ( in ( cx ) let array_buffer_view: ArrayBufferView = abv) ;
811
- match array_buffer_view {
812
- Ok ( mut v) => Ok ( v. as_slice ( ) . to_vec ( ) ) ,
808
+ let mut array_buffer_view = RootedTraceableBox :: new ( ArrayBufferView :: from ( cx , abv) ) ;
809
+ match * array_buffer_view {
810
+ Ok ( ref mut v) => Ok ( v. as_slice ( ) . to_vec ( ) ) ,
813
811
Err ( _) => Err ( Error :: Type ( "Not an ArrayBufferView" . to_owned ( ) ) ) ,
814
812
}
815
813
}
@@ -1194,9 +1192,9 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
1194
1192
return Ok ( self . webgl_error ( InvalidValue ) ) ;
1195
1193
}
1196
1194
1197
- typedarray ! ( in ( cx ) let array_buffer: ArrayBuffer = data) ;
1198
- let data_vec = match array_buffer {
1199
- Ok ( mut data) => data. as_slice ( ) . to_vec ( ) ,
1195
+ let mut array_buffer = RootedTraceableBox :: new ( ArrayBufferView :: from ( cx , data) ) ;
1196
+ let data_vec = match * array_buffer {
1197
+ Ok ( ref mut data) => data. as_slice ( ) . to_vec ( ) ,
1200
1198
Err ( _) => try!( fallible_array_buffer_view_to_vec ( cx, data) ) ,
1201
1199
} ;
1202
1200
@@ -1262,9 +1260,9 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
1262
1260
return Ok ( self . webgl_error ( InvalidValue ) ) ;
1263
1261
}
1264
1262
1265
- typedarray ! ( in ( cx ) let array_buffer: ArrayBuffer = data) ;
1266
- let data_vec = match array_buffer {
1267
- Ok ( mut data) => data. as_slice ( ) . to_vec ( ) ,
1263
+ let mut array_buffer = RootedTraceableBox :: new ( ArrayBufferView :: from ( cx , data) ) ;
1264
+ let data_vec = match * array_buffer {
1265
+ Ok ( ref mut data) => data. as_slice ( ) . to_vec ( ) ,
1268
1266
Err ( _) => try!( fallible_array_buffer_view_to_vec ( cx, data) ) ,
1269
1267
} ;
1270
1268
@@ -2080,7 +2078,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
2080
2078
return Ok ( self . webgl_error ( InvalidValue ) ) ;
2081
2079
}
2082
2080
2083
- typedarray ! ( in ( cx ) let mut pixels_data: ArrayBufferView = pixels) ;
2081
+ let mut pixels_data = RootedTraceableBox :: new ( ArrayBufferView :: from ( cx , pixels) ) ;
2084
2082
let ( array_type, mut data) = match { pixels_data. as_mut ( ) } {
2085
2083
Ok ( data) => ( data. get_array_type ( ) , data. as_mut_slice ( ) ) ,
2086
2084
Err ( _) => return Err ( Error :: Type ( "Not an ArrayBufferView" . to_owned ( ) ) ) ,
0 commit comments