@@ -58,6 +58,9 @@ use jsapi::UnwrapUint16Array;
58
58
use jsapi:: UnwrapUint32Array ;
59
59
use jsapi:: UnwrapUint8Array ;
60
60
use jsapi:: UnwrapUint8ClampedArray ;
61
+ use jsapi:: JS_GetDataViewByteLength ;
62
+ use jsapi:: JS_GetDataViewData ;
63
+ use jsapi:: JS_NewDataView ;
61
64
use rust:: { HandleValue , MutableHandleObject , MutableHandleValue } ;
62
65
use rust:: CustomTrace ;
63
66
@@ -318,6 +321,53 @@ macro_rules! typed_array_element {
318
321
) ;
319
322
}
320
323
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 ) ;
321
371
typed_array_element ! ( Uint8 ,
322
372
u8 ,
323
373
UnwrapUint8Array ,
@@ -392,6 +442,7 @@ macro_rules! array_alias {
392
442
}
393
443
}
394
444
445
+ array_alias ! ( MaxTypedArrayViewType , HeapMaxTypedArrayViewType , ArrayBufferViewU8 ) ;
395
446
array_alias ! ( Uint8ClampedArray , HeapUint8ClampedArray , ClampedU8 ) ;
396
447
array_alias ! ( Uint8Array , HeapUint8Array , Uint8 ) ;
397
448
array_alias ! ( Int8Array , HeapInt8Array , Int8 ) ;
0 commit comments