mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibWeb: Port Attr interface from DeprecatedString to String
There are an unfortunate number of DeprecatedString conversions required here, but these should all fall away and look much more pretty again when other places are also ported away from DeprecatedString. Leaves only the Element IDL interface left :^)
This commit is contained in:
parent
a41f23a0fc
commit
3bd04d2c58
Notes:
sideshowbarker
2024-07-18 03:20:18 +09:00
Author: https://github.com/shannonbooth Commit: https://github.com/SerenityOS/serenity/commit/3bd04d2c58 Pull-request: https://github.com/SerenityOS/serenity/pull/21174 Reviewed-by: https://github.com/awesomekling
15 changed files with 172 additions and 117 deletions
|
@ -3689,7 +3689,7 @@ JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> @constructor_class@::constru
|
|||
// 3. Set element's namespace to the HTML namespace.
|
||||
// 4. Set element's namespace prefix to null.
|
||||
// 5. Set element's local name to definition's local name.
|
||||
auto element = realm.heap().allocate<@fully_qualified_name@>(realm, window.associated_document(), DOM::QualifiedName { definition->local_name().to_deprecated_string(), {}, Namespace::HTML });
|
||||
auto element = realm.heap().allocate<@fully_qualified_name@>(realm, window.associated_document(), DOM::QualifiedName { definition->local_name(), {}, Namespace::HTML });
|
||||
|
||||
// https://webidl.spec.whatwg.org/#internally-create-a-new-object-implementing-the-interface
|
||||
// Important steps from "internally create a new object implementing the interface"
|
||||
|
|
|
@ -15,12 +15,12 @@
|
|||
|
||||
namespace Web::DOM {
|
||||
|
||||
JS::NonnullGCPtr<Attr> Attr::create(Document& document, DeprecatedFlyString local_name, DeprecatedString value, Element* owner_element)
|
||||
JS::NonnullGCPtr<Attr> Attr::create(Document& document, FlyString local_name, String value, Element* owner_element)
|
||||
{
|
||||
return document.heap().allocate<Attr>(document.realm(), document, QualifiedName(move(local_name), {}, {}), move(value), owner_element);
|
||||
return document.heap().allocate<Attr>(document.realm(), document, QualifiedName(move(local_name), Optional<FlyString> {}, Optional<FlyString> {}), move(value), owner_element);
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<Attr> Attr::create(Document& document, QualifiedName qualified_name, DeprecatedString value, Element* owner_element)
|
||||
JS::NonnullGCPtr<Attr> Attr::create(Document& document, QualifiedName qualified_name, String value, Element* owner_element)
|
||||
{
|
||||
return document.heap().allocate<Attr>(document.realm(), document, move(qualified_name), move(value), owner_element);
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ JS::NonnullGCPtr<Attr> Attr::clone(Document& document)
|
|||
return *heap().allocate<Attr>(realm(), document, m_qualified_name, m_value, nullptr);
|
||||
}
|
||||
|
||||
Attr::Attr(Document& document, QualifiedName qualified_name, DeprecatedString value, Element* owner_element)
|
||||
Attr::Attr(Document& document, QualifiedName qualified_name, String value, Element* owner_element)
|
||||
: Node(document, NodeType::ATTRIBUTE_NODE)
|
||||
, m_qualified_name(move(qualified_name))
|
||||
, m_value(move(value))
|
||||
|
@ -66,7 +66,7 @@ void Attr::set_owner_element(Element* owner_element)
|
|||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#set-an-existing-attribute-value
|
||||
void Attr::set_value(DeprecatedString value)
|
||||
void Attr::set_value(String value)
|
||||
{
|
||||
// 1. If attribute’s element is null, then set attribute’s value to value.
|
||||
if (!owner_element()) {
|
||||
|
@ -79,7 +79,7 @@ void Attr::set_value(DeprecatedString value)
|
|||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-element-attributes-change
|
||||
void Attr::change_attribute(DeprecatedString value)
|
||||
void Attr::change_attribute(String value)
|
||||
{
|
||||
// 1. Let oldValue be attribute’s value.
|
||||
auto old_value = move(m_value);
|
||||
|
@ -88,14 +88,18 @@ void Attr::change_attribute(DeprecatedString value)
|
|||
m_value = move(value);
|
||||
|
||||
// 3. Handle attribute changes for attribute with attribute’s element, oldValue, and value.
|
||||
handle_attribute_changes(*owner_element(), old_value, m_value);
|
||||
handle_attribute_changes(*owner_element(), old_value.to_deprecated_string(), m_value.to_deprecated_string());
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#handle-attribute-changes
|
||||
void Attr::handle_attribute_changes(Element& element, DeprecatedString const& old_value, DeprecatedString const& new_value)
|
||||
{
|
||||
DeprecatedString deprecated_namespace_uri;
|
||||
if (namespace_uri().has_value())
|
||||
deprecated_namespace_uri = namespace_uri().value().to_deprecated_fly_string();
|
||||
|
||||
// 1. Queue a mutation record of "attributes" for element with attribute’s local name, attribute’s namespace, oldValue, « », « », null, and null.
|
||||
element.queue_mutation_record(MutationType::attributes, local_name(), namespace_uri(), old_value, {}, {}, nullptr, nullptr);
|
||||
element.queue_mutation_record(MutationType::attributes, local_name().to_deprecated_fly_string(), deprecated_namespace_uri, old_value, {}, {}, nullptr, nullptr);
|
||||
|
||||
// 2. If element is custom, then enqueue a custom element callback reaction with element, callback name "attributeChangedCallback", and an argument list containing attribute’s local name, oldValue, newValue, and attribute’s namespace.
|
||||
if (element.is_custom()) {
|
||||
|
@ -105,13 +109,13 @@ void Attr::handle_attribute_changes(Element& element, DeprecatedString const& ol
|
|||
arguments.append(JS::PrimitiveString::create(vm, local_name()));
|
||||
arguments.append(old_value.is_null() ? JS::js_null() : JS::PrimitiveString::create(vm, old_value));
|
||||
arguments.append(new_value.is_null() ? JS::js_null() : JS::PrimitiveString::create(vm, new_value));
|
||||
arguments.append(namespace_uri().is_null() ? JS::js_null() : JS::PrimitiveString::create(vm, namespace_uri()));
|
||||
arguments.append(!namespace_uri().has_value() ? JS::js_null() : JS::PrimitiveString::create(vm, namespace_uri().value()));
|
||||
|
||||
element.enqueue_a_custom_element_callback_reaction(HTML::CustomElementReactionNames::attributeChangedCallback, move(arguments));
|
||||
}
|
||||
|
||||
// 3. Run the attribute change steps with element, attribute’s local name, oldValue, newValue, and attribute’s namespace.
|
||||
element.run_attribute_change_steps(local_name(), old_value, new_value, namespace_uri());
|
||||
element.run_attribute_change_steps(local_name().to_deprecated_fly_string(), old_value, new_value, deprecated_namespace_uri);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,22 +18,22 @@ class Attr final : public Node {
|
|||
WEB_PLATFORM_OBJECT(Attr, Node);
|
||||
|
||||
public:
|
||||
[[nodiscard]] static JS::NonnullGCPtr<Attr> create(Document&, QualifiedName, DeprecatedString value = "", Element* = nullptr);
|
||||
[[nodiscard]] static JS::NonnullGCPtr<Attr> create(Document&, DeprecatedFlyString local_name, DeprecatedString value = "", Element* = nullptr);
|
||||
[[nodiscard]] static JS::NonnullGCPtr<Attr> create(Document&, QualifiedName, String value = {}, Element* = nullptr);
|
||||
[[nodiscard]] static JS::NonnullGCPtr<Attr> create(Document&, FlyString local_name, String value = {}, Element* = nullptr);
|
||||
JS::NonnullGCPtr<Attr> clone(Document&);
|
||||
|
||||
virtual ~Attr() override = default;
|
||||
|
||||
virtual FlyString node_name() const override { return MUST(FlyString::from_deprecated_fly_string(name())); }
|
||||
virtual FlyString node_name() const override { return name(); }
|
||||
|
||||
DeprecatedFlyString const& namespace_uri() const { return m_qualified_name.namespace_(); }
|
||||
DeprecatedFlyString const& prefix() const { return m_qualified_name.prefix(); }
|
||||
DeprecatedFlyString const& local_name() const { return m_qualified_name.local_name(); }
|
||||
DeprecatedFlyString const& name() const { return m_qualified_name.as_string(); }
|
||||
Optional<FlyString> const& namespace_uri() const { return m_qualified_name.namespace_(); }
|
||||
Optional<FlyString> const& prefix() const { return m_qualified_name.prefix(); }
|
||||
FlyString const& local_name() const { return m_qualified_name.local_name(); }
|
||||
FlyString const& name() const { return m_qualified_name.as_string(); }
|
||||
|
||||
DeprecatedString const& value() const { return m_value; }
|
||||
void set_value(DeprecatedString value);
|
||||
void change_attribute(DeprecatedString value);
|
||||
String const& value() const { return m_value; }
|
||||
void set_value(String value);
|
||||
void change_attribute(String value);
|
||||
|
||||
Element* owner_element();
|
||||
Element const* owner_element() const;
|
||||
|
@ -45,13 +45,13 @@ public:
|
|||
void handle_attribute_changes(Element&, DeprecatedString const& old_value, DeprecatedString const& new_value);
|
||||
|
||||
private:
|
||||
Attr(Document&, QualifiedName, DeprecatedString value, Element*);
|
||||
Attr(Document&, QualifiedName, String value, Element*);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
QualifiedName m_qualified_name;
|
||||
DeprecatedString m_value;
|
||||
String m_value;
|
||||
JS::GCPtr<Element> m_owner_element;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#import <DOM/Node.idl>
|
||||
#import <DOM/Element.idl>
|
||||
|
||||
[Exposed=Window, UseDeprecatedAKString]
|
||||
[Exposed=Window]
|
||||
interface Attr : Node {
|
||||
readonly attribute DOMString? namespaceURI;
|
||||
readonly attribute DOMString? prefix;
|
||||
|
|
|
@ -1387,7 +1387,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> Document::create_element_ns(Optio
|
|||
}
|
||||
|
||||
// 4. Return the result of creating an element given document, localName, namespace, prefix, is, and with the synchronous custom elements flag set.
|
||||
return TRY(DOM::create_element(*this, extracted_qualified_name.local_name(), extracted_qualified_name.namespace_(), extracted_qualified_name.prefix(), move(is_value), true));
|
||||
return TRY(DOM::create_element(*this, extracted_qualified_name.local_name().to_deprecated_fly_string(), extracted_qualified_name.deprecated_namespace_(), extracted_qualified_name.deprecated_prefix(), move(is_value), true));
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<DocumentFragment> Document::create_document_fragment()
|
||||
|
@ -2963,7 +2963,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> Document::create_attribute(String co
|
|||
// 2. If this is an HTML document, then set localName to localName in ASCII lowercase.
|
||||
// 3. Return a new attribute whose local name is localName and node document is this.
|
||||
auto deprecated_local_name = local_name.to_deprecated_string();
|
||||
return Attr::create(*this, is_html_document() ? deprecated_local_name.to_lowercase() : deprecated_local_name);
|
||||
return Attr::create(*this, MUST(FlyString::from_deprecated_fly_string(is_html_document() ? deprecated_local_name.to_lowercase() : deprecated_local_name)));
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-document-createattributens
|
||||
|
|
|
@ -141,7 +141,7 @@ DeprecatedString Element::get_attribute(DeprecatedFlyString const& name) const
|
|||
return {};
|
||||
|
||||
// 3. Return attr’s value.
|
||||
return attribute->value();
|
||||
return attribute->value().to_deprecated_string();
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-element-attributes-get-value
|
||||
|
@ -155,7 +155,7 @@ DeprecatedString Element::get_attribute_value(DeprecatedFlyString const& local_n
|
|||
return DeprecatedString::empty();
|
||||
|
||||
// 3. Return attr’s value.
|
||||
return attribute->value();
|
||||
return attribute->value().to_deprecated_string();
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-element-getattributenode
|
||||
|
@ -183,14 +183,14 @@ WebIDL::ExceptionOr<void> Element::set_attribute(DeprecatedFlyString const& name
|
|||
// 4. If attribute is null, create an attribute whose local name is qualifiedName, value is value, and node document
|
||||
// is this’s node document, then append this attribute to this, and then return.
|
||||
if (!attribute) {
|
||||
auto new_attribute = Attr::create(document(), insert_as_lowercase ? name.to_lowercase() : name, value);
|
||||
auto new_attribute = Attr::create(document(), MUST(String::from_deprecated_string(insert_as_lowercase ? name.to_lowercase() : name)), MUST(String::from_deprecated_string(value)));
|
||||
m_attributes->append_attribute(new_attribute);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// 5. Change attribute to value.
|
||||
attribute->change_attribute(value);
|
||||
attribute->change_attribute(MUST(String::from_deprecated_string(value)));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
@ -243,7 +243,7 @@ WebIDL::ExceptionOr<QualifiedName> validate_and_extract(JS::Realm& realm, Deprec
|
|||
return WebIDL::NamespaceError::create(realm, "Namespace is the XMLNS namespace and neither qualifiedName nor prefix is 'xmlns'."_fly_string);
|
||||
|
||||
// 10. Return namespace, prefix, and localName.
|
||||
return QualifiedName { local_name, prefix, namespace_ };
|
||||
return QualifiedName { MUST(FlyString::from_deprecated_fly_string(local_name)), prefix, namespace_ };
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-element-setattributens
|
||||
|
@ -253,7 +253,7 @@ WebIDL::ExceptionOr<void> Element::set_attribute_ns(DeprecatedFlyString const& n
|
|||
auto extracted_qualified_name = TRY(validate_and_extract(realm(), namespace_, qualified_name));
|
||||
|
||||
// 2. Set an attribute value for this using localName, value, and also prefix and namespace.
|
||||
set_attribute_value(extracted_qualified_name.local_name(), value, extracted_qualified_name.prefix(), extracted_qualified_name.namespace_());
|
||||
set_attribute_value(extracted_qualified_name.local_name().to_deprecated_fly_string(), value, extracted_qualified_name.deprecated_prefix(), extracted_qualified_name.deprecated_namespace_());
|
||||
|
||||
return {};
|
||||
}
|
||||
|
@ -268,16 +268,16 @@ void Element::set_attribute_value(DeprecatedFlyString const& local_name, Depreca
|
|||
// is localName, value is value, and node document is element’s node document, then append this attribute to element,
|
||||
// and then return.
|
||||
if (!attribute) {
|
||||
QualifiedName name { local_name, prefix, namespace_ };
|
||||
QualifiedName name { MUST(FlyString::from_deprecated_fly_string(local_name)), prefix, namespace_ };
|
||||
|
||||
auto new_attribute = Attr::create(document(), move(name), value);
|
||||
auto new_attribute = Attr::create(document(), move(name), MUST(String::from_deprecated_string(value)));
|
||||
m_attributes->append_attribute(new_attribute);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. Change attribute to value.
|
||||
attribute->change_attribute(value);
|
||||
attribute->change_attribute(MUST(String::from_deprecated_string(value)));
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-element-setattributenode
|
||||
|
@ -338,7 +338,7 @@ WebIDL::ExceptionOr<bool> Element::toggle_attribute(DeprecatedFlyString const& n
|
|||
// 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 this’s node document, then append this attribute to this, and then return true.
|
||||
if (!force.has_value() || force.value()) {
|
||||
auto new_attribute = Attr::create(document(), insert_as_lowercase ? name.to_lowercase() : name, "");
|
||||
auto new_attribute = Attr::create(document(), MUST(String::from_deprecated_string(insert_as_lowercase ? name.to_lowercase() : name)), String {});
|
||||
m_attributes->append_attribute(new_attribute);
|
||||
|
||||
return true;
|
||||
|
@ -365,7 +365,7 @@ Vector<DeprecatedString> Element::get_attribute_names() const
|
|||
Vector<DeprecatedString> names;
|
||||
for (size_t i = 0; i < m_attributes->length(); ++i) {
|
||||
auto const* attribute = m_attributes->item(i);
|
||||
names.append(attribute->name());
|
||||
names.append(attribute->name().to_deprecated_fly_string());
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
@ -1744,7 +1744,7 @@ JS::ThrowCompletionOr<void> Element::upgrade_element(JS::NonnullGCPtr<HTML::Cust
|
|||
arguments.append(JS::PrimitiveString::create(vm, attribute->local_name()));
|
||||
arguments.append(JS::js_null());
|
||||
arguments.append(JS::PrimitiveString::create(vm, attribute->value()));
|
||||
arguments.append(JS::PrimitiveString::create(vm, attribute->namespace_uri()));
|
||||
arguments.append(attribute->namespace_uri().has_value() ? JS::PrimitiveString::create(vm, attribute->namespace_uri().value()) : JS::js_null());
|
||||
|
||||
enqueue_a_custom_element_callback_reaction(HTML::CustomElementReactionNames::attributeChangedCallback, move(arguments));
|
||||
}
|
||||
|
@ -1850,14 +1850,14 @@ void Element::setup_custom_element_from_constructor(HTML::CustomElementDefinitio
|
|||
|
||||
void Element::set_prefix(DeprecatedFlyString const& value)
|
||||
{
|
||||
m_qualified_name.set_prefix(value);
|
||||
m_qualified_name.set_prefix(MUST(FlyString::from_deprecated_fly_string(value)));
|
||||
}
|
||||
|
||||
void Element::for_each_attribute(Function<void(DeprecatedFlyString const&, DeprecatedString const&)> callback) const
|
||||
{
|
||||
for (size_t i = 0; i < m_attributes->length(); ++i) {
|
||||
auto const* attribute = m_attributes->item(i);
|
||||
callback(attribute->name(), attribute->value());
|
||||
callback(attribute->name().to_deprecated_fly_string(), attribute->value().to_deprecated_string());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -74,21 +74,22 @@ class Element
|
|||
public:
|
||||
virtual ~Element() override;
|
||||
|
||||
DeprecatedFlyString const& qualified_name() const { return m_qualified_name.as_string(); }
|
||||
DeprecatedFlyString qualified_name() const { return m_qualified_name.as_string().to_deprecated_fly_string(); }
|
||||
DeprecatedString const& html_uppercased_qualified_name() const { return m_html_uppercased_qualified_name; }
|
||||
|
||||
virtual FlyString node_name() const final { return MUST(FlyString::from_deprecated_fly_string(html_uppercased_qualified_name())); }
|
||||
DeprecatedFlyString const& local_name() const { return m_qualified_name.local_name(); }
|
||||
DeprecatedFlyString local_name() const { return m_qualified_name.local_name().to_deprecated_fly_string(); }
|
||||
|
||||
// NOTE: This is for the JS bindings
|
||||
DeprecatedString const& tag_name() const { return html_uppercased_qualified_name(); }
|
||||
|
||||
DeprecatedFlyString const& prefix() const { return m_qualified_name.prefix(); }
|
||||
DeprecatedFlyString prefix() const { return m_qualified_name.deprecated_prefix(); }
|
||||
void set_prefix(DeprecatedFlyString const& value);
|
||||
|
||||
DeprecatedFlyString const& namespace_() const { return m_qualified_name.namespace_(); }
|
||||
DeprecatedFlyString namespace_() const { return m_qualified_name.deprecated_namespace_(); }
|
||||
|
||||
// NOTE: This is for the JS bindings
|
||||
DeprecatedFlyString const& namespace_uri() const { return namespace_(); }
|
||||
DeprecatedFlyString namespace_uri() const { return namespace_(); }
|
||||
|
||||
bool has_attribute(DeprecatedFlyString const& name) const;
|
||||
bool has_attribute_ns(DeprecatedFlyString namespace_, DeprecatedFlyString const& name) const;
|
||||
|
|
|
@ -272,7 +272,7 @@ bool is_unknown_html_element(DeprecatedFlyString const& tag_name)
|
|||
// https://html.spec.whatwg.org/#elements-in-the-dom:element-interface
|
||||
static JS::NonnullGCPtr<Element> create_html_element(JS::Realm& realm, Document& document, QualifiedName qualified_name)
|
||||
{
|
||||
auto lowercase_tag_name = qualified_name.local_name().to_lowercase();
|
||||
auto lowercase_tag_name = qualified_name.local_name().to_deprecated_fly_string().to_lowercase();
|
||||
|
||||
if (lowercase_tag_name == HTML::TagNames::a)
|
||||
return realm.heap().allocate<HTML::HTMLAnchorElement>(realm, document, move(qualified_name));
|
||||
|
@ -426,7 +426,7 @@ static JS::NonnullGCPtr<Element> create_html_element(JS::Realm& realm, Document&
|
|||
|
||||
static JS::GCPtr<SVG::SVGElement> create_svg_element(JS::Realm& realm, Document& document, QualifiedName qualified_name)
|
||||
{
|
||||
auto const& local_name = qualified_name.local_name();
|
||||
auto const& local_name = qualified_name.local_name().to_deprecated_fly_string();
|
||||
|
||||
if (local_name == SVG::TagNames::svg)
|
||||
return realm.heap().allocate<SVG::SVGSVGElement>(realm, document, move(qualified_name));
|
||||
|
@ -481,7 +481,7 @@ static JS::GCPtr<SVG::SVGElement> create_svg_element(JS::Realm& realm, Document&
|
|||
|
||||
static JS::GCPtr<MathML::MathMLElement> create_mathml_element(JS::Realm& realm, Document& document, QualifiedName qualified_name)
|
||||
{
|
||||
auto const& local_name = MUST(FlyString::from_deprecated_fly_string(qualified_name.local_name()));
|
||||
auto const& local_name = qualified_name.local_name();
|
||||
|
||||
if (local_name.is_one_of(MathML::TagNames::annotation, MathML::TagNames::annotation_xml, MathML::TagNames::maction, MathML::TagNames::math, MathML::TagNames::merror, MathML::TagNames::mfrac, MathML::TagNames::mi, MathML::TagNames::mmultiscripts, MathML::TagNames::mn, MathML::TagNames::mo, MathML::TagNames::mover, MathML::TagNames::mpadded, MathML::TagNames::mphantom, MathML::TagNames::mprescripts, MathML::TagNames::mroot, MathML::TagNames::mrow, MathML::TagNames::ms, MathML::TagNames::mspace, MathML::TagNames::msqrt, MathML::TagNames::mstyle, MathML::TagNames::msub, MathML::TagNames::msubsup, MathML::TagNames::msup, MathML::TagNames::mtable, MathML::TagNames::mtd, MathML::TagNames::mtext, MathML::TagNames::mtr, MathML::TagNames::munder, MathML::TagNames::munderover, MathML::TagNames::semantics))
|
||||
return realm.heap().allocate<MathML::MathMLElement>(realm, document, move(qualified_name));
|
||||
|
@ -511,7 +511,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element(Document& document
|
|||
// 2. Set result to a new element that implements interface, with no attributes, namespace set to the HTML namespace,
|
||||
// namespace prefix set to prefix, local name set to localName, custom element state set to "undefined", custom element definition set to null,
|
||||
// is value set to is, and node document set to document.
|
||||
auto element = create_html_element(realm, document, QualifiedName { local_name, prefix, Namespace::HTML });
|
||||
auto element = create_html_element(realm, document, QualifiedName { MUST(FlyString::from_deprecated_fly_string(local_name)), prefix, Namespace::HTML });
|
||||
|
||||
// 3. If the synchronous custom elements flag is set, then run this step while catching any exceptions:
|
||||
if (synchronous_custom_elements_flag) {
|
||||
|
@ -596,7 +596,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element(Document& document
|
|||
|
||||
// 2. Set result to a new element that implements the HTMLUnknownElement interface, with no attributes, namespace set to the HTML namespace, namespace prefix set to prefix,
|
||||
// local name set to localName, custom element state set to "failed", custom element definition set to null, is value set to null, and node document set to document.
|
||||
JS::NonnullGCPtr<Element> element = realm.heap().allocate<HTML::HTMLUnknownElement>(realm, document, QualifiedName { local_name, prefix, Namespace::HTML });
|
||||
JS::NonnullGCPtr<Element> element = realm.heap().allocate<HTML::HTMLUnknownElement>(realm, document, QualifiedName { MUST(FlyString::from_deprecated_fly_string(local_name)), prefix, Namespace::HTML });
|
||||
element->set_custom_element_state(CustomElementState::Failed);
|
||||
return element;
|
||||
}
|
||||
|
@ -607,7 +607,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element(Document& document
|
|||
// 2. Otherwise:
|
||||
// 1. Set result to a new element that implements the HTMLElement interface, with no attributes, namespace set to the HTML namespace, namespace prefix set to prefix,
|
||||
// local name set to localName, custom element state set to "undefined", custom element definition set to null, is value set to null, and node document set to document.
|
||||
auto element = realm.heap().allocate<HTML::HTMLElement>(realm, document, QualifiedName { local_name, prefix, Namespace::HTML });
|
||||
auto element = realm.heap().allocate<HTML::HTMLElement>(realm, document, QualifiedName { MUST(FlyString::from_deprecated_fly_string(local_name)), prefix, Namespace::HTML });
|
||||
element->set_custom_element_state(CustomElementState::Undefined);
|
||||
|
||||
// 2. Enqueue a custom element upgrade reaction given result and definition.
|
||||
|
@ -621,7 +621,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element(Document& document
|
|||
// local name set to localName, custom element state set to "uncustomized", custom element definition set to null, is value set to is,
|
||||
// and node document set to document.
|
||||
|
||||
auto qualified_name = QualifiedName { local_name, prefix, namespace_ };
|
||||
auto qualified_name = QualifiedName { MUST(FlyString::from_deprecated_fly_string(local_name)), prefix, namespace_ };
|
||||
|
||||
if (namespace_ == Namespace::HTML) {
|
||||
auto element = create_html_element(realm, document, move(qualified_name));
|
||||
|
|
|
@ -53,8 +53,9 @@ Vector<DeprecatedString> NamedNodeMap::supported_property_names() const
|
|||
names.ensure_capacity(m_attributes.size());
|
||||
|
||||
for (auto const& attribute : m_attributes) {
|
||||
if (!names.contains_slow(attribute->name()))
|
||||
names.append(attribute->name());
|
||||
auto const attribute_name = attribute->name().to_deprecated_fly_string();
|
||||
if (!names.contains_slow(attribute_name))
|
||||
names.append(attribute_name);
|
||||
}
|
||||
|
||||
// 2. If this NamedNodeMap object’s element is in the HTML namespace and its node document is an HTML document, then for each name in names:
|
||||
|
@ -193,7 +194,8 @@ Attr const* NamedNodeMap::get_attribute_ns(StringView namespace_, StringView loc
|
|||
|
||||
// 2. Return the attribute in element’s attribute list whose namespace is namespace and local name is localName, if any; otherwise null.
|
||||
for (auto const& attribute : m_attributes) {
|
||||
if (attribute->namespace_uri() == namespace_ && attribute->local_name() == local_name)
|
||||
// FIXME: This is quite awkard. We should probably be taking an Optional<FlyString> for namespace here.
|
||||
if ((!attribute->namespace_uri().has_value() == namespace_.is_null() || attribute->namespace_uri() == namespace_) && attribute->local_name() == local_name)
|
||||
return attribute.ptr();
|
||||
if (item_index)
|
||||
++(*item_index);
|
||||
|
@ -211,7 +213,11 @@ WebIDL::ExceptionOr<JS::GCPtr<Attr>> NamedNodeMap::set_attribute(Attr& attribute
|
|||
|
||||
// 2. Let oldAttr be the result of getting an attribute given attr’s namespace, attr’s local name, and element.
|
||||
size_t old_attribute_index = 0;
|
||||
auto* old_attribute = get_attribute_ns(attribute.namespace_uri(), attribute.local_name(), &old_attribute_index);
|
||||
DeprecatedString deprecated_namespace_uri;
|
||||
if (attribute.namespace_uri().has_value())
|
||||
deprecated_namespace_uri = attribute.namespace_uri().value().to_deprecated_fly_string();
|
||||
|
||||
auto* old_attribute = get_attribute_ns(deprecated_namespace_uri, attribute.local_name(), &old_attribute_index);
|
||||
|
||||
// 3. If oldAttr is attr, return attr.
|
||||
if (old_attribute == &attribute)
|
||||
|
@ -246,7 +252,7 @@ void NamedNodeMap::replace_attribute(Attr& old_attribute, Attr& new_attribute, s
|
|||
old_attribute.set_owner_element(nullptr);
|
||||
|
||||
// 4. Handle attribute changes for oldAttr with newAttr’s element, oldAttr’s value, and newAttr’s value.
|
||||
old_attribute.handle_attribute_changes(*new_attribute.owner_element(), old_attribute.value(), new_attribute.value());
|
||||
old_attribute.handle_attribute_changes(*new_attribute.owner_element(), old_attribute.value().to_deprecated_string(), new_attribute.value().to_deprecated_string());
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-element-attributes-append
|
||||
|
@ -259,7 +265,7 @@ void NamedNodeMap::append_attribute(Attr& attribute)
|
|||
attribute.set_owner_element(&associated_element());
|
||||
|
||||
// 3. Handle attribute changes for attribute with element, null, and attribute’s value.
|
||||
attribute.handle_attribute_changes(associated_element(), {}, attribute.value());
|
||||
attribute.handle_attribute_changes(associated_element(), {}, attribute.value().to_deprecated_string());
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-element-attributes-remove
|
||||
|
@ -278,7 +284,7 @@ void NamedNodeMap::remove_attribute_at_index(size_t attribute_index)
|
|||
attribute->set_owner_element(nullptr);
|
||||
|
||||
// 4. Handle attribute changes for attribute with element, attribute’s value, and null.
|
||||
attribute->handle_attribute_changes(*element, attribute->value(), {});
|
||||
attribute->handle_attribute_changes(*element, attribute->value().to_deprecated_string(), {});
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-element-attributes-remove-by-name
|
||||
|
|
|
@ -166,7 +166,7 @@ Optional<String> Node::text_content() const
|
|||
|
||||
// If Attr node, return this's value.
|
||||
if (is<Attr>(*this))
|
||||
return MUST(String::from_deprecated_string(static_cast<Attr const&>(*this).value()));
|
||||
return static_cast<Attr const&>(*this).value();
|
||||
|
||||
// Otherwise, return null
|
||||
return {};
|
||||
|
@ -196,7 +196,7 @@ void Node::set_text_content(Optional<String> const& maybe_content)
|
|||
|
||||
// If Attr, set an existing attribute value with this and the given value.
|
||||
if (is<Attr>(*this)) {
|
||||
static_cast<Attr&>(*this).set_value(content);
|
||||
static_cast<Attr&>(*this).set_value(MUST(String::from_deprecated_string(content)));
|
||||
}
|
||||
|
||||
// Otherwise, do nothing.
|
||||
|
@ -212,7 +212,7 @@ Optional<String> Node::node_value() const
|
|||
|
||||
// If Attr, return this’s value.
|
||||
if (is<Attr>(this)) {
|
||||
return MUST(String::from_deprecated_string(verify_cast<Attr>(this)->value()));
|
||||
return verify_cast<Attr>(this)->value();
|
||||
}
|
||||
|
||||
// If CharacterData, return this’s data.
|
||||
|
@ -233,7 +233,7 @@ void Node::set_node_value(Optional<String> const& maybe_value)
|
|||
|
||||
// If Attr, set an existing attribute value with this and the given value.
|
||||
if (is<Attr>(this)) {
|
||||
verify_cast<Attr>(this)->set_value(value.to_deprecated_string());
|
||||
verify_cast<Attr>(this)->set_value(move(value));
|
||||
} else if (is<CharacterData>(this)) {
|
||||
// If CharacterData, replace data with node this, offset 0, count this’s length, and data the given value.
|
||||
verify_cast<CharacterData>(this)->set_data(value);
|
||||
|
|
|
@ -9,10 +9,20 @@
|
|||
|
||||
namespace Web::DOM {
|
||||
|
||||
static unsigned hash_impl(FlyString const& local_name, Optional<FlyString> const& prefix, Optional<FlyString> const& namespace_)
|
||||
{
|
||||
unsigned hash = local_name.hash();
|
||||
if (prefix.has_value())
|
||||
hash = pair_int_hash(hash, prefix->hash());
|
||||
if (namespace_.has_value())
|
||||
hash = pair_int_hash(hash, namespace_->hash());
|
||||
return hash;
|
||||
}
|
||||
|
||||
struct ImplTraits : public Traits<QualifiedName::Impl*> {
|
||||
static unsigned hash(QualifiedName::Impl* impl)
|
||||
{
|
||||
return pair_int_hash(impl->local_name.hash(), pair_int_hash(impl->prefix.hash(), impl->namespace_.hash()));
|
||||
return hash_impl(impl->local_name, impl->prefix, impl->namespace_);
|
||||
}
|
||||
|
||||
static bool equals(QualifiedName::Impl* a, QualifiedName::Impl* b)
|
||||
|
@ -25,9 +35,10 @@ struct ImplTraits : public Traits<QualifiedName::Impl*> {
|
|||
|
||||
static HashTable<QualifiedName::Impl*, ImplTraits> impls;
|
||||
|
||||
static NonnullRefPtr<QualifiedName::Impl> ensure_impl(DeprecatedFlyString const& local_name, DeprecatedFlyString const& prefix, DeprecatedFlyString const& namespace_)
|
||||
static NonnullRefPtr<QualifiedName::Impl> ensure_impl(FlyString const& local_name, Optional<FlyString> const& prefix, Optional<FlyString> const& namespace_)
|
||||
{
|
||||
auto hash = pair_int_hash(local_name.hash(), pair_int_hash(prefix.hash(), namespace_.hash()));
|
||||
unsigned hash = hash_impl(local_name, prefix, namespace_);
|
||||
|
||||
auto it = impls.find(hash, [&](QualifiedName::Impl* entry) {
|
||||
return entry->local_name == local_name
|
||||
&& entry->prefix == prefix
|
||||
|
@ -38,12 +49,17 @@ static NonnullRefPtr<QualifiedName::Impl> ensure_impl(DeprecatedFlyString const&
|
|||
return adopt_ref(*new QualifiedName::Impl(local_name, prefix, namespace_));
|
||||
}
|
||||
|
||||
QualifiedName::QualifiedName(DeprecatedFlyString const& local_name, DeprecatedFlyString const& prefix, DeprecatedFlyString const& namespace_)
|
||||
QualifiedName::QualifiedName(FlyString const& local_name, Optional<FlyString> const& prefix, Optional<FlyString> const& namespace_)
|
||||
: m_impl(ensure_impl(local_name, prefix, namespace_))
|
||||
{
|
||||
}
|
||||
|
||||
QualifiedName::Impl::Impl(DeprecatedFlyString const& a_local_name, DeprecatedFlyString const& a_prefix, DeprecatedFlyString const& a_namespace)
|
||||
QualifiedName::QualifiedName(FlyString const& local_name, DeprecatedFlyString const& prefix, DeprecatedFlyString const& namespace_)
|
||||
: QualifiedName(local_name, prefix.is_null() ? Optional<FlyString> {} : MUST(FlyString::from_deprecated_fly_string(prefix)), namespace_.is_null() ? Optional<FlyString> {} : MUST(FlyString::from_deprecated_fly_string(namespace_)))
|
||||
{
|
||||
}
|
||||
|
||||
QualifiedName::Impl::Impl(FlyString const& a_local_name, Optional<FlyString> const& a_prefix, Optional<FlyString> const& a_namespace)
|
||||
: local_name(a_local_name)
|
||||
, prefix(a_prefix)
|
||||
, namespace_(a_namespace)
|
||||
|
@ -62,17 +78,17 @@ QualifiedName::Impl::~Impl()
|
|||
void QualifiedName::Impl::make_internal_string()
|
||||
{
|
||||
// This is possible to do according to the spec: "User agents could have this as an internal slot as an optimization."
|
||||
if (prefix.is_null()) {
|
||||
if (!prefix.has_value()) {
|
||||
as_string = local_name;
|
||||
return;
|
||||
}
|
||||
|
||||
as_string = DeprecatedString::formatted("{}:{}", prefix, local_name);
|
||||
as_string = MUST(String::formatted("{}:{}", prefix.value(), local_name));
|
||||
}
|
||||
|
||||
void QualifiedName::set_prefix(DeprecatedFlyString const& value)
|
||||
void QualifiedName::set_prefix(Optional<FlyString> value)
|
||||
{
|
||||
m_impl->prefix = value;
|
||||
m_impl->prefix = move(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,31 +8,48 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/DeprecatedFlyString.h>
|
||||
#include <AK/FlyString.h>
|
||||
#include <AK/Optional.h>
|
||||
|
||||
namespace Web::DOM {
|
||||
|
||||
class QualifiedName {
|
||||
public:
|
||||
QualifiedName(DeprecatedFlyString const& local_name, DeprecatedFlyString const& prefix, DeprecatedFlyString const& namespace_);
|
||||
QualifiedName(FlyString const& local_name, Optional<FlyString> const& prefix, Optional<FlyString> const& namespace_);
|
||||
QualifiedName(FlyString const& local_name, DeprecatedFlyString const& prefix, DeprecatedFlyString const& namespace_);
|
||||
|
||||
DeprecatedFlyString const& local_name() const { return m_impl->local_name; }
|
||||
DeprecatedFlyString const& prefix() const { return m_impl->prefix; }
|
||||
DeprecatedFlyString const& namespace_() const { return m_impl->namespace_; }
|
||||
FlyString const& local_name() const { return m_impl->local_name; }
|
||||
Optional<FlyString> const& prefix() const { return m_impl->prefix; }
|
||||
Optional<FlyString> const& namespace_() const { return m_impl->namespace_; }
|
||||
|
||||
DeprecatedFlyString const& as_string() const { return m_impl->as_string; }
|
||||
DeprecatedFlyString deprecated_prefix() const
|
||||
{
|
||||
if (!m_impl->prefix.has_value())
|
||||
return {};
|
||||
return m_impl->prefix->to_deprecated_fly_string();
|
||||
}
|
||||
|
||||
DeprecatedFlyString deprecated_namespace_() const
|
||||
{
|
||||
if (!m_impl->namespace_.has_value())
|
||||
return {};
|
||||
return m_impl->namespace_->to_deprecated_fly_string();
|
||||
}
|
||||
|
||||
FlyString const& as_string() const { return m_impl->as_string; }
|
||||
|
||||
struct Impl : public RefCounted<Impl> {
|
||||
Impl(DeprecatedFlyString const& local_name, DeprecatedFlyString const& prefix, DeprecatedFlyString const& namespace_);
|
||||
Impl(FlyString const& local_name, Optional<FlyString> const& prefix, Optional<FlyString> const& namespace_);
|
||||
~Impl();
|
||||
|
||||
void make_internal_string();
|
||||
DeprecatedFlyString local_name;
|
||||
DeprecatedFlyString prefix;
|
||||
DeprecatedFlyString namespace_;
|
||||
DeprecatedFlyString as_string;
|
||||
FlyString local_name;
|
||||
Optional<FlyString> prefix;
|
||||
Optional<FlyString> namespace_;
|
||||
FlyString as_string;
|
||||
};
|
||||
|
||||
void set_prefix(DeprecatedFlyString const& value);
|
||||
void set_prefix(Optional<FlyString> value);
|
||||
|
||||
private:
|
||||
NonnullRefPtr<Impl> m_impl;
|
||||
|
|
|
@ -236,25 +236,28 @@ static Optional<DeprecatedString> record_namespace_information(DOM::Element cons
|
|||
|
||||
// 1. Let attribute namespace be the value of attr's namespaceURI value.
|
||||
auto const& attribute_namespace = attribute->namespace_uri();
|
||||
DeprecatedFlyString deprecated_attribute_namespace;
|
||||
if (attribute_namespace.has_value())
|
||||
deprecated_attribute_namespace = attribute_namespace->to_deprecated_fly_string();
|
||||
|
||||
// 2. Let attribute prefix be the value of attr's prefix.
|
||||
auto const& attribute_prefix = attribute->prefix();
|
||||
|
||||
// 3. If the attribute namespace is the XMLNS namespace, then:
|
||||
if (attribute_namespace == Namespace::XMLNS) {
|
||||
if (deprecated_attribute_namespace == Namespace::XMLNS) {
|
||||
// 1. If attribute prefix is null, then attr is a default namespace declaration. Set the default namespace attr value to attr's value and stop running these steps,
|
||||
// returning to Main to visit the next attribute.
|
||||
if (attribute_prefix.is_null()) {
|
||||
default_namespace_attribute_value = attribute->value();
|
||||
if (!attribute_prefix.has_value()) {
|
||||
default_namespace_attribute_value = attribute->value().to_deprecated_string();
|
||||
continue;
|
||||
}
|
||||
|
||||
// 2. Otherwise, the attribute prefix is not null and attr is a namespace prefix definition. Run the following steps:
|
||||
// 1. Let prefix definition be the value of attr's localName.
|
||||
auto const& prefix_definition = attribute->local_name();
|
||||
auto const& prefix_definition = attribute->local_name().to_deprecated_fly_string();
|
||||
|
||||
// 2. Let namespace definition be the value of attr's value.
|
||||
auto namespace_definition = attribute->value();
|
||||
auto namespace_definition = attribute->value().to_deprecated_string();
|
||||
|
||||
// 3. If namespace definition is the XML namespace, then stop running these steps, and return to Main to visit the next attribute.
|
||||
if (namespace_definition == Namespace::XML)
|
||||
|
@ -272,7 +275,7 @@ static Optional<DeprecatedString> record_namespace_information(DOM::Element cons
|
|||
add_prefix_to_namespace_prefix_map(namespace_prefix_map, prefix_definition, namespace_definition);
|
||||
|
||||
// 7. Add the value of prefix definition as a new key to the local prefixes map, with the namespace definition as the key's value replacing the value of null with the empty string if applicable.
|
||||
local_prefix_map.set(prefix_definition, namespace_definition.is_null() ? DeprecatedString::empty() : namespace_definition);
|
||||
local_prefix_map.set(prefix_definition, namespace_definition.is_null() ? DeprecatedString::empty() : DeprecatedString { namespace_definition });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -331,11 +334,15 @@ static WebIDL::ExceptionOr<DeprecatedString> serialize_element_attributes(DOM::E
|
|||
auto const* attribute = element.attributes()->item(attribute_index);
|
||||
VERIFY(attribute);
|
||||
|
||||
DeprecatedFlyString deprecated_attribute_namespace;
|
||||
if (attribute->namespace_uri().has_value())
|
||||
deprecated_attribute_namespace = attribute->namespace_uri()->to_deprecated_fly_string();
|
||||
|
||||
// 1. If the require well-formed flag is set (its value is true), and the localname set contains a tuple whose values match those of a new tuple consisting of attr's namespaceURI attribute and localName attribute,
|
||||
// then throw an exception; the serialization of this attr would fail to produce a well-formed element serialization.
|
||||
if (require_well_formed == RequireWellFormed::Yes) {
|
||||
auto local_name_set_iterator = local_name_set.find_if([&attribute](LocalNameSetEntry const& entry) {
|
||||
return entry.namespace_uri == attribute->namespace_uri() && entry.local_name == attribute->local_name();
|
||||
auto local_name_set_iterator = local_name_set.find_if([&attribute, &deprecated_attribute_namespace](LocalNameSetEntry const& entry) {
|
||||
return entry.namespace_uri == deprecated_attribute_namespace && entry.local_name == attribute->local_name().to_deprecated_fly_string();
|
||||
});
|
||||
|
||||
if (local_name_set_iterator != local_name_set.end())
|
||||
|
@ -344,8 +351,8 @@ static WebIDL::ExceptionOr<DeprecatedString> serialize_element_attributes(DOM::E
|
|||
|
||||
// 2. Create a new tuple consisting of attr's namespaceURI attribute and localName attribute, and add it to the localname set.
|
||||
LocalNameSetEntry new_local_name_set_entry {
|
||||
.namespace_uri = attribute->namespace_uri(),
|
||||
.local_name = attribute->local_name(),
|
||||
.namespace_uri = deprecated_attribute_namespace,
|
||||
.local_name = attribute->local_name().to_deprecated_fly_string(),
|
||||
};
|
||||
|
||||
local_name_set.append(move(new_local_name_set_entry));
|
||||
|
@ -357,41 +364,45 @@ static WebIDL::ExceptionOr<DeprecatedString> serialize_element_attributes(DOM::E
|
|||
Optional<DeprecatedString> candidate_prefix;
|
||||
|
||||
// 5. If attribute namespace is not null, then run these sub-steps:
|
||||
if (!attribute_namespace.is_null()) {
|
||||
if (attribute_namespace.has_value()) {
|
||||
// 1. Let candidate prefix be the result of retrieving a preferred prefix string from map given namespace attribute namespace with preferred prefix being attr's prefix value.
|
||||
candidate_prefix = retrieve_a_preferred_prefix_string(attribute->prefix(), namespace_prefix_map, attribute_namespace);
|
||||
DeprecatedString deprecated_prefix;
|
||||
if (attribute->prefix().has_value())
|
||||
deprecated_prefix = attribute->prefix()->to_deprecated_fly_string();
|
||||
|
||||
candidate_prefix = retrieve_a_preferred_prefix_string(deprecated_prefix, namespace_prefix_map, deprecated_attribute_namespace);
|
||||
|
||||
// 2. If the value of attribute namespace is the XMLNS namespace, then run these steps:
|
||||
if (attribute_namespace == Namespace::XMLNS) {
|
||||
if (deprecated_attribute_namespace == Namespace::XMLNS) {
|
||||
// 1. If any of the following are true, then stop running these steps and goto Loop to visit the next attribute:
|
||||
// - the attr's value is the XML namespace;
|
||||
if (attribute->value() == Namespace::XML)
|
||||
if (attribute->value().to_deprecated_string() == Namespace::XML)
|
||||
continue;
|
||||
|
||||
// - the attr's prefix is null and the ignore namespace definition attribute flag is true (the Element's default namespace attribute should be skipped);
|
||||
if (attribute->prefix().is_null() && ignore_namespace_definition_attribute)
|
||||
if (!attribute->prefix().has_value() && ignore_namespace_definition_attribute)
|
||||
continue;
|
||||
|
||||
// - the attr's prefix is not null and either
|
||||
if (!attribute->prefix().is_null()) {
|
||||
if (attribute->prefix().has_value()) {
|
||||
// - the attr's localName is not a key contained in the local prefixes map, or
|
||||
auto name_in_local_prefix_map_iterator = local_prefixes_map.find(attribute->local_name());
|
||||
auto name_in_local_prefix_map_iterator = local_prefixes_map.find(attribute->local_name().to_deprecated_fly_string());
|
||||
if (name_in_local_prefix_map_iterator == local_prefixes_map.end())
|
||||
continue;
|
||||
|
||||
// - the attr's localName is present in the local prefixes map but the value of the key does not match attr's value
|
||||
if (name_in_local_prefix_map_iterator->value != attribute->value())
|
||||
if (name_in_local_prefix_map_iterator->value != attribute->value().to_deprecated_string())
|
||||
continue;
|
||||
}
|
||||
|
||||
// and furthermore that the attr's localName (as the prefix to find) is found in the namespace prefix map given the namespace consisting of the attr's value
|
||||
// (the current namespace prefix definition was exactly defined previously--on an ancestor element not the current element whose attributes are being processed).
|
||||
if (prefix_is_in_prefix_map(attribute->local_name(), namespace_prefix_map, attribute->value()))
|
||||
if (prefix_is_in_prefix_map(attribute->local_name().to_deprecated_fly_string(), namespace_prefix_map, attribute->value().to_deprecated_string()))
|
||||
continue;
|
||||
|
||||
// 2. If the require well-formed flag is set (its value is true), and the value of attr's value attribute matches the XMLNS namespace,
|
||||
// then throw an exception; the serialization of this attribute would produce invalid XML because the XMLNS namespace is reserved and cannot be applied as an element's namespace via XML parsing.
|
||||
if (require_well_formed == RequireWellFormed::Yes && attribute->value() == Namespace::XMLNS)
|
||||
if (require_well_formed == RequireWellFormed::Yes && attribute->value().to_deprecated_string() == Namespace::XMLNS)
|
||||
return WebIDL::InvalidStateError::create(realm, "The XMLNS namespace cannot be used as an element's namespace"_fly_string);
|
||||
|
||||
// 3. If the require well-formed flag is set (its value is true), and the value of attr's value attribute is the empty string,
|
||||
|
@ -407,7 +418,7 @@ static WebIDL::ExceptionOr<DeprecatedString> serialize_element_attributes(DOM::E
|
|||
// 3. Otherwise, the attribute namespace in not the XMLNS namespace. Run these steps:
|
||||
else {
|
||||
// 1. Let candidate prefix be the result of generating a prefix providing map, attribute namespace, and prefix index as input.
|
||||
candidate_prefix = generate_a_prefix(namespace_prefix_map, attribute_namespace, prefix_index);
|
||||
candidate_prefix = generate_a_prefix(namespace_prefix_map, deprecated_attribute_namespace, prefix_index);
|
||||
|
||||
// 2. Append the following to result, in the order listed:
|
||||
// 1. " " (U+0020 SPACE);
|
||||
|
@ -422,7 +433,7 @@ static WebIDL::ExceptionOr<DeprecatedString> serialize_element_attributes(DOM::E
|
|||
result.append("=\""sv);
|
||||
|
||||
// 5. The result of serializing an attribute value given attribute namespace and the require well-formed flag as input
|
||||
result.append(TRY(serialize_an_attribute_value(attribute_namespace, require_well_formed)));
|
||||
result.append(TRY(serialize_an_attribute_value(deprecated_attribute_namespace, require_well_formed)));
|
||||
|
||||
// 6. """ (U+0022 QUOTATION MARK).
|
||||
result.append('"');
|
||||
|
@ -439,12 +450,12 @@ static WebIDL::ExceptionOr<DeprecatedString> serialize_element_attributes(DOM::E
|
|||
// 8. If the require well-formed flag is set (its value is true), and this attr's localName attribute contains the character ":" (U+003A COLON)
|
||||
// or does not match the XML Name production or equals "xmlns" and attribute namespace is null, then throw an exception; the serialization of this attr would not be a well-formed attribute.
|
||||
if (require_well_formed == RequireWellFormed::Yes) {
|
||||
if (attribute->local_name().view().contains(':'))
|
||||
if (attribute->local_name().bytes_as_string_view().contains(':'))
|
||||
return WebIDL::InvalidStateError::create(realm, "Attribute's local name contains a colon"_fly_string);
|
||||
|
||||
// FIXME: Check attribute's local name against the XML Name production.
|
||||
|
||||
if (attribute->local_name() == "xmlns"sv && attribute_namespace.is_null())
|
||||
if (attribute->local_name() == "xmlns"sv && deprecated_attribute_namespace.is_null())
|
||||
return WebIDL::InvalidStateError::create(realm, "Attribute's local name is 'xmlns' and the attribute has no namespace"_fly_string);
|
||||
}
|
||||
|
||||
|
@ -456,7 +467,7 @@ static WebIDL::ExceptionOr<DeprecatedString> serialize_element_attributes(DOM::E
|
|||
result.append("=\""sv);
|
||||
|
||||
// 3. The result of serializing an attribute value given attr's value attribute and the require well-formed flag as input;
|
||||
result.append(TRY(serialize_an_attribute_value(attribute->value(), require_well_formed)));
|
||||
result.append(TRY(serialize_an_attribute_value(attribute->value().to_deprecated_string(), require_well_formed)));
|
||||
|
||||
// 4. """ (U+0022 QUOTATION MARK).
|
||||
result.append('"');
|
||||
|
|
|
@ -461,7 +461,7 @@ class PlaceholderElement final : public HTMLDivElement {
|
|||
|
||||
public:
|
||||
PlaceholderElement(DOM::Document& document)
|
||||
: HTMLDivElement(document, DOM::QualifiedName { HTML::TagNames::div, ""sv, Namespace::HTML })
|
||||
: HTMLDivElement(document, DOM::QualifiedName { MUST(FlyString::from_deprecated_fly_string(HTML::TagNames::div)), ""sv, Namespace::HTML })
|
||||
{
|
||||
}
|
||||
virtual Optional<CSS::Selector::PseudoElement> pseudo_element() const override { return CSS::Selector::PseudoElement::Placeholder; }
|
||||
|
|
|
@ -109,7 +109,7 @@ JS::GCPtr<DOM::Attr> prescan_get_attribute(DOM::Document& document, ByteBuffer c
|
|||
} else if (input[position] == '\t' || input[position] == '\n' || input[position] == '\f' || input[position] == '\r' || input[position] == ' ')
|
||||
goto spaces;
|
||||
else if (input[position] == '/' || input[position] == '>')
|
||||
return *DOM::Attr::create(document, attribute_name.to_deprecated_string(), "");
|
||||
return *DOM::Attr::create(document, MUST(attribute_name.to_string()), String {});
|
||||
else
|
||||
attribute_name.append_as_lowercase(input[position]);
|
||||
++position;
|
||||
|
@ -121,7 +121,7 @@ spaces:
|
|||
if (!prescan_skip_whitespace_and_slashes(input, position))
|
||||
return {};
|
||||
if (input[position] != '=')
|
||||
return DOM::Attr::create(document, attribute_name.to_deprecated_string(), "");
|
||||
return DOM::Attr::create(document, MUST(attribute_name.to_string()), String {});
|
||||
++position;
|
||||
|
||||
value:
|
||||
|
@ -134,13 +134,13 @@ value:
|
|||
++position;
|
||||
for (; !prescan_should_abort(input, position); ++position) {
|
||||
if (input[position] == quote_character)
|
||||
return DOM::Attr::create(document, attribute_name.to_deprecated_string(), attribute_value.to_deprecated_string());
|
||||
return DOM::Attr::create(document, MUST(attribute_name.to_string()), MUST(attribute_value.to_string()));
|
||||
else
|
||||
attribute_value.append_as_lowercase(input[position]);
|
||||
}
|
||||
return {};
|
||||
} else if (input[position] == '>')
|
||||
return DOM::Attr::create(document, attribute_name.to_deprecated_string(), "");
|
||||
return DOM::Attr::create(document, MUST(attribute_name.to_string()), String {});
|
||||
else
|
||||
attribute_value.append_as_lowercase(input[position]);
|
||||
|
||||
|
@ -150,7 +150,7 @@ value:
|
|||
|
||||
for (; !prescan_should_abort(input, position); ++position) {
|
||||
if (input[position] == '\t' || input[position] == '\n' || input[position] == '\f' || input[position] == '\r' || input[position] == ' ' || input[position] == '>')
|
||||
return DOM::Attr::create(document, attribute_name.to_deprecated_string(), attribute_value.to_deprecated_string());
|
||||
return DOM::Attr::create(document, MUST(attribute_name.to_string()), MUST(attribute_value.to_string()));
|
||||
else
|
||||
attribute_value.append_as_lowercase(input[position]);
|
||||
}
|
||||
|
@ -188,7 +188,7 @@ Optional<DeprecatedString> run_prescan_byte_stream_algorithm(DOM::Document& docu
|
|||
&& (input[position + 4] == 'A' || input[position + 4] == 'a')
|
||||
&& prescan_is_whitespace_or_slash(input[position + 5])) {
|
||||
position += 6;
|
||||
Vector<DeprecatedString> attribute_list {};
|
||||
Vector<FlyString> attribute_list {};
|
||||
bool got_pragma = false;
|
||||
Optional<bool> need_pragma {};
|
||||
Optional<DeprecatedString> charset {};
|
||||
|
@ -199,13 +199,13 @@ Optional<DeprecatedString> run_prescan_byte_stream_algorithm(DOM::Document& docu
|
|||
break;
|
||||
if (attribute_list.contains_slow(attribute->name()))
|
||||
continue;
|
||||
auto& attribute_name = attribute->name();
|
||||
auto const& attribute_name = attribute->name();
|
||||
attribute_list.append(attribute->name());
|
||||
|
||||
if (attribute_name == "http-equiv") {
|
||||
got_pragma = attribute->value() == "content-type";
|
||||
} else if (attribute_name == "content") {
|
||||
auto encoding = extract_character_encoding_from_meta_element(attribute->value());
|
||||
auto encoding = extract_character_encoding_from_meta_element(attribute->value().to_deprecated_string());
|
||||
if (encoding.has_value() && !charset.has_value()) {
|
||||
charset = encoding.value();
|
||||
need_pragma = true;
|
||||
|
|
Loading…
Reference in a new issue