mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-20 00:11:23 +00:00
Add support for optional bools
This commit is contained in:
committed by
Alex Crichton
parent
0ef528165f
commit
4a0c69ffed
@ -173,7 +173,13 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
bail!("unsupported optional argument type for calling JS function from Rust: {:?}", arg);
|
||||
match *arg {
|
||||
Descriptor::Boolean => {
|
||||
self.js_arguments.push(format!("{0} === 0xFFFFFF ? undefined : {0} !== 0", abi));
|
||||
return Ok(())
|
||||
},
|
||||
_ => bail!("unsupported optional argument type for calling JS function from Rust: {:?}", arg),
|
||||
};
|
||||
}
|
||||
|
||||
if let Some(signed) = arg.get_64() {
|
||||
@ -424,7 +430,17 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
bail!("unsupported optional return type for calling JS function from Rust: {:?}", ty);
|
||||
match *ty {
|
||||
Descriptor::Boolean => {
|
||||
self.cx.expose_is_like_none();
|
||||
self.ret_expr = "
|
||||
const val = JS;
|
||||
return isLikeNone(val) ? 0xFFFFFF : val ? 1 : 0;
|
||||
".to_string();
|
||||
return Ok(());
|
||||
},
|
||||
_ => bail!("unsupported optional return type for calling JS function from Rust: {:?}", ty),
|
||||
};
|
||||
}
|
||||
if ty.is_number() {
|
||||
self.ret_expr = "return JS;".to_string();
|
||||
|
Reference in New Issue
Block a user