Skip to content

Commit

Permalink
Tweak ArrayBuffer IDL type expansion slightly
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexcrichton committed Sep 6, 2018
1 parent 3c41d39 commit cda7175
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions crates/webidl/src/idl_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,11 @@ impl<'a> IdlType<'a> {
},
IdlType::Object => {
let path = vec![rust_ident("js_sys"), rust_ident("Object")];
Some(leading_colon_path_ty(path))
let ty = leading_colon_path_ty(path);
Some(match pos {
TypePosition::Argument => shared_ref(ty, false),
TypePosition::Return => ty,
})
},
IdlType::Symbol => None,
IdlType::Error => None,
Expand All @@ -471,7 +475,11 @@ impl<'a> IdlType<'a> {

IdlType::ArrayBufferView | IdlType::BufferSource => {
let path = vec![rust_ident("js_sys"), rust_ident("Object")];
Some(leading_colon_path_ty(path))
let ty = leading_colon_path_ty(path);
Some(match pos {
TypePosition::Argument => shared_ref(ty, false),
TypePosition::Return => ty,
})
},
IdlType::Interface(name)
| IdlType::Dictionary(name) => {
Expand Down Expand Up @@ -577,9 +585,12 @@ impl<'a> IdlType<'a> {
.iter()
.flat_map(|idl_type| idl_type.flatten())
.collect(),
IdlType::ArrayBufferView | IdlType::BufferSource =>
vec![IdlType::Object, IdlType::Uint8ArrayMut],

IdlType::ArrayBufferView => {
vec![IdlType::ArrayBufferView, IdlType::Uint8ArrayMut]
}
IdlType::BufferSource => {
vec![IdlType::BufferSource, IdlType::Uint8ArrayMut]
}
idl_type @ _ => vec![idl_type.clone()],
}
}
Expand Down

0 comments on commit cda7175

Please sign in to comment.