Map u64/i64 to BigInt in JS

This commit is an implementation of mapping u64/i64 to `BigInt` in JS through
the unstable BigInt APIs. The BigInt type will ship soon in Chrome and so this
commit builds out the necessary support for wasm-bindgen to use it!
This commit is contained in:
Alex Crichton
2018-05-05 14:10:25 -07:00
parent 484fbbfe31
commit 237fff0698
10 changed files with 364 additions and 63 deletions

View File

@ -98,6 +98,28 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
return Ok(())
}
if let Some(signed) = arg.get_64bit() {
let f = if signed {
self.cx.expose_int64_cvt_shim()
} else {
self.cx.expose_uint64_cvt_shim()
};
let hi = self.shim_argument();
let name = format!("n{}", abi);
self.prelude(&format!("\
u32CvtShim[0] = {lo};\n\
u32CvtShim[1] = {hi};\n\
const {name} = {f}[0];\n\
",
lo = abi,
hi = hi,
f = f,
name = name,
));
self.js_arguments.push(name);
return Ok(())
}
if let Some(class) = arg.rust_struct() {
if arg.is_by_ref() {
bail!("cannot invoke JS functions with custom ref types yet")
@ -229,6 +251,21 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
self.ret_expr = "return JS;".to_string();
return Ok(())
}
if let Some(signed) = ty.get_64bit() {
let f = if signed {
self.cx.expose_int64_memory();
"getInt64Memory"
} else {
self.cx.expose_uint64_memory();
"getUint64Memory"
};
self.shim_arguments.insert(0, "ret".to_string());
self.ret_expr = format!("\
const val = JS;\n\
{}()[ret / 8] = val;\n\
", f);
return Ok(())
}
self.ret_expr = match *ty {
Descriptor::Boolean => "return JS ? 1 : 0;".to_string(),
Descriptor::Anyref => {