Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigInt doesn't play nicely with WebGL bindings #800

Closed
blm768 opened this issue Sep 8, 2018 · 3 comments
Closed

BigInt doesn't play nicely with WebGL bindings #800

blm768 opened this issue Sep 8, 2018 · 3 comments
Labels
frontend:webidl Issues related to the WebIDL frontend to wasm-bindgen web-sys Issues related to the `web-sys` crate

Comments

@blm768
Copy link
Contributor

blm768 commented Sep 8, 2018

I've been experimenting with the WebGLRenderingContext bindings, and I've discovered that there's a weird interaction between the WebIDL types, wasm-bindgen's type mapping, and what browsers actually support in their WebGL implementations. Basically, there are several methods which take a GLintptr, which is a long long, which wasm-bindgen maps to i64 and BigInt. But the actual API throws an exception if you pass it a BigNum. Using an i32 or u32 seems to work fine.

The simple solution would seem to be changing the definition of GLintptr in the WebIDL, but is there another alternative that isn't so hacky?

@alexcrichton
Copy link
Contributor

Thanks for the report! I think it probably makes sense to basically never generate BigInt and/or i64 for webidl bindings as they're likely not already accepting it (as you've seen). Instead I think we could perhaps do something like (f64 or i32) to get larger ranges with f64 and more ergonomic ranges with i32?

cc @fitzgen

@alexcrichton alexcrichton added frontend:webidl Issues related to the WebIDL frontend to wasm-bindgen web-sys Issues related to the `web-sys` crate labels Sep 9, 2018
@blm768
Copy link
Contributor Author

blm768 commented Sep 10, 2018

I could see it going either way. Right now, it looks like BigInt support is extremely limited outside of Chrome, so it's probably not seeing significant use, but I could imagine cases where people would want it in the future. Unless long long shows up in other bindings, this feels like it's more of just an awkward quirk of the WebGL spec being almost a direct port of the OpenGL C API.

alexcrichton added a commit to alexcrichton/wasm-bindgen that referenced this issue Sep 10, 2018
This commit tweaks WebIDL expansion of the "long long" and "unsigned long long"
types to expand to a union of an 32-bit integer and a double. This reflects how
almost none of the APIs on the web today actually work with a `BigInt` (what the
previous Rust type of `i64` translates to) and how JS itself fundamentally
operates with these APIs.

Eventually this may not be necessary if we can natively connect to C++ engines
with the `i64` type, but until that day comes this should provide more useful
interfaces as they shoudl work in all browsers.

Closes rustwasm#800
@alexcrichton
Copy link
Contributor

Ok I've opened up #804 with a change to use i32/f64 instead of i64

alexcrichton added a commit to alexcrichton/wasm-bindgen that referenced this issue Sep 10, 2018
This commit tweaks WebIDL expansion of the "long long" and "unsigned long long"
types to expand to a union of an 32-bit integer and a double. This reflects how
almost none of the APIs on the web today actually work with a `BigInt` (what the
previous Rust type of `i64` translates to) and how JS itself fundamentally
operates with these APIs.

Eventually this may not be necessary if we can natively connect to C++ engines
with the `i64` type, but until that day comes this should provide more useful
interfaces as they shoudl work in all browsers.

Closes rustwasm#800
alexcrichton added a commit to alexcrichton/wasm-bindgen that referenced this issue Sep 10, 2018
This commit tweaks WebIDL expansion of the "long long" and "unsigned long long"
types to expand to a union of an 32-bit integer and a double. This reflects how
almost none of the APIs on the web today actually work with a `BigInt` (what the
previous Rust type of `i64` translates to) and how JS itself fundamentally
operates with these APIs.

Eventually this may not be necessary if we can natively connect to C++ engines
with the `i64` type, but until that day comes this should provide more useful
interfaces as they shoudl work in all browsers.

Closes rustwasm#800
MaxDesiatov added a commit to swiftwasm/WebAPIKit that referenced this issue May 12, 2022
This fixes an issue with 
```swift
func vertexAttribPointer(
  index: GLuint, 
  size: GLint, 
  type: GLenum, 
  normalized: GLboolean, 
  stride: GLsizei,
  offset: GLintptr
)
``` 
passing `offset` value of `BigInt` type to the JS function due to `public typealias GLintptr = Int64`, which led to `can't cast BigInt to number` runtime errors.

Either WebGL spec is wrong, or browsers implement it incorrectly. Rust folks had a similar issue and they went with `i32`, see rustwasm/wasm-bindgen#800.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend:webidl Issues related to the WebIDL frontend to wasm-bindgen web-sys Issues related to the `web-sys` crate
Projects
None yet
Development

No branches or pull requests

2 participants