@@ -34,8 +34,10 @@ pub(crate) enum IdlType<'a> {
34
34
ArrayBuffer ,
35
35
DataView ,
36
36
Int8Array ,
37
- Uint8Array ,
38
- Uint8ArrayMut ,
37
+ Uint8Array {
38
+ /// Whether or not the generated web-sys function should use an immutable slice
39
+ immutable : bool ,
40
+ } ,
39
41
Uint8ClampedArray ,
40
42
Int16Array ,
41
43
Uint16Array ,
@@ -46,8 +48,14 @@ pub(crate) enum IdlType<'a> {
46
48
immutable : bool ,
47
49
} ,
48
50
Float64Array ,
49
- ArrayBufferView ,
50
- BufferSource ,
51
+ ArrayBufferView {
52
+ /// Whether or not the generated web-sys function should use an immutable slice
53
+ immutable : bool ,
54
+ } ,
55
+ BufferSource {
56
+ /// Whether or not the generated web-sys function should use an immutable slice
57
+ immutable : bool ,
58
+ } ,
51
59
52
60
Interface ( & ' a str ) ,
53
61
Dictionary ( & ' a str ) ,
@@ -327,15 +335,6 @@ impl<'a> ToIdlType<'a> for Identifier<'a> {
327
335
}
328
336
}
329
337
330
- // We default to Float32Array's being mutable, but in certain cases where we're certain that
331
- // slices won't get mutated on the JS side (such as the WebGL APIs) we might, later in the flow,
332
- // instead use the immutable version.
333
- impl < ' a > ToIdlType < ' a > for term:: Float32Array {
334
- fn to_idl_type ( & self , _record : & FirstPassRecord < ' a > ) -> IdlType < ' a > {
335
- IdlType :: Float32Array { immutable : false }
336
- }
337
- }
338
-
339
338
macro_rules! terms_to_idl_type {
340
339
( $( $t: tt => $r: tt) * ) => ( $(
341
340
impl <' a> ToIdlType <' a> for term:: $t {
@@ -346,6 +345,19 @@ macro_rules! terms_to_idl_type {
346
345
) * ) ;
347
346
}
348
347
348
+ // We default to arrays being mutable, but in certain cases where we're certain that
349
+ // slices won't get mutated on the JS side (such as the WebGL APIs) we might, later in the flow,
350
+ // instead use the immutable version.
351
+ macro_rules! terms_to_idl_type_maybe_immutable {
352
+ ( $( $t: tt => $r: tt) * ) => ( $(
353
+ impl <' a> ToIdlType <' a> for term:: $t {
354
+ fn to_idl_type( & self , _record: & FirstPassRecord <' a>) -> IdlType <' a> {
355
+ IdlType :: $r { immutable: false }
356
+ }
357
+ }
358
+ ) * ) ;
359
+ }
360
+
349
361
terms_to_idl_type ! {
350
362
Symbol => Symbol
351
363
ByteString => ByteString
@@ -366,14 +378,18 @@ terms_to_idl_type! {
366
378
Int8Array => Int8Array
367
379
Int16Array => Int16Array
368
380
Int32Array => Int32Array
369
- Uint8Array => Uint8Array
370
381
Uint16Array => Uint16Array
371
382
Uint32Array => Uint32Array
372
383
Uint8ClampedArray => Uint8ClampedArray
373
384
Float64Array => Float64Array
385
+ Error => Error
386
+ }
387
+
388
+ terms_to_idl_type_maybe_immutable ! {
389
+ Uint8Array => Uint8Array
390
+ Float32Array => Float32Array
374
391
ArrayBufferView => ArrayBufferView
375
392
BufferSource => BufferSource
376
- Error => Error
377
393
}
378
394
379
395
impl < ' a > IdlType < ' a > {
@@ -400,17 +416,16 @@ impl<'a> IdlType<'a> {
400
416
IdlType :: ArrayBuffer => dst. push_str ( "array_buffer" ) ,
401
417
IdlType :: DataView => dst. push_str ( "data_view" ) ,
402
418
IdlType :: Int8Array => dst. push_str ( "i8_array" ) ,
403
- IdlType :: Uint8Array => dst. push_str ( "u8_array" ) ,
404
- IdlType :: Uint8ArrayMut => dst. push_str ( "u8_array" ) ,
419
+ IdlType :: Uint8Array { .. } => dst. push_str ( "u8_array" ) ,
405
420
IdlType :: Uint8ClampedArray => dst. push_str ( "u8_clamped_array" ) ,
406
421
IdlType :: Int16Array => dst. push_str ( "i16_array" ) ,
407
422
IdlType :: Uint16Array => dst. push_str ( "u16_array" ) ,
408
423
IdlType :: Int32Array => dst. push_str ( "i32_array" ) ,
409
424
IdlType :: Uint32Array => dst. push_str ( "u32_array" ) ,
410
425
IdlType :: Float32Array { .. } => dst. push_str ( "f32_array" ) ,
411
426
IdlType :: Float64Array => dst. push_str ( "f64_array" ) ,
412
- IdlType :: ArrayBufferView => dst. push_str ( "array_buffer_view" ) ,
413
- IdlType :: BufferSource => dst. push_str ( "buffer_source" ) ,
427
+ IdlType :: ArrayBufferView { .. } => dst. push_str ( "array_buffer_view" ) ,
428
+ IdlType :: BufferSource { .. } => dst. push_str ( "buffer_source" ) ,
414
429
415
430
IdlType :: Interface ( name) => dst. push_str ( & snake_case_ident ( name) ) ,
416
431
IdlType :: UnknownInterface ( name) => dst. push_str ( & snake_case_ident ( name) ) ,
@@ -513,8 +528,7 @@ impl<'a> IdlType<'a> {
513
528
IdlType :: ArrayBuffer => js_sys ( "ArrayBuffer" ) ,
514
529
IdlType :: DataView => None ,
515
530
IdlType :: Int8Array => Some ( array ( "i8" , pos, false ) ) ,
516
- IdlType :: Uint8Array => Some ( array ( "u8" , pos, false ) ) ,
517
- IdlType :: Uint8ArrayMut => Some ( array ( "u8" , pos, false ) ) ,
531
+ IdlType :: Uint8Array { immutable } => Some ( array ( "u8" , pos, * immutable) ) ,
518
532
IdlType :: Uint8ClampedArray => Some ( clamped ( array ( "u8" , pos, false ) ) ) ,
519
533
IdlType :: Int16Array => Some ( array ( "i16" , pos, false ) ) ,
520
534
IdlType :: Uint16Array => Some ( array ( "u16" , pos, false ) ) ,
@@ -523,7 +537,7 @@ impl<'a> IdlType<'a> {
523
537
IdlType :: Float32Array { immutable } => Some ( array ( "f32" , pos, * immutable) ) ,
524
538
IdlType :: Float64Array => Some ( array ( "f64" , pos, false ) ) ,
525
539
526
- IdlType :: ArrayBufferView | IdlType :: BufferSource => js_sys ( "Object" ) ,
540
+ IdlType :: ArrayBufferView { .. } | IdlType :: BufferSource { .. } => js_sys ( "Object" ) ,
527
541
IdlType :: Interface ( name)
528
542
| IdlType :: Dictionary ( name)
529
543
| IdlType :: CallbackInterface { name, .. } => {
@@ -654,8 +668,22 @@ impl<'a> IdlType<'a> {
654
668
. iter ( )
655
669
. flat_map ( |idl_type| idl_type. flatten ( ) )
656
670
. collect ( ) ,
657
- IdlType :: ArrayBufferView => vec ! [ IdlType :: ArrayBufferView , IdlType :: Uint8ArrayMut ] ,
658
- IdlType :: BufferSource => vec ! [ IdlType :: BufferSource , IdlType :: Uint8ArrayMut ] ,
671
+ IdlType :: ArrayBufferView { immutable } => vec ! [
672
+ IdlType :: ArrayBufferView {
673
+ immutable: * immutable,
674
+ } ,
675
+ IdlType :: Uint8Array {
676
+ immutable: * immutable,
677
+ } ,
678
+ ] ,
679
+ IdlType :: BufferSource { immutable } => vec ! [
680
+ IdlType :: BufferSource {
681
+ immutable: * immutable,
682
+ } ,
683
+ IdlType :: Uint8Array {
684
+ immutable: * immutable,
685
+ } ,
686
+ ] ,
659
687
IdlType :: LongLong => vec ! [ IdlType :: Long , IdlType :: Double ] ,
660
688
IdlType :: UnsignedLongLong => vec ! [ IdlType :: UnsignedLong , IdlType :: Double ] ,
661
689
IdlType :: CallbackInterface {
0 commit comments