ladybird/Userland/Libraries/LibWeb/DOM/NamedNodeMap.h
Andreas Kling 6f433c8656 LibWeb+LibJS: Make the EventTarget hierarchy (incl. DOM) GC-allocated
This is a monster patch that turns all EventTargets into GC-allocated
PlatformObjects. Their C++ wrapper classes are removed, and the LibJS
garbage collector is now responsible for their lifetimes.

There's a fair amount of hacks and band-aids in this patch, and we'll
have a lot of cleanup to do after this.
2022-09-06 00:27:09 +02:00

66 lines
2.3 KiB
C++

/*
* Copyright (c) 2021, Tim Flynn <trflynn89@serenityos.org>
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/NonnullRefPtrVector.h>
#include <AK/String.h>
#include <AK/StringView.h>
#include <LibWeb/Bindings/LegacyPlatformObject.h>
#include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/Forward.h>
namespace Web::DOM {
// https://dom.spec.whatwg.org/#interface-namednodemap
class NamedNodeMap : public Bindings::LegacyPlatformObject {
WEB_PLATFORM_OBJECT(NamedNodeMap, Bindings::LegacyPlatformObject);
public:
static JS::NonnullGCPtr<NamedNodeMap> create(Element&);
~NamedNodeMap() = default;
virtual bool is_supported_property_index(u32 index) const override;
virtual Vector<String> supported_property_names() const override;
virtual JS::Value item_value(size_t index) const override;
virtual JS::Value named_item_value(FlyString const& name) const override;
size_t length() const { return m_attributes.size(); }
bool is_empty() const { return m_attributes.is_empty(); }
// Methods defined by the spec for JavaScript:
Attribute const* item(u32 index) const;
Attribute const* get_named_item(StringView qualified_name) const;
ExceptionOr<Attribute const*> set_named_item(Attribute& attribute);
ExceptionOr<Attribute const*> remove_named_item(StringView qualified_name);
// Methods defined by the spec for internal use:
Attribute* get_attribute(StringView qualified_name, size_t* item_index = nullptr);
Attribute const* get_attribute(StringView qualified_name, size_t* item_index = nullptr) const;
ExceptionOr<Attribute const*> set_attribute(Attribute& attribute);
void replace_attribute(Attribute& old_attribute, Attribute& new_attribute, size_t old_attribute_index);
void append_attribute(Attribute& attribute);
Attribute const* remove_attribute(StringView qualified_name);
private:
explicit NamedNodeMap(Element&);
virtual void visit_edges(Cell::Visitor&) override;
Element& associated_element() { return *m_element; }
Element const& associated_element() const { return *m_element; }
void remove_attribute_at_index(size_t attribute_index);
JS::NonnullGCPtr<DOM::Element> m_element;
Vector<JS::NonnullGCPtr<Attribute>> m_attributes;
};
}
WRAPPER_HACK(NamedNodeMap, Web::DOM)