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

fix: post-return on error return bindgen #490

Merged
merged 3 commits into from
Aug 20, 2024
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
54 changes: 28 additions & 26 deletions crates/js-component-bindgen/src/function_bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1153,38 +1153,40 @@ impl Bindgen for FunctionBindgen<'_> {
Instruction::Return { amt, .. } => {
if *amt == 0 {
if let Some(f) = &self.post_return {
uwriteln!(self.src, "{f}()");
uwriteln!(self.src, "{f}();");
}
return;
}
let ret_assign = if self.post_return.is_some() {
"const retVal ="
} else if *amt == 1 && self.err == ErrHandling::ThrowResultErr {
let component_err = self.intrinsic(Intrinsic::ComponentError);
let op = &operands[0];
uwriteln!(self.src, "const retVal = {op};");
if let Some(f) = &self.post_return {
uwriteln!(self.src, "{f}(ret);");
}
uwriteln!(
self.src,
"if (typeof retVal === 'object' && retVal.tag === 'err') {{
throw new {component_err}(retVal.val);
}}
return retVal.val;"
);
} else {
"return"
};
if *amt == 1 {
if self.err == ErrHandling::ThrowResultErr {
let component_err = self.intrinsic(Intrinsic::ComponentError);
let op = &operands[0];
let ret_assign = if self.post_return.is_some() {
"const retVal ="
} else {
"return"
};
if *amt == 1 {
uwriteln!(self.src, "{ret_assign} {};", operands[0]);
} else {
uwriteln!(self.src, "{ret_assign} [{}];", operands.join(", "));
}
if let Some(f) = &self.post_return {
uwriteln!(
self.src,
"if (typeof {op} === 'object' && {op}.tag === 'err') {{
throw new {component_err}({op}.val);
}}
{ret_assign} {op}.val;"
"{f}(ret);
return retVal;"
);
} else {
uwriteln!(self.src, "{ret_assign} {};", operands[0]);
}
} else {
uwriteln!(self.src, "{ret_assign} [{}];", operands.join(", "));
}
if let Some(f) = &self.post_return {
uwriteln!(
self.src,
"{f}(ret);
return retVal;"
);
}
}

Expand Down
7 changes: 0 additions & 7 deletions crates/js-component-bindgen/src/transpile_bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1307,13 +1307,6 @@ impl<'a> Instantiator<'a, '_> {
// mapping can be used to construct virtual nested namespaces
// which is used eg to support WASI interface groupings
if let Some(iface_member) = iface_member {
// if local_name.starts_with("Poll") {
// dbg!( &[
// &import_specifier,
// &iface_member.to_lower_camel_case(),
// &import_binding.as_ref().unwrap().to_string(),
// ], &local_name);
// }
self.gen.esm_bindgen.add_import_binding(
&[
import_specifier,
Expand Down
Loading