1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 02:08:11 +00:00

LibWeb: Rename Attribute to Attr

This name is not very good, but it's what the specification calls it.
This commit is contained in:
Andreas Kling 2022-09-18 01:03:58 +02:00
parent 3c3ae3a768
commit 530675993b
18 changed files with 85 additions and 85 deletions

View file

@ -41,7 +41,7 @@ static bool is_wrappable_type(Type const& type)
return true; return true;
if (type.name() == "Selection") if (type.name() == "Selection")
return true; return true;
if (type.name() == "Attribute") if (type.name() == "Attr")
return true; return true;
if (type.name() == "NamedNodeMap") if (type.name() == "NamedNodeMap")
return true; return true;

View file

@ -14,8 +14,8 @@
#include <LibWeb/Bindings/AbortSignalPrototype.h> #include <LibWeb/Bindings/AbortSignalPrototype.h>
#include <LibWeb/Bindings/AbstractRangeConstructor.h> #include <LibWeb/Bindings/AbstractRangeConstructor.h>
#include <LibWeb/Bindings/AbstractRangePrototype.h> #include <LibWeb/Bindings/AbstractRangePrototype.h>
#include <LibWeb/Bindings/AttributeConstructor.h> #include <LibWeb/Bindings/AttrConstructor.h>
#include <LibWeb/Bindings/AttributePrototype.h> #include <LibWeb/Bindings/AttrPrototype.h>
#include <LibWeb/Bindings/AudioConstructor.h> #include <LibWeb/Bindings/AudioConstructor.h>
#include <LibWeb/Bindings/BlobConstructor.h> #include <LibWeb/Bindings/BlobConstructor.h>
#include <LibWeb/Bindings/BlobPrototype.h> #include <LibWeb/Bindings/BlobPrototype.h>
@ -402,7 +402,7 @@
ADD_WINDOW_OBJECT_INTERFACE(AbortController) \ ADD_WINDOW_OBJECT_INTERFACE(AbortController) \
ADD_WINDOW_OBJECT_INTERFACE(AbortSignal) \ ADD_WINDOW_OBJECT_INTERFACE(AbortSignal) \
ADD_WINDOW_OBJECT_INTERFACE(AbstractRange) \ ADD_WINDOW_OBJECT_INTERFACE(AbstractRange) \
ADD_WINDOW_OBJECT_INTERFACE(Attribute) \ ADD_WINDOW_OBJECT_INTERFACE(Attr) \
ADD_WINDOW_OBJECT_INTERFACE(Blob) \ ADD_WINDOW_OBJECT_INTERFACE(Blob) \
ADD_WINDOW_OBJECT_INTERFACE(CDATASection) \ ADD_WINDOW_OBJECT_INTERFACE(CDATASection) \
ADD_WINDOW_OBJECT_INTERFACE(CSSConditionRule) \ ADD_WINDOW_OBJECT_INTERFACE(CSSConditionRule) \

View file

@ -74,8 +74,8 @@ set(SOURCES
DOM/AbortController.cpp DOM/AbortController.cpp
DOM/AbortSignal.cpp DOM/AbortSignal.cpp
DOM/AbstractRange.cpp DOM/AbstractRange.cpp
DOM/Attribute.cpp DOM/Attr.cpp
DOM/Attribute.idl DOM/Attr.idl
DOM/CDATASection.cpp DOM/CDATASection.cpp
DOM/CharacterData.cpp DOM/CharacterData.cpp
DOM/CharacterData.idl DOM/CharacterData.idl

View file

@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#include <LibWeb/DOM/Attribute.h> #include <LibWeb/DOM/Attr.h>
#include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Element.h> #include <LibWeb/DOM/Element.h>
#include <LibWeb/DOM/MutationType.h> #include <LibWeb/DOM/MutationType.h>
@ -12,43 +12,43 @@
namespace Web::DOM { namespace Web::DOM {
JS::NonnullGCPtr<Attribute> Attribute::create(Document& document, FlyString local_name, String value, Element const* owner_element) JS::NonnullGCPtr<Attr> Attr::create(Document& document, FlyString local_name, String value, Element const* owner_element)
{ {
return *document.heap().allocate<Attribute>(document.realm(), document, move(local_name), move(value), owner_element); return *document.heap().allocate<Attr>(document.realm(), document, move(local_name), move(value), owner_element);
} }
Attribute::Attribute(Document& document, FlyString local_name, String value, Element const* owner_element) Attr::Attr(Document& document, FlyString local_name, String value, Element const* owner_element)
: Node(document, NodeType::ATTRIBUTE_NODE) : Node(document, NodeType::ATTRIBUTE_NODE)
, m_qualified_name(move(local_name), {}, {}) , m_qualified_name(move(local_name), {}, {})
, m_value(move(value)) , m_value(move(value))
, m_owner_element(owner_element) , m_owner_element(owner_element)
{ {
set_prototype(&window().cached_web_prototype("Attribute")); set_prototype(&window().cached_web_prototype("Attr"));
} }
void Attribute::visit_edges(Cell::Visitor& visitor) void Attr::visit_edges(Cell::Visitor& visitor)
{ {
Base::visit_edges(visitor); Base::visit_edges(visitor);
visitor.visit(m_owner_element.ptr()); visitor.visit(m_owner_element.ptr());
} }
Element* Attribute::owner_element() Element* Attr::owner_element()
{ {
return m_owner_element.ptr(); return m_owner_element.ptr();
} }
Element const* Attribute::owner_element() const Element const* Attr::owner_element() const
{ {
return m_owner_element.ptr(); return m_owner_element.ptr();
} }
void Attribute::set_owner_element(Element const* owner_element) void Attr::set_owner_element(Element const* owner_element)
{ {
m_owner_element = owner_element; m_owner_element = owner_element;
} }
// https://dom.spec.whatwg.org/#set-an-existing-attribute-value // https://dom.spec.whatwg.org/#set-an-existing-attribute-value
void Attribute::set_value(String value) void Attr::set_value(String value)
{ {
// 1. If attributes element is null, then set attributes value to value. // 1. If attributes element is null, then set attributes value to value.
if (!owner_element()) { if (!owner_element()) {
@ -66,7 +66,7 @@ void Attribute::set_value(String value)
} }
// https://dom.spec.whatwg.org/#handle-attribute-changes // https://dom.spec.whatwg.org/#handle-attribute-changes
void Attribute::handle_attribute_changes(Element& element, String const& old_value, [[maybe_unused]] String const& new_value) void Attr::handle_attribute_changes(Element& element, String const& old_value, [[maybe_unused]] String const& new_value)
{ {
// 1. Queue a mutation record of "attributes" for element with attributes local name, attributes namespace, oldValue, « », « », null, and null. // 1. Queue a mutation record of "attributes" for element with attributes local name, attributes namespace, oldValue, « », « », null, and null.
element.queue_mutation_record(MutationType::attributes, local_name(), namespace_uri(), old_value, StaticNodeList::create(window(), {}), StaticNodeList::create(window(), {}), nullptr, nullptr); element.queue_mutation_record(MutationType::attributes, local_name(), namespace_uri(), old_value, StaticNodeList::create(window(), {}), StaticNodeList::create(window(), {}), nullptr, nullptr);

View file

@ -14,13 +14,13 @@
namespace Web::DOM { namespace Web::DOM {
// https://dom.spec.whatwg.org/#attr // https://dom.spec.whatwg.org/#attr
class Attribute final : public Node { class Attr final : public Node {
WEB_PLATFORM_OBJECT(Attribute, Node); WEB_PLATFORM_OBJECT(Attr, Node);
public: public:
static JS::NonnullGCPtr<Attribute> create(Document&, FlyString local_name, String value, Element const* = nullptr); static JS::NonnullGCPtr<Attr> create(Document&, FlyString local_name, String value, Element const* = nullptr);
virtual ~Attribute() override = default; virtual ~Attr() override = default;
virtual FlyString node_name() const override { return name(); } virtual FlyString node_name() const override { return name(); }
@ -42,7 +42,7 @@ public:
void handle_attribute_changes(Element&, String const& old_value, String const& new_value); void handle_attribute_changes(Element&, String const& old_value, String const& new_value);
private: private:
Attribute(Document&, FlyString local_name, String value, Element const*); Attr(Document&, FlyString local_name, String value, Element const*);
virtual void visit_edges(Cell::Visitor&) override; virtual void visit_edges(Cell::Visitor&) override;
@ -52,8 +52,8 @@ private:
}; };
template<> template<>
inline bool Node::fast_is<Attribute>() const { return is_attribute(); } inline bool Node::fast_is<Attr>() const { return is_attribute(); }
} }
WRAPPER_HACK(Attribute, Web::DOM) WRAPPER_HACK(Attr, Web::DOM)

View file

@ -2,7 +2,7 @@
#import <DOM/Element.idl> #import <DOM/Element.idl>
[Exposed=Window] [Exposed=Window]
interface Attribute : Node { interface Attr : Node {
readonly attribute DOMString? namespaceURI; readonly attribute DOMString? namespaceURI;
readonly attribute DOMString? prefix; readonly attribute DOMString? prefix;
readonly attribute DOMString localName; readonly attribute DOMString localName;

View file

@ -98,7 +98,7 @@ ExceptionOr<void> Element::set_attribute(FlyString const& name, String const& va
// 4. If attribute is null, create an attribute whose local name is qualifiedName, value is value, and node document is thiss node document, then append this attribute to this, and then return. // 4. If attribute is null, create an attribute whose local name is qualifiedName, value is value, and node document is thiss node document, then append this attribute to this, and then return.
if (!attribute) { if (!attribute) {
auto new_attribute = Attribute::create(document(), insert_as_lowercase ? name.to_lowercase() : name, value); auto new_attribute = Attr::create(document(), insert_as_lowercase ? name.to_lowercase() : name, value);
m_attributes->append_attribute(new_attribute); m_attributes->append_attribute(new_attribute);
attribute = new_attribute.ptr(); attribute = new_attribute.ptr();
@ -208,7 +208,7 @@ DOM::ExceptionOr<bool> Element::toggle_attribute(FlyString const& name, Optional
if (!attribute) { if (!attribute) {
// 1. If force is not given or is true, create an attribute whose local name is qualifiedName, value is the empty string, and node document is thiss node document, then append this attribute to this, and then return true. // 1. If force is not given or is true, create an attribute whose local name is qualifiedName, value is the empty string, and node document is thiss node document, then append this attribute to this, and then return true.
if (!force.has_value() || force.value()) { if (!force.has_value() || force.value()) {
auto new_attribute = Attribute::create(document(), insert_as_lowercase ? name.to_lowercase() : name, ""); auto new_attribute = Attr::create(document(), insert_as_lowercase ? name.to_lowercase() : name, "");
m_attributes->append_attribute(new_attribute); m_attributes->append_attribute(new_attribute);
parse_attribute(new_attribute->local_name(), ""); parse_attribute(new_attribute->local_name(), "");

View file

@ -10,7 +10,7 @@
#include <AK/String.h> #include <AK/String.h>
#include <LibWeb/CSS/CSSStyleDeclaration.h> #include <LibWeb/CSS/CSSStyleDeclaration.h>
#include <LibWeb/CSS/StyleComputer.h> #include <LibWeb/CSS/StyleComputer.h>
#include <LibWeb/DOM/Attribute.h> #include <LibWeb/DOM/Attr.h>
#include <LibWeb/DOM/ChildNode.h> #include <LibWeb/DOM/ChildNode.h>
#include <LibWeb/DOM/ExceptionOr.h> #include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/DOM/NamedNodeMap.h> #include <LibWeb/DOM/NamedNodeMap.h>

View file

@ -5,7 +5,7 @@
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#include <LibWeb/DOM/Attribute.h> #include <LibWeb/DOM/Attr.h>
#include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/NamedNodeMap.h> #include <LibWeb/DOM/NamedNodeMap.h>
#include <LibWeb/Namespace.h> #include <LibWeb/Namespace.h>
@ -63,7 +63,7 @@ Vector<String> NamedNodeMap::supported_property_names() const
} }
// https://dom.spec.whatwg.org/#dom-namednodemap-item // https://dom.spec.whatwg.org/#dom-namednodemap-item
Attribute const* NamedNodeMap::item(u32 index) const Attr const* NamedNodeMap::item(u32 index) const
{ {
// 1. If index is equal to or greater than thiss attribute lists size, then return null. // 1. If index is equal to or greater than thiss attribute lists size, then return null.
if (index >= m_attributes.size()) if (index >= m_attributes.size())
@ -74,19 +74,19 @@ Attribute const* NamedNodeMap::item(u32 index) const
} }
// https://dom.spec.whatwg.org/#dom-namednodemap-getnameditem // https://dom.spec.whatwg.org/#dom-namednodemap-getnameditem
Attribute const* NamedNodeMap::get_named_item(StringView qualified_name) const Attr const* NamedNodeMap::get_named_item(StringView qualified_name) const
{ {
return get_attribute(qualified_name); return get_attribute(qualified_name);
} }
// https://dom.spec.whatwg.org/#dom-namednodemap-setnameditem // https://dom.spec.whatwg.org/#dom-namednodemap-setnameditem
ExceptionOr<Attribute const*> NamedNodeMap::set_named_item(Attribute& attribute) ExceptionOr<Attr const*> NamedNodeMap::set_named_item(Attr& attribute)
{ {
return set_attribute(attribute); return set_attribute(attribute);
} }
// https://dom.spec.whatwg.org/#dom-namednodemap-removenameditem // https://dom.spec.whatwg.org/#dom-namednodemap-removenameditem
ExceptionOr<Attribute const*> NamedNodeMap::remove_named_item(StringView qualified_name) ExceptionOr<Attr const*> NamedNodeMap::remove_named_item(StringView qualified_name)
{ {
// 1. Let attr be the result of removing an attribute given qualifiedName and element. // 1. Let attr be the result of removing an attribute given qualifiedName and element.
auto const* attribute = remove_attribute(qualified_name); auto const* attribute = remove_attribute(qualified_name);
@ -100,13 +100,13 @@ ExceptionOr<Attribute const*> NamedNodeMap::remove_named_item(StringView qualifi
} }
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name // https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name
Attribute* NamedNodeMap::get_attribute(StringView qualified_name, size_t* item_index) Attr* NamedNodeMap::get_attribute(StringView qualified_name, size_t* item_index)
{ {
return const_cast<Attribute*>(const_cast<NamedNodeMap const*>(this)->get_attribute(qualified_name, item_index)); return const_cast<Attr*>(const_cast<NamedNodeMap const*>(this)->get_attribute(qualified_name, item_index));
} }
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name // https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name
Attribute const* NamedNodeMap::get_attribute(StringView qualified_name, size_t* item_index) const Attr const* NamedNodeMap::get_attribute(StringView qualified_name, size_t* item_index) const
{ {
if (item_index) if (item_index)
*item_index = 0; *item_index = 0;
@ -133,7 +133,7 @@ Attribute const* NamedNodeMap::get_attribute(StringView qualified_name, size_t*
} }
// https://dom.spec.whatwg.org/#concept-element-attributes-set // https://dom.spec.whatwg.org/#concept-element-attributes-set
ExceptionOr<Attribute const*> NamedNodeMap::set_attribute(Attribute& attribute) ExceptionOr<Attr const*> NamedNodeMap::set_attribute(Attr& attribute)
{ {
// 1. If attrs element is neither null nor element, throw an "InUseAttributeError" DOMException. // 1. If attrs element is neither null nor element, throw an "InUseAttributeError" DOMException.
if ((attribute.owner_element() != nullptr) && (attribute.owner_element() != &associated_element())) if ((attribute.owner_element() != nullptr) && (attribute.owner_element() != &associated_element()))
@ -162,7 +162,7 @@ ExceptionOr<Attribute const*> NamedNodeMap::set_attribute(Attribute& attribute)
} }
// https://dom.spec.whatwg.org/#concept-element-attributes-replace // https://dom.spec.whatwg.org/#concept-element-attributes-replace
void NamedNodeMap::replace_attribute(Attribute& old_attribute, Attribute& new_attribute, size_t old_attribute_index) void NamedNodeMap::replace_attribute(Attr& old_attribute, Attr& new_attribute, size_t old_attribute_index)
{ {
// 1. Handle attribute changes for oldAttr with oldAttrs element, oldAttrs value, and newAttrs value. // 1. Handle attribute changes for oldAttr with oldAttrs element, oldAttrs value, and newAttrs value.
VERIFY(old_attribute.owner_element()); VERIFY(old_attribute.owner_element());
@ -180,7 +180,7 @@ void NamedNodeMap::replace_attribute(Attribute& old_attribute, Attribute& new_at
} }
// https://dom.spec.whatwg.org/#concept-element-attributes-append // https://dom.spec.whatwg.org/#concept-element-attributes-append
void NamedNodeMap::append_attribute(Attribute& attribute) void NamedNodeMap::append_attribute(Attr& attribute)
{ {
// 1. Handle attribute changes for attribute with element, null, and attributes value. // 1. Handle attribute changes for attribute with element, null, and attributes value.
attribute.handle_attribute_changes(associated_element(), {}, attribute.value()); attribute.handle_attribute_changes(associated_element(), {}, attribute.value());
@ -195,7 +195,7 @@ void NamedNodeMap::append_attribute(Attribute& attribute)
// https://dom.spec.whatwg.org/#concept-element-attributes-remove // https://dom.spec.whatwg.org/#concept-element-attributes-remove
void NamedNodeMap::remove_attribute_at_index(size_t attribute_index) void NamedNodeMap::remove_attribute_at_index(size_t attribute_index)
{ {
JS::NonnullGCPtr<Attribute> attribute = m_attributes.at(attribute_index); JS::NonnullGCPtr<Attr> attribute = m_attributes.at(attribute_index);
// 1. Handle attribute changes for attribute with attributes element, attributes value, and null. // 1. Handle attribute changes for attribute with attributes element, attributes value, and null.
VERIFY(attribute->owner_element()); VERIFY(attribute->owner_element());
@ -209,7 +209,7 @@ void NamedNodeMap::remove_attribute_at_index(size_t attribute_index)
} }
// https://dom.spec.whatwg.org/#concept-element-attributes-remove-by-name // https://dom.spec.whatwg.org/#concept-element-attributes-remove-by-name
Attribute const* NamedNodeMap::remove_attribute(StringView qualified_name) Attr const* NamedNodeMap::remove_attribute(StringView qualified_name)
{ {
size_t item_index = 0; size_t item_index = 0;

View file

@ -33,18 +33,18 @@ public:
bool is_empty() const { return m_attributes.is_empty(); } bool is_empty() const { return m_attributes.is_empty(); }
// Methods defined by the spec for JavaScript: // Methods defined by the spec for JavaScript:
Attribute const* item(u32 index) const; Attr const* item(u32 index) const;
Attribute const* get_named_item(StringView qualified_name) const; Attr const* get_named_item(StringView qualified_name) const;
ExceptionOr<Attribute const*> set_named_item(Attribute& attribute); ExceptionOr<Attr const*> set_named_item(Attr& attribute);
ExceptionOr<Attribute const*> remove_named_item(StringView qualified_name); ExceptionOr<Attr const*> remove_named_item(StringView qualified_name);
// Methods defined by the spec for internal use: // Methods defined by the spec for internal use:
Attribute* get_attribute(StringView qualified_name, size_t* item_index = nullptr); Attr* get_attribute(StringView qualified_name, size_t* item_index = nullptr);
Attribute const* get_attribute(StringView qualified_name, size_t* item_index = nullptr) const; Attr const* get_attribute(StringView qualified_name, size_t* item_index = nullptr) const;
ExceptionOr<Attribute const*> set_attribute(Attribute& attribute); ExceptionOr<Attr const*> set_attribute(Attr& attribute);
void replace_attribute(Attribute& old_attribute, Attribute& new_attribute, size_t old_attribute_index); void replace_attribute(Attr& old_attribute, Attr& new_attribute, size_t old_attribute_index);
void append_attribute(Attribute& attribute); void append_attribute(Attr& attribute);
Attribute const* remove_attribute(StringView qualified_name); Attr const* remove_attribute(StringView qualified_name);
private: private:
explicit NamedNodeMap(Element&); explicit NamedNodeMap(Element&);
@ -57,7 +57,7 @@ private:
void remove_attribute_at_index(size_t attribute_index); void remove_attribute_at_index(size_t attribute_index);
JS::NonnullGCPtr<DOM::Element> m_element; JS::NonnullGCPtr<DOM::Element> m_element;
Vector<JS::NonnullGCPtr<Attribute>> m_attributes; Vector<JS::NonnullGCPtr<Attr>> m_attributes;
}; };
} }

View file

@ -1,16 +1,16 @@
#import <DOM/Attribute.idl> #import <DOM/Attr.idl>
[Exposed=Window, LegacyUnenumerableNamedProperties] [Exposed=Window, LegacyUnenumerableNamedProperties]
interface NamedNodeMap { interface NamedNodeMap {
readonly attribute unsigned long length; readonly attribute unsigned long length;
getter Attribute? item(unsigned long index); getter Attr? item(unsigned long index);
getter Attribute? getNamedItem(DOMString qualifiedName); getter Attr? getNamedItem(DOMString qualifiedName);
// Attribute? getNamedItemNS(DOMString? namespace, DOMString localName); // Attr? getNamedItemNS(DOMString? namespace, DOMString localName);
[CEReactions] Attribute? setNamedItem(Attribute attr); [CEReactions] Attr? setNamedItem(Attr attr);
// [CEReactions] Attribute? setNamedItemNS(Attribute attr); // [CEReactions] Attr? setNamedItemNS(Attr attr);
[CEReactions] Attribute removeNamedItem(DOMString qualifiedName); [CEReactions] Attr removeNamedItem(DOMString qualifiedName);
// [CEReactions] Attribute removeNamedItemNS(DOMString? namespace, DOMString localName); // [CEReactions] Attr removeNamedItemNS(DOMString? namespace, DOMString localName);
}; };

View file

@ -188,8 +188,8 @@ String Node::node_value() const
// The nodeValue getter steps are to return the following, switching on the interface this implements: // The nodeValue getter steps are to return the following, switching on the interface this implements:
// If Attr, return thiss value. // If Attr, return thiss value.
if (is<Attribute>(this)) { if (is<Attr>(this)) {
return verify_cast<Attribute>(this)->value(); return verify_cast<Attr>(this)->value();
} }
// If CharacterData, return thiss data. // If CharacterData, return thiss data.
@ -208,8 +208,8 @@ void Node::set_node_value(String const& value)
// and then do as described below, switching on the interface this implements: // and then do as described below, switching on the interface this implements:
// If Attr, set an existing attribute value with this and the given value. // If Attr, set an existing attribute value with this and the given value.
if (is<Attribute>(this)) { if (is<Attr>(this)) {
verify_cast<Attribute>(this)->set_value(value); verify_cast<Attr>(this)->set_value(value);
} else if (is<CharacterData>(this)) { } else if (is<CharacterData>(this)) {
// If CharacterData, replace data with node this, offset 0, count thiss length, and data the given value. // If CharacterData, replace data with node this, offset 0, count thiss length, and data the given value.
verify_cast<CharacterData>(this)->set_data(value); verify_cast<CharacterData>(this)->set_data(value);
@ -733,7 +733,7 @@ JS::NonnullGCPtr<Node> Node::clone_node(Document* document, bool clone_children)
document_type_copy->set_public_id(document_type->public_id()); document_type_copy->set_public_id(document_type->public_id());
document_type_copy->set_system_id(document_type->system_id()); document_type_copy->set_system_id(document_type->system_id());
copy = move(document_type_copy); copy = move(document_type_copy);
} else if (is<Attribute>(this)) { } else if (is<Attr>(this)) {
// FIXME: // FIXME:
// Attr // Attr
// Set copys namespace, namespace prefix, local name, and value to those of node. // Set copys namespace, namespace prefix, local name, and value to those of node.
@ -898,19 +898,19 @@ u16 Node::compare_document_position(JS::GCPtr<Node> other)
Node* node2 = this; Node* node2 = this;
// 3. Let attr1 and attr2 be null. // 3. Let attr1 and attr2 be null.
Attribute* attr1; Attr* attr1;
Attribute* attr2; Attr* attr2;
// 4. If node1 is an attribute, then set attr1 to node1 and node1 to attr1s element. // 4. If node1 is an attribute, then set attr1 to node1 and node1 to attr1s element.
if (is<Attribute>(node1)) { if (is<Attr>(node1)) {
attr1 = verify_cast<Attribute>(node1); attr1 = verify_cast<Attr>(node1);
node1 = const_cast<Element*>(attr1->owner_element()); node1 = const_cast<Element*>(attr1->owner_element());
} }
// 5. If node2 is an attribute, then: // 5. If node2 is an attribute, then:
if (is<Attribute>(node2)) { if (is<Attr>(node2)) {
// 1. Set attr2 to node2 and node2 to attr2s element. // 1. Set attr2 to node2 and node2 to attr2s element.
attr2 = verify_cast<Attribute>(node2); attr2 = verify_cast<Attr>(node2);
node2 = const_cast<Element*>(attr2->owner_element()); node2 = const_cast<Element*>(attr2->owner_element());
// 2. If attr1 and node1 are non-null, and node2 is node1, then: // 2. If attr1 and node1 are non-null, and node2 is node1, then:

View file

@ -6,7 +6,7 @@
*/ */
#include <AK/TypeCasts.h> #include <AK/TypeCasts.h>
#include <LibWeb/DOM/Attribute.h> #include <LibWeb/DOM/Attr.h>
#include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/DocumentType.h> #include <LibWeb/DOM/DocumentType.h>
#include <LibWeb/DOM/ExceptionOr.h> #include <LibWeb/DOM/ExceptionOr.h>
@ -26,10 +26,10 @@ StaticRange::~StaticRange() = default;
ExceptionOr<StaticRange*> StaticRange::create_with_global_object(HTML::Window& window, StaticRangeInit& init) ExceptionOr<StaticRange*> StaticRange::create_with_global_object(HTML::Window& window, StaticRangeInit& init)
{ {
// 1. If init["startContainer"] or init["endContainer"] is a DocumentType or Attr node, then throw an "InvalidNodeTypeError" DOMException. // 1. If init["startContainer"] or init["endContainer"] is a DocumentType or Attr node, then throw an "InvalidNodeTypeError" DOMException.
if (is<DocumentType>(*init.start_container) || is<Attribute>(*init.start_container)) if (is<DocumentType>(*init.start_container) || is<Attr>(*init.start_container))
return DOM::InvalidNodeTypeError::create(window, "startContainer cannot be a DocumentType or Attribute node."); return DOM::InvalidNodeTypeError::create(window, "startContainer cannot be a DocumentType or Attribute node.");
if (is<DocumentType>(*init.end_container) || is<Attribute>(*init.end_container)) if (is<DocumentType>(*init.end_container) || is<Attr>(*init.end_container))
return DOM::InvalidNodeTypeError::create(window, "endContainer cannot be a DocumentType or Attribute node."); return DOM::InvalidNodeTypeError::create(window, "endContainer cannot be a DocumentType or Attribute node.");
// 2. Set thiss start to (init["startContainer"], init["startOffset"]) and end to (init["endContainer"], init["endOffset"]). // 2. Set thiss start to (init["startContainer"], init["startOffset"]) and end to (init["endContainer"], init["endOffset"]).

View file

@ -204,7 +204,7 @@ DOM::ExceptionOr<String> serialize_node_to_xml_string_impl(JS::NonnullGCPtr<DOM:
return serialize_processing_instruction(static_cast<DOM::ProcessingInstruction&>(*root), require_well_formed); return serialize_processing_instruction(static_cast<DOM::ProcessingInstruction&>(*root), require_well_formed);
} }
if (is<DOM::Attribute>(*root)) { if (is<DOM::Attr>(*root)) {
// -> An Attr object // -> An Attr object
// Return an empty string. // Return an empty string.
return String::empty(); return String::empty();

View file

@ -129,7 +129,7 @@ namespace Web::DOM {
class AbstractRange; class AbstractRange;
class AbortController; class AbortController;
class AbortSignal; class AbortSignal;
class Attribute; class Attr;
class CDATASection; class CDATASection;
class CharacterData; class CharacterData;
class Comment; class Comment;

View file

@ -9,7 +9,7 @@
#include <AK/StringView.h> #include <AK/StringView.h>
#include <AK/Utf8View.h> #include <AK/Utf8View.h>
#include <LibTextCodec/Decoder.h> #include <LibTextCodec/Decoder.h>
#include <LibWeb/DOM/Attribute.h> #include <LibWeb/DOM/Attr.h>
#include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/Parser/HTMLEncodingDetection.h> #include <LibWeb/HTML/Parser/HTMLEncodingDetection.h>
#include <ctype.h> #include <ctype.h>
@ -96,7 +96,7 @@ Optional<StringView> extract_character_encoding_from_meta_element(String const&
return TextCodec::get_standardized_encoding(encoding); return TextCodec::get_standardized_encoding(encoding);
} }
JS::GCPtr<DOM::Attribute> prescan_get_attribute(DOM::Document& document, ByteBuffer const& input, size_t& position) JS::GCPtr<DOM::Attr> prescan_get_attribute(DOM::Document& document, ByteBuffer const& input, size_t& position)
{ {
if (!prescan_skip_whitespace_and_slashes(input, position)) if (!prescan_skip_whitespace_and_slashes(input, position))
return {}; return {};
@ -111,7 +111,7 @@ JS::GCPtr<DOM::Attribute> prescan_get_attribute(DOM::Document& document, ByteBuf
} else if (input[position] == '\t' || input[position] == '\n' || input[position] == '\f' || input[position] == '\r' || input[position] == ' ') } else if (input[position] == '\t' || input[position] == '\n' || input[position] == '\f' || input[position] == '\r' || input[position] == ' ')
goto spaces; goto spaces;
else if (input[position] == '/' || input[position] == '>') else if (input[position] == '/' || input[position] == '>')
return *DOM::Attribute::create(document, attribute_name.to_string(), ""); return *DOM::Attr::create(document, attribute_name.to_string(), "");
else else
attribute_name.append_as_lowercase(input[position]); attribute_name.append_as_lowercase(input[position]);
++position; ++position;
@ -123,7 +123,7 @@ spaces:
if (!prescan_skip_whitespace_and_slashes(input, position)) if (!prescan_skip_whitespace_and_slashes(input, position))
return {}; return {};
if (input[position] != '=') if (input[position] != '=')
return DOM::Attribute::create(document, attribute_name.to_string(), ""); return DOM::Attr::create(document, attribute_name.to_string(), "");
++position; ++position;
value: value:
@ -136,13 +136,13 @@ value:
++position; ++position;
for (; !prescan_should_abort(input, position); ++position) { for (; !prescan_should_abort(input, position); ++position) {
if (input[position] == quote_character) if (input[position] == quote_character)
return DOM::Attribute::create(document, attribute_name.to_string(), attribute_value.to_string()); return DOM::Attr::create(document, attribute_name.to_string(), attribute_value.to_string());
else else
attribute_value.append_as_lowercase(input[position]); attribute_value.append_as_lowercase(input[position]);
} }
return {}; return {};
} else if (input[position] == '>') } else if (input[position] == '>')
return DOM::Attribute::create(document, attribute_name.to_string(), ""); return DOM::Attr::create(document, attribute_name.to_string(), "");
else else
attribute_value.append_as_lowercase(input[position]); attribute_value.append_as_lowercase(input[position]);
@ -152,7 +152,7 @@ value:
for (; !prescan_should_abort(input, position); ++position) { for (; !prescan_should_abort(input, position); ++position) {
if (input[position] == '\t' || input[position] == '\n' || input[position] == '\f' || input[position] == '\r' || input[position] == ' ' || input[position] == '>') if (input[position] == '\t' || input[position] == '\n' || input[position] == '\f' || input[position] == '\r' || input[position] == ' ' || input[position] == '>')
return DOM::Attribute::create(document, attribute_name.to_string(), attribute_value.to_string()); return DOM::Attr::create(document, attribute_name.to_string(), attribute_value.to_string());
else else
attribute_value.append_as_lowercase(input[position]); attribute_value.append_as_lowercase(input[position]);
} }

View file

@ -16,7 +16,7 @@ bool prescan_should_abort(ByteBuffer const& input, size_t const& position);
bool prescan_is_whitespace_or_slash(u8 const& byte); bool prescan_is_whitespace_or_slash(u8 const& byte);
bool prescan_skip_whitespace_and_slashes(ByteBuffer const& input, size_t& position); bool prescan_skip_whitespace_and_slashes(ByteBuffer const& input, size_t& position);
Optional<StringView> extract_character_encoding_from_meta_element(String const&); Optional<StringView> extract_character_encoding_from_meta_element(String const&);
JS::GCPtr<DOM::Attribute> prescan_get_attribute(DOM::Document&, ByteBuffer const& input, size_t& position); JS::GCPtr<DOM::Attr> prescan_get_attribute(DOM::Document&, ByteBuffer const& input, size_t& position);
Optional<String> run_prescan_byte_stream_algorithm(DOM::Document&, ByteBuffer const& input); Optional<String> run_prescan_byte_stream_algorithm(DOM::Document&, ByteBuffer const& input);
String run_encoding_sniffing_algorithm(DOM::Document&, ByteBuffer const& input); String run_encoding_sniffing_algorithm(DOM::Document&, ByteBuffer const& input);

View file

@ -21,7 +21,7 @@ libweb_js_wrapper(CSS/Screen)
libweb_js_wrapper(CSS/StyleSheet) libweb_js_wrapper(CSS/StyleSheet)
libweb_js_wrapper(CSS/StyleSheetList) libweb_js_wrapper(CSS/StyleSheetList)
libweb_js_wrapper(DOM/AbstractRange) libweb_js_wrapper(DOM/AbstractRange)
libweb_js_wrapper(DOM/Attribute) libweb_js_wrapper(DOM/Attr)
libweb_js_wrapper(DOM/AbortController) libweb_js_wrapper(DOM/AbortController)
libweb_js_wrapper(DOM/AbortSignal) libweb_js_wrapper(DOM/AbortSignal)
libweb_js_wrapper(DOM/CDATASection) libweb_js_wrapper(DOM/CDATASection)