Skip to content

Commit cd16a42

Browse files
committed
fix ArrayBufferView
1 parent 2ddcf8e commit cd16a42

5 files changed

+96
-103
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// This file was auto-generated by WebIDLToSwift. DO NOT EDIT!
2+
3+
import JavaScriptEventLoop
4+
import JavaScriptKit
5+
6+
// TODO: expand this to BigInt arrays
7+
public protocol AnyArrayBufferView: ConvertibleToJSValue {}
8+
extension DataView: AnyArrayBufferView {}
9+
extension JSTypedArray: AnyArrayBufferView {}
10+
11+
public enum ArrayBufferView: JSValueCompatible, AnyArrayBufferView {
12+
case dataView(DataView)
13+
// case bigInt64Array(BigInt64Array)
14+
// case bigUint64Array(BigUint64Array)
15+
case float32Array(Float32Array)
16+
case float64Array(Float64Array)
17+
case int16Array(Int16Array)
18+
case int32Array(Int32Array)
19+
case int8Array(Int8Array)
20+
case uint16Array(Uint16Array)
21+
case uint32Array(Uint32Array)
22+
case uint8Array(Uint8Array)
23+
case uint8ClampedArray(Uint8ClampedArray)
24+
25+
public static func construct(from value: JSValue) -> Self? {
26+
// if let bigInt64Array: BigInt64Array = value.fromJSValue() {
27+
// return .bigInt64Array(bigInt64Array)
28+
// }
29+
// if let bigUint64Array: BigUint64Array = value.fromJSValue() {
30+
// return .bigUint64Array(bigUint64Array)
31+
// }
32+
if let dataView: DataView = value.fromJSValue() {
33+
return .dataView(dataView)
34+
}
35+
if let float32Array: Float32Array = value.fromJSValue() {
36+
return .float32Array(float32Array)
37+
}
38+
if let float64Array: Float64Array = value.fromJSValue() {
39+
return .float64Array(float64Array)
40+
}
41+
if let int16Array: Int16Array = value.fromJSValue() {
42+
return .int16Array(int16Array)
43+
}
44+
if let int32Array: Int32Array = value.fromJSValue() {
45+
return .int32Array(int32Array)
46+
}
47+
if let int8Array: Int8Array = value.fromJSValue() {
48+
return .int8Array(int8Array)
49+
}
50+
if let uint16Array: Uint16Array = value.fromJSValue() {
51+
return .uint16Array(uint16Array)
52+
}
53+
if let uint32Array: Uint32Array = value.fromJSValue() {
54+
return .uint32Array(uint32Array)
55+
}
56+
if let uint8Array: Uint8Array = value.fromJSValue() {
57+
return .uint8Array(uint8Array)
58+
}
59+
if let uint8ClampedArray: Uint8ClampedArray = value.fromJSValue() {
60+
return .uint8ClampedArray(uint8ClampedArray)
61+
}
62+
return nil
63+
}
64+
65+
public func jsValue() -> JSValue {
66+
switch self {
67+
// case let .bigInt64Array(bigInt64Array):
68+
// return bigInt64Array.jsValue()
69+
// case let .bigUint64Array(bigUint64Array):
70+
// return bigUint64Array.jsValue()
71+
case let .dataView(dataView):
72+
return dataView.jsValue()
73+
case let .float32Array(float32Array):
74+
return float32Array.jsValue()
75+
case let .float64Array(float64Array):
76+
return float64Array.jsValue()
77+
case let .int16Array(int16Array):
78+
return int16Array.jsValue()
79+
case let .int32Array(int32Array):
80+
return int32Array.jsValue()
81+
case let .int8Array(int8Array):
82+
return int8Array.jsValue()
83+
case let .uint16Array(uint16Array):
84+
return uint16Array.jsValue()
85+
case let .uint32Array(uint32Array):
86+
return uint32Array.jsValue()
87+
case let .uint8Array(uint8Array):
88+
return uint8Array.jsValue()
89+
case let .uint8ClampedArray(uint8ClampedArray):
90+
return uint8ClampedArray.jsValue()
91+
}
92+
}
93+
}

Sources/DOMKit/WebIDL/BigInt64Array_or_BigUint64Array_or_DataView_or_Float32Array_or_Float64Array_or_Int16Array_or_Int32Array_or_Int8Array_or_Uint16Array_or_Uint32Array_or_Uint8Array_or_Uint8ClampedArray.swift

Lines changed: 0 additions & 102 deletions
This file was deleted.

Sources/DOMKit/WebIDL/Typedefs.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ public typealias GPUColor = GPUColorDict_or_seq_of_Double
122122
public typealias GPUOrigin2D = GPUOrigin2DDict_or_seq_of_GPUIntegerCoordinate
123123
public typealias GPUOrigin3D = GPUOrigin3DDict_or_seq_of_GPUIntegerCoordinate
124124
public typealias GPUExtent3D = GPUExtent3DDict_or_seq_of_GPUIntegerCoordinate
125-
public typealias ArrayBufferView = BigInt64Array_or_BigUint64Array_or_DataView_or_Float32Array_or_Float64Array_or_Int16Array_or_Int32Array_or_Int8Array_or_Uint16Array_or_Uint32Array_or_Uint8Array_or_Uint8ClampedArray
126125
public typealias BufferSource = ArrayBuffer_or_ArrayBufferView
127126
public typealias DOMTimeStamp = UInt64
128127
public typealias MLNamedOperands = [String: MLOperand]

Sources/WebIDLToSwift/IDLBuilder.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ enum IDLBuilder {
1616
"Client_or_MessagePort_or_ServiceWorker", "ExtendableMessageEventInit",
1717
// redundant unions
1818
"CSSColorValue_or_CSSStyleValue",
19+
// implemented manually
20+
"BigInt64Array_or_BigUint64Array_or_DataView_or_Float32Array_or_Float64Array_or_Int16Array_or_Int32Array_or_Int8Array_or_Uint16Array_or_Uint32Array_or_Uint8Array_or_Uint8ClampedArray",
1921
]
2022

2123
static let outDir = "Sources/DOMKit/WebIDL/"

Sources/WebIDLToSwift/MergeDeclarations.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ enum DeclarationMerger {
55
"Function",
66
"AudioWorkletProcessorConstructor",
77
"CustomElementConstructor",
8+
"ArrayBufferView"
89
]
910
static let validExposures: Set<String> = ["Window"]
1011

0 commit comments

Comments
 (0)