Skip to content

Commit cda7175

Browse files
committed
Tweak ArrayBuffer IDL type expansion slightly
A few small changes here: * `ArrayBufferView` and `BufferSource` are expanded to themselves plus `Uint8ArrayMut` instead of `Object` to ensure we keep the original type. * Generating an argument type for `ArrayBufferView`, `BufferSource`, and `Object` all now generate shared references instead of owned objects, which is a little more consistent with the other interface types.
1 parent 3c41d39 commit cda7175

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

crates/webidl/src/idl_type.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,11 @@ impl<'a> IdlType<'a> {
448448
},
449449
IdlType::Object => {
450450
let path = vec![rust_ident("js_sys"), rust_ident("Object")];
451-
Some(leading_colon_path_ty(path))
451+
let ty = leading_colon_path_ty(path);
452+
Some(match pos {
453+
TypePosition::Argument => shared_ref(ty, false),
454+
TypePosition::Return => ty,
455+
})
452456
},
453457
IdlType::Symbol => None,
454458
IdlType::Error => None,
@@ -471,7 +475,11 @@ impl<'a> IdlType<'a> {
471475

472476
IdlType::ArrayBufferView | IdlType::BufferSource => {
473477
let path = vec![rust_ident("js_sys"), rust_ident("Object")];
474-
Some(leading_colon_path_ty(path))
478+
let ty = leading_colon_path_ty(path);
479+
Some(match pos {
480+
TypePosition::Argument => shared_ref(ty, false),
481+
TypePosition::Return => ty,
482+
})
475483
},
476484
IdlType::Interface(name)
477485
| IdlType::Dictionary(name) => {
@@ -577,9 +585,12 @@ impl<'a> IdlType<'a> {
577585
.iter()
578586
.flat_map(|idl_type| idl_type.flatten())
579587
.collect(),
580-
IdlType::ArrayBufferView | IdlType::BufferSource =>
581-
vec![IdlType::Object, IdlType::Uint8ArrayMut],
582-
588+
IdlType::ArrayBufferView => {
589+
vec![IdlType::ArrayBufferView, IdlType::Uint8ArrayMut]
590+
}
591+
IdlType::BufferSource => {
592+
vec![IdlType::BufferSource, IdlType::Uint8ArrayMut]
593+
}
583594
idl_type @ _ => vec![idl_type.clone()],
584595
}
585596
}

0 commit comments

Comments
 (0)