mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-14 13:31:22 +00:00
Support multi-value JS engines (#1863)
This commit adds support to wasm-bindgen to run over interface types-enabled modules that use multi-value returns and returns are loaded from the returned array rather than from memory.
This commit is contained in:
@ -282,9 +282,22 @@ impl<'a, 'b> Builder<'a, 'b> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// No return pointer? That's much easier! We just have one input
|
// No return pointer? That's much easier!
|
||||||
// of `ret` which is created in the JS shim below.
|
//
|
||||||
None => ret_args.push("ret".to_string()),
|
// If there's one return value we just have one input of `ret`
|
||||||
|
// which is created in the JS shim below. If there's multiple
|
||||||
|
// return values (a multi-value module) then we'll pull results
|
||||||
|
// from the returned array.
|
||||||
|
None => {
|
||||||
|
let amt = self.cx.module.types.get(binding.wasm_ty).results().len();
|
||||||
|
if amt == 1 {
|
||||||
|
ret_args.push("ret".to_string());
|
||||||
|
} else {
|
||||||
|
for i in 0..amt {
|
||||||
|
ret_args.push(format!("ret[{}]", i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
js = JsBuilder::new(ret_args);
|
js = JsBuilder::new(ret_args);
|
||||||
let mut ret = outgoing::Outgoing::new(self.cx, &mut js);
|
let mut ret = outgoing::Outgoing::new(self.cx, &mut js);
|
||||||
|
@ -85,7 +85,7 @@ pub fn typescript(module: &Module) -> Result<String, Error> {
|
|||||||
ret = match ty.results().len() {
|
ret = match ty.results().len() {
|
||||||
0 => "void",
|
0 => "void",
|
||||||
1 => "number",
|
1 => "number",
|
||||||
_ => bail!("cannot support multi-return yet"),
|
_ => "Array",
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user