Skip to content

Commit 7dc1602

Browse files
committed
Improve subscript support
- merge setters with getters to make them visible - support setters delegating to a getter in the superclass - output method representation for named getters
1 parent b9c529a commit 7dc1602

File tree

3 files changed

+249
-21
lines changed

3 files changed

+249
-21
lines changed

Sources/DOM/Generated.swift

Lines changed: 128 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3640,6 +3640,11 @@ public class DOMRectList: JSBridgedClass {
36403640
@inlinable public subscript(key: Int) -> DOMRect? {
36413641
jsObject[key].fromJSValue()
36423642
}
3643+
3644+
@inlinable public func item(index: UInt32) -> DOMRect? {
3645+
let this = jsObject
3646+
return this[Strings.item].function!(this: this, arguments: [_toJSValue(index)]).fromJSValue()!
3647+
}
36433648
}
36443649

36453650
public class DOMRectReadOnly: JSBridgedClass {
@@ -3715,6 +3720,11 @@ public class DOMStringList: JSBridgedClass {
37153720
jsObject[key].fromJSValue()
37163721
}
37173722

3723+
@inlinable public func item(index: UInt32) -> String? {
3724+
let this = jsObject
3725+
return this[Strings.item].function!(this: this, arguments: [_toJSValue(index)]).fromJSValue()!
3726+
}
3727+
37183728
@inlinable public func contains(string: String) -> Bool {
37193729
let this = jsObject
37203730
return this[Strings.contains].function!(this: this, arguments: [_toJSValue(string)]).fromJSValue()!
@@ -3731,11 +3741,14 @@ public class DOMStringMap: JSBridgedClass {
37313741
}
37323742

37333743
@inlinable public subscript(key: String) -> String {
3734-
jsObject[key].fromJSValue()!
3744+
get {
3745+
jsObject[key].fromJSValue()!
3746+
}
3747+
set {
3748+
jsObject[key] = _toJSValue(newValue)
3749+
}
37353750
}
37363751

3737-
// XXX: unsupported setter for keys of type String
3738-
37393752
// XXX: unsupported deleter for keys of type String
37403753
}
37413754

@@ -3757,6 +3770,11 @@ public class DOMTokenList: JSBridgedClass, Sequence {
37573770
jsObject[key].fromJSValue()
37583771
}
37593772

3773+
@inlinable public func item(index: UInt32) -> String? {
3774+
let this = jsObject
3775+
return this[Strings.item].function!(this: this, arguments: [_toJSValue(index)]).fromJSValue()!
3776+
}
3777+
37603778
@inlinable public func contains(token: String) -> Bool {
37613779
let this = jsObject
37623780
return this[Strings.contains].function!(this: this, arguments: [_toJSValue(token)]).fromJSValue()!
@@ -5535,6 +5553,11 @@ public class FileList: JSBridgedClass {
55355553
jsObject[key].fromJSValue()
55365554
}
55375555

5556+
@inlinable public func item(index: UInt32) -> File? {
5557+
let this = jsObject
5558+
return this[Strings.item].function!(this: this, arguments: [_toJSValue(index)]).fromJSValue()!
5559+
}
5560+
55385561
@ReadonlyAttribute
55395562
public var length: UInt32
55405563
}
@@ -6223,6 +6246,11 @@ public class HTMLAllCollection: JSBridgedClass {
62236246
jsObject[key].fromJSValue()
62246247
}
62256248

6249+
@inlinable public func namedItem(name: String) -> Element_or_HTMLCollection? {
6250+
let this = jsObject
6251+
return this[Strings.namedItem].function!(this: this, arguments: [_toJSValue(name)]).fromJSValue()!
6252+
}
6253+
62266254
@inlinable public func item(nameOrIndex: String? = nil) -> Element_or_HTMLCollection? {
62276255
let this = jsObject
62286256
return this[Strings.item].function!(this: this, arguments: [_toJSValue(nameOrIndex)]).fromJSValue()!
@@ -6570,9 +6598,19 @@ public class HTMLCollection: JSBridgedClass {
65706598
jsObject[key].fromJSValue()
65716599
}
65726600

6601+
@inlinable public func item(index: UInt32) -> Element? {
6602+
let this = jsObject
6603+
return this[Strings.item].function!(this: this, arguments: [_toJSValue(index)]).fromJSValue()!
6604+
}
6605+
65736606
@inlinable public subscript(key: String) -> Element? {
65746607
jsObject[key].fromJSValue()
65756608
}
6609+
6610+
@inlinable public func namedItem(name: String) -> Element? {
6611+
let this = jsObject
6612+
return this[Strings.namedItem].function!(this: this, arguments: [_toJSValue(name)]).fromJSValue()!
6613+
}
65766614
}
65776615

65786616
public class HTMLDListElement: HTMLElement {
@@ -6934,6 +6972,11 @@ public class HTMLFormControlsCollection: HTMLCollection {
69346972
@inlinable public subscript(key: String) -> Element_or_RadioNodeList? {
69356973
jsObject[key].fromJSValue()
69366974
}
6975+
6976+
@inlinable override public func namedItem(name: String) -> Element_or_RadioNodeList? {
6977+
let this = jsObject
6978+
return this[Strings.namedItem].function!(this: this, arguments: [_toJSValue(name)]).fromJSValue()!
6979+
}
69376980
}
69386981

69396982
public class HTMLFormElement: HTMLElement {
@@ -8440,7 +8483,14 @@ public class HTMLOptionsCollection: HTMLCollection {
84408483
set { _length.wrappedValue = newValue }
84418484
}
84428485

8443-
// XXX: unsupported setter for keys of type UInt32
8486+
@inlinable override public subscript(key: Int) -> HTMLOptionElement? {
8487+
get {
8488+
super[key] as? HTMLOptionElement
8489+
}
8490+
set {
8491+
jsObject[key] = _toJSValue(newValue)
8492+
}
8493+
}
84448494

84458495
@inlinable public func add(element: HTMLOptGroupElement_or_HTMLOptionElement, before: HTMLElement_or_Int32? = nil) {
84468496
let this = jsObject
@@ -8796,8 +8846,9 @@ public class HTMLSelectElement: HTMLElement {
87968846
@ReadWriteAttribute
87978847
public var length: UInt32
87988848

8799-
@inlinable public subscript(key: Int) -> HTMLOptionElement? {
8800-
jsObject[key].fromJSValue()
8849+
@inlinable public func item(index: UInt32) -> HTMLOptionElement? {
8850+
let this = jsObject
8851+
return this[Strings.item].function!(this: this, arguments: [_toJSValue(index)]).fromJSValue()!
88018852
}
88028853

88038854
@inlinable public func namedItem(name: String) -> HTMLOptionElement? {
@@ -8820,7 +8871,14 @@ public class HTMLSelectElement: HTMLElement {
88208871
_ = this[Strings.remove].function!(this: this, arguments: [_toJSValue(index)])
88218872
}
88228873

8823-
// XXX: unsupported setter for keys of type UInt32
8874+
@inlinable public subscript(key: Int) -> HTMLOptionElement? {
8875+
get {
8876+
jsObject[key].fromJSValue()
8877+
}
8878+
set {
8879+
jsObject[key] = _toJSValue(newValue)
8880+
}
8881+
}
88248882

88258883
@ReadonlyAttribute
88268884
public var selectedOptions: HTMLCollection
@@ -11619,9 +11677,19 @@ public class MimeTypeArray: JSBridgedClass {
1161911677
jsObject[key].fromJSValue()
1162011678
}
1162111679

11680+
@inlinable public func item(index: UInt32) -> MimeType? {
11681+
let this = jsObject
11682+
return this[Strings.item].function!(this: this, arguments: [_toJSValue(index)]).fromJSValue()!
11683+
}
11684+
1162211685
@inlinable public subscript(key: String) -> MimeType? {
1162311686
jsObject[key].fromJSValue()
1162411687
}
11688+
11689+
@inlinable public func namedItem(name: String) -> MimeType? {
11690+
let this = jsObject
11691+
return this[Strings.namedItem].function!(this: this, arguments: [_toJSValue(name)]).fromJSValue()!
11692+
}
1162511693
}
1162611694

1162711695
public class MouseEvent: UIEvent {
@@ -11953,10 +12021,20 @@ public class NamedNodeMap: JSBridgedClass {
1195312021
jsObject[key].fromJSValue()
1195412022
}
1195512023

12024+
@inlinable public func item(index: UInt32) -> Attr? {
12025+
let this = jsObject
12026+
return this[Strings.item].function!(this: this, arguments: [_toJSValue(index)]).fromJSValue()!
12027+
}
12028+
1195612029
@inlinable public subscript(key: String) -> Attr? {
1195712030
jsObject[key].fromJSValue()
1195812031
}
1195912032

12033+
@inlinable public func getNamedItem(qualifiedName: String) -> Attr? {
12034+
let this = jsObject
12035+
return this[Strings.getNamedItem].function!(this: this, arguments: [_toJSValue(qualifiedName)]).fromJSValue()!
12036+
}
12037+
1196012038
@inlinable public func getNamedItemNS(namespace: String?, localName: String) -> Attr? {
1196112039
let this = jsObject
1196212040
return this[Strings.getNamedItemNS].function!(this: this, arguments: [_toJSValue(namespace), _toJSValue(localName)]).fromJSValue()!
@@ -12394,6 +12472,11 @@ public class NodeList: JSBridgedClass, Sequence {
1239412472
jsObject[key].fromJSValue()
1239512473
}
1239612474

12475+
@inlinable public func item(index: UInt32) -> Node? {
12476+
let this = jsObject
12477+
return this[Strings.item].function!(this: this, arguments: [_toJSValue(index)]).fromJSValue()!
12478+
}
12479+
1239712480
@ReadonlyAttribute
1239812481
public var length: UInt32
1239912482

@@ -12659,9 +12742,19 @@ public class Plugin: JSBridgedClass {
1265912742
jsObject[key].fromJSValue()
1266012743
}
1266112744

12745+
@inlinable public func item(index: UInt32) -> MimeType? {
12746+
let this = jsObject
12747+
return this[Strings.item].function!(this: this, arguments: [_toJSValue(index)]).fromJSValue()!
12748+
}
12749+
1266212750
@inlinable public subscript(key: String) -> MimeType? {
1266312751
jsObject[key].fromJSValue()
1266412752
}
12753+
12754+
@inlinable public func namedItem(name: String) -> MimeType? {
12755+
let this = jsObject
12756+
return this[Strings.namedItem].function!(this: this, arguments: [_toJSValue(name)]).fromJSValue()!
12757+
}
1266512758
}
1266612759

1266712760
public class PluginArray: JSBridgedClass {
@@ -12686,9 +12779,19 @@ public class PluginArray: JSBridgedClass {
1268612779
jsObject[key].fromJSValue()
1268712780
}
1268812781

12782+
@inlinable public func item(index: UInt32) -> Plugin? {
12783+
let this = jsObject
12784+
return this[Strings.item].function!(this: this, arguments: [_toJSValue(index)]).fromJSValue()!
12785+
}
12786+
1268912787
@inlinable public subscript(key: String) -> Plugin? {
1269012788
jsObject[key].fromJSValue()
1269112789
}
12790+
12791+
@inlinable public func namedItem(name: String) -> Plugin? {
12792+
let this = jsObject
12793+
return this[Strings.namedItem].function!(this: this, arguments: [_toJSValue(name)]).fromJSValue()!
12794+
}
1269212795
}
1269312796

1269412797
public class PopStateEvent: Event {
@@ -14540,11 +14643,19 @@ public class Storage: JSBridgedClass {
1454014643
return this[Strings.key].function!(this: this, arguments: [_toJSValue(index)]).fromJSValue()!
1454114644
}
1454214645

14543-
@inlinable public subscript(key: String) -> String? {
14544-
jsObject[key].fromJSValue()
14646+
@inlinable public func getItem(key: String) -> String? {
14647+
let this = jsObject
14648+
return this[Strings.getItem].function!(this: this, arguments: [_toJSValue(key)]).fromJSValue()!
1454514649
}
1454614650

14547-
// XXX: unsupported setter for keys of type String
14651+
@inlinable public subscript(key: String) -> String? {
14652+
get {
14653+
jsObject[key].fromJSValue()
14654+
}
14655+
set {
14656+
jsObject[key] = _toJSValue(newValue)
14657+
}
14658+
}
1454814659

1454914660
// XXX: unsupported deleter for keys of type String
1455014661

@@ -15257,6 +15368,11 @@ public class TouchList: JSBridgedClass {
1525715368
@inlinable public subscript(key: Int) -> Touch? {
1525815369
jsObject[key].fromJSValue()
1525915370
}
15371+
15372+
@inlinable public func item(index: UInt32) -> Touch? {
15373+
let this = jsObject
15374+
return this[Strings.item].function!(this: this, arguments: [_toJSValue(index)]).fromJSValue()!
15375+
}
1526015376
}
1526115377

1526215378
public enum TouchType: JSString, JSValueCompatible {
@@ -18510,8 +18626,10 @@ public class XSLTProcessor: JSBridgedClass {
1851018626
@usableFromInline static let getElementsByTagName: JSString = "getElementsByTagName"
1851118627
@usableFromInline static let getElementsByTagNameNS: JSString = "getElementsByTagNameNS"
1851218628
@usableFromInline static let getImageData: JSString = "getImageData"
18629+
@usableFromInline static let getItem: JSString = "getItem"
1851318630
@usableFromInline static let getLineDash: JSString = "getLineDash"
1851418631
@usableFromInline static let getModifierState: JSString = "getModifierState"
18632+
@usableFromInline static let getNamedItem: JSString = "getNamedItem"
1851518633
@usableFromInline static let getNamedItemNS: JSString = "getNamedItemNS"
1851618634
@usableFromInline static let getParameter: JSString = "getParameter"
1851718635
@usableFromInline static let getReader: JSString = "getReader"

0 commit comments

Comments
 (0)