Skip to content

Commit e934a0f

Browse files
authored
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.
1 parent 8513900 commit e934a0f

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

crates/cli-support/src/js/binding.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,22 @@ impl<'a, 'b> Builder<'a, 'b> {
282282
}
283283
}
284284

285-
// No return pointer? That's much easier! We just have one input
286-
// of `ret` which is created in the JS shim below.
287-
None => ret_args.push("ret".to_string()),
285+
// No return pointer? That's much easier!
286+
//
287+
// If there's one return value we just have one input of `ret`
288+
// which is created in the JS shim below. If there's multiple
289+
// return values (a multi-value module) then we'll pull results
290+
// from the returned array.
291+
None => {
292+
let amt = self.cx.module.types.get(binding.wasm_ty).results().len();
293+
if amt == 1 {
294+
ret_args.push("ret".to_string());
295+
} else {
296+
for i in 0..amt {
297+
ret_args.push(format!("ret[{}]", i));
298+
}
299+
}
300+
}
288301
}
289302
js = JsBuilder::new(ret_args);
290303
let mut ret = outgoing::Outgoing::new(self.cx, &mut js);

crates/cli-support/src/wasm2es6js.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub fn typescript(module: &Module) -> Result<String, Error> {
8585
ret = match ty.results().len() {
8686
0 => "void",
8787
1 => "number",
88-
_ => bail!("cannot support multi-return yet"),
88+
_ => "Array",
8989
},
9090
));
9191
}

0 commit comments

Comments
 (0)