Skip to content

Commit 7c8310f

Browse files
Bashamegasaschanaz
andauthored
Migrate Document element properties (#2343)
Co-authored-by: saschanaz <[email protected]>
1 parent 45515c6 commit 7c8310f

File tree

5 files changed

+71
-54
lines changed

5 files changed

+71
-54
lines changed

inputfiles/overridingTypes.jsonc

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -536,60 +536,6 @@
536536
]
537537
}
538538
}
539-
},
540-
"properties": {
541-
"property": {
542-
"defaultView": {
543-
"name": "defaultView",
544-
"overrideType": "WindowProxy & typeof globalThis"
545-
},
546-
"documentElement": {
547-
"name": "documentElement",
548-
"overrideType": "HTMLElement",
549-
"nullable": false
550-
},
551-
"head": {
552-
"nullable": false
553-
},
554-
"anchors": {
555-
"name": "anchors",
556-
"overrideType": "HTMLCollectionOf<HTMLAnchorElement>"
557-
},
558-
"embeds": {
559-
"name": "embeds",
560-
"overrideType": "HTMLCollectionOf<HTMLEmbedElement>"
561-
},
562-
"forms": {
563-
"name": "forms",
564-
"overrideType": "HTMLCollectionOf<HTMLFormElement>"
565-
},
566-
"images": {
567-
"name": "images",
568-
"overrideType": "HTMLCollectionOf<HTMLImageElement>"
569-
},
570-
"links": {
571-
"name": "links",
572-
"overrideType": "HTMLCollectionOf<HTMLAnchorElement | HTMLAreaElement>"
573-
},
574-
"plugins": {
575-
"name": "plugins",
576-
"overrideType": "HTMLCollectionOf<HTMLEmbedElement>"
577-
},
578-
"scripts": {
579-
"name": "scripts",
580-
"overrideType": "HTMLCollectionOf<HTMLScriptElement>"
581-
},
582-
"location": {
583-
// Pre-TS-5.1 hack to make document.location assignable
584-
"readonly": false,
585-
// Technically this can be null for a detached iframe.
586-
// But that's an edge case and flipping this also breaks compatibility.
587-
"nullable": false
588-
},
589-
"body": {
590-
"nullable": false
591-
}
592-
}
593539
}
594540
},
595541
"DocumentFragment": {

inputfiles/patches/dom.kdl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ interface EventListenerObject noInterfaceObject=#true {
1111
}
1212
}
1313

14+
interface Document {
15+
property documentElement {
16+
type HTMLElement nullable=#false
17+
}
18+
}
19+
1420
enum InsertPosition {
1521
beforebegin
1622
beforeend

inputfiles/patches/events.kdl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Events should ideally be autogenerated.
2+
13
interface-mixin AbstractWorker {
24
event error type=ErrorEvent
35
}

inputfiles/patches/globals.kdl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Emitter should ideally add globalThis automatically.
2+
3+
interface Document {
4+
property defaultView overrideType="WindowProxy & typeof globalThis"
5+
}

inputfiles/patches/html.kdl

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,64 @@ dictionary StructuredSerializeOptions {
7979
}
8080
}
8181

82+
// https://html.spec.whatwg.org/multipage/dom.html#the-document-object
83+
interface Document {
84+
// Pre-TS-5.1 hack to make document.location assignable
85+
property location readonly=#false {
86+
// Technically this can be null for a detached iframe.
87+
// But that's an edge case and flipping this also breaks compatibility.
88+
type nullable=#false
89+
}
90+
91+
// Similarly body and head are mostly non-null for HTML documents.
92+
// body can frequently be null when executing scripts in head, but flipping
93+
// it also breaks compatibiliity.
94+
property body {
95+
type nullable=#false
96+
}
97+
property head {
98+
type nullable=#false
99+
}
100+
101+
// More specific types for HTMLCollection properties
102+
property anchors {
103+
type HTMLCollectionOf {
104+
type HTMLAnchorElement
105+
}
106+
}
107+
property embeds {
108+
type HTMLCollectionOf {
109+
type HTMLEmbedElement
110+
}
111+
}
112+
property forms {
113+
type HTMLCollectionOf {
114+
type HTMLFormElement
115+
}
116+
}
117+
property images {
118+
type HTMLCollectionOf {
119+
type HTMLImageElement
120+
}
121+
}
122+
property links {
123+
type HTMLCollectionOf {
124+
type HTMLAnchorElement
125+
type HTMLAreaElement
126+
}
127+
}
128+
property plugins {
129+
type HTMLCollectionOf {
130+
type HTMLEmbedElement
131+
}
132+
}
133+
property scripts {
134+
type HTMLCollectionOf {
135+
type HTMLScriptElement
136+
}
137+
}
138+
}
139+
82140
removals {
83141
dictionary CanvasRenderingContext2DSettings {
84142
member colorType // Blink-only as of 2025-12, being tested in WebKit

0 commit comments

Comments
 (0)