Add support for optional chars

This commit is contained in:
Anton Danilkin
2018-08-03 20:45:57 +03:00
committed by Alex Crichton
parent 4a0c69ffed
commit afaf94a428
5 changed files with 85 additions and 0 deletions

View File

@ -178,6 +178,15 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
self.js_arguments.push(format!("{0} === 0xFFFFFF ? undefined : {0} !== 0", abi));
return Ok(())
},
Descriptor::Char => {
let value = self.shim_argument();
self.js_arguments.push(format!(
"{present} === 0 ? undefined : String.fromCodePoint({value})",
value = value,
present = abi,
));
return Ok(())
},
_ => bail!("unsupported optional argument type for calling JS function from Rust: {:?}", arg),
};
}
@ -439,6 +448,17 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
".to_string();
return Ok(());
},
Descriptor::Char => {
self.cx.expose_is_like_none();
self.cx.expose_uint32_memory();
self.shim_arguments.insert(0, "ret".to_string());
self.ret_expr = "
const val = JS;
getUint32Memory()[ret / 4] = !isLikeNone(val);
getUint32Memory()[ret / 4 + 1] = isLikeNone(val) ? 0 : val.codePointAt(0);
".to_string();
return Ok(());
},
_ => bail!("unsupported optional return type for calling JS function from Rust: {:?}", ty),
};
}