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

@ -212,13 +212,14 @@ impl Descriptor {
}
}
pub fn stack_closure(&self) -> Option<&Function> {
let inner = match *self {
Descriptor::Ref(ref d) => &**d,
pub fn stack_closure(&self) -> Option<(&Function, bool)> {
let (inner, mutable) = match *self {
Descriptor::Ref(ref d) => (&**d, false),
Descriptor::RefMut(ref d) => (&**d, true),
_ => return None,
};
match *inner {
Descriptor::Function(ref f) => Some(f),
Descriptor::Function(ref f) => Some((f, mutable)),
_ => None,
}
}