Skip to content

Commit 23b7e5a

Browse files
committed
Enable a couple more APIs
1 parent 14827c6 commit 23b7e5a

File tree

4 files changed

+40
-15
lines changed

4 files changed

+40
-15
lines changed

Sources/DOM/Customized.swift

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import Foundation
1+
import ECMAScript
2+
import JavaScriptKit
23

34
public extension HTMLFormControlsCollection {
45
// removes `override` since the superclass returns a more constrained type `Element`
@@ -7,3 +8,29 @@ public extension HTMLFormControlsCollection {
78
return this[Strings.namedItem].function!(this: this, arguments: [_toJSValue(name)]).fromJSValue()!
89
}
910
}
11+
12+
// copied out of generated file to rename `returnValue` to `returnValueAsString` so the types don’t collide
13+
public class BeforeUnloadEvent: Event {
14+
@inlinable override public class var constructor: JSFunction? { JSObject.global[Strings.BeforeUnloadEvent].function }
15+
16+
public required init(unsafelyWrapping jsObject: JSObject) {
17+
_returnValue = ReadWriteAttribute(jsObject: jsObject, name: Strings.returnValue)
18+
super.init(unsafelyWrapping: jsObject)
19+
}
20+
21+
@available(*, unavailable)
22+
override public var returnValue: Bool {
23+
get { !_returnValue.wrappedValue.isEmpty }
24+
set {}
25+
}
26+
27+
@usableFromInline let _returnValue: ReadWriteAttribute<String>
28+
@inlinable public var returnValueAsString: String {
29+
get { _returnValue.wrappedValue }
30+
set { _returnValue.wrappedValue = newValue }
31+
}
32+
}
33+
34+
extension Strings {
35+
@usableFromInline static let BeforeUnloadEvent: JSString = "BeforeUnloadEvent"
36+
}

Sources/DOM/Generated.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -949,16 +949,6 @@ public class BarProp: JSBridgedClass {
949949
public var visible: Bool
950950
}
951951

952-
public class BeforeUnloadEvent: Event {
953-
@inlinable override public class var constructor: JSFunction? { JSObject.global[Strings.BeforeUnloadEvent].function }
954-
955-
public required init(unsafelyWrapping jsObject: JSObject) {
956-
super.init(unsafelyWrapping: jsObject)
957-
}
958-
959-
// XXX: member 'returnValue' is ignored
960-
}
961-
962952
public enum BitrateMode: JSString, JSValueCompatible {
963953
case constant = "constant"
964954
case variable = "variable"
@@ -17882,7 +17872,6 @@ public class XSLTProcessor: JSBridgedClass {
1788217872
@usableFromInline static let AudioTrack: JSString = "AudioTrack"
1788317873
@usableFromInline static let AudioTrackList: JSString = "AudioTrackList"
1788417874
@usableFromInline static let BarProp: JSString = "BarProp"
17885-
@usableFromInline static let BeforeUnloadEvent: JSString = "BeforeUnloadEvent"
1788617875
@usableFromInline static let Blob: JSString = "Blob"
1788717876
@usableFromInline static let BlobEvent: JSString = "BlobEvent"
1788817877
@usableFromInline static let BroadcastChannel: JSString = "BroadcastChannel"

Sources/WebAudio/Customized.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import ECMAScript
2+
3+
public extension AudioBufferSourceNode {
4+
// removes `override` since the superclass function has fewer parameters
5+
@inlinable func start(when: Double? = nil, offset: Double? = nil, duration: Double? = nil) {
6+
let this = jsObject
7+
_ = this[Strings.start].function!(this: this, arguments: [_toJSValue(when), _toJSValue(offset), _toJSValue(duration)])
8+
}
9+
}

Sources/WebIDLToSwift/IDLBuilder.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ enum IDLBuilder {
2727
"RenderingContext",
2828
"OffscreenRenderingContext",
2929
"OffscreenRenderingContextId",
30+
"BeforeUnloadEvent",
3031
]
3132

3233
static func writeFile(path: String, content: String, moduleDependencies: [String]) throws {
@@ -65,14 +66,13 @@ enum IDLBuilder {
6566
// XPathNSResolver
6667
"XPathEvaluatorBase": ["createExpression", "createNSResolver", "evaluate"],
6768
// invalid override in Swift
68-
"BeforeUnloadEvent": ["returnValue"],
6969
"CSSColor": ["colorSpace"],
7070
"SVGElement": ["className"],
71-
"AudioBufferSourceNode": ["start"],
7271
// manually implemented
7372
"HTMLCanvasElement": ["getContext"],
7473
"OffscreenCanvas": ["getContext"],
75-
"HTMLFormControlsCollection": ["namedItem"]
74+
"HTMLFormControlsCollection": ["namedItem"],
75+
"AudioBufferSourceNode": ["start"],
7676
],
7777
types: merged.types
7878
)

0 commit comments

Comments
 (0)