Merge pull request #831 from alexcrichton/more-webidl-types

Add bindings for a few more "long long" types
This commit is contained in:
Nick Fitzgerald 2018-09-17 15:17:17 -07:00 committed by GitHub
commit 6ce5e6e1dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 4 deletions

View File

@ -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! {

View File

@ -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<IdlType<'a>> {
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))
@ -458,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"))),