Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multi-value JS engines #1863

Merged
merged 1 commit into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions crates/cli-support/src/js/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,22 @@ impl<'a, 'b> Builder<'a, 'b> {
}
}

// No return pointer? That's much easier! We just have one input
// of `ret` which is created in the JS shim below.
None => ret_args.push("ret".to_string()),
// No return pointer? That's much easier!
//
// 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);
let mut ret = outgoing::Outgoing::new(self.cx, &mut js);
Expand Down
2 changes: 1 addition & 1 deletion crates/cli-support/src/wasm2es6js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub fn typescript(module: &Module) -> Result<String, Error> {
ret = match ty.results().len() {
0 => "void",
1 => "number",
_ => bail!("cannot support multi-return yet"),
_ => "Array",
},
));
}
Expand Down