Add support for mutable stack closures

This commit adds support for passing `&mut FnMut(..)` to JS via imports. These
closures cannot be invoked recursively in JS (they invalidate themselves while
they're being invoked) and otherwise work the same as `&Fn(..)` closures.

Closes #123
This commit is contained in:
Alex Crichton
2018-04-13 14:13:14 -07:00
parent 3305621012
commit a8d6ca3d62
6 changed files with 198 additions and 12 deletions

View File

@ -495,7 +495,14 @@ impl ToTokens for ast::ImportFunction {
::into_abi(#var, &mut __stack);
});
}
ast::TypeKind::ByMutRef => panic!("urgh mut"),
ast::TypeKind::ByMutRef => {
abi_argument_names.push(name);
abi_arguments.push(quote! { #name: u32 });
arg_conversions.push(quote! {
let #name = <#t as ::wasm_bindgen::convert::ToRefMutWasmBoundary>
::to_abi_ref_mut(#name, &mut __stack);
});
}
ast::TypeKind::ByRef => {
abi_argument_names.push(name);
abi_arguments.push(quote! { #name: u32 });