Making ArrayBufferView & BufferSource a union

This commit is contained in:
Benjamin Kampmann
2018-08-30 12:15:37 +02:00
parent 031ba39036
commit 8b08fc16c5
2 changed files with 28 additions and 9 deletions

View File

@ -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()],
}

View File

@ -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>`