mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-21 16:51: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::Float32Array => Some(array("f32", pos)),
|
||||||
IdlType::Float64Array => Some(array("f64", pos)),
|
IdlType::Float64Array => Some(array("f64", pos)),
|
||||||
|
|
||||||
// we alias ArrayBufferView & BufferSource to &u8 in Rust
|
IdlType::ArrayBufferView | IdlType::BufferSource => {
|
||||||
IdlType::ArrayBufferView
|
let path = vec![rust_ident("js_sys"), rust_ident("Object")];
|
||||||
| IdlType::BufferSource => Some(array("u8", pos)),
|
Some(leading_colon_path_ty(path))
|
||||||
|
},
|
||||||
IdlType::Interface(name)
|
IdlType::Interface(name)
|
||||||
| IdlType::Dictionary(name) => {
|
| IdlType::Dictionary(name) => {
|
||||||
let ty = ident_ty(rust_ident(camel_case_ident(name).as_str()));
|
let ty = ident_ty(rust_ident(camel_case_ident(name).as_str()));
|
||||||
@ -573,6 +574,8 @@ impl<'a> IdlType<'a> {
|
|||||||
.iter()
|
.iter()
|
||||||
.flat_map(|idl_type| idl_type.flatten())
|
.flat_map(|idl_type| idl_type.flatten())
|
||||||
.collect(),
|
.collect(),
|
||||||
|
IdlType::ArrayBufferView | IdlType::BufferSource =>
|
||||||
|
vec![IdlType::Object, IdlType::Uint8Array],
|
||||||
|
|
||||||
idl_type @ _ => vec![idl_type.clone()],
|
idl_type @ _ => vec![idl_type.clone()],
|
||||||
}
|
}
|
||||||
|
@ -291,12 +291,28 @@ impl<'src> FirstPassRecord<'src> {
|
|||||||
|
|
||||||
// Slice types aren't supported because they don't implement
|
// Slice types aren't supported because they don't implement
|
||||||
// `Into<JsValue>`
|
// `Into<JsValue>`
|
||||||
if let syn::Type::Reference(ty) = &ty {
|
match ty {
|
||||||
match &*ty.elem {
|
syn::Type::Reference(ref i) =>
|
||||||
syn::Type::Slice(_) => return None,
|
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
|
// Similarly i64/u64 aren't supported because they don't
|
||||||
// implement `Into<JsValue>`
|
// implement `Into<JsValue>`
|
||||||
|
Reference in New Issue
Block a user