Skip to content

Commit 6ce5e6e

Browse files
authored
Merge pull request #831 from alexcrichton/more-webidl-types
Add bindings for a few more "long long" types
2 parents 4db375b + ae60bb4 commit 6ce5e6e

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

crates/backend/src/codegen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ impl ToTokens for ast::Const {
10871087
Null => unimplemented!(),
10881088
};
10891089

1090-
let declaration = quote!(#vis const #name: #ty = #value;);
1090+
let declaration = quote!(#vis const #name: #ty = #value as #ty;);
10911091

10921092
if let Some(class) = &self.class {
10931093
(quote! {

crates/webidl/src/idl_type.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,10 @@ impl<'a> ToIdlType<'a> for AttributedType<'a> {
287287

288288
impl<'a> ToIdlType<'a> for Identifier<'a> {
289289
fn to_idl_type(&self, record: &FirstPassRecord<'a>) -> Option<IdlType<'a>> {
290-
if let Some(idl_type) = record.typedefs.get(&self.0) {
290+
if self.0 == "DOMTimeStamp" {
291+
// https://heycam.github.io/webidl/#DOMTimeStamp
292+
Some(IdlType::UnsignedLongLong)
293+
} else if let Some(idl_type) = record.typedefs.get(&self.0) {
291294
idl_type.to_idl_type(record)
292295
} else if record.interfaces.contains_key(self.0) {
293296
Some(IdlType::Interface(self.0))
@@ -458,8 +461,22 @@ impl<'a> IdlType<'a> {
458461
IdlType::UnsignedShort => Some(ident_ty(raw_ident("u16"))),
459462
IdlType::Long => Some(ident_ty(raw_ident("i32"))),
460463
IdlType::UnsignedLong => Some(ident_ty(raw_ident("u32"))),
461-
IdlType::LongLong => None,
462-
IdlType::UnsignedLongLong => None,
464+
465+
// Technically these are 64-bit numbers, but we're binding web
466+
// APIs that don't actually have return the corresponding 64-bit
467+
// type, `BigInt`. Instead the web basically uses floats for these
468+
// values. We already expand these types in argument position to
469+
// i32/f64 (convenience for i32, losslessness for f64). If we get
470+
// here then we're looking at an un-flattened long type such as
471+
// dictionary fields or return types. In order to generate bindings
472+
// for these functions we just use `f64` here, which should match
473+
// exactly what the JS web currently uses anyway.
474+
//
475+
// Perhaps one day we'll bind to u64/i64 here, but we need `BigInt`
476+
// to see more usage!
477+
IdlType::LongLong |
478+
IdlType::UnsignedLongLong => Some(ident_ty(raw_ident("f64"))),
479+
463480
IdlType::Float => Some(ident_ty(raw_ident("f32"))),
464481
IdlType::UnrestrictedFloat => Some(ident_ty(raw_ident("f32"))),
465482
IdlType::Double => Some(ident_ty(raw_ident("f64"))),

0 commit comments

Comments
 (0)