@@ -15,6 +15,7 @@ use dom::bindings::inheritance::Castable;
1515use dom:: bindings:: js:: { JS , LayoutJS , MutNullableJS , Root } ;
1616use dom:: bindings:: reflector:: { DomObject , Reflector , reflect_dom_object} ;
1717use dom:: bindings:: str:: DOMString ;
18+ use dom:: bindings:: trace:: RootedTraceableBox ;
1819use dom:: event:: { Event , EventBubbles , EventCancelable } ;
1920use dom:: globalscope:: GlobalScope ;
2021use dom:: htmlcanvaselement:: HTMLCanvasElement ;
@@ -38,9 +39,9 @@ use dom_struct::dom_struct;
3839use euclid:: size:: Size2D ;
3940use ipc_channel:: ipc:: { self , IpcSender } ;
4041use js:: conversions:: ConversionBehavior ;
41- use js:: jsapi:: { JSContext , JSObject , Type , Rooted } ;
42+ use js:: jsapi:: { JSContext , JSObject , Type } ;
4243use 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 } ;
4445use net_traits:: image:: base:: PixelFormat ;
4546use net_traits:: image_cache_thread:: ImageResponse ;
4647use offscreen_gl_context:: { GLContextAttributes , GLLimits } ;
@@ -512,8 +513,8 @@ impl WebGLRenderingContext {
512513 // if it is UNSIGNED_SHORT_5_6_5, UNSIGNED_SHORT_4_4_4_4,
513514 // or UNSIGNED_SHORT_5_5_5_1, a Uint16Array must be supplied.
514515 // 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) ) ;
517518 let received_size = if data. is_null ( ) {
518519 element_size
519520 } else {
@@ -779,15 +780,12 @@ unsafe fn typed_array_or_sequence_to_vec<T>(cx: *mut JSContext,
779780 sequence_or_abv : * mut JSObject ,
780781 config : <T :: Element as FromJSValConvertible >:: Config )
781782 -> Result < Vec < T :: Element > , Error >
782- where T : TypedArrayElement ,
783+ where T : TypedArrayElement + ' static ,
783784 T :: Element : FromJSValConvertible + Clone ,
784785 <T :: Element as FromJSValConvertible >:: Config : Clone ,
785786{
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 {
791789 return Ok ( typed_array. as_slice ( ) . to_vec ( ) ) ;
792790 }
793791 assert ! ( !sequence_or_abv. is_null( ) ) ;
@@ -807,9 +805,9 @@ unsafe fn typed_array_or_sequence_to_vec<T>(cx: *mut JSContext,
807805unsafe fn fallible_array_buffer_view_to_vec ( cx : * mut JSContext , abv : * mut JSObject ) -> Result < Vec < u8 > , Error >
808806{
809807 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 ( ) ) ,
813811 Err ( _) => Err ( Error :: Type ( "Not an ArrayBufferView" . to_owned ( ) ) ) ,
814812 }
815813}
@@ -1194,9 +1192,9 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
11941192 return Ok ( self . webgl_error ( InvalidValue ) ) ;
11951193 }
11961194
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 ( ) ,
12001198 Err ( _) => try!( fallible_array_buffer_view_to_vec ( cx, data) ) ,
12011199 } ;
12021200
@@ -1262,9 +1260,9 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
12621260 return Ok ( self . webgl_error ( InvalidValue ) ) ;
12631261 }
12641262
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 ( ) ,
12681266 Err ( _) => try!( fallible_array_buffer_view_to_vec ( cx, data) ) ,
12691267 } ;
12701268
@@ -2080,7 +2078,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
20802078 return Ok ( self . webgl_error ( InvalidValue ) ) ;
20812079 }
20822080
2083- typedarray ! ( in ( cx ) let mut pixels_data: ArrayBufferView = pixels) ;
2081+ let mut pixels_data = RootedTraceableBox :: new ( ArrayBufferView :: from ( cx , pixels) ) ;
20842082 let ( array_type, mut data) = match { pixels_data. as_mut ( ) } {
20852083 Ok ( data) => ( data. get_array_type ( ) , data. as_mut_slice ( ) ) ,
20862084 Err ( _) => return Err ( Error :: Type ( "Not an ArrayBufferView" . to_owned ( ) ) ) ,
0 commit comments