mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-20 16:26:33 +00:00
Making ArrayBufferView & BufferSource a union
This commit is contained in:
@ -466,9 +466,10 @@ impl<'a> IdlType<'a> {
|
||||
IdlType::Float32Array => Some(array("f32", pos)),
|
||||
IdlType::Float64Array => Some(array("f64", pos)),
|
||||
|
||||
// we alias ArrayBufferView & BufferSource to &u8 in Rust
|
||||
IdlType::ArrayBufferView
|
||||
| IdlType::BufferSource => Some(array("u8", pos)),
|
||||
IdlType::ArrayBufferView | IdlType::BufferSource => {
|
||||
let path = vec![rust_ident("js_sys"), rust_ident("Object")];
|
||||
Some(leading_colon_path_ty(path))
|
||||
},
|
||||
IdlType::Interface(name)
|
||||
| IdlType::Dictionary(name) => {
|
||||
let ty = ident_ty(rust_ident(camel_case_ident(name).as_str()));
|
||||
@ -573,6 +574,8 @@ impl<'a> IdlType<'a> {
|
||||
.iter()
|
||||
.flat_map(|idl_type| idl_type.flatten())
|
||||
.collect(),
|
||||
IdlType::ArrayBufferView | IdlType::BufferSource =>
|
||||
vec![IdlType::Object, IdlType::Uint8Array],
|
||||
|
||||
idl_type @ _ => vec![idl_type.clone()],
|
||||
}
|
||||
|
@ -291,12 +291,28 @@ impl<'src> FirstPassRecord<'src> {
|
||||
|
||||
// Slice types aren't supported because they don't implement
|
||||
// `Into<JsValue>`
|
||||
if let syn::Type::Reference(ty) = &ty {
|
||||
match &*ty.elem {
|
||||
match ty {
|
||||
syn::Type::Reference(ref i) =>
|
||||
match &*i.elem {
|
||||
syn::Type::Slice(_) => return None,
|
||||
_ => {}
|
||||
_ => ()
|
||||
}
|
||||
syn::Type::Path(ref path, ..) =>
|
||||
// check that our inner don't contains slices either
|
||||
for seg in path.path.segments.iter() {
|
||||
if let syn::PathArguments::AngleBracketed(ref arg) = seg.arguments {
|
||||
for elem in &arg.args {
|
||||
if let syn::GenericArgument::Type(syn::Type::Reference(ref i)) = elem {
|
||||
match &*i.elem {
|
||||
syn::Type::Slice(_) => return None,
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => ()
|
||||
};
|
||||
|
||||
// Similarly i64/u64 aren't supported because they don't
|
||||
// implement `Into<JsValue>`
|
||||
|
Reference in New Issue
Block a user