@@ -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,52 @@ 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
+ $data: ident) => (
330
+ pub struct $t;
331
+
332
+ impl TypedArrayElement for $t {
333
+ type Element = $element;
334
+ unsafe fn unwrap_array( obj: * mut JSObject ) -> * mut JSObject {
335
+ $unwrap( obj)
336
+ }
337
+
338
+ unsafe fn length( obj: * mut JSObject ) -> u32 {
339
+ $length( obj)
340
+ }
341
+ unsafe fn data( obj: * mut JSObject ) -> * mut Self :: Element {
342
+ $data( obj)
343
+ }
344
+ }
345
+ ) ;
346
+
347
+ ( $t: ident,
348
+ $element: ty,
349
+ $unwrap: ident,
350
+ $length: ident,
351
+ $data: ident,
352
+ $create_new: ident,
353
+ $get_data: ident) => (
354
+ typed_array_element!( $t, $element, $unwrap, $length, $data) ;
355
+ impl TypedArrayElementCreator for $t {
356
+ unsafe fn create_new( cx: * mut JSContext , array_buffer: * mut JSObject , byte_offset: u32 , byte_length: u32 ) -> * mut JSObject {
357
+ $create_new( cx, array_buffer, byte_offset, byte_length)
358
+ }
359
+
360
+ unsafe fn get_data( obj: * mut JSObject ) -> * mut Self :: Element {
361
+ let mut shared = false ;
362
+ let data = $get_data( obj, & mut shared, ptr:: null_mut( ) ) ;
363
+ assert!( !shared) ;
364
+ data
365
+ }
366
+ }
367
+ ) ;
368
+ }
369
+
321
370
typed_array_element ! ( Uint8 ,
322
371
u8 ,
323
372
UnwrapUint8Array ,
0 commit comments