Skip to content

Commit 5b41da2

Browse files
authored
Map GLintptr IDL type to Swift Int32 (#42)
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.
1 parent f83fbb4 commit 5b41da2

File tree

4 files changed

+6
-2
lines changed

4 files changed

+6
-2
lines changed

Sources/WebAPIKit/Generated.swift

-1
Original file line numberDiff line numberDiff line change
@@ -21238,7 +21238,6 @@ public typealias GLbyte = Int8
2123821238
public typealias GLshort = Int16
2123921239
public typealias GLint = Int32
2124021240
public typealias GLsizei = Int32
21241-
public typealias GLintptr = Int64
2124221241
public typealias GLsizeiptr = Int64
2124321242
public typealias GLubyte = UInt8
2124421243
public typealias GLushort = UInt16

Sources/WebAPIKit/Support.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import JavaScriptKit
21
@_exported import ECMAScript
2+
import JavaScriptKit
33

44
/* TODO: fix this */
55
public typealias __UNSUPPORTED_BIGINT__ = JSValue
@@ -22,3 +22,4 @@ public typealias HTMLOrSVGImageElement = HTMLImageElement
2222
public typealias HTMLOrSVGScriptElement = HTMLScriptElement
2323
public typealias BodyInit = XMLHttpRequestBodyInit
2424
public typealias CustomElementConstructor = JSFunction
25+
public typealias GLintptr = Int32

Sources/WebIDLToSwift/MergeDeclarations.swift

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ enum DeclarationMerger {
77
"CustomElementConstructor",
88
"ArrayBufferView",
99
"RotationMatrixType",
10+
// Mapped to `Int32` manually. This can't be represented as `Int64` due to `BigInt` representation on JS side,
11+
// but as a pointer it can't be represented as floating point number either.
12+
"GLintptr",
1013
]
1114
static let validExposures: Set<String> = ["Window"]
1215

Sources/WebIDLToSwift/WebIDL+SwiftRepresentation.swift

+1
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ extension IDLType: SwiftRepresentable {
541541
"byte": "Int8",
542542
"short": "Int16",
543543
"long": "Int32",
544+
// FIXME: this maps to BigInt when bridged to JS, which most probably leads to issues.
544545
"long long": "Int64",
545546
"Function": "JSFunction",
546547
"bigint": "__UNSUPPORTED_BIGINT__",

0 commit comments

Comments
 (0)