@@ -75,10 +75,10 @@ export class DOMTokenList {
7575export class HTMLCollection {
7676
7777 /**
78- * @param {NodeList } list
78+ * @param {NodeList } [ list]
7979 */
80- constructor ( list ) {
81- this . _list = list . _list
80+ constructor ( list = [ ] ) {
81+ this . _list = list
8282 }
8383
8484 /**
@@ -97,6 +97,31 @@ export class HTMLCollection {
9797 }
9898}
9999
100+ export class NamedNodeMap {
101+
102+ /**
103+ * @param {NodeList } [list]
104+ */
105+ constructor ( list = [ ] ) {
106+ this . _list = list
107+ }
108+
109+ /**
110+ * @param {number } index
111+ * @returns {Element|null }
112+ */
113+ item ( index ) {
114+ return this . _list [ index ]
115+ }
116+
117+ /**
118+ * @returns {number }
119+ */
120+ get length ( ) {
121+ return this . _list . length
122+ }
123+ }
124+
100125export class NodeList {
101126
102127 /**
@@ -248,7 +273,7 @@ export class Document extends Node {
248273 globalThis . document = this
249274
250275 this . activeViewTransition = activeViewTransition
251- this . children = new HTMLCollection ( this . childNodes )
276+ this . children = new HTMLCollection ( this . childNodes . _list )
252277 this . location = new URL ( url )
253278 this . URL = url
254279
@@ -290,7 +315,7 @@ export class DocumentFragment extends Node {
290315 */
291316 constructor ( properties ) {
292317 super ( properties )
293- this . children = new HTMLCollection ( this . childNodes )
318+ this . children = new HTMLCollection ( this . childNodes . _list )
294319 }
295320
296321 /**
@@ -350,17 +375,17 @@ export class Element extends Node {
350375 selectors = [ ] ,
351376 } = properties
352377
353- this . attributes = attributes . map ( ( { localName, namespaceURI = null , value = '' } ) =>
354- ( { localName, namespaceURI, ownerElement : this , value } ) )
355- this . children = new HTMLCollection ( this . childNodes )
378+ this . attributes = new NamedNodeMap ( attributes . map ( ( { localName, namespaceURI = null , value = '' } ) =>
379+ ( { localName, namespaceURI, ownerElement : this , value } ) ) )
380+ this . children = new HTMLCollection ( this . childNodes . _list )
356381 this . classList = new DOMTokenList ( this . getAttribute ( 'class' ) ?. split ( ' ' ) )
357382 this . indeterminate = indeterminate
358383 this . isContentEditable = isContentEditable
359384 this . localName = localName
360385
361386 this . form = form
362- form ?. elements . push ( this )
363- fieldSet ?. elements . push ( this )
387+ form ?. elements . _list . push ( this )
388+ fieldSet ?. elements . _list . push ( this )
364389 this . name = this . getAttribute ( 'name' ) ?? ''
365390 this . required = ! ! this . getAttributeNode ( 'required' )
366391 this . slot = this . getAttribute ( 'slot' ) ?? ''
@@ -418,7 +443,7 @@ export class Element extends Node {
418443 * @returns {object|null }
419444 */
420445 getAttributeNodeNS ( namespace , name ) {
421- return this . attributes . find ( attribute => attribute . localName === name && attribute . namespaceURI === namespace ) ?? null
446+ return this . attributes . _list . find ( attribute => attribute . localName === name && attribute . namespaceURI === namespace ) ?? null
422447 }
423448
424449 /**
@@ -460,7 +485,7 @@ export class Element extends Node {
460485 if ( node ) {
461486 node . value = value
462487 } else {
463- this . attributes . push ( { localName : name , namespaceURI : null , ownerElement : this , value } )
488+ this . attributes . _list . push ( { localName : name , namespaceURI : null , ownerElement : this , value } )
464489 }
465490 }
466491
@@ -579,13 +604,13 @@ export class HTMLDialogElement extends HTMLElement { localName = 'dialog' }
579604export class HTMLDivElement extends HTMLElement { localName = 'div' }
580605
581606export class HTMLFieldSetElement extends HTMLElement {
582- elements = [ ]
607+ elements = new HTMLCollection
583608 localName = 'fieldset'
584609 type = 'fieldset'
585610}
586611
587612export class HTMLFormElement extends HTMLElement {
588- elements = [ ]
613+ elements = new HTMLCollection
589614 localName = 'form'
590615}
591616
0 commit comments