Skip to content

Commit 7d5867e

Browse files
committed
Update to new JSKit API, add support for callback interfaces
1 parent c280c36 commit 7d5867e

File tree

133 files changed

+1171
-1337
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+1171
-1337
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let package = Package(
1111
targets: ["DOMKit"]),
1212
],
1313
dependencies: [
14-
.package(name: "JavaScriptKit", url: "https://github.com/j-f1/forked-JavaScriptKit.git", .revision("fa1a06d")),
14+
.package(name: "JavaScriptKit", url: "https://github.com/j-f1/forked-JavaScriptKit.git", .revision("745bb00")),
1515
],
1616
targets: [
1717
.target(

Sources/DOMKit/ECMAScript/ArrayBuffer.swift

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,33 @@
33
//
44

55
import JavaScriptKit
6+
import _CJavaScriptKit
67

7-
public class ArrayBuffer: JSBridgedType {
8+
public typealias Int8Array = JSTypedArray<Int8>
9+
public typealias Int16Array = JSTypedArray<Int16>
10+
public typealias Int32Array = JSTypedArray<Int32>
11+
public typealias Uint8Array = JSTypedArray<UInt8>
12+
public typealias Uint16Array = JSTypedArray<UInt16>
13+
public typealias Uint32Array = JSTypedArray<UInt32>
14+
//public typealias Uint8ClampedArray = JSTypedArray<Uint8Clamped>
15+
public typealias Float32Array = JSTypedArray<Float32>
16+
public typealias Float64Array = JSTypedArray<Float64>
17+
18+
public class ArrayBuffer: JSBridgedClass {
819

920
public class var classRef: JSFunctionRef { JSObjectRef.global.ArrayBuffer.function! }
1021

1122
public let objectRef: JSObjectRef
1223

13-
public required init(objectRef: JSObjectRef) {
24+
public required init(withCompatibleObject objectRef: JSObjectRef) {
1425
self.objectRef = objectRef
1526
}
1627

1728
public convenience init(length: Int) {
18-
19-
self.init(objectRef: Self.classRef(new: length))
29+
self.init(withCompatibleObject: Self.classRef.new( length))
2030
}
2131

2232
public static func isView(_ object: AnyJSValueCodable) -> Bool {
23-
return JSObjectRef.global.ArrayBuffer.object!.isView!(object).fromJSValue()
33+
return JSObjectRef.global.ArrayBuffer.object!.isView!(object).fromJSValue()!
2434
}
2535
}

Sources/DOMKit/ECMAScript/DataView.swift

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
import JavaScriptKit
66

7-
public class DataView: JSBridgedType {
7+
public class DataView: JSBridgedClass {
88

99
public class var classRef: JSFunctionRef { JSObjectRef.global.DataView.function! }
1010

1111
public let objectRef: JSObjectRef
1212

13-
public required init(objectRef: JSObjectRef) {
13+
public required init(withCompatibleObject objectRef: JSObjectRef) {
1414
_buffer = ReadonlyAttribute(objectRef: objectRef, name: "buffer")
1515
_byteOffset = ReadonlyAttribute(objectRef: objectRef, name: "byteOffset")
1616
_byteLength = ReadonlyAttribute(objectRef: objectRef, name: "byteLength")
@@ -19,17 +19,17 @@ public class DataView: JSBridgedType {
1919

2020
public convenience init(buffer: ArrayBuffer) {
2121

22-
self.init(objectRef: DataView.classRef(new: JSValue(from: buffer)))
22+
self.init(withCompatibleObject: DataView.classRef.new(buffer.jsValue()))
2323
}
2424

2525
public convenience init(buffer: ArrayBuffer, byteOffset: UInt32) {
2626

27-
self.init(objectRef: DataView.classRef(new: JSValue(from: buffer), JSValue(from: byteOffset)))
27+
self.init(withCompatibleObject: DataView.classRef.new(buffer.jsValue(), byteOffset.jsValue()))
2828
}
2929

3030
public convenience init(buffer: ArrayBuffer, byteOffset: UInt32, byteLength: UInt32) {
3131

32-
self.init(objectRef: DataView.classRef(new: JSValue(from: buffer), JSValue(from: byteOffset), JSValue(from: byteLength)))
32+
self.init(withCompatibleObject: DataView.classRef.new(buffer.jsValue(), byteOffset.jsValue(), byteLength.jsValue()))
3333
}
3434

3535
@ReadonlyAttribute
@@ -44,128 +44,128 @@ public class DataView: JSBridgedType {
4444

4545
public func getFloat32(byteOffset: UInt32) -> Float {
4646

47-
return objectRef.getFloat32!(JSValue(from: byteOffset)).fromJSValue()
47+
return objectRef.getFloat32!(byteOffset.jsValue()).fromJSValue()!
4848
}
4949

5050
public func getFloat32(byteOffset: UInt32, littleEndian: Bool) -> Float {
5151

52-
return objectRef.getFloat32!(JSValue(from: byteOffset), JSValue(from: littleEndian)).fromJSValue()
52+
return objectRef.getFloat32!(byteOffset.jsValue(), littleEndian.jsValue()).fromJSValue()!
5353
}
5454

5555
public func getFloat64(byteOffset: UInt32) -> Double {
5656

57-
return objectRef.getFloat64!(JSValue(from: byteOffset)).fromJSValue()
57+
return objectRef.getFloat64!(byteOffset.jsValue()).fromJSValue()!
5858
}
5959

6060
public func getFloat64(byteOffset: UInt32, littleEndian: Bool) -> Double {
6161

62-
return objectRef.getFloat64!(JSValue(from: byteOffset), JSValue(from: littleEndian)).fromJSValue()
62+
return objectRef.getFloat64!(byteOffset.jsValue(), littleEndian.jsValue()).fromJSValue()!
6363
}
6464

6565
public func getUint8(byteOffset: UInt32) -> UInt8 {
6666

67-
return objectRef.getUint8!(JSValue(from: byteOffset)).fromJSValue()
67+
return objectRef.getUint8!(byteOffset.jsValue()).fromJSValue()!
6868
}
6969

7070
public func getUint16(byteOffset: UInt32) -> UInt16 {
7171

72-
return objectRef.getUint16!(JSValue(from: byteOffset)).fromJSValue()
72+
return objectRef.getUint16!(byteOffset.jsValue()).fromJSValue()!
7373
}
7474

7575
public func getUint16(byteOffset: UInt32, littleEndian: Bool) -> UInt16 {
7676

77-
return objectRef.getUint16!(JSValue(from: byteOffset), JSValue(from: littleEndian)).fromJSValue()
77+
return objectRef.getUint16!(byteOffset.jsValue(), littleEndian.jsValue()).fromJSValue()!
7878
}
7979

8080
public func getUint32(byteOffset: UInt32) -> UInt32 {
8181

82-
return objectRef.getUint32!(JSValue(from: byteOffset)).fromJSValue()
82+
return objectRef.getUint32!(byteOffset.jsValue()).fromJSValue()!
8383
}
8484

8585
public func getUint32(byteOffset: UInt32, littleEndian: Bool) -> UInt32 {
8686

87-
return objectRef.getUint32!(JSValue(from: byteOffset), JSValue(from: littleEndian)).fromJSValue()
87+
return objectRef.getUint32!(byteOffset.jsValue(), littleEndian.jsValue()).fromJSValue()!
8888
}
8989

9090
public func getInt8(byteOffset: UInt32) -> Int8 {
9191

92-
return objectRef.getInt8!(JSValue(from: byteOffset)).fromJSValue()
92+
return objectRef.getInt8!(byteOffset.jsValue()).fromJSValue()!
9393
}
9494

9595
public func getInt16(byteOffset: UInt32) -> Int16 {
9696

97-
return objectRef.getInt16!(JSValue(from: byteOffset)).fromJSValue()
97+
return objectRef.getInt16!(byteOffset.jsValue()).fromJSValue()!
9898
}
9999

100100
public func getInt16(byteOffset: UInt32, littleEndian: Bool) -> Int16 {
101101

102-
return objectRef.getInt16!(JSValue(from: byteOffset), JSValue(from: littleEndian)).fromJSValue()
102+
return objectRef.getInt16!(byteOffset.jsValue(), littleEndian.jsValue()).fromJSValue()!
103103
}
104104

105105
public func getInt32(byteOffset: UInt32) -> Int32 {
106106

107-
return objectRef.getInt32!(JSValue(from: byteOffset)).fromJSValue()
107+
return objectRef.getInt32!(byteOffset.jsValue()).fromJSValue()!
108108
}
109109

110110
public func getInt32(byteOffset: UInt32, littleEndian: Bool) -> Int32 {
111111

112-
return objectRef.getInt32!(JSValue(from: byteOffset), JSValue(from: littleEndian)).fromJSValue()
112+
return objectRef.getInt32!(byteOffset.jsValue(), littleEndian.jsValue()).fromJSValue()!
113113
}
114114

115115
public func setUint8(byteOffset: UInt32, value: UInt8) {
116-
_ = objectRef.setUint8!(JSValue(from: byteOffset), JSValue(from: value))
116+
_ = objectRef.setUint8!(byteOffset.jsValue(), value.jsValue())
117117
}
118118

119119
public func setUint16(byteOffset: UInt32, value: UInt16) {
120-
_ = objectRef.setUint16!(JSValue(from: byteOffset), JSValue(from: value))
120+
_ = objectRef.setUint16!(byteOffset.jsValue(), value.jsValue())
121121
}
122122

123123
public func setUint16(byteOffset: UInt32, value: UInt16, littleEndian: Bool) {
124-
_ = objectRef.setUint16!(JSValue(from: byteOffset), JSValue(from: value), JSValue(from: littleEndian))
124+
_ = objectRef.setUint16!(byteOffset.jsValue(), value.jsValue(), littleEndian.jsValue())
125125
}
126126

127127
public func setUint32(byteOffset: UInt32, value: UInt32) {
128-
_ = objectRef.setUint32!(JSValue(from: byteOffset), JSValue(from: value))
128+
_ = objectRef.setUint32!(byteOffset.jsValue(), value.jsValue())
129129
}
130130

131131
public func setUint32(byteOffset: UInt32, value: UInt32, littleEndian: Bool) {
132-
_ = objectRef.setUint32!(JSValue(from: byteOffset), JSValue(from: value), JSValue(from: littleEndian))
132+
_ = objectRef.setUint32!(byteOffset.jsValue(), value.jsValue(), littleEndian.jsValue())
133133
}
134134

135135
public func setInt8(byteOffset: UInt32, value: Int8) {
136-
_ = objectRef.setUint8!(JSValue(from: byteOffset), JSValue(from: value))
136+
_ = objectRef.setUint8!(byteOffset.jsValue(), value.jsValue())
137137
}
138138

139139
public func setInt16(byteOffset: UInt32, value: Int16) {
140-
_ = objectRef.setInt16!(JSValue(from: byteOffset), JSValue(from: value))
140+
_ = objectRef.setInt16!(byteOffset.jsValue(), value.jsValue())
141141
}
142142

143143
public func setInt16(byteOffset: UInt32, value: Int16, littleEndian: Bool) {
144-
_ = objectRef.setInt16!(JSValue(from: byteOffset), JSValue(from: value), JSValue(from: littleEndian))
144+
_ = objectRef.setInt16!(byteOffset.jsValue(), value.jsValue(), littleEndian.jsValue())
145145
}
146146

147147
public func setInt32(byteOffset: UInt32, value: Int32) {
148-
_ = objectRef.setInt32!(JSValue(from: byteOffset), JSValue(from: value))
148+
_ = objectRef.setInt32!(byteOffset.jsValue(), value.jsValue())
149149
}
150150

151151
public func setInt32(byteOffset: UInt32, value: Int32, littleEndian: Bool) {
152-
_ = objectRef.setInt32!(JSValue(from: byteOffset), JSValue(from: value), JSValue(from: littleEndian))
152+
_ = objectRef.setInt32!(byteOffset.jsValue(), value.jsValue(), littleEndian.jsValue())
153153
}
154154

155155
public func setFloat32(byteOffset: UInt32, value: Float) {
156-
_ = objectRef.setFloat32!(JSValue(from: byteOffset), JSValue(from: value))
156+
_ = objectRef.setFloat32!(byteOffset.jsValue(), value.jsValue())
157157
}
158158

159159
public func setFloat32(byteOffset: UInt32, value: Float, littleEndian: Bool) {
160-
_ = objectRef.setFloat32!(JSValue(from: byteOffset), JSValue(from: value), JSValue(from: littleEndian))
160+
_ = objectRef.setFloat32!(byteOffset.jsValue(), value.jsValue(), littleEndian.jsValue())
161161
}
162162

163163
public func setFloat64(byteOffset: UInt32, value: Double) {
164-
_ = objectRef.setFloat64!(JSValue(from: byteOffset), JSValue(from: value))
164+
_ = objectRef.setFloat64!(byteOffset.jsValue(), value.jsValue())
165165
}
166166

167167
public func setFloat64(byteOffset: UInt32, value: Double, littleEndian: Bool) {
168-
_ = objectRef.setFloat64!(JSValue(from: byteOffset), JSValue(from: value), JSValue(from: littleEndian))
168+
_ = objectRef.setFloat64!(byteOffset.jsValue(), value.jsValue(), littleEndian.jsValue())
169169
}
170170
}
171171

Sources/DOMKit/ECMAScript/Date.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44

55
import JavaScriptKit
66

7-
public class Date: JSBridgedType {
7+
public class Date: JSBridgedClass {
88

99
public class var classRef: JSFunctionRef { JSObjectRef.global.Date.function! }
1010

1111
public let objectRef: JSObjectRef
1212

13-
public required init(objectRef: JSObjectRef) {
13+
public required init(withCompatibleObject objectRef: JSObjectRef) {
1414
self.objectRef = objectRef
1515
}
1616

1717
public convenience init() {
18-
self.init(objectRef: Date.classRef(.new))
18+
self.init(withCompatibleObject: Date.classRef.new())
1919
}
2020

2121
public func toDateString() -> String {
22-
return objectRef.toDateString!().fromJSValue()
22+
return objectRef.toDateString!().fromJSValue()!
2323
}
2424

2525
public func getTime() -> Double {
26-
return objectRef.getTime!().fromJSValue()
26+
return objectRef.getTime!().fromJSValue()!
2727
}
2828
}

0 commit comments

Comments
 (0)