1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 20:17:44 +00:00

LibWeb: Make NamedNodeMap GC-allocated

This commit is contained in:
Andreas Kling 2022-08-08 15:06:56 +02:00
parent ae11d70b0c
commit a56b3f9862
7 changed files with 49 additions and 29 deletions

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2021, Tim Flynn <trflynn89@serenityos.org>
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -7,30 +8,29 @@
#pragma once
#include <AK/NonnullRefPtrVector.h>
#include <AK/RefCountForwarder.h>
#include <AK/RefCounted.h>
#include <AK/String.h>
#include <AK/StringView.h>
#include <AK/WeakPtr.h>
#include <LibWeb/Bindings/Wrappable.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 final
: public RefCountForwarder<Element>
, public Bindings::Wrappable {
class NamedNodeMap : public Bindings::LegacyPlatformObject {
JS_OBJECT(NamedNodeMap, Bindings::LegacyPlatformObject);
public:
using WrapperType = Bindings::NamedNodeMapWrapper;
static NonnullRefPtr<NamedNodeMap> create(Element& associated_element);
static NamedNodeMap* create(Element&);
explicit NamedNodeMap(Element&);
~NamedNodeMap() = default;
bool is_supported_property_index(u32 index) const;
Vector<String> supported_property_names() const;
NamedNodeMap& impl() { return *this; }
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(); }
@ -50,20 +50,18 @@ public:
Attribute const* remove_attribute(StringView qualified_name);
private:
explicit NamedNodeMap(Element& associated_element);
Element& associated_element() { return ref_count_target(); }
Element const& associated_element() const { return ref_count_target(); }
Element& associated_element() { return m_element; }
Element const& associated_element() const { return m_element; }
void remove_attribute_at_index(size_t attribute_index);
DOM::Element& m_element;
NonnullRefPtrVector<Attribute> m_attributes;
};
}
namespace Web::Bindings {
NamedNodeMapWrapper* wrap(JS::Realm&, DOM::NamedNodeMap&);
inline JS::Object* wrap(JS::Realm&, Web::DOM::NamedNodeMap& object) { return &object; }
using NamedNodeMapWrapper = Web::DOM::NamedNodeMap;
}