Skip to content

Commit 3b06e58

Browse files
committed
Handle more slice types in flag_slices_immutable
Should address the latest comment on #1539
1 parent f1cd643 commit 3b06e58

File tree

2 files changed

+55
-38
lines changed

2 files changed

+55
-38
lines changed

crates/webidl/src/idl_type.rs

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,37 @@ pub(crate) enum IdlType<'a> {
3333

3434
ArrayBuffer,
3535
DataView,
36-
Int8Array,
36+
Int8Array {
37+
immutable: bool,
38+
},
3739
Uint8Array {
38-
/// Whether or not the generated web-sys function should use an immutable slice
3940
immutable: bool,
4041
},
41-
Uint8ClampedArray,
42-
Int16Array,
43-
Uint16Array,
44-
Int32Array,
45-
Uint32Array,
42+
Uint8ClampedArray {
43+
immutable: bool,
44+
},
45+
Int16Array {
46+
immutable: bool,
47+
},
48+
Uint16Array {
49+
immutable: bool,
50+
},
51+
Int32Array {
52+
immutable: bool,
53+
},
54+
Uint32Array {
55+
immutable: bool,
56+
},
4657
Float32Array {
47-
/// Whether or not the generated web-sys function should use an immutable slice
4858
immutable: bool,
4959
},
50-
Float64Array,
60+
Float64Array {
61+
immutable: bool,
62+
},
5163
ArrayBufferView {
52-
/// Whether or not the generated web-sys function should use an immutable slice
5364
immutable: bool,
5465
},
5566
BufferSource {
56-
/// Whether or not the generated web-sys function should use an immutable slice
5767
immutable: bool,
5868
},
5969

@@ -381,21 +391,21 @@ terms_to_idl_type! {
381391
Void => Void
382392
ArrayBuffer => ArrayBuffer
383393
DataView => DataView
384-
Int8Array => Int8Array
385-
Int16Array => Int16Array
386-
Int32Array => Int32Array
387-
Uint16Array => Uint16Array
388-
Uint32Array => Uint32Array
389-
Uint8ClampedArray => Uint8ClampedArray
390-
Float64Array => Float64Array
391394
Error => Error
392395
}
393396

394397
terms_to_idl_type_maybe_immutable! {
395-
Uint8Array => Uint8Array
396-
Float32Array => Float32Array
397398
ArrayBufferView => ArrayBufferView
398399
BufferSource => BufferSource
400+
Float32Array => Float32Array
401+
Float64Array => Float64Array
402+
Int16Array => Int16Array
403+
Int32Array => Int32Array
404+
Int8Array => Int8Array
405+
Uint16Array => Uint16Array
406+
Uint32Array => Uint32Array
407+
Uint8Array => Uint8Array
408+
Uint8ClampedArray => Uint8ClampedArray
399409
}
400410

401411
impl<'a> IdlType<'a> {
@@ -421,15 +431,15 @@ impl<'a> IdlType<'a> {
421431

422432
IdlType::ArrayBuffer => dst.push_str("array_buffer"),
423433
IdlType::DataView => dst.push_str("data_view"),
424-
IdlType::Int8Array => dst.push_str("i8_array"),
434+
IdlType::Int8Array { .. } => dst.push_str("i8_array"),
425435
IdlType::Uint8Array { .. } => dst.push_str("u8_array"),
426-
IdlType::Uint8ClampedArray => dst.push_str("u8_clamped_array"),
427-
IdlType::Int16Array => dst.push_str("i16_array"),
428-
IdlType::Uint16Array => dst.push_str("u16_array"),
429-
IdlType::Int32Array => dst.push_str("i32_array"),
430-
IdlType::Uint32Array => dst.push_str("u32_array"),
436+
IdlType::Uint8ClampedArray { .. } => dst.push_str("u8_clamped_array"),
437+
IdlType::Int16Array { .. } => dst.push_str("i16_array"),
438+
IdlType::Uint16Array { .. } => dst.push_str("u16_array"),
439+
IdlType::Int32Array { .. } => dst.push_str("i32_array"),
440+
IdlType::Uint32Array { .. } => dst.push_str("u32_array"),
431441
IdlType::Float32Array { .. } => dst.push_str("f32_array"),
432-
IdlType::Float64Array => dst.push_str("f64_array"),
442+
IdlType::Float64Array { .. } => dst.push_str("f64_array"),
433443
IdlType::ArrayBufferView { .. } => dst.push_str("array_buffer_view"),
434444
IdlType::BufferSource { .. } => dst.push_str("buffer_source"),
435445

@@ -533,15 +543,15 @@ impl<'a> IdlType<'a> {
533543

534544
IdlType::ArrayBuffer => js_sys("ArrayBuffer"),
535545
IdlType::DataView => None,
536-
IdlType::Int8Array => Some(array("i8", pos, false)),
546+
IdlType::Int8Array { immutable } => Some(array("i8", pos, *immutable)),
537547
IdlType::Uint8Array { immutable } => Some(array("u8", pos, *immutable)),
538-
IdlType::Uint8ClampedArray => Some(clamped(array("u8", pos, false))),
539-
IdlType::Int16Array => Some(array("i16", pos, false)),
540-
IdlType::Uint16Array => Some(array("u16", pos, false)),
541-
IdlType::Int32Array => Some(array("i32", pos, false)),
542-
IdlType::Uint32Array => Some(array("u32", pos, false)),
548+
IdlType::Uint8ClampedArray { immutable } => Some(clamped(array("u8", pos, *immutable))),
549+
IdlType::Int16Array { immutable } => Some(array("i16", pos, *immutable)),
550+
IdlType::Uint16Array { immutable } => Some(array("u16", pos, *immutable)),
551+
IdlType::Int32Array { immutable } => Some(array("i32", pos, *immutable)),
552+
IdlType::Uint32Array { immutable } => Some(array("u32", pos, *immutable)),
543553
IdlType::Float32Array { immutable } => Some(array("f32", pos, *immutable)),
544-
IdlType::Float64Array => Some(array("f64", pos, false)),
554+
IdlType::Float64Array { immutable } => Some(array("f64", pos, *immutable)),
545555

546556
IdlType::ArrayBufferView { .. } | IdlType::BufferSource { .. } => js_sys("Object"),
547557
IdlType::Interface(name)

crates/webidl/src/util.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -735,10 +735,17 @@ pub fn public() -> syn::Visibility {
735735

736736
fn flag_slices_immutable(ty: &mut IdlType) {
737737
match ty {
738-
IdlType::Uint8Array { immutable } => *immutable = true,
739-
IdlType::Float32Array { immutable } => *immutable = true,
740-
IdlType::ArrayBufferView { immutable } => *immutable = true,
741-
IdlType::BufferSource { immutable } => *immutable = true,
738+
IdlType::Int8Array { immutable }
739+
| IdlType::Uint8Array { immutable }
740+
| IdlType::Uint8ClampedArray { immutable }
741+
| IdlType::Int16Array { immutable }
742+
| IdlType::Uint16Array { immutable }
743+
| IdlType::Int32Array { immutable }
744+
| IdlType::Uint32Array { immutable }
745+
| IdlType::Float32Array { immutable }
746+
| IdlType::Float64Array { immutable }
747+
| IdlType::ArrayBufferView { immutable }
748+
| IdlType::BufferSource { immutable } => *immutable = true,
742749
IdlType::Nullable(item) => flag_slices_immutable(item),
743750
IdlType::FrozenArray(item) => flag_slices_immutable(item),
744751
IdlType::Sequence(item) => flag_slices_immutable(item),

0 commit comments

Comments
 (0)