Skip to content

Commit c4af2ad

Browse files
committed
Fix compatibility with Embedded Swift in remaining patched modules
1. Direct accessors are used instead of property wrappers in both DOM and SVG modules. 2. Avoiding use of `override` function declaration modifier in favor of `final` with an explicit generic types to avoid using implicit metatypes incompatible with Embedded Swift. 3. Formatting changes to make code compatible with the standard swift-format tool, that fixes automation incompatible with use of SwiftFormat instead of swift-format.
1 parent 7bb5907 commit c4af2ad

File tree

4 files changed

+34
-49
lines changed

4 files changed

+34
-49
lines changed

Patches/CSSOM.patch

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ index 9cd2fb3..7aec5a8 100644
33
--- a/Sources/CSSOM/Generated.swift
44
+++ b/Sources/CSSOM/Generated.swift
55
@@ -411,7 +411,7 @@ public class CSSColorValue: CSSStyleValue {
6-
6+
77
public required init(unsafelyWrapping jsObject: JSObject) { super.init(unsafelyWrapping: jsObject) }
8-
8+
99
- @inlinable override public class func parse(cssText: String) -> CSSColorValue_or_CSSStyleValue {
1010
+ @inlinable public class func parse(cssText: String) -> CSSColorValue {
1111
let this = constructor!
@@ -14,7 +14,7 @@ index 9cd2fb3..7aec5a8 100644
1414
@@ -947,7 +947,7 @@ public class CSSNumericValue: CSSStyleValue {
1515
return this[Strings.type].function!(this: this, arguments: []).fromJSValue()!
1616
}
17-
17+
1818
- @inlinable override public class func parse(cssText: String) -> CSSNumericValue {
1919
+ @inlinable public class func parse(cssText: String) -> CSSNumericValue {
2020
let this = constructor!
@@ -23,15 +23,15 @@ index 9cd2fb3..7aec5a8 100644
2323
@@ -2072,9 +2072,10 @@ public class StylePropertyMapReadOnly: JSBridgedClass, Sequence {
2424
ValueIterableIterator(sequence: self)
2525
}
26-
26+
2727
- @inlinable final public func get(property: String) -> CSSStyleValue_or_Void {
2828
+ // TODO: remove patch once https://github.com/w3c/css-houdini-drafts/issues/1095 is fixed
2929
+ @inlinable final public func get(property: String) -> CSSStyleValue? {
3030
let this = jsObject
3131
- return this[Strings.get].function!(this: this, arguments: [_toJSValue(property)]).fromJSValue()!
3232
+ return this[Strings.get].function!(this: this, arguments: [_toJSValue(property)]).fromJSValue()
3333
}
34-
34+
3535
@inlinable final public func getAll(property: String) -> [CSSStyleValue] {
3636
@@ -2706,49 +2707,6 @@ public enum CSSStyleValue_or_String: JSValueCompatible, Any_CSSStyleValue_or_Str
3737
}
@@ -68,25 +68,18 @@ index 9cd2fb3..7aec5a8 100644
6868
- }
6969
-
7070
- public static func construct(from value: JSValue) -> Self? {
71-
- if let cssStyleValue: CSSStyleValue = value.fromJSValue() {
72-
- return .cssStyleValue(cssStyleValue)
73-
- }
74-
- if let void: Void = value.fromJSValue() {
75-
- return .void(void)
76-
- }
71+
- if let cssStyleValue: CSSStyleValue = value.fromJSValue() { return .cssStyleValue(cssStyleValue) }
72+
- if let void: Void = value.fromJSValue() { return .void(void) }
7773
- return nil
7874
- }
7975
-
8076
- public var jsValue: JSValue {
8177
- switch self {
82-
- case let .cssStyleValue(cssStyleValue):
83-
- return cssStyleValue.jsValue
84-
- case let .void(void):
85-
- return void.jsValue
78+
- case let .cssStyleValue(cssStyleValue): return cssStyleValue.jsValue
79+
- case let .void(void): return void.jsValue
8680
- }
8781
- }
8882
-}
89-
-
9083
public protocol Any_CSSUnparsedSegment: ConvertibleToJSValue {}
9184
extension CSSVariableReferenceValue: Any_CSSUnparsedSegment {}
9285
extension String: Any_CSSUnparsedSegment {}

Patches/DOM.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ index 9fa75ba..0339568 100644
33
--- a/Sources/DOM/Generated.swift
44
+++ b/Sources/DOM/Generated.swift
55
@@ -1094,6 +1094,17 @@ public class BeforeUnloadEvent: Event {
6-
6+
77
public required init(unsafelyWrapping jsObject: JSObject) { super.init(unsafelyWrapping: jsObject) }
8-
8+
99
+ @available(*, unavailable)
1010
+ override public var returnValue: Bool {
1111
+ get { !self.returnValueAsString.isEmpty }
@@ -18,7 +18,7 @@ index 9fa75ba..0339568 100644
1818
+ set { self.jsObject[Strings.returnValue] = .string(newValue) }
1919
+ }
2020
}
21-
21+
2222
public enum BitrateMode: JSString, JSValueCompatible {
2323
@@ -24231,14 +24242,6 @@ public enum CanvasImageSource: JSValueCompatible, Any_CanvasImageSource {
2424
let val: CanvasImageSource = .htmlOrSVGImageElement(htmlOrSVGImageElement)

Patches/SVG.patch

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1+
diff --git a/Sources/SVG/Generated.swift b/Sources/SVG/Generated.swift
2+
index 176385b..bf8f1dd 100644
13
--- a/Sources/SVG/Generated.swift
24
+++ b/Sources/SVG/Generated.swift
3-
@@ -544,14 +544,16 @@ public class SVGElement: Element, GlobalEventHandlers, DocumentAndElementEventHa
4-
@inlinable override public class var constructor: JSFunction? { JSObject.global[Strings.SVGElement].function }
5+
@@ -524,7 +524,9 @@ public class SVGElement: Element, GlobalEventHandlers, SVGElementInstance, HTMLO
56

6-
public required init(unsafelyWrapping jsObject: JSObject) {
7-
- _className = ReadonlyAttribute(jsObject: jsObject, name: Strings.className)
8-
+ _svgClassName = ReadonlyAttribute(jsObject: jsObject, name: Strings.className)
9-
_ownerSVGElement = ReadonlyAttribute(jsObject: jsObject, name: Strings.ownerSVGElement)
10-
_viewportElement = ReadonlyAttribute(jsObject: jsObject, name: Strings.viewportElement)
11-
super.init(unsafelyWrapping: jsObject)
12-
}
7+
public required init(unsafelyWrapping jsObject: JSObject) { super.init(unsafelyWrapping: jsObject) }
138

9+
- @inlinable public var className: SVGAnimatedString { jsObject[Strings.className].fromJSValue()! }
1410
+ // Renamed because superclass has a `className` property of type `String`
1511
+ // NOTE! Accessing `className` on an SVGElement will crash your app
16-
@ReadonlyAttribute
17-
- public var className: SVGAnimatedString
18-
+ public var svgClassName: SVGAnimatedString
12+
+ @inlinable public var svgClassName: SVGAnimatedString { jsObject[Strings.className].fromJSValue()! }
13+
14+
@inlinable public var ownerSVGElement: SVGSVGElement? { jsObject[Strings.ownerSVGElement].fromJSValue() }
1915

20-
@ReadonlyAttribute
21-
public var ownerSVGElement: SVGSVGElement?

Patches/WebAudio.patch

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1+
diff --git a/Sources/WebAudio/Generated.swift b/Sources/WebAudio/Generated.swift
2+
index fff1563..d672d8c 100644
13
--- a/Sources/WebAudio/Generated.swift
24
+++ b/Sources/WebAudio/Generated.swift
3-
@@ -195,7 +195,8 @@ public class AudioBufferSourceNode: AudioScheduledSourceNode {
4-
@ReadWriteAttribute
5-
public var loopEnd: Double
5+
@@ -535,11 +535,11 @@ public class AudioNode: EventTarget {
66

7-
- @inlinable override public func start(when: Double? = nil, offset: Double? = nil, duration: Double? = nil) {
8-
+ // `override` removed since the superclass function has fewer parameters
9-
+ @inlinable func start(when: Double? = nil, offset: Double? = nil, duration: Double? = nil) {
10-
let this = jsObject
11-
_ = this[Strings.start].function!(this: this, arguments: [_toJSValue(when), _toJSValue(offset), _toJSValue(duration)])
12-
}
13-
@@ -492,7 +493,7 @@ public class AudioNode: EventTarget {
14-
super.init(unsafelyWrapping: jsObject)
15-
}
7+
public required init(unsafelyWrapping jsObject: JSObject) { super.init(unsafelyWrapping: jsObject) }
168

17-
- @inlinable public func connect(destinationNode: AudioNode, output: UInt32? = nil, input: UInt32? = nil) -> Self {
18-
+ @discardableResult @inlinable public func connect<NodeType: AudioNode>(destinationNode: NodeType, output: UInt32? = nil, input: UInt32? = nil) -> NodeType {
9+
- @inlinable final public func connect(
10+
- destinationNode: AudioNode,
11+
+ @discardableResult @inlinable public final func connect<NodeType: AudioNode>(
12+
+ destinationNode: NodeType,
13+
output: UInt32? = nil,
14+
input: UInt32? = nil
15+
- ) -> AudioNode {
16+
+ ) -> NodeType {
1917
let this = jsObject
20-
return this[Strings.connect].function!(this: this, arguments: [_toJSValue(destinationNode), _toJSValue(output), _toJSValue(input)]).fromJSValue()!
21-
}
18+
return this[Strings.connect].function!(
19+
this: this,

0 commit comments

Comments
 (0)