Skip to content

Commit bcf43c4

Browse files
committed
Cleanup unused code, fix event handlers crash
1 parent 44739dc commit bcf43c4

28 files changed

+622
-300
lines changed

Sources/DOMKit/WebIDL/AddEventListenerOptions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ public struct AddEventListenerOptions: ExpressibleByDictionaryLiteral, JSBridged
1212

1313
private let dictionary: [String: JSValue]
1414

15-
public init(uniqueKeysWithValues elements: [(Key, JSValueConvertible)]) {
15+
public init(uniqueKeysWithValues elements: [(Key, ConvertibleToJSValue)]) {
1616
dictionary = Dictionary(uniqueKeysWithValues: elements.map { ($0.0.rawValue, $0.1.jsValue()) })
1717
}
1818

19-
public init(dictionaryLiteral elements: (Key, JSValueConvertible)...) {
19+
public init(dictionaryLiteral elements: (Key, ConvertibleToJSValue)...) {
2020
dictionary = Dictionary(uniqueKeysWithValues: elements.map { ($0.0.rawValue, $0.1.jsValue()) })
2121
}
2222

Sources/DOMKit/WebIDL/AnyDocumentAndElementEventHandlers.swift

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

Sources/DOMKit/WebIDL/AnyGlobalEventHandlers.swift

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

Sources/DOMKit/WebIDL/ArrayBufferView.swift

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,58 @@
55

66
import JavaScriptKit
77

8-
public typealias ArrayBufferView = Int8ArrayOrInt16ArrayOrInt32ArrayOrUint8ArrayOrUint16ArrayOrUint32ArrayOrUint8ClampedArrayOrFloat32ArrayOrFloat64ArrayOrDataView
8+
public enum ArrayBufferView: JSBridgedType {
9+
case int8Array(JSTypedArray<Int8>)
10+
case int16Array(JSTypedArray<Int16>)
11+
case int32Array(JSTypedArray<Int32>)
12+
case uint8Array(JSTypedArray<UInt8>)
13+
case uint16Array(JSTypedArray<UInt16>)
14+
case uint32Array(JSTypedArray<UInt32>)
15+
case uint8ClampedArray(JSTypedArray<UInt8>)
16+
case float32Array(JSTypedArray<Float>)
17+
case float64Array(JSTypedArray<Double>)
18+
case dataView(DataView)
19+
20+
public init?(from value: JSValue) {
21+
if let decoded: JSTypedArray<Int8> = value.fromJSValue() {
22+
self = .int8Array(decoded)
23+
} else if let decoded: JSTypedArray<Int16> = value.fromJSValue() {
24+
self = .int16Array(decoded)
25+
} else if let decoded: JSTypedArray<Int32> = value.fromJSValue() {
26+
self = .int32Array(decoded)
27+
} else if let decoded: JSTypedArray<UInt8> = value.fromJSValue() {
28+
self = .uint8Array(decoded)
29+
} else if let decoded: JSTypedArray<UInt16> = value.fromJSValue() {
30+
self = .uint16Array(decoded)
31+
} else if let decoded: JSTypedArray<UInt32> = value.fromJSValue() {
32+
self = .uint32Array(decoded)
33+
} else if let decoded: JSTypedArray<UInt8> = value.fromJSValue() {
34+
self = .uint8ClampedArray(decoded)
35+
} else if let decoded: JSTypedArray<Float> = value.fromJSValue() {
36+
self = .float32Array(decoded)
37+
} else if let decoded: JSTypedArray<Double> = value.fromJSValue() {
38+
self = .float64Array(decoded)
39+
} else if let decoded: DataView = value.fromJSValue() {
40+
self = .dataView(decoded)
41+
} else {
42+
return nil
43+
}
44+
}
45+
46+
public var value: JSValue { jsValue() }
47+
48+
public func jsValue() -> JSValue {
49+
switch self {
50+
case let .int8Array(v): return v.jsValue()
51+
case let .int16Array(v): return v.jsValue()
52+
case let .int32Array(v): return v.jsValue()
53+
case let .uint8Array(v): return v.jsValue()
54+
case let .uint16Array(v): return v.jsValue()
55+
case let .uint32Array(v): return v.jsValue()
56+
case let .uint8ClampedArray(v): return v.jsValue()
57+
case let .float32Array(v): return v.jsValue()
58+
case let .float64Array(v): return v.jsValue()
59+
case let .dataView(v): return v.jsValue()
60+
}
61+
}
62+
}

Sources/DOMKit/WebIDL/AssignedNodesOptions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ public struct AssignedNodesOptions: ExpressibleByDictionaryLiteral, JSBridgedTyp
1212

1313
private let dictionary: [String: JSValue]
1414

15-
public init(uniqueKeysWithValues elements: [(Key, JSValueConvertible)]) {
15+
public init(uniqueKeysWithValues elements: [(Key, ConvertibleToJSValue)]) {
1616
dictionary = Dictionary(uniqueKeysWithValues: elements.map { ($0.0.rawValue, $0.1.jsValue()) })
1717
}
1818

19-
public init(dictionaryLiteral elements: (Key, JSValueConvertible)...) {
19+
public init(dictionaryLiteral elements: (Key, ConvertibleToJSValue)...) {
2020
dictionary = Dictionary(uniqueKeysWithValues: elements.map { ($0.0.rawValue, $0.1.jsValue()) })
2121
}
2222

Sources/DOMKit/WebIDL/BlobPropertyBag.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ public struct BlobPropertyBag: ExpressibleByDictionaryLiteral, JSBridgedType {
1212

1313
private let dictionary: [String: JSValue]
1414

15-
public init(uniqueKeysWithValues elements: [(Key, JSValueConvertible)]) {
15+
public init(uniqueKeysWithValues elements: [(Key, ConvertibleToJSValue)]) {
1616
dictionary = Dictionary(uniqueKeysWithValues: elements.map { ($0.0.rawValue, $0.1.jsValue()) })
1717
}
1818

19-
public init(dictionaryLiteral elements: (Key, JSValueConvertible)...) {
19+
public init(dictionaryLiteral elements: (Key, ConvertibleToJSValue)...) {
2020
dictionary = Dictionary(uniqueKeysWithValues: elements.map { ($0.0.rawValue, $0.1.jsValue()) })
2121
}
2222

Sources/DOMKit/WebIDL/CustomEventInit.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ public struct CustomEventInit: ExpressibleByDictionaryLiteral, JSBridgedType {
1212

1313
private let dictionary: [String: JSValue]
1414

15-
public init(uniqueKeysWithValues elements: [(Key, JSValueConvertible)]) {
15+
public init(uniqueKeysWithValues elements: [(Key, ConvertibleToJSValue)]) {
1616
dictionary = Dictionary(uniqueKeysWithValues: elements.map { ($0.0.rawValue, $0.1.jsValue()) })
1717
}
1818

19-
public init(dictionaryLiteral elements: (Key, JSValueConvertible)...) {
19+
public init(dictionaryLiteral elements: (Key, ConvertibleToJSValue)...) {
2020
dictionary = Dictionary(uniqueKeysWithValues: elements.map { ($0.0.rawValue, $0.1.jsValue()) })
2121
}
2222

Sources/DOMKit/WebIDL/ElementCreationOptions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ public struct ElementCreationOptions: ExpressibleByDictionaryLiteral, JSBridgedT
1212

1313
private let dictionary: [String: JSValue]
1414

15-
public init(uniqueKeysWithValues elements: [(Key, JSValueConvertible)]) {
15+
public init(uniqueKeysWithValues elements: [(Key, ConvertibleToJSValue)]) {
1616
dictionary = Dictionary(uniqueKeysWithValues: elements.map { ($0.0.rawValue, $0.1.jsValue()) })
1717
}
1818

19-
public init(dictionaryLiteral elements: (Key, JSValueConvertible)...) {
19+
public init(dictionaryLiteral elements: (Key, ConvertibleToJSValue)...) {
2020
dictionary = Dictionary(uniqueKeysWithValues: elements.map { ($0.0.rawValue, $0.1.jsValue()) })
2121
}
2222

Sources/DOMKit/WebIDL/EndingType.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import JavaScriptKit
77

8-
public enum EndingType: String, JSValueCodable {
8+
public enum EndingType: String, JSValueCompatible {
99
public static func construct(from jsValue: JSValue) -> EndingType? {
1010
if let string = jsValue.string,
1111
let value = EndingType(rawValue: string)

Sources/DOMKit/WebIDL/EventInit.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ public struct EventInit: ExpressibleByDictionaryLiteral, JSBridgedType {
1212

1313
private let dictionary: [String: JSValue]
1414

15-
public init(uniqueKeysWithValues elements: [(Key, JSValueConvertible)]) {
15+
public init(uniqueKeysWithValues elements: [(Key, ConvertibleToJSValue)]) {
1616
dictionary = Dictionary(uniqueKeysWithValues: elements.map { ($0.0.rawValue, $0.1.jsValue()) })
1717
}
1818

19-
public init(dictionaryLiteral elements: (Key, JSValueConvertible)...) {
19+
public init(dictionaryLiteral elements: (Key, ConvertibleToJSValue)...) {
2020
dictionary = Dictionary(uniqueKeysWithValues: elements.map { ($0.0.rawValue, $0.1.jsValue()) })
2121
}
2222

0 commit comments

Comments
 (0)