From 941397745d187ed3b8b3c00ff679eb4df528a46a Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 14 Sep 2018 18:44:38 -0700 Subject: [PATCH 1/2] Enable DOMTimeStamp as UnsignedLongLong This is apparently how webidl defines it! --- crates/webidl/src/idl_type.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/webidl/src/idl_type.rs b/crates/webidl/src/idl_type.rs index 5e03e96d..3bfcf36e 100644 --- a/crates/webidl/src/idl_type.rs +++ b/crates/webidl/src/idl_type.rs @@ -287,7 +287,10 @@ impl<'a> ToIdlType<'a> for AttributedType<'a> { impl<'a> ToIdlType<'a> for Identifier<'a> { fn to_idl_type(&self, record: &FirstPassRecord<'a>) -> Option> { - if let Some(idl_type) = record.typedefs.get(&self.0) { + if self.0 == "DOMTimeStamp" { + // https://heycam.github.io/webidl/#DOMTimeStamp + Some(IdlType::UnsignedLongLong) + } else if let Some(idl_type) = record.typedefs.get(&self.0) { idl_type.to_idl_type(record) } else if record.interfaces.contains_key(self.0) { Some(IdlType::Interface(self.0)) From ae60bb4ba88ba1b2cda4502e810f812402bba2f0 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 14 Sep 2018 18:44:54 -0700 Subject: [PATCH 2/2] Translate LongLong types to f64 Any LongLong still present after flattening now gets translated to a `f64` type so we can bind these types. While not a true integral value or truely 64-bits of integer precision, it's all JS has anyway! --- crates/backend/src/codegen.rs | 2 +- crates/webidl/src/idl_type.rs | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/crates/backend/src/codegen.rs b/crates/backend/src/codegen.rs index df04405f..ca84b5b6 100644 --- a/crates/backend/src/codegen.rs +++ b/crates/backend/src/codegen.rs @@ -1087,7 +1087,7 @@ impl ToTokens for ast::Const { Null => unimplemented!(), }; - let declaration = quote!(#vis const #name: #ty = #value;); + let declaration = quote!(#vis const #name: #ty = #value as #ty;); if let Some(class) = &self.class { (quote! { diff --git a/crates/webidl/src/idl_type.rs b/crates/webidl/src/idl_type.rs index 3bfcf36e..2696ebfb 100644 --- a/crates/webidl/src/idl_type.rs +++ b/crates/webidl/src/idl_type.rs @@ -461,8 +461,22 @@ impl<'a> IdlType<'a> { IdlType::UnsignedShort => Some(ident_ty(raw_ident("u16"))), IdlType::Long => Some(ident_ty(raw_ident("i32"))), IdlType::UnsignedLong => Some(ident_ty(raw_ident("u32"))), - IdlType::LongLong => None, - IdlType::UnsignedLongLong => None, + + // Technically these are 64-bit numbers, but we're binding web + // APIs that don't actually have return the corresponding 64-bit + // type, `BigInt`. Instead the web basically uses floats for these + // values. We already expand these types in argument position to + // i32/f64 (convenience for i32, losslessness for f64). If we get + // here then we're looking at an un-flattened long type such as + // dictionary fields or return types. In order to generate bindings + // for these functions we just use `f64` here, which should match + // exactly what the JS web currently uses anyway. + // + // Perhaps one day we'll bind to u64/i64 here, but we need `BigInt` + // to see more usage! + IdlType::LongLong | + IdlType::UnsignedLongLong => Some(ident_ty(raw_ident("f64"))), + IdlType::Float => Some(ident_ty(raw_ident("f32"))), IdlType::UnrestrictedFloat => Some(ident_ty(raw_ident("f32"))), IdlType::Double => Some(ident_ty(raw_ident("f64"))),