2021-10-02 20:33:45 +01:00
/*
* Copyright ( c ) 2021 , Luke Wilde < lukew @ serenityos . org >
*
* SPDX - License - Identifier : BSD - 2 - Clause
*/
2024-11-15 04:01:23 +13:00
# include <LibGC/Heap.h>
2023-07-09 11:40:17 +03:30
# include <LibJS/Runtime/Error.h>
2021-10-02 20:33:45 +01:00
# include <LibWeb/DOM/StaticNodeList.h>
namespace Web : : DOM {
2024-11-15 04:01:23 +13:00
GC_DEFINE_ALLOCATOR ( StaticNodeList ) ;
2023-11-19 19:47:52 +01:00
2024-11-15 04:01:23 +13:00
GC : : Ref < NodeList > StaticNodeList : : create ( JS : : Realm & realm , Vector < GC : : Root < Node > > static_nodes )
2022-08-28 13:42:07 +02:00
{
2024-11-14 05:50:17 +13:00
return realm . create < StaticNodeList > ( realm , move ( static_nodes ) ) ;
2022-08-28 13:42:07 +02:00
}
2024-11-15 04:01:23 +13:00
StaticNodeList : : StaticNodeList ( JS : : Realm & realm , Vector < GC : : Root < Node > > static_nodes )
2022-09-25 16:15:49 -06:00
: NodeList ( realm )
2021-10-02 20:33:45 +01:00
{
2022-09-01 16:30:26 +02:00
for ( auto & node : static_nodes )
m_static_nodes . append ( * node ) ;
}
StaticNodeList : : ~ StaticNodeList ( ) = default ;
void StaticNodeList : : visit_edges ( Cell : : Visitor & visitor )
{
Base : : visit_edges ( visitor ) ;
2024-04-15 13:58:21 +02:00
visitor . visit ( m_static_nodes ) ;
2021-10-02 20:33:45 +01:00
}
// https://dom.spec.whatwg.org/#dom-nodelist-length
u32 StaticNodeList : : length ( ) const
{
return m_static_nodes . size ( ) ;
}
// https://dom.spec.whatwg.org/#dom-nodelist-item
Node const * StaticNodeList : : item ( u32 index ) const
{
// The item(index) method must return the indexth node in the collection. If there is no indexth node in the collection, then the method must return null.
if ( index > = m_static_nodes . size ( ) )
return nullptr ;
2023-02-26 16:09:02 -07:00
return m_static_nodes [ index ] ;
2021-10-02 20:33:45 +01:00
}
}