@@ -58,6 +58,9 @@ use jsapi::UnwrapUint16Array;
5858use jsapi:: UnwrapUint32Array ;
5959use jsapi:: UnwrapUint8Array ;
6060use jsapi:: UnwrapUint8ClampedArray ;
61+ use jsapi:: JS_GetDataViewByteLength ;
62+ use jsapi:: JS_GetDataViewData ;
63+ use jsapi:: JS_NewDataView ;
6164use rust:: { HandleValue , MutableHandleObject , MutableHandleValue } ;
6265use rust:: CustomTrace ;
6366
@@ -318,6 +321,53 @@ macro_rules! typed_array_element {
318321 ) ;
319322}
320323
324+ macro_rules! data_view_element {
325+ ( $t: ident,
326+ $element: ty,
327+ $unwrap: ident,
328+ $length: ident) => (
329+ pub struct $t;
330+
331+ impl TypedArrayElement for $t {
332+ type Element = $element;
333+ unsafe fn unwrap_array( obj: * mut JSObject ) -> * mut JSObject {
334+ $unwrap( obj)
335+ }
336+
337+ unsafe fn length_and_data( obj: * mut JSObject ) -> ( u32 , ) {
338+ ( $length( obj) , )
339+ }
340+
341+ }
342+ ) ;
343+
344+ ( $t: ident,
345+ $element: ty,
346+ $unwrap: ident,
347+ $length: ident,
348+ $create_new: ident,
349+ $get_data: ident) => (
350+ data_view_element!( $t, $element, $unwrap, $length) ;
351+ impl TypedArrayElementCreator for $t {
352+ unsafe fn create_new( cx: * mut JSContext , array_buffer: * mut JSObject , byte_offset: u32 , byte_length: u32 ) -> * mut JSObject {
353+ $create_new( cx, array_buffer, byte_offset, byte_length)
354+ }
355+
356+ unsafe fn get_data( obj: * mut JSObject ) -> * mut Self :: Element {
357+ let mut shared = false ;
358+ let data = $get_data( obj, & mut shared, ptr:: null_mut( ) ) ;
359+ assert!( !shared) ;
360+ data
361+ }
362+ }
363+ ) ;
364+ }
365+ data_view_element ! ( MaxTypedArrayViewType ,
366+ u8 ,
367+ UnwrapArrayBufferView ,
368+ JS_GetDataViewByteLength ,
369+ JS_NewDataView ,
370+ JS_GetDataViewData ) ;
321371typed_array_element ! ( Uint8 ,
322372 u8 ,
323373 UnwrapUint8Array ,
@@ -392,6 +442,7 @@ macro_rules! array_alias {
392442 }
393443}
394444
445+ array_alias ! ( MaxTypedArrayViewType , HeapMaxTypedArrayViewType , ArrayBufferViewU8 ) ;
395446array_alias ! ( Uint8ClampedArray , HeapUint8ClampedArray , ClampedU8 ) ;
396447array_alias ! ( Uint8Array , HeapUint8Array , Uint8 ) ;
397448array_alias ! ( Int8Array , HeapInt8Array , Int8 ) ;
0 commit comments