Files
ladybird/Libraries/LibWeb/HTML/DOMStringList.cpp
Shannon Booth fd44da6829 LibWeb/Bindings: Emit one bindings header and cpp per IDL
Previously, the LibWeb bindings generator would output multiple per
interface files like Prototype/Constructor/Namespace/GlobalMixin
depending on the contents of that IDL file.

This complicates the build system as it means that it does not know
what files will be generated without knowledge of the contents of that
IDL file.

Instead, for each IDL file only generate a single Bindings/<IDLFile>.h
and Bindings/<IDLFile>.cpp.
2026-04-21 07:36:13 +02:00

68 lines
2.0 KiB
C++

/*
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/DOMStringList.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/HTML/DOMStringList.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::HTML {
GC_DEFINE_ALLOCATOR(DOMStringList);
GC::Ref<DOMStringList> DOMStringList::create(JS::Realm& realm, Vector<String> list)
{
return realm.create<DOMStringList>(realm, list);
}
DOMStringList::DOMStringList(JS::Realm& realm, Vector<String> list)
: Bindings::PlatformObject(realm)
, m_list(move(list))
{
m_legacy_platform_object_flags = LegacyPlatformObjectFlags { .supports_indexed_properties = true };
}
void DOMStringList::initialize(JS::Realm& realm)
{
WEB_SET_PROTOTYPE_FOR_INTERFACE(DOMStringList);
Base::initialize(realm);
}
// https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#dom-domstringlist-length
u32 DOMStringList::length() const
{
// The length getter steps are to return this's associated list's size.
return m_list.size();
}
// https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#dom-domstringlist-item
Optional<String> DOMStringList::item(u32 index) const
{
// The item(index) method steps are to return the indexth item in this's associated list, or null if index plus one
// is greater than this's associated list's size.
if (index >= m_list.size())
return {};
return m_list.at(index);
}
// https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#dom-domstringlist-contains
bool DOMStringList::contains(StringView string)
{
// The contains(string) method steps are to return true if this's associated list contains string, and false otherwise.
return m_list.contains_slow(string);
}
Optional<JS::Value> DOMStringList::item_value(size_t index) const
{
if (index >= m_list.size())
return {};
return JS::PrimitiveString::create(vm(), m_list.at(index));
}
}