mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-28 07:51:07 +00:00
Translate ByteString
in WebIDL to [u8]
(#505)
In arguments take `&[u8]` and in return value return `Vec<u8>`. Should help fill out a few more APIs on `Header` and `Response`!
This commit is contained in:
parent
32fa5724dd
commit
9b6804a01b
@ -15,8 +15,9 @@ spans = ["proc-macro2/nightly"]
|
|||||||
extra-traits = ["syn/extra-traits"]
|
extra-traits = ["syn/extra-traits"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
quote = '0.6'
|
log = "0.4"
|
||||||
proc-macro2 = "0.4.8"
|
proc-macro2 = "0.4.8"
|
||||||
wasm-bindgen-shared = { path = "../shared", version = "=0.2.11" }
|
quote = '0.6'
|
||||||
syn = { version = '0.14', features = ['full', 'visit-mut'] }
|
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
syn = { version = '0.14', features = ['full', 'visit-mut'] }
|
||||||
|
wasm-bindgen-shared = { path = "../shared", version = "=0.2.11" }
|
||||||
|
@ -269,7 +269,12 @@ where
|
|||||||
self.retain(|x| {
|
self.retain(|x| {
|
||||||
let mut all_defined = true;
|
let mut all_defined = true;
|
||||||
x.imported_type_references(&mut |id| {
|
x.imported_type_references(&mut |id| {
|
||||||
all_defined = all_defined && is_defined(id);
|
if all_defined {
|
||||||
|
if !is_defined(id) {
|
||||||
|
info!("removing due to {} not being defined", id);
|
||||||
|
all_defined = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
all_defined
|
all_defined
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
#![cfg_attr(feature = "extra-traits", deny(missing_debug_implementations))]
|
#![cfg_attr(feature = "extra-traits", deny(missing_debug_implementations))]
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate log;
|
||||||
extern crate proc_macro2;
|
extern crate proc_macro2;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate quote;
|
extern crate quote;
|
||||||
|
@ -79,7 +79,7 @@ fn compile_ast(mut ast: backend::ast::Program) -> String {
|
|||||||
let mut defined = BTreeSet::from_iter(
|
let mut defined = BTreeSet::from_iter(
|
||||||
vec![
|
vec![
|
||||||
"str", "char", "bool", "JsValue", "u8", "i8", "u16", "i16", "u32", "i32", "u64", "i64",
|
"str", "char", "bool", "JsValue", "u8", "i8", "u16", "i16", "u32", "i32", "u64", "i64",
|
||||||
"usize", "isize", "f32", "f64", "Result",
|
"usize", "isize", "f32", "f64", "Result", "String", "Vec",
|
||||||
].into_iter()
|
].into_iter()
|
||||||
.map(|id| proc_macro2::Ident::new(id, proc_macro2::Span::call_site())),
|
.map(|id| proc_macro2::Ident::new(id, proc_macro2::Span::call_site())),
|
||||||
);
|
);
|
||||||
|
@ -89,6 +89,30 @@ fn result_ty(t: syn::Type) -> syn::Type {
|
|||||||
ty.into()
|
ty.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn slice_ty(t: syn::Type) -> syn::Type {
|
||||||
|
syn::TypeSlice {
|
||||||
|
bracket_token: Default::default(),
|
||||||
|
elem: Box::new(t),
|
||||||
|
}.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn vec_ty(t: syn::Type) -> syn::Type {
|
||||||
|
let arguments = syn::PathArguments::AngleBracketed(syn::AngleBracketedGenericArguments {
|
||||||
|
colon2_token: None,
|
||||||
|
lt_token: Default::default(),
|
||||||
|
args: FromIterator::from_iter(vec![
|
||||||
|
syn::GenericArgument::Type(t),
|
||||||
|
]),
|
||||||
|
gt_token: Default::default(),
|
||||||
|
});
|
||||||
|
|
||||||
|
let ident = raw_ident("Vec");
|
||||||
|
let seg = syn::PathSegment { ident, arguments };
|
||||||
|
let path: syn::Path = seg.into();
|
||||||
|
let ty = syn::TypePath { qself: None, path };
|
||||||
|
ty.into()
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum TypePosition {
|
pub enum TypePosition {
|
||||||
Argument,
|
Argument,
|
||||||
@ -155,10 +179,18 @@ impl<'a> FirstPassRecord<'a> {
|
|||||||
// `DOMString` is not supported yet in other positions.
|
// `DOMString` is not supported yet in other positions.
|
||||||
webidl::ast::TypeKind::DOMString => return None,
|
webidl::ast::TypeKind::DOMString => return None,
|
||||||
|
|
||||||
|
// `ByteString -> `&[u8]` for arguments
|
||||||
|
webidl::ast::TypeKind::ByteString if pos == TypePosition::Argument => {
|
||||||
|
shared_ref(slice_ty(ident_ty(raw_ident("u8"))))
|
||||||
|
}
|
||||||
|
// ... and `Vec<u8>` for arguments
|
||||||
|
webidl::ast::TypeKind::ByteString => {
|
||||||
|
vec_ty(ident_ty(raw_ident("u8")))
|
||||||
|
}
|
||||||
|
|
||||||
// Support for these types is not yet implemented, so skip
|
// Support for these types is not yet implemented, so skip
|
||||||
// generating any bindings for this function.
|
// generating any bindings for this function.
|
||||||
webidl::ast::TypeKind::ArrayBuffer
|
webidl::ast::TypeKind::ArrayBuffer
|
||||||
| webidl::ast::TypeKind::ByteString
|
|
||||||
| webidl::ast::TypeKind::DataView
|
| webidl::ast::TypeKind::DataView
|
||||||
| webidl::ast::TypeKind::Error
|
| webidl::ast::TypeKind::Error
|
||||||
| webidl::ast::TypeKind::Float32Array
|
| webidl::ast::TypeKind::Float32Array
|
||||||
|
Loading…
x
Reference in New Issue
Block a user