LibWeb: Make Web::Namespace::Foo strings be FlyString

This required dealing with a *lot* of fallout, but it's all basically
just switching from DeprecatedFlyString to either FlyString or
Optional<FlyString> in a hundred places to accommodate the change.
This commit is contained in:
Andreas Kling 2023-11-04 18:42:04 +01:00
parent 6b20a109c6
commit 3ff81dcb65
31 changed files with 184 additions and 185 deletions

View file

@ -43,7 +43,7 @@ JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> AudioConstructor::construct(
auto& document = window.associated_document();
// 2. Let audio be the result of creating an element given document, audio, and the HTML namespace.
auto audio = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() { return DOM::create_element(document, HTML::TagNames::audio, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))); }));
auto audio = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() { return DOM::create_element(document, HTML::TagNames::audio, Namespace::HTML); }));
// 3. Set an attribute value for audio using "preload" and "auto".
MUST(audio->set_attribute(HTML::AttributeNames::preload, "auto"_string));

View file

@ -43,7 +43,7 @@ JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> ImageConstructor::construct(
auto& document = window.associated_document();
// 2. Let img be the result of creating an element given document, img, and the HTML namespace.
auto image_element = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() { return DOM::create_element(document, HTML::TagNames::img, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))); }));
auto image_element = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() { return DOM::create_element(document, HTML::TagNames::img, Namespace::HTML); }));
// 3. If width is given, then set an attribute value for img using "width" and width.
if (vm.argument_count() > 0) {

View file

@ -47,7 +47,7 @@ JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> OptionConstructor::construct
auto& document = window.associated_document();
// 2. Let option be the result of creating an element given document, option, and the HTML namespace.
auto element = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() { return DOM::create_element(document, HTML::TagNames::option, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))); }));
auto element = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() { return DOM::create_element(document, HTML::TagNames::option, Namespace::HTML); }));
JS::NonnullGCPtr<HTML::HTMLOptionElement> option_element = verify_cast<HTML::HTMLOptionElement>(*element);
// 3. If text is not the empty string, then append to option a new Text node whose data is text.

View file

@ -280,7 +280,7 @@ StyleComputer::RuleCache const& StyleComputer::rule_cache_for_cascade_origin(Cas
{
// FIXME: Filter out non-default namespace using prefixes
auto namespace_uri = rule.sheet->default_namespace();
if (namespace_uri.has_value() && namespace_uri.value() != element.namespace_()) {
if (namespace_uri.has_value() && namespace_uri.value() != element.namespace_uri()) {
return false;
}
return true;
@ -2023,7 +2023,7 @@ void StyleComputer::transform_box_type_if_needed(StyleProperties& style, DOM::El
// https://w3c.github.io/mathml-core/#new-display-math-value
// For elements that are not MathML elements, if the specified value of display is inline math or block math
// then the computed value is block flow and inline flow respectively.
if (element.namespace_() != Namespace::MathML)
if (element.namespace_uri() != Namespace::MathML)
new_display = CSS::Display { display.outside(), CSS::DisplayInside::Flow };
// For the mtable element the computed value is block table and inline table respectively.
else if (element.tag_name().equals_ignoring_ascii_case("mtable"sv))

View file

@ -70,12 +70,15 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> DOMImplementation::create_docume
xml_document->set_origin(document().origin());
// 7. documents content type is determined by namespace:
auto deprecated_namespace = namespace_.has_value() ? namespace_->to_deprecated_string() : DeprecatedString::empty();
// FIXME: This conversion is ugly
Optional<FlyString> namespace_to_use;
if (namespace_.has_value())
namespace_to_use = namespace_.value();
if (deprecated_namespace == Namespace::HTML) {
if (namespace_to_use == Namespace::HTML) {
// -> HTML namespace
xml_document->set_content_type("application/xhtml+xml"_string);
} else if (deprecated_namespace == Namespace::SVG) {
} else if (namespace_to_use == Namespace::SVG) {
// -> SVG namespace
xml_document->set_content_type("image/svg+xml"_string);
} else {
@ -104,17 +107,17 @@ JS::NonnullGCPtr<Document> DOMImplementation::create_html_document(Optional<Stri
MUST(html_document->append_child(*doctype));
// 4. Append the result of creating an element given doc, html, and the HTML namespace, to doc.
auto html_element = create_element(html_document, HTML::TagNames::html, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto html_element = create_element(html_document, HTML::TagNames::html, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(html_document->append_child(html_element));
// 5. Append the result of creating an element given doc, head, and the HTML namespace, to the html element created earlier.
auto head_element = create_element(html_document, HTML::TagNames::head, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto head_element = create_element(html_document, HTML::TagNames::head, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(html_element->append_child(head_element));
// 6. If title is given:
if (title.has_value()) {
// 1. Append the result of creating an element given doc, title, and the HTML namespace, to the head element created earlier.
auto title_element = create_element(html_document, HTML::TagNames::title, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto title_element = create_element(html_document, HTML::TagNames::title, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(head_element->append_child(title_element));
// 2. Append a new Text node, with its data set to title (which could be the empty string) and its node document set to doc, to the title element created earlier.
@ -123,7 +126,7 @@ JS::NonnullGCPtr<Document> DOMImplementation::create_html_document(Optional<Stri
}
// 7. Append the result of creating an element given doc, body, and the HTML namespace, to the html element created earlier.
auto body_element = create_element(html_document, HTML::TagNames::body, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto body_element = create_element(html_document, HTML::TagNames::body, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(html_element->append_child(body_element));
// 8. docs origin is thiss associated documents origin.

View file

@ -741,7 +741,7 @@ WebIDL::ExceptionOr<void> Document::set_title(String const& title)
else {
// 1. Let element be the result of creating an element given the document element's node document, title,
// and the SVG namespace.
element = TRY(DOM::create_element(*this, HTML::TagNames::title, MUST(FlyString::from_deprecated_fly_string(Namespace::SVG))));
element = TRY(DOM::create_element(*this, HTML::TagNames::title, Namespace::SVG));
// 2. Insert element as the first child of the document element.
document_element->insert_before(*element, nullptr);
@ -752,7 +752,7 @@ WebIDL::ExceptionOr<void> Document::set_title(String const& title)
}
// -> If the document element is in the HTML namespace
else if (document_element && document_element->namespace_() == Namespace::HTML) {
else if (document_element && document_element->namespace_uri() == Namespace::HTML) {
auto title_element = this->title_element();
auto* head_element = this->head();
@ -770,7 +770,7 @@ WebIDL::ExceptionOr<void> Document::set_title(String const& title)
else {
// 1. Let element be the result of creating an element given the document element's node document, title,
// and the HTML namespace.
element = TRY(DOM::create_element(*this, HTML::TagNames::title, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))));
element = TRY(DOM::create_element(*this, HTML::TagNames::title, Namespace::HTML));
// 2. Append element to the head element.
TRY(head_element->append_child(*element));
@ -1358,7 +1358,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> Document::create_element(String c
// 5. Let namespace be the HTML namespace, if this is an HTML document or thiss content type is "application/xhtml+xml"; otherwise null.
Optional<FlyString> namespace_;
if (document_type() == Type::HTML || content_type() == "application/xhtml+xml"sv)
namespace_ = MUST(FlyString::from_deprecated_fly_string(Namespace::HTML));
namespace_ = Namespace::HTML;
// 6. Return the result of creating an element given this, localName, namespace, null, is, and with the synchronous custom elements flag set.
return TRY(DOM::create_element(*this, MUST(FlyString::from_deprecated_fly_string(local_name)), move(namespace_), {}, move(is_value), true));
@ -1369,12 +1369,12 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> Document::create_element(String c
WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> Document::create_element_ns(Optional<String> const& namespace_, String const& qualified_name, Variant<String, ElementCreationOptions> const& options)
{
// FIXME: This conversion is ugly
StringView namespace_view;
Optional<FlyString> namespace_to_use;
if (namespace_.has_value())
namespace_view = namespace_->bytes_as_string_view();
namespace_to_use = namespace_.value();
// 1. Let namespace, prefix, and localName be the result of passing namespace and qualifiedName to validate and extract.
auto extracted_qualified_name = TRY(validate_and_extract(realm(), namespace_view, qualified_name.to_deprecated_string()));
auto extracted_qualified_name = TRY(validate_and_extract(realm(), namespace_to_use, qualified_name.to_deprecated_string()));
// 2. Let is be null.
Optional<String> is_value;
@ -2435,7 +2435,7 @@ void Document::set_window(HTML::Window& window)
JS::GCPtr<HTML::CustomElementDefinition> Document::lookup_custom_element_definition(Optional<FlyString> const& namespace_, FlyString const& local_name, Optional<String> const& is) const
{
// 1. If namespace is not the HTML namespace, return null.
if (namespace_ != MUST(FlyString::from_deprecated_fly_string(Namespace::HTML)))
if (namespace_ != Namespace::HTML)
return nullptr;
// 2. If document's browsing context is null, return null.
@ -3005,12 +3005,12 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> Document::create_attribute(String co
WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> Document::create_attribute_ns(Optional<String> const& namespace_, String const& qualified_name)
{
// FIXME: This conversion is ugly
StringView namespace_view;
Optional<FlyString> namespace_to_use;
if (namespace_.has_value())
namespace_view = namespace_->bytes_as_string_view();
namespace_to_use = namespace_.value();
// 1. Let namespace, prefix, and localName be the result of passing namespace and qualifiedName to validate and extract.
auto extracted_qualified_name = TRY(validate_and_extract(realm(), namespace_view, qualified_name.to_deprecated_string()));
auto extracted_qualified_name = TRY(validate_and_extract(realm(), namespace_to_use, qualified_name.to_deprecated_string()));
// 2. Return a new attribute whose namespace is namespace, namespace prefix is prefix, local name is localName, and node document is this.

View file

@ -79,21 +79,21 @@ static bool build_markdown_document(DOM::Document& document, ByteBuffer const& d
static bool build_text_document(DOM::Document& document, ByteBuffer const& data)
{
auto html_element = DOM::create_element(document, HTML::TagNames::html, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto html_element = DOM::create_element(document, HTML::TagNames::html, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(document.append_child(html_element));
auto head_element = DOM::create_element(document, HTML::TagNames::head, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto head_element = DOM::create_element(document, HTML::TagNames::head, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(html_element->append_child(head_element));
auto title_element = DOM::create_element(document, HTML::TagNames::title, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto title_element = DOM::create_element(document, HTML::TagNames::title, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(head_element->append_child(title_element));
auto title_text = document.create_text_node(MUST(String::from_deprecated_string(document.url().basename())));
MUST(title_element->append_child(title_text));
auto body_element = DOM::create_element(document, HTML::TagNames::body, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto body_element = DOM::create_element(document, HTML::TagNames::body, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(html_element->append_child(body_element));
auto pre_element = DOM::create_element(document, HTML::TagNames::pre, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto pre_element = DOM::create_element(document, HTML::TagNames::pre, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(body_element->append_child(pre_element));
MUST(pre_element->append_child(document.create_text_node(String::from_utf8(StringView { data }).release_value_but_fixme_should_propagate_errors())));
@ -110,22 +110,22 @@ static bool build_image_document(DOM::Document& document, ByteBuffer const& data
if (!bitmap)
return false;
auto html_element = DOM::create_element(document, HTML::TagNames::html, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto html_element = DOM::create_element(document, HTML::TagNames::html, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(document.append_child(html_element));
auto head_element = DOM::create_element(document, HTML::TagNames::head, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto head_element = DOM::create_element(document, HTML::TagNames::head, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(html_element->append_child(head_element));
auto title_element = DOM::create_element(document, HTML::TagNames::title, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto title_element = DOM::create_element(document, HTML::TagNames::title, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(head_element->append_child(title_element));
auto basename = LexicalPath::basename(document.url().serialize_path());
auto title_text = document.heap().allocate<DOM::Text>(document.realm(), document, MUST(String::formatted("{} [{}x{}]", basename, bitmap->width(), bitmap->height())));
MUST(title_element->append_child(*title_text));
auto body_element = DOM::create_element(document, HTML::TagNames::body, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto body_element = DOM::create_element(document, HTML::TagNames::body, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(html_element->append_child(body_element));
auto image_element = DOM::create_element(document, HTML::TagNames::img, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto image_element = DOM::create_element(document, HTML::TagNames::img, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(image_element->set_attribute(HTML::AttributeNames::src, MUST(document.url().to_string())));
MUST(body_element->append_child(image_element));
@ -160,16 +160,16 @@ bool build_xml_document(DOM::Document& document, ByteBuffer const& data)
static bool build_video_document(DOM::Document& document)
{
auto html_element = DOM::create_element(document, HTML::TagNames::html, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto html_element = DOM::create_element(document, HTML::TagNames::html, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(document.append_child(html_element));
auto head_element = DOM::create_element(document, HTML::TagNames::head, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto head_element = DOM::create_element(document, HTML::TagNames::head, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(html_element->append_child(head_element));
auto body_element = DOM::create_element(document, HTML::TagNames::body, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto body_element = DOM::create_element(document, HTML::TagNames::body, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(html_element->append_child(body_element));
auto video_element = DOM::create_element(document, HTML::TagNames::video, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto video_element = DOM::create_element(document, HTML::TagNames::video, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(video_element->set_attribute(HTML::AttributeNames::src, MUST(document.url().to_string())));
MUST(video_element->set_attribute(HTML::AttributeNames::autoplay, String {}));
MUST(video_element->set_attribute(HTML::AttributeNames::controls, String {}));
@ -180,16 +180,16 @@ static bool build_video_document(DOM::Document& document)
static bool build_audio_document(DOM::Document& document)
{
auto html_element = DOM::create_element(document, HTML::TagNames::html, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto html_element = DOM::create_element(document, HTML::TagNames::html, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(document.append_child(html_element));
auto head_element = DOM::create_element(document, HTML::TagNames::head, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto head_element = DOM::create_element(document, HTML::TagNames::head, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(html_element->append_child(head_element));
auto body_element = DOM::create_element(document, HTML::TagNames::body, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto body_element = DOM::create_element(document, HTML::TagNames::body, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(html_element->append_child(body_element));
auto video_element = DOM::create_element(document, HTML::TagNames::audio, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto video_element = DOM::create_element(document, HTML::TagNames::audio, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(video_element->set_attribute(HTML::AttributeNames::src, MUST(document.url().to_string())));
MUST(video_element->set_attribute(HTML::AttributeNames::autoplay, String {}));
MUST(video_element->set_attribute(HTML::AttributeNames::controls, String {}));

View file

@ -185,7 +185,7 @@ WebIDL::ExceptionOr<void> Element::set_attribute(DeprecatedFlyString const& name
// 2. If this is in the HTML namespace and its node document is an HTML document, then set qualifiedName to qualifiedName in ASCII lowercase.
// FIXME: Handle the second condition, assume it is an HTML document for now.
bool insert_as_lowercase = namespace_() == Namespace::HTML;
bool insert_as_lowercase = namespace_uri() == Namespace::HTML;
// 3. Let attribute be the first attribute in thiss attribute list whose qualified name is qualifiedName, and null otherwise.
auto* attribute = m_attributes->get_attribute(name);
@ -211,10 +211,10 @@ WebIDL::ExceptionOr<void> Element::set_attribute(DeprecatedFlyString const& name
}
// https://dom.spec.whatwg.org/#validate-and-extract
WebIDL::ExceptionOr<QualifiedName> validate_and_extract(JS::Realm& realm, DeprecatedFlyString namespace_, DeprecatedFlyString qualified_name)
WebIDL::ExceptionOr<QualifiedName> validate_and_extract(JS::Realm& realm, Optional<FlyString> namespace_, DeprecatedFlyString qualified_name)
{
// 1. If namespace is the empty string, then set it to null.
if (namespace_.is_empty())
if (namespace_.has_value() && namespace_.value().is_empty())
namespace_ = {};
// 2. Validate qualifiedName.
@ -234,7 +234,7 @@ WebIDL::ExceptionOr<QualifiedName> validate_and_extract(JS::Realm& realm, Deprec
}
// 6. If prefix is non-null and namespace is null, then throw a "NamespaceError" DOMException.
if (prefix.has_value() && namespace_.is_null())
if (prefix.has_value() && !namespace_.has_value())
return WebIDL::NamespaceError::create(realm, "Prefix is non-null and namespace is null."_fly_string);
// 7. If prefix is "xml" and namespace is not the XML namespace, then throw a "NamespaceError" DOMException.
@ -256,12 +256,13 @@ WebIDL::ExceptionOr<QualifiedName> validate_and_extract(JS::Realm& realm, Deprec
// https://dom.spec.whatwg.org/#dom-element-setattributens
WebIDL::ExceptionOr<void> Element::set_attribute_ns(Optional<String> const& namespace_, FlyString const& qualified_name, FlyString const& value)
{
DeprecatedFlyString deprecated_namespace;
// FIXME: This conversion is ugly
Optional<FlyString> namespace_to_use;
if (namespace_.has_value())
deprecated_namespace = namespace_->to_deprecated_string();
namespace_to_use = namespace_.value();
// 1. Let namespace, prefix, and localName be the result of passing namespace and qualifiedName to validate and extract.
auto extracted_qualified_name = TRY(validate_and_extract(realm(), deprecated_namespace, qualified_name.to_deprecated_fly_string()));
auto extracted_qualified_name = TRY(validate_and_extract(realm(), namespace_to_use, qualified_name.to_deprecated_fly_string()));
// 2. Set an attribute value for this using localName, value, and also prefix and namespace.
set_attribute_value(extracted_qualified_name.local_name(), value.to_deprecated_fly_string(), extracted_qualified_name.prefix(), extracted_qualified_name.deprecated_namespace_());
@ -343,7 +344,7 @@ WebIDL::ExceptionOr<bool> Element::toggle_attribute(FlyString const& name, Optio
// 2. If this is in the HTML namespace and its node document is an HTML document, then set qualifiedName to qualifiedName in ASCII lowercase.
// FIXME: Handle the second condition, assume it is an HTML document for now.
bool insert_as_lowercase = namespace_() == Namespace::HTML;
bool insert_as_lowercase = namespace_uri() == Namespace::HTML;
// 3. Let attribute be the first attribute in thiss attribute list whose qualified name is qualifiedName, and null otherwise.
auto* attribute = m_attributes->get_attribute(name);
@ -632,7 +633,7 @@ DOMTokenList* Element::class_list()
WebIDL::ExceptionOr<JS::NonnullGCPtr<ShadowRoot>> Element::attach_shadow(ShadowRootInit init)
{
// 1. If thiss namespace is not the HTML namespace, then throw a "NotSupportedError" DOMException.
if (namespace_() != Namespace::HTML)
if (namespace_uri() != Namespace::HTML)
return WebIDL::NotSupportedError::create(realm(), "Element's namespace is not the HTML namespace"_fly_string);
// 2. If thiss local name is not one of the following:
@ -823,7 +824,7 @@ CSS::CSSStyleDeclaration* Element::style_for_bindings()
void Element::make_html_uppercased_qualified_name()
{
// This is allowed by the spec: "User agents could optimize qualified name and HTML-uppercased qualified name by storing them in internal slots."
if (namespace_() == Namespace::HTML && document().document_type() == Document::Type::HTML)
if (namespace_uri() == Namespace::HTML && document().document_type() == Document::Type::HTML)
m_html_uppercased_qualified_name = MUST(Infra::to_ascii_uppercase(qualified_name()));
else
m_html_uppercased_qualified_name = qualified_name();
@ -1413,7 +1414,7 @@ WebIDL::ExceptionOr<void> Element::insert_adjacent_html(String const& position,
if (!is<Element>(*context)
|| (context->document().document_type() == Document::Type::HTML
&& static_cast<Element const&>(*context).local_name() == "html"sv
&& static_cast<Element const&>(*context).namespace_() == Namespace::HTML)) {
&& static_cast<Element const&>(*context).namespace_uri() == Namespace::HTML)) {
// FIXME: let context be a new Element with
// - body as its local name,
// - The HTML namespace as its namespace, and

View file

@ -441,6 +441,6 @@ private:
template<>
inline bool Node::fast_is<Element>() const { return is_element(); }
WebIDL::ExceptionOr<QualifiedName> validate_and_extract(JS::Realm&, DeprecatedFlyString namespace_, DeprecatedFlyString qualified_name);
WebIDL::ExceptionOr<QualifiedName> validate_and_extract(JS::Realm&, Optional<FlyString> namespace_, DeprecatedFlyString qualified_name);
}

View file

@ -624,7 +624,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element(Document& document
auto qualified_name = QualifiedName { local_name, prefix, namespace_ };
if (namespace_ == MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))) {
if (namespace_ == Namespace::HTML) {
auto element = create_html_element(realm, document, move(qualified_name));
element->set_is_value(move(is_value));
element->set_custom_element_state(CustomElementState::Uncustomized);
@ -637,7 +637,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element(Document& document
return element;
}
if (namespace_ == MUST(FlyString::from_deprecated_fly_string(Namespace::SVG))) {
if (namespace_ == Namespace::SVG) {
auto element = create_svg_element(realm, document, qualified_name);
if (element) {
element->set_is_value(move(is_value));
@ -646,7 +646,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element(Document& document
}
}
if (namespace_ == MUST(FlyString::from_deprecated_fly_string(Namespace::MathML))) {
if (namespace_ == Namespace::MathML) {
auto element = create_mathml_element(realm, document, qualified_name);
if (element) {
element->set_is_value(move(is_value));

View file

@ -90,7 +90,7 @@ Element* HTMLCollection::named_item(FlyString const& name_) const
if (auto it = elements.find_if([&](auto& entry) { return entry->deprecated_attribute(HTML::AttributeNames::id) == name; }); it != elements.end())
return *it;
// - it is in the HTML namespace and has a name attribute whose value is key;
if (auto it = elements.find_if([&](auto& entry) { return entry->namespace_() == Namespace::HTML && entry->name() == name; }); it != elements.end())
if (auto it = elements.find_if([&](auto& entry) { return entry->namespace_uri() == Namespace::HTML && entry->name() == name; }); it != elements.end())
return *it;
// or null if there is no such element.
return nullptr;
@ -115,7 +115,7 @@ Vector<DeprecatedString> HTMLCollection::supported_property_names() const
}
// 2. If element is in the HTML namespace and has a name attribute whose value is neither the empty string nor is in result, append elements name attribute value to result.
if (element->namespace_() == Namespace::HTML && element->has_attribute(HTML::AttributeNames::name)) {
if (element->namespace_uri() == Namespace::HTML && element->has_attribute(HTML::AttributeNames::name)) {
auto name = element->deprecated_attribute(HTML::AttributeNames::name);
if (!name.is_empty() && !result.contains_slow(name))

View file

@ -60,7 +60,7 @@ Vector<DeprecatedString> NamedNodeMap::supported_property_names() const
// 2. If this NamedNodeMap objects element is in the HTML namespace and its node document is an HTML document, then for each name in names:
// FIXME: Handle the second condition, assume it is an HTML document for now.
if (associated_element().namespace_() == Namespace::HTML) {
if (associated_element().namespace_uri() == Namespace::HTML) {
// 1. Let lowercaseName be name, in ASCII lowercase.
// 2. If lowercaseName is not equal to name, remove name from names.
names.remove_all_matching([](auto const& name) { return name != name.to_lowercase(); });
@ -157,7 +157,7 @@ Attr const* NamedNodeMap::get_attribute(StringView qualified_name, size_t* item_
// 1. If element is in the HTML namespace and its node document is an HTML document, then set qualifiedName to qualifiedName in ASCII lowercase.
// FIXME: Handle the second condition, assume it is an HTML document for now.
bool compare_as_lowercase = associated_element().namespace_() == Namespace::HTML;
bool compare_as_lowercase = associated_element().namespace_uri() == Namespace::HTML;
// 2. Return the first attribute in elements attribute list whose qualified name is qualifiedName; otherwise null.
for (auto const& attribute : m_attributes) {

View file

@ -149,7 +149,7 @@ JS::NonnullGCPtr<HTMLCollection> ParentNode::get_elements_by_tag_name(Deprecated
auto qualified_name_in_ascii_lowercase = MUST(FlyString::from_deprecated_fly_string(qualified_name.to_lowercase()));
return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [qualified_name, qualified_name_in_ascii_lowercase](Element const& element) {
// - Whose namespace is the HTML namespace and whose qualified name is qualifiedName, in ASCII lowercase.
if (element.namespace_() == Namespace::HTML)
if (element.namespace_uri() == Namespace::HTML)
return element.qualified_name() == qualified_name_in_ascii_lowercase;
// - Whose namespace is not the HTML namespace and whose qualified name is qualifiedName.

View file

@ -1181,7 +1181,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::create_contextual
// - "body" as its local name,
// - The HTML namespace as its namespace, and
// - The context object's node document as its node document.
element = TRY(DOM::create_element(node->document(), HTML::TagNames::body, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))));
element = TRY(DOM::create_element(node->document(), HTML::TagNames::body, Namespace::HTML));
}
// 3. Let fragment node be the result of invoking the fragment parsing algorithm with fragment as markup, and element as the context element.

View file

@ -49,16 +49,16 @@ WebIDL::ExceptionOr<DeprecatedString> XMLSerializer::serialize_to_string(JS::Non
}
// https://w3c.github.io/DOM-Parsing/#dfn-add
static void add_prefix_to_namespace_prefix_map(HashMap<DeprecatedFlyString, Vector<DeprecatedString>>& prefix_map, DeprecatedString const& prefix, DeprecatedFlyString const& namespace_)
static void add_prefix_to_namespace_prefix_map(HashMap<FlyString, Vector<Optional<FlyString>>>& prefix_map, Optional<FlyString> const& prefix, Optional<FlyString> const& namespace_)
{
// 1. Let candidates list be the result of retrieving a list from map where there exists a key in map that matches the value of ns or if there is no such key, then let candidates list be null.
auto candidates_list_iterator = prefix_map.find(namespace_);
auto candidates_list_iterator = namespace_.has_value() ? prefix_map.find(*namespace_) : prefix_map.end();
// 2. If candidates list is null, then create a new list with prefix as the only item in the list, and associate that list with a new key ns in map.
if (candidates_list_iterator == prefix_map.end()) {
Vector<DeprecatedString> new_list;
Vector<Optional<FlyString>> new_list;
new_list.append(prefix);
prefix_map.set(namespace_, move(new_list));
prefix_map.set(*namespace_, move(new_list));
return;
}
@ -67,11 +67,13 @@ static void add_prefix_to_namespace_prefix_map(HashMap<DeprecatedFlyString, Vect
}
// https://w3c.github.io/DOM-Parsing/#dfn-retrieving-a-preferred-prefix-string
static Optional<DeprecatedString> retrieve_a_preferred_prefix_string(DeprecatedString const& preferred_prefix, HashMap<DeprecatedFlyString, Vector<DeprecatedString>> const& namespace_prefix_map, DeprecatedFlyString const& namespace_)
static Optional<FlyString> retrieve_a_preferred_prefix_string(Optional<FlyString> const& preferred_prefix, HashMap<FlyString, Vector<Optional<FlyString>>> const& namespace_prefix_map, Optional<FlyString> const& namespace_)
{
// 1. Let candidates list be the result of retrieving a list from map where there exists a key in map that matches the value of ns or if there is no such key,
// then stop running these steps, and return the null value.
auto candidates_list_iterator = namespace_prefix_map.find(namespace_);
if (!namespace_.has_value())
return {};
auto candidates_list_iterator = namespace_prefix_map.find(*namespace_);
if (candidates_list_iterator == namespace_prefix_map.end())
return {};
@ -93,10 +95,10 @@ static Optional<DeprecatedString> retrieve_a_preferred_prefix_string(DeprecatedS
}
// https://w3c.github.io/DOM-Parsing/#dfn-generating-a-prefix
static DeprecatedString generate_a_prefix(HashMap<DeprecatedFlyString, Vector<DeprecatedString>>& namespace_prefix_map, DeprecatedFlyString const& new_namespace, u64& prefix_index)
static FlyString generate_a_prefix(HashMap<FlyString, Vector<Optional<FlyString>>>& namespace_prefix_map, Optional<FlyString> const& new_namespace, u64& prefix_index)
{
// 1. Let generated prefix be the concatenation of the string "ns" and the current numerical value of prefix index.
auto generated_prefix = DeprecatedString::formatted("ns{}", prefix_index);
auto generated_prefix = FlyString(MUST(String::formatted("ns{}", prefix_index)));
// 2. Let the value of prefix index be incremented by one.
++prefix_index;
@ -109,11 +111,13 @@ static DeprecatedString generate_a_prefix(HashMap<DeprecatedFlyString, Vector<De
}
// https://w3c.github.io/DOM-Parsing/#dfn-found
static bool prefix_is_in_prefix_map(DeprecatedString const& prefix, HashMap<DeprecatedFlyString, Vector<DeprecatedString>> const& namespace_prefix_map, DeprecatedFlyString const& namespace_)
static bool prefix_is_in_prefix_map(FlyString const& prefix, HashMap<FlyString, Vector<Optional<FlyString>>> const& namespace_prefix_map, Optional<FlyString> const& namespace_)
{
// 1. Let candidates list be the result of retrieving a list from map where there exists a key in map that matches the value of ns
// or if there is no such key, then stop running these steps, and return false.
auto candidates_list_iterator = namespace_prefix_map.find(namespace_);
if (!namespace_.has_value())
return false;
auto candidates_list_iterator = namespace_prefix_map.find(*namespace_);
if (candidates_list_iterator == namespace_prefix_map.end())
return false;
@ -121,7 +125,7 @@ static bool prefix_is_in_prefix_map(DeprecatedString const& prefix, HashMap<Depr
return candidates_list_iterator->value.contains_slow(prefix);
}
WebIDL::ExceptionOr<DeprecatedString> serialize_node_to_xml_string_impl(JS::NonnullGCPtr<DOM::Node const> root, Optional<DeprecatedFlyString>& namespace_, HashMap<DeprecatedFlyString, Vector<DeprecatedString>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed);
WebIDL::ExceptionOr<DeprecatedString> serialize_node_to_xml_string_impl(JS::NonnullGCPtr<DOM::Node const> root, Optional<FlyString>& namespace_, HashMap<FlyString, Vector<Optional<FlyString>>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed);
// https://w3c.github.io/DOM-Parsing/#dfn-xml-serialization
WebIDL::ExceptionOr<DeprecatedString> serialize_node_to_xml_string(JS::NonnullGCPtr<DOM::Node const> root, RequireWellFormed require_well_formed)
@ -129,13 +133,13 @@ WebIDL::ExceptionOr<DeprecatedString> serialize_node_to_xml_string(JS::NonnullGC
// 1. Let namespace be a context namespace with value null. The context namespace tracks the XML serialization algorithm's current default namespace.
// The context namespace is changed when either an Element Node has a default namespace declaration, or the algorithm generates a default namespace declaration
// for the Element Node to match its own namespace. The algorithm assumes no namespace (null) to start.
Optional<DeprecatedFlyString> namespace_;
Optional<FlyString> namespace_;
// 2. Let prefix map be a new namespace prefix map.
HashMap<DeprecatedFlyString, Vector<DeprecatedString>> prefix_map;
HashMap<FlyString, Vector<Optional<FlyString>>> prefix_map;
// 3. Add the XML namespace with prefix value "xml" to prefix map.
add_prefix_to_namespace_prefix_map(prefix_map, "xml"sv, Namespace::XML);
add_prefix_to_namespace_prefix_map(prefix_map, "xml"_fly_string, Namespace::XML);
// 4. Let prefix index be a generated namespace prefix index with value 1. The generated namespace prefix index is used to generate a new unique prefix value
// when no suitable existing namespace prefix is available to serialize a node's namespaceURI (or the namespaceURI of one of node's attributes).
@ -148,16 +152,16 @@ WebIDL::ExceptionOr<DeprecatedString> serialize_node_to_xml_string(JS::NonnullGC
return serialize_node_to_xml_string_impl(root, namespace_, prefix_map, prefix_index, require_well_formed);
}
static WebIDL::ExceptionOr<DeprecatedString> serialize_element(DOM::Element const& element, Optional<DeprecatedFlyString>& namespace_, HashMap<DeprecatedFlyString, Vector<DeprecatedString>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed);
static WebIDL::ExceptionOr<DeprecatedString> serialize_document(DOM::Document const& document, Optional<DeprecatedFlyString>& namespace_, HashMap<DeprecatedFlyString, Vector<DeprecatedString>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed);
static WebIDL::ExceptionOr<DeprecatedString> serialize_element(DOM::Element const& element, Optional<FlyString>& namespace_, HashMap<FlyString, Vector<Optional<FlyString>>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed);
static WebIDL::ExceptionOr<DeprecatedString> serialize_document(DOM::Document const& document, Optional<FlyString>& namespace_, HashMap<FlyString, Vector<Optional<FlyString>>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed);
static WebIDL::ExceptionOr<DeprecatedString> serialize_comment(DOM::Comment const& comment, RequireWellFormed require_well_formed);
static WebIDL::ExceptionOr<DeprecatedString> serialize_text(DOM::Text const& text, RequireWellFormed require_well_formed);
static WebIDL::ExceptionOr<DeprecatedString> serialize_document_fragment(DOM::DocumentFragment const& document_fragment, Optional<DeprecatedFlyString>& namespace_, HashMap<DeprecatedFlyString, Vector<DeprecatedString>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed);
static WebIDL::ExceptionOr<DeprecatedString> serialize_document_fragment(DOM::DocumentFragment const& document_fragment, Optional<FlyString>& namespace_, HashMap<FlyString, Vector<Optional<FlyString>>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed);
static WebIDL::ExceptionOr<DeprecatedString> serialize_document_type(DOM::DocumentType const& document_type, RequireWellFormed require_well_formed);
static WebIDL::ExceptionOr<DeprecatedString> serialize_processing_instruction(DOM::ProcessingInstruction const& processing_instruction, RequireWellFormed require_well_formed);
// https://w3c.github.io/DOM-Parsing/#dfn-xml-serialization-algorithm
WebIDL::ExceptionOr<DeprecatedString> serialize_node_to_xml_string_impl(JS::NonnullGCPtr<DOM::Node const> root, Optional<DeprecatedFlyString>& namespace_, HashMap<DeprecatedFlyString, Vector<DeprecatedString>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed)
WebIDL::ExceptionOr<DeprecatedString> serialize_node_to_xml_string_impl(JS::NonnullGCPtr<DOM::Node const> root, Optional<FlyString>& namespace_, HashMap<FlyString, Vector<Optional<FlyString>>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed)
{
// Each of the following algorithms for producing an XML serialization of a DOM node take as input a node to serialize and the following arguments:
// - A context namespace namespace
@ -224,10 +228,10 @@ WebIDL::ExceptionOr<DeprecatedString> serialize_node_to_xml_string_impl(JS::Nonn
}
// https://w3c.github.io/DOM-Parsing/#dfn-recording-the-namespace-information
static Optional<DeprecatedString> record_namespace_information(DOM::Element const& element, HashMap<DeprecatedFlyString, Vector<DeprecatedString>>& namespace_prefix_map, HashMap<DeprecatedString, DeprecatedString>& local_prefix_map)
static Optional<FlyString> record_namespace_information(DOM::Element const& element, HashMap<FlyString, Vector<Optional<FlyString>>>& namespace_prefix_map, HashMap<FlyString, Optional<FlyString>>& local_prefix_map)
{
// 1. Let default namespace attr value be null.
Optional<DeprecatedString> default_namespace_attribute_value;
Optional<FlyString> default_namespace_attribute_value;
// 2. Main: For each attribute attr in element's attributes, in the order they are specified in the element's attribute list:
for (size_t attribute_index = 0; attribute_index < element.attributes()->length(); ++attribute_index) {
@ -236,28 +240,25 @@ 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 (deprecated_attribute_namespace == Namespace::XMLNS) {
if (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.has_value()) {
default_namespace_attribute_value = attribute->value().to_deprecated_string();
default_namespace_attribute_value = attribute->value();
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().to_deprecated_fly_string();
auto const& prefix_definition = attribute->local_name();
// 2. Let namespace definition be the value of attr's value.
DeprecatedFlyString namespace_definition = attribute->value().to_deprecated_string();
Optional<FlyString> namespace_definition = attribute->value();
// 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)
@ -275,7 +276,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() : DeprecatedString { namespace_definition });
local_prefix_map.set(prefix_definition, namespace_definition.value_or(FlyString {}));
}
}
@ -284,42 +285,40 @@ static Optional<DeprecatedString> record_namespace_information(DOM::Element cons
}
// https://w3c.github.io/DOM-Parsing/#dfn-serializing-an-attribute-value
static WebIDL::ExceptionOr<DeprecatedString> serialize_an_attribute_value(OneOf<DeprecatedString, DeprecatedFlyString> auto const& attribute_value, [[maybe_unused]] RequireWellFormed require_well_formed)
static WebIDL::ExceptionOr<DeprecatedString> serialize_an_attribute_value(Optional<FlyString> const& attribute_value, [[maybe_unused]] RequireWellFormed require_well_formed)
{
// FIXME: 1. If the require well-formed flag is set (its value is true), and attribute value contains characters that are not matched by the XML Char production,
// then throw an exception; the serialization of this attribute value would fail to produce a well-formed element serialization.
// 2. If attribute value is null, then return the empty string.
if constexpr (requires { attribute_value.is_null(); }) {
if (attribute_value.is_null())
return DeprecatedString::empty();
}
if (!attribute_value.has_value())
return DeprecatedString::empty();
// 3. Otherwise, attribute value is a string. Return the value of attribute value, first replacing any occurrences of the following:
DeprecatedString final_attribute_value = attribute_value;
auto final_attribute_value = attribute_value->to_string();
// 1. "&" with "&amp;"
final_attribute_value = final_attribute_value.replace("&"sv, "&amp;"sv, ReplaceMode::All);
final_attribute_value = MUST(final_attribute_value.replace("&"sv, "&amp;"sv, ReplaceMode::All));
// 2. """ with "&quot;"
final_attribute_value = final_attribute_value.replace("\""sv, "&quot;"sv, ReplaceMode::All);
final_attribute_value = MUST(final_attribute_value.replace("\""sv, "&quot;"sv, ReplaceMode::All));
// 3. "<" with "&lt;"
final_attribute_value = final_attribute_value.replace("<"sv, "&lt;"sv, ReplaceMode::All);
final_attribute_value = MUST(final_attribute_value.replace("<"sv, "&lt;"sv, ReplaceMode::All));
// 4. ">" with "&gt;"
final_attribute_value = final_attribute_value.replace(">"sv, "&gt;"sv, ReplaceMode::All);
final_attribute_value = MUST(final_attribute_value.replace(">"sv, "&gt;"sv, ReplaceMode::All));
return final_attribute_value;
}
struct LocalNameSetEntry {
DeprecatedString namespace_uri;
DeprecatedString local_name;
Optional<FlyString> namespace_uri;
FlyString local_name;
};
// https://w3c.github.io/DOM-Parsing/#dfn-xml-serialization-of-the-attributes
static WebIDL::ExceptionOr<DeprecatedString> serialize_element_attributes(DOM::Element const& element, HashMap<DeprecatedFlyString, Vector<DeprecatedString>>& namespace_prefix_map, u64& prefix_index, HashMap<DeprecatedString, DeprecatedString> const& local_prefixes_map, bool ignore_namespace_definition_attribute, RequireWellFormed require_well_formed)
static WebIDL::ExceptionOr<DeprecatedString> serialize_element_attributes(DOM::Element const& element, HashMap<FlyString, Vector<Optional<FlyString>>>& namespace_prefix_map, u64& prefix_index, HashMap<FlyString, Optional<FlyString>> const& local_prefixes_map, bool ignore_namespace_definition_attribute, RequireWellFormed require_well_formed)
{
auto& realm = element.realm();
@ -336,15 +335,11 @@ 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, &deprecated_attribute_namespace](LocalNameSetEntry const& entry) {
return entry.namespace_uri == deprecated_attribute_namespace && entry.local_name == attribute->local_name().to_deprecated_fly_string();
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();
});
if (local_name_set_iterator != local_name_set.end())
@ -353,8 +348,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 = deprecated_attribute_namespace,
.local_name = attribute->local_name().to_deprecated_fly_string(),
.namespace_uri = attribute->namespace_uri(),
.local_name = attribute->local_name(),
};
local_name_set.append(move(new_local_name_set_entry));
@ -363,7 +358,7 @@ static WebIDL::ExceptionOr<DeprecatedString> serialize_element_attributes(DOM::E
auto const& attribute_namespace = attribute->namespace_uri();
// 4. Let candidate prefix be null.
Optional<DeprecatedString> candidate_prefix;
Optional<FlyString> candidate_prefix;
// 5. If attribute namespace is not null, then run these sub-steps:
if (attribute_namespace.has_value()) {
@ -372,13 +367,13 @@ static WebIDL::ExceptionOr<DeprecatedString> serialize_element_attributes(DOM::E
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);
candidate_prefix = retrieve_a_preferred_prefix_string(attribute->prefix(), namespace_prefix_map, attribute->namespace_uri());
// 2. If the value of attribute namespace is the XMLNS namespace, then run these steps:
if (deprecated_attribute_namespace == Namespace::XMLNS) {
if (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().to_deprecated_string() == Namespace::XML)
if (attribute->value() == 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);
@ -388,23 +383,23 @@ static WebIDL::ExceptionOr<DeprecatedString> serialize_element_attributes(DOM::E
// - the attr's prefix is not null and either
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().to_deprecated_fly_string());
auto name_in_local_prefix_map_iterator = local_prefixes_map.find(attribute->local_name());
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().to_deprecated_string())
if (name_in_local_prefix_map_iterator->value != attribute->value())
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().to_deprecated_fly_string(), namespace_prefix_map, attribute->value().to_deprecated_string()))
if (prefix_is_in_prefix_map(attribute->local_name(), namespace_prefix_map, attribute->value()))
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().to_deprecated_string() == Namespace::XMLNS)
if (require_well_formed == RequireWellFormed::Yes && attribute->value() == 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,
@ -414,13 +409,13 @@ static WebIDL::ExceptionOr<DeprecatedString> serialize_element_attributes(DOM::E
// 4. [If] the attr's prefix matches the string "xmlns", then let candidate prefix be the string "xmlns".
if (attribute->prefix() == "xmlns"sv)
candidate_prefix = "xmlns"sv;
candidate_prefix = "xmlns"_fly_string;
}
// 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, deprecated_attribute_namespace, prefix_index);
candidate_prefix = generate_a_prefix(namespace_prefix_map, attribute->namespace_uri(), prefix_index);
// 2. Append the following to result, in the order listed:
// 1. " " (U+0020 SPACE);
@ -435,7 +430,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(deprecated_attribute_namespace, require_well_formed)));
result.append(TRY(serialize_an_attribute_value(attribute->namespace_uri(), require_well_formed)));
// 6. """ (U+0022 QUOTATION MARK).
result.append('"');
@ -457,7 +452,7 @@ static WebIDL::ExceptionOr<DeprecatedString> serialize_element_attributes(DOM::E
// FIXME: Check attribute's local name against the XML Name production.
if (attribute->local_name() == "xmlns"sv && deprecated_attribute_namespace.is_null())
if (attribute->local_name() == "xmlns"sv && !attribute->namespace_uri().has_value())
return WebIDL::InvalidStateError::create(realm, "Attribute's local name is 'xmlns' and the attribute has no namespace"_fly_string);
}
@ -469,7 +464,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().to_deprecated_string(), require_well_formed)));
result.append(TRY(serialize_an_attribute_value(attribute->value(), require_well_formed)));
// 4. """ (U+0022 QUOTATION MARK).
result.append('"');
@ -480,7 +475,7 @@ static WebIDL::ExceptionOr<DeprecatedString> serialize_element_attributes(DOM::E
}
// https://w3c.github.io/DOM-Parsing/#xml-serializing-an-element-node
static WebIDL::ExceptionOr<DeprecatedString> serialize_element(DOM::Element const& element, Optional<DeprecatedFlyString>& namespace_, HashMap<DeprecatedFlyString, Vector<DeprecatedString>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed)
static WebIDL::ExceptionOr<DeprecatedString> serialize_element(DOM::Element const& element, Optional<FlyString>& namespace_, HashMap<FlyString, Vector<Optional<FlyString>>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed)
{
auto& realm = element.realm();
@ -507,7 +502,7 @@ static WebIDL::ExceptionOr<DeprecatedString> serialize_element(DOM::Element cons
bool ignore_namespace_definition_attribute = false;
// 6. Given prefix map, copy a namespace prefix map and let map be the result.
HashMap<DeprecatedFlyString, Vector<DeprecatedString>> map;
HashMap<FlyString, Vector<Optional<FlyString>>> map;
// https://w3c.github.io/DOM-Parsing/#dfn-copy-a-namespace-prefix-map
// NOTE: This is only used here.
@ -519,7 +514,7 @@ static WebIDL::ExceptionOr<DeprecatedString> serialize_element(DOM::Element cons
// 7. Let local prefixes map be an empty map. The map has unique Node prefix strings as its keys, with corresponding namespaceURI Node values
// as the map's key values (in this map, the null namespace is represented by the empty string).
HashMap<DeprecatedString, DeprecatedString> local_prefixes_map;
HashMap<FlyString, Optional<FlyString>> local_prefixes_map;
// 8. Let local default namespace be the result of recording the namespace information for node given map and local prefixes map.
auto local_default_namespace = record_namespace_information(element, map, local_prefixes_map);
@ -528,7 +523,7 @@ static WebIDL::ExceptionOr<DeprecatedString> serialize_element(DOM::Element cons
auto inherited_ns = namespace_;
// 10. Let ns be the value of node's namespaceURI attribute.
auto const& ns = element.namespace_();
auto const& ns = element.namespace_uri();
// 11. If inherited ns is equal to ns, then:
if (inherited_ns == ns) {
@ -551,7 +546,7 @@ static WebIDL::ExceptionOr<DeprecatedString> serialize_element(DOM::Element cons
// 12. Otherwise, inherited ns is not equal to ns (the node's own namespace is different from the context namespace of its parent). Run these sub-steps:
else {
// 1. Let prefix be the value of node's prefix attribute.
auto prefix = element.deprecated_prefix();
auto prefix = element.prefix();
// 2. Let candidate prefix be the result of retrieving a preferred prefix string prefix from map given namespace ns.
auto candidate_prefix = retrieve_a_preferred_prefix_string(prefix, map, ns);
@ -586,9 +581,9 @@ static WebIDL::ExceptionOr<DeprecatedString> serialize_element(DOM::Element cons
}
// 5. Otherwise, if prefix is not null, then:
else if (!prefix.is_null()) {
else if (prefix.has_value()) {
// 1. If the local prefixes map contains a key matching prefix, then let prefix be the result of generating a prefix providing as input map, ns, and prefix index.
if (local_prefixes_map.contains(prefix))
if (local_prefixes_map.contains(*prefix))
prefix = generate_a_prefix(map, ns, prefix_index);
// 2. Add prefix to map given namespace ns.
@ -606,7 +601,7 @@ static WebIDL::ExceptionOr<DeprecatedString> serialize_element(DOM::Element cons
markup.append(" xmlns:"sv);
// 3. The value of prefix;
markup.append(prefix);
markup.append(prefix.value());
// 4. "="" (U+003D EQUALS SIGN, U+0022 QUOTATION MARK);
markup.append("=\""sv);
@ -722,7 +717,7 @@ static WebIDL::ExceptionOr<DeprecatedString> serialize_element(DOM::Element cons
}
// https://w3c.github.io/DOM-Parsing/#xml-serializing-a-document-node
static WebIDL::ExceptionOr<DeprecatedString> serialize_document(DOM::Document const& document, Optional<DeprecatedFlyString>& namespace_, HashMap<DeprecatedFlyString, Vector<DeprecatedString>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed)
static WebIDL::ExceptionOr<DeprecatedString> serialize_document(DOM::Document const& document, Optional<FlyString>& namespace_, HashMap<FlyString, Vector<Optional<FlyString>>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed)
{
// If the require well-formed flag is set (its value is true), and this node has no documentElement (the documentElement attribute's value is null),
// then throw an exception; the serialization of this node would not be a well-formed document.
@ -784,7 +779,7 @@ static WebIDL::ExceptionOr<DeprecatedString> serialize_text(DOM::Text const& tex
}
// https://w3c.github.io/DOM-Parsing/#xml-serializing-a-documentfragment-node
static WebIDL::ExceptionOr<DeprecatedString> serialize_document_fragment(DOM::DocumentFragment const& document_fragment, Optional<DeprecatedFlyString>& namespace_, HashMap<DeprecatedFlyString, Vector<DeprecatedString>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed)
static WebIDL::ExceptionOr<DeprecatedString> serialize_document_fragment(DOM::DocumentFragment const& document_fragment, Optional<FlyString>& namespace_, HashMap<FlyString, Vector<Optional<FlyString>>>& namespace_prefix_map, u64& prefix_index, RequireWellFormed require_well_formed)
{
// 1. Let markup the empty string.
StringBuilder markup;

View file

@ -244,10 +244,10 @@ WebIDL::ExceptionOr<BrowsingContext::BrowsingContextAndDocument> BrowsingContext
document->set_ready_for_post_load_tasks(true);
// 18. Ensure that document has a single child html node, which itself has two empty child nodes: a head element, and a body element.
auto html_node = TRY(DOM::create_element(document, HTML::TagNames::html, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))));
auto head_element = TRY(DOM::create_element(document, HTML::TagNames::head, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))));
auto html_node = TRY(DOM::create_element(document, HTML::TagNames::html, Namespace::HTML));
auto head_element = TRY(DOM::create_element(document, HTML::TagNames::head, Namespace::HTML));
TRY(html_node->append_child(head_element));
auto body_element = TRY(DOM::create_element(document, HTML::TagNames::body, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))));
auto body_element = TRY(DOM::create_element(document, HTML::TagNames::body, Namespace::HTML));
TRY(html_node->append_child(body_element));
TRY(document->append_child(html_node));

View file

@ -286,7 +286,7 @@ JS::ThrowCompletionOr<void> CustomElementRegistry::define(String const& name, We
auto& inclusive_descendant_element = static_cast<DOM::Element&>(inclusive_descendant);
if (inclusive_descendant_element.namespace_() == Namespace::HTML && inclusive_descendant_element.local_name() == local_name && (!extends.has_value() || inclusive_descendant_element.is_value() == name))
if (inclusive_descendant_element.namespace_uri() == Namespace::HTML && inclusive_descendant_element.local_name() == local_name && (!extends.has_value() || inclusive_descendant_element.is_value() == name))
upgrade_candidates.append(JS::make_handle(inclusive_descendant_element));
return IterationDecision::Continue;

View file

@ -112,11 +112,11 @@ WebIDL::ExceptionOr<void> HTMLDetailsElement::create_shadow_tree(JS::Realm& real
shadow_root->set_slot_assignment(Bindings::SlotAssignmentMode::Manual);
// The first slot is expected to take the details element's first summary element child, if any.
auto summary_slot = TRY(DOM::create_element(document(), HTML::TagNames::slot, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))));
auto summary_slot = TRY(DOM::create_element(document(), HTML::TagNames::slot, Namespace::HTML));
MUST(shadow_root->append_child(summary_slot));
// The second slot is expected to take the details element's remaining descendants, if any.
auto descendants_slot = TRY(DOM::create_element(document(), HTML::TagNames::slot, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))));
auto descendants_slot = TRY(DOM::create_element(document(), HTML::TagNames::slot, Namespace::HTML));
MUST(shadow_root->append_child(descendants_slot));
m_summary_slot = static_cast<HTML::HTMLSlotElement&>(*summary_slot);

View file

@ -536,7 +536,7 @@ void HTMLInputElement::create_text_input_shadow_tree()
{
auto shadow_root = heap().allocate<DOM::ShadowRoot>(realm(), document(), *this, Bindings::ShadowRootMode::Closed);
auto initial_value = m_value;
auto element = DOM::create_element(document(), HTML::TagNames::div, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto element = DOM::create_element(document(), HTML::TagNames::div, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(element->set_attribute(HTML::AttributeNames::style, R"~~~(
display: flex;
height: 100%;
@ -555,7 +555,7 @@ void HTMLInputElement::create_text_input_shadow_tree()
MUST(m_placeholder_element->append_child(*m_placeholder_text_node));
MUST(element->append_child(*m_placeholder_element));
m_inner_text_element = DOM::create_element(document(), HTML::TagNames::div, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
m_inner_text_element = DOM::create_element(document(), HTML::TagNames::div, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(m_inner_text_element->style_for_bindings()->set_property(CSS::PropertyID::Height, "1lh"sv));
m_text_node = heap().allocate<DOM::Text>(realm(), document(), MUST(String::from_deprecated_string(initial_value)));
@ -587,7 +587,7 @@ void HTMLInputElement::create_color_input_shadow_tree()
auto color = value_sanitization_algorithm(m_value);
auto border = DOM::create_element(document(), HTML::TagNames::div, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto border = DOM::create_element(document(), HTML::TagNames::div, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(border->set_attribute(HTML::AttributeNames::style, R"~~~(
width: fit-content;
height: fit-content;
@ -596,7 +596,7 @@ void HTMLInputElement::create_color_input_shadow_tree()
background-color: ButtonFace;
)~~~"_string));
m_color_well_element = DOM::create_element(document(), HTML::TagNames::div, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
m_color_well_element = DOM::create_element(document(), HTML::TagNames::div, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(m_color_well_element->set_attribute(HTML::AttributeNames::style, R"~~~(
width: 24px;
height: 24px;

View file

@ -118,7 +118,7 @@ JS::NonnullGCPtr<HTMLTableCaptionElement> HTMLTableElement::create_caption()
return *maybe_caption;
}
auto caption = DOM::create_element(document(), TagNames::caption, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto caption = DOM::create_element(document(), TagNames::caption, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(pre_insert(caption, first_child()));
return static_cast<HTMLTableCaptionElement&>(*caption);
}
@ -196,7 +196,7 @@ JS::NonnullGCPtr<HTMLTableSectionElement> HTMLTableElement::create_t_head()
if (maybe_thead)
return *maybe_thead;
auto thead = DOM::create_element(document(), TagNames::thead, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto thead = DOM::create_element(document(), TagNames::thead, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
// We insert the new thead after any <caption> or <colgroup> elements
DOM::Node* child_to_insert_before = nullptr;
@ -272,7 +272,7 @@ JS::NonnullGCPtr<HTMLTableSectionElement> HTMLTableElement::create_t_foot()
if (maybe_tfoot)
return *maybe_tfoot;
auto tfoot = DOM::create_element(document(), TagNames::tfoot, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto tfoot = DOM::create_element(document(), TagNames::tfoot, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(append_child(tfoot));
return static_cast<HTMLTableSectionElement&>(*tfoot);
}
@ -302,7 +302,7 @@ JS::NonnullGCPtr<DOM::HTMLCollection> HTMLTableElement::t_bodies()
// https://html.spec.whatwg.org/multipage/tables.html#dom-table-createtbody
JS::NonnullGCPtr<HTMLTableSectionElement> HTMLTableElement::create_t_body()
{
auto tbody = DOM::create_element(document(), TagNames::tbody, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto tbody = DOM::create_element(document(), TagNames::tbody, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
// We insert the new tbody after the last <tbody> element
DOM::Node* child_to_insert_before = nullptr;
@ -365,9 +365,9 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<HTMLTableRowElement>> HTMLTableElement::ins
if (index < -1 || index > (long)rows_length) {
return WebIDL::IndexSizeError::create(realm(), "Index is negative or greater than the number of rows"_fly_string);
}
auto& tr = static_cast<HTMLTableRowElement&>(*TRY(DOM::create_element(document(), TagNames::tr, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML)))));
auto& tr = static_cast<HTMLTableRowElement&>(*TRY(DOM::create_element(document(), TagNames::tr, Namespace::HTML)));
if (rows_length == 0 && !has_child_of_type<HTMLTableRowElement>()) {
auto tbody = TRY(DOM::create_element(document(), TagNames::tbody, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))));
auto tbody = TRY(DOM::create_element(document(), TagNames::tbody, Namespace::HTML));
TRY(tbody->append_child(tr));
TRY(append_child(tbody));
} else if (rows_length == 0) {

View file

@ -132,7 +132,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<HTMLTableCellElement>> HTMLTableRowElement:
return WebIDL::IndexSizeError::create(realm(), "Index is negative or greater than the number of cells"_fly_string);
// 2. Let table cell be the result of creating an element given this tr element's node document, td, and the HTML namespace.
auto& table_cell = static_cast<HTMLTableCellElement&>(*TRY(DOM::create_element(document(), HTML::TagNames::td, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML)))));
auto& table_cell = static_cast<HTMLTableCellElement&>(*TRY(DOM::create_element(document(), HTML::TagNames::td, Namespace::HTML)));
// 3. If index is equal to 1 or equal to the number of items in cells collection, then append table cell to this tr element.
if (index == -1 || index == cells_collection_size)

View file

@ -57,7 +57,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<HTMLTableRowElement>> HTMLTableSectionEleme
return WebIDL::IndexSizeError::create(realm(), "Index is negative or greater than the number of rows"_fly_string);
// 2. Let table row be the result of creating an element given this element's node document, tr, and the HTML namespace.
auto& table_row = static_cast<HTMLTableRowElement&>(*TRY(DOM::create_element(document(), TagNames::tr, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML)))));
auto& table_row = static_cast<HTMLTableRowElement&>(*TRY(DOM::create_element(document(), TagNames::tr, Namespace::HTML)));
// 3. If index is 1 or equal to the number of items in the rows collection, then append table row to this element.
if (index == -1 || index == rows_collection_size)

View file

@ -97,9 +97,9 @@ void HTMLTextAreaElement::create_shadow_tree_if_needed()
return;
auto shadow_root = heap().allocate<DOM::ShadowRoot>(realm(), document(), *this, Bindings::ShadowRootMode::Closed);
auto element = MUST(DOM::create_element(document(), HTML::TagNames::div, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))));
auto element = MUST(DOM::create_element(document(), HTML::TagNames::div, Namespace::HTML));
m_inner_text_element = MUST(DOM::create_element(document(), HTML::TagNames::div, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))));
m_inner_text_element = MUST(DOM::create_element(document(), HTML::TagNames::div, Namespace::HTML));
m_text_node = heap().allocate<DOM::Text>(realm(), document(), String {});
m_text_node->set_always_editable(true);

View file

@ -181,7 +181,7 @@ void HTMLParser::run()
// https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
// As each token is emitted from the tokenizer, the user agent must follow the appropriate steps from the following list, known as the tree construction dispatcher:
if (m_stack_of_open_elements.is_empty()
|| adjusted_current_node().namespace_() == Namespace::HTML
|| adjusted_current_node().namespace_uri() == Namespace::HTML
|| (is_html_integration_point(adjusted_current_node()) && (token.is_start_tag() || token.is_character()))
|| token.is_end_of_file()) {
// -> If the stack of open elements is empty
@ -539,7 +539,7 @@ void HTMLParser::handle_before_html(HTMLToken& token)
// -> A start tag whose tag name is "html"
if (token.is_start_tag() && token.tag_name() == HTML::TagNames::html) {
// Create an element for the token in the HTML namespace, with the Document as the intended parent. Append it to the Document object. Put this element in the stack of open elements.
auto element = create_element_for(token, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML)), document());
auto element = create_element_for(token, Namespace::HTML, document());
MUST(document().append_child(*element));
m_stack_of_open_elements.push(move(element));
@ -564,7 +564,7 @@ void HTMLParser::handle_before_html(HTMLToken& token)
// -> Anything else
AnythingElse:
// Create an html element whose node document is the Document object. Append it to the Document object. Put this element in the stack of open elements.
auto element = create_element(document(), HTML::TagNames::html, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto element = create_element(document(), HTML::TagNames::html, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(document().append_child(element));
m_stack_of_open_elements.push(element);
@ -772,7 +772,7 @@ JS::NonnullGCPtr<DOM::Element> HTMLParser::insert_foreign_element(HTMLToken cons
JS::NonnullGCPtr<DOM::Element> HTMLParser::insert_html_element(HTMLToken const& token)
{
return insert_foreign_element(token, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML)));
return insert_foreign_element(token, Namespace::HTML);
}
void HTMLParser::handle_before_head(HTMLToken& token)
@ -882,7 +882,7 @@ void HTMLParser::handle_in_head(HTMLToken& token)
if (token.is_start_tag() && token.tag_name() == HTML::TagNames::script) {
auto adjusted_insertion_location = find_appropriate_place_for_inserting_node();
auto element = create_element_for(token, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML)), *adjusted_insertion_location.parent);
auto element = create_element_for(token, Namespace::HTML, *adjusted_insertion_location.parent);
auto& script_element = verify_cast<HTMLScriptElement>(*element);
script_element.set_parser_document(Badge<HTMLParser> {}, document());
script_element.set_force_async(Badge<HTMLParser> {}, false);
@ -1383,7 +1383,7 @@ HTMLParser::AdoptionAgencyAlgorithmOutcome HTMLParser::run_the_adoption_agency_a
// 6. Create an element for the token for which the element node was created,
// in the HTML namespace, with common ancestor as the intended parent;
// FIXME: hold onto the real token
auto element = create_element_for(HTMLToken::make_start_tag(node->local_name()), MUST(FlyString::from_deprecated_fly_string(Namespace::HTML)), *common_ancestor);
auto element = create_element_for(HTMLToken::make_start_tag(node->local_name()), Namespace::HTML, *common_ancestor);
// replace the entry for node in the list of active formatting elements with an entry for the new element,
m_list_of_active_formatting_elements.replace(*node, *element);
// replace the entry for node in the stack of open elements with an entry for the new element,
@ -1412,7 +1412,7 @@ HTMLParser::AdoptionAgencyAlgorithmOutcome HTMLParser::run_the_adoption_agency_a
// 15. Create an element for the token for which formatting element was created,
// in the HTML namespace, with furthest block as the intended parent.
// FIXME: hold onto the real token
auto element = create_element_for(HTMLToken::make_start_tag(formatting_element->local_name()), MUST(FlyString::from_deprecated_fly_string(Namespace::HTML)), *furthest_block);
auto element = create_element_for(HTMLToken::make_start_tag(formatting_element->local_name()), Namespace::HTML, *furthest_block);
// 16. Take all of the child nodes of furthest block and append them to the element created in the last step.
for (auto& child : furthest_block->children_as_vector())
@ -1439,7 +1439,7 @@ HTMLParser::AdoptionAgencyAlgorithmOutcome HTMLParser::run_the_adoption_agency_a
// https://html.spec.whatwg.org/multipage/parsing.html#special
bool HTMLParser::is_special_tag(FlyString const& tag_name, Optional<FlyString> const& namespace_)
{
if (namespace_ == MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))) {
if (namespace_ == Namespace::HTML) {
return tag_name.is_one_of(
HTML::TagNames::address,
HTML::TagNames::applet,
@ -1523,12 +1523,12 @@ bool HTMLParser::is_special_tag(FlyString const& tag_name, Optional<FlyString> c
HTML::TagNames::ul,
HTML::TagNames::wbr,
HTML::TagNames::xmp);
} else if (namespace_ == MUST(FlyString::from_deprecated_fly_string(Namespace::SVG))) {
} else if (namespace_ == Namespace::SVG) {
return tag_name.is_one_of(
SVG::TagNames::desc,
SVG::TagNames::foreignObject,
SVG::TagNames::title);
} else if (namespace_ == MUST(FlyString::from_deprecated_fly_string(Namespace::MathML))) {
} else if (namespace_ == Namespace::MathML) {
return tag_name.is_one_of(
MathML::TagNames::mi,
MathML::TagNames::mo,
@ -2127,7 +2127,7 @@ void HTMLParser::handle_in_body(HTMLToken& token)
adjust_mathml_attributes(token);
adjust_foreign_attributes(token);
(void)insert_foreign_element(token, MUST(FlyString::from_deprecated_fly_string(Namespace::MathML)));
(void)insert_foreign_element(token, Namespace::MathML);
if (token.is_self_closing()) {
(void)m_stack_of_open_elements.pop();
@ -2141,7 +2141,7 @@ void HTMLParser::handle_in_body(HTMLToken& token)
adjust_svg_attributes(token);
adjust_foreign_attributes(token);
(void)insert_foreign_element(token, MUST(FlyString::from_deprecated_fly_string(Namespace::SVG)));
(void)insert_foreign_element(token, Namespace::SVG);
if (token.is_self_closing()) {
(void)m_stack_of_open_elements.pop();
@ -3480,7 +3480,7 @@ void HTMLParser::process_using_the_rules_for_foreign_content(HTMLToken& token)
// While the current node is not a MathML text integration point, an HTML integration point, or an element in the HTML namespace, pop elements from the stack of open elements.
while (!is_mathml_text_integration_point(current_node())
&& !is_html_integration_point(current_node())
&& current_node().namespace_() != Namespace::HTML) {
&& current_node().namespace_uri() != Namespace::HTML) {
(void)m_stack_of_open_elements.pop();
}
@ -3492,13 +3492,13 @@ void HTMLParser::process_using_the_rules_for_foreign_content(HTMLToken& token)
// Any other start tag
if (token.is_start_tag()) {
// If the adjusted current node is an element in the MathML namespace, adjust MathML attributes for the token. (This fixes the case of MathML attributes that are not all lowercase.)
if (adjusted_current_node().namespace_() == Namespace::MathML) {
if (adjusted_current_node().namespace_uri() == Namespace::MathML) {
adjust_mathml_attributes(token);
}
// If the adjusted current node is an element in the SVG namespace, and the token's tag name is one of the ones in the first column of the
// following table, change the tag name to the name given in the corresponding cell in the second column. (This fixes the case of SVG
// elements that are not all lowercase.)
else if (adjusted_current_node().namespace_() == Namespace::SVG) {
else if (adjusted_current_node().namespace_uri() == Namespace::SVG) {
adjust_svg_tag_names(token);
// If the adjusted current node is an element in the SVG namespace, adjust SVG attributes for the token. (This fixes the case of SVG attributes that are not all lowercase.)
adjust_svg_attributes(token);
@ -3514,7 +3514,7 @@ void HTMLParser::process_using_the_rules_for_foreign_content(HTMLToken& token)
if (token.is_self_closing()) {
// -> If the token's tag name is "script", and the new current node is in the SVG namespace
if (token.tag_name() == SVG::TagNames::script && current_node().namespace_() == Namespace::SVG) {
if (token.tag_name() == SVG::TagNames::script && current_node().namespace_uri() == Namespace::SVG) {
// Acknowledge the token's self-closing flag, and then act as described in the steps for a "script" end tag below.
token.acknowledge_self_closing_flag_if_set();
goto ScriptEndTag;
@ -3531,7 +3531,7 @@ void HTMLParser::process_using_the_rules_for_foreign_content(HTMLToken& token)
}
// -> An end tag whose tag name is "script", if the current node is an SVG script element
if (token.is_end_tag() && current_node().namespace_() == Namespace::SVG && current_node().tag_name() == SVG::TagNames::script) {
if (token.is_end_tag() && current_node().namespace_uri() == Namespace::SVG && current_node().tag_name() == SVG::TagNames::script) {
ScriptEndTag:
// Pop the current node off the stack of open elements.
(void)m_stack_of_open_elements.pop();
@ -3587,7 +3587,7 @@ void HTMLParser::process_using_the_rules_for_foreign_content(HTMLToken& token)
node = m_stack_of_open_elements.elements().at(i - 1).ptr();
// 6. If node is not an element in the HTML namespace, return to the step labeled loop.
if (node->namespace_() != Namespace::HTML)
if (node->namespace_uri() != Namespace::HTML)
continue;
// 7. Otherwise, process the token according to the rules given in the section corresponding to the current insertion mode in HTML content.
@ -3772,7 +3772,7 @@ Vector<JS::Handle<DOM::Node>> HTMLParser::parse_html_fragment(DOM::Element& cont
}
// 5. Let root be a new html element with no attributes.
auto root = create_element(context_element.document(), HTML::TagNames::html, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto root = create_element(context_element.document(), HTML::TagNames::html, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
// 6. Append the element root to the Document node created above.
MUST(temp_document->append_child(root));

View file

@ -44,7 +44,7 @@ public:
struct Attribute {
DeprecatedString prefix;
FlyString local_name;
DeprecatedString namespace_;
FlyString namespace_;
String value;
Position name_start_position;
Position value_start_position;
@ -290,7 +290,7 @@ public:
});
}
void adjust_foreign_attribute(FlyString const& old_name, DeprecatedFlyString const& prefix, FlyString const& local_name, DeprecatedFlyString const& namespace_)
void adjust_foreign_attribute(FlyString const& old_name, DeprecatedFlyString const& prefix, FlyString const& local_name, FlyString const& namespace_)
{
VERIFY(is_start_tag() || is_end_tag());
for_each_attribute([&](Attribute& attribute) {

View file

@ -421,7 +421,7 @@ _StartOfFunction:
if (consume_next_if_match("[CDATA["sv)) {
// We keep the parser optional so that syntax highlighting can be lexer-only.
// The parser registers itself with the lexer it creates.
if (m_parser != nullptr && m_parser->adjusted_current_node().namespace_() != Namespace::HTML) {
if (m_parser != nullptr && m_parser->adjusted_current_node().namespace_uri() != Namespace::HTML) {
SWITCH_TO(CDATASection);
} else {
create_new_token(HTMLToken::Type::Comment);

View file

@ -8,7 +8,7 @@
namespace Web::Namespace {
#define __ENUMERATE_NAMESPACE(name, namespace_) DeprecatedFlyString name;
#define __ENUMERATE_NAMESPACE(name, namespace_) FlyString name;
ENUMERATE_NAMESPACES
#undef __ENUMERATE_NAMESPACE
@ -18,7 +18,7 @@ void initialize_strings()
VERIFY(!s_initialized);
#define __ENUMERATE_NAMESPACE(name, namespace_) \
name = namespace_;
name = namespace_##_fly_string;
ENUMERATE_NAMESPACES
#undef __ENUMERATE_NAMESPACE

View file

@ -6,8 +6,8 @@
#pragma once
#include <AK/DeprecatedFlyString.h>
#include <AK/Error.h>
#include <AK/FlyString.h>
namespace Web::Namespace {
@ -19,7 +19,7 @@ namespace Web::Namespace {
__ENUMERATE_NAMESPACE(XML, "http://www.w3.org/XML/1998/namespace") \
__ENUMERATE_NAMESPACE(XMLNS, "http://www.w3.org/2000/xmlns/")
#define __ENUMERATE_NAMESPACE(name, namespace_) extern DeprecatedFlyString name;
#define __ENUMERATE_NAMESPACE(name, namespace_) extern FlyString name;
ENUMERATE_NAMESPACES
#undef __ENUMERATE_NAMESPACE

View file

@ -58,7 +58,7 @@ Response capture_element_screenshot(Painter const& painter, Page& page, DOM::Ele
auto viewport_rect = page.top_level_traversable()->viewport_rect();
rect.intersect(page.enclosing_device_rect(viewport_rect).to_type<int>());
auto canvas_element = DOM::create_element(element.document(), HTML::TagNames::canvas, MUST(FlyString::from_deprecated_fly_string(Namespace::HTML))).release_value_but_fixme_should_propagate_errors();
auto canvas_element = DOM::create_element(element.document(), HTML::TagNames::canvas, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
auto& canvas = verify_cast<HTML::HTMLCanvasElement>(*canvas_element);
if (!canvas.create_bitmap(rect.width(), rect.height())) {

View file

@ -57,7 +57,7 @@ void XMLDocumentBuilder::element_start(const XML::Name& name, HashMap<XML::Name,
if (auto it = attributes.find("xmlns"); it != attributes.end()) {
m_namespace_stack.append({ m_namespace, 1 });
m_namespace = it->value;
m_namespace = MUST(FlyString::from_deprecated_fly_string(it->value));
} else {
m_namespace_stack.last().depth += 1;
}
@ -67,7 +67,7 @@ void XMLDocumentBuilder::element_start(const XML::Name& name, HashMap<XML::Name,
return;
}
auto node = DOM::create_element(m_document, MUST(FlyString::from_deprecated_fly_string(name)), MUST(FlyString::from_deprecated_fly_string(m_namespace))).release_value_but_fixme_should_propagate_errors();
auto node = DOM::create_element(m_document, MUST(FlyString::from_deprecated_fly_string(name)), m_namespace).release_value_but_fixme_should_propagate_errors();
// When an XML parser with XML scripting support enabled creates a script element,
// it must have its parser document set and its "force async" flag must be unset.

View file

@ -42,10 +42,10 @@ private:
XMLScriptingSupport m_scripting_support { XMLScriptingSupport::Enabled };
bool m_has_error { false };
StringBuilder text_builder;
DeprecatedFlyString m_namespace {};
FlyString m_namespace;
struct NamespaceStackEntry {
DeprecatedFlyString ns;
FlyString ns;
size_t depth;
};
Vector<NamespaceStackEntry, 2> m_namespace_stack;