diff --git a/Userland/Libraries/LibWeb/DOM/DOMImplementation.cpp b/Userland/Libraries/LibWeb/DOM/DOMImplementation.cpp index b5bca1fe04..5caa2abdf9 100644 --- a/Userland/Libraries/LibWeb/DOM/DOMImplementation.cpp +++ b/Userland/Libraries/LibWeb/DOM/DOMImplementation.cpp @@ -46,7 +46,7 @@ void DOMImplementation::visit_edges(Cell::Visitor& visitor) } // https://dom.spec.whatwg.org/#dom-domimplementation-createdocument -WebIDL::ExceptionOr> DOMImplementation::create_document(Optional const& namespace_, String const& qualified_name, JS::GCPtr doctype) const +WebIDL::ExceptionOr> DOMImplementation::create_document(Optional const& namespace_, String const& qualified_name, JS::GCPtr doctype) const { // 1. Let document be a new XMLDocument auto xml_document = XMLDocument::create(realm()); @@ -72,15 +72,10 @@ WebIDL::ExceptionOr> DOMImplementation::create_docume xml_document->set_origin(document().origin()); // 7. document’s content type is determined by namespace: - // FIXME: This conversion is ugly - Optional namespace_to_use; - if (namespace_.has_value()) - namespace_to_use = namespace_.value(); - - if (namespace_to_use == Namespace::HTML) { + if (namespace_ == Namespace::HTML) { // -> HTML namespace xml_document->set_content_type("application/xhtml+xml"_string); - } else if (namespace_to_use == Namespace::SVG) { + } else if (namespace_ == Namespace::SVG) { // -> SVG namespace xml_document->set_content_type("image/svg+xml"_string); } else { diff --git a/Userland/Libraries/LibWeb/DOM/DOMImplementation.h b/Userland/Libraries/LibWeb/DOM/DOMImplementation.h index f9b777aa92..ab048a4daa 100644 --- a/Userland/Libraries/LibWeb/DOM/DOMImplementation.h +++ b/Userland/Libraries/LibWeb/DOM/DOMImplementation.h @@ -21,7 +21,7 @@ public: [[nodiscard]] static JS::NonnullGCPtr create(Document&); virtual ~DOMImplementation(); - WebIDL::ExceptionOr> create_document(Optional const&, String const&, JS::GCPtr) const; + WebIDL::ExceptionOr> create_document(Optional const&, String const&, JS::GCPtr) const; JS::NonnullGCPtr create_html_document(Optional const& title) const; WebIDL::ExceptionOr> create_document_type(String const& qualified_name, String const& public_id, String const& system_id); diff --git a/Userland/Libraries/LibWeb/DOM/DOMImplementation.idl b/Userland/Libraries/LibWeb/DOM/DOMImplementation.idl index 14060e83ea..d30b107a72 100644 --- a/Userland/Libraries/LibWeb/DOM/DOMImplementation.idl +++ b/Userland/Libraries/LibWeb/DOM/DOMImplementation.idl @@ -5,7 +5,7 @@ interface DOMImplementation { // FIXME: This should return XMLDocument instead of Document. - [NewObject] Document createDocument(DOMString? namespace, [LegacyNullToEmptyString] DOMString qualifiedName, optional DocumentType? doctype = null); + [NewObject] Document createDocument([FlyString] DOMString? namespace, [LegacyNullToEmptyString] DOMString qualifiedName, optional DocumentType? doctype = null); [NewObject] Document createHTMLDocument(optional DOMString title); [NewObject] DocumentType createDocumentType(DOMString qualifiedName, DOMString publicId, DOMString systemId); diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index c8e8c72f3a..a2aab2061e 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -1426,15 +1426,10 @@ WebIDL::ExceptionOr> Document::create_element(String c // https://dom.spec.whatwg.org/#dom-document-createelementns // https://dom.spec.whatwg.org/#internal-createelementns-steps -WebIDL::ExceptionOr> Document::create_element_ns(Optional const& namespace_, String const& qualified_name, Variant const& options) +WebIDL::ExceptionOr> Document::create_element_ns(Optional const& namespace_, String const& qualified_name, Variant const& options) { - // FIXME: This conversion is ugly - Optional namespace_to_use; - if (namespace_.has_value()) - 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_to_use, qualified_name)); + auto extracted_qualified_name = TRY(validate_and_extract(realm(), namespace_, qualified_name)); // 2. Let is be null. Optional is_value; @@ -3082,15 +3077,10 @@ WebIDL::ExceptionOr> Document::create_attribute(String co } // https://dom.spec.whatwg.org/#dom-document-createattributens -WebIDL::ExceptionOr> Document::create_attribute_ns(Optional const& namespace_, String const& qualified_name) +WebIDL::ExceptionOr> Document::create_attribute_ns(Optional const& namespace_, String const& qualified_name) { - // FIXME: This conversion is ugly - Optional namespace_to_use; - if (namespace_.has_value()) - 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_to_use, qualified_name)); + auto extracted_qualified_name = TRY(validate_and_extract(realm(), namespace_, qualified_name)); // 2. Return a new attribute whose namespace is namespace, namespace prefix is prefix, local name is localName, and node document is this. diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index d90d70cb71..4db04655e1 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -238,14 +238,14 @@ public: HTML::EnvironmentSettingsObject& relevant_settings_object() const; WebIDL::ExceptionOr> create_element(String const& local_name, Variant const& options); - WebIDL::ExceptionOr> create_element_ns(Optional const& namespace_, String const& qualified_name, Variant const& options); + WebIDL::ExceptionOr> create_element_ns(Optional const& namespace_, String const& qualified_name, Variant const& options); JS::NonnullGCPtr create_document_fragment(); JS::NonnullGCPtr create_text_node(String const& data); JS::NonnullGCPtr create_comment(String const& data); WebIDL::ExceptionOr> create_processing_instruction(String const& target, String const& data); WebIDL::ExceptionOr> create_attribute(String const& local_name); - WebIDL::ExceptionOr> create_attribute_ns(Optional const& namespace_, String const& qualified_name); + WebIDL::ExceptionOr> create_attribute_ns(Optional const& namespace_, String const& qualified_name); WebIDL::ExceptionOr> create_event(StringView interface); JS::NonnullGCPtr create_range(); diff --git a/Userland/Libraries/LibWeb/DOM/Document.idl b/Userland/Libraries/LibWeb/DOM/Document.idl index c6dc9d4544..8640fec711 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.idl +++ b/Userland/Libraries/LibWeb/DOM/Document.idl @@ -76,14 +76,14 @@ interface Document : Node { readonly attribute HTMLCollection all; [CEReactions, NewObject] Element createElement(DOMString tagName, optional (DOMString or ElementCreationOptions) options = {}); - [CEReactions, NewObject] Element createElementNS(DOMString? namespace, DOMString qualifiedName, optional (DOMString or ElementCreationOptions) options = {}); + [CEReactions, NewObject] Element createElementNS([FlyString] DOMString? namespace, DOMString qualifiedName, optional (DOMString or ElementCreationOptions) options = {}); DocumentFragment createDocumentFragment(); Text createTextNode(DOMString data); Comment createComment(DOMString data); [NewObject] ProcessingInstruction createProcessingInstruction(DOMString target, DOMString data); [NewObject] Attr createAttribute(DOMString localName); - [NewObject] Attr createAttributeNS(DOMString? namespace, DOMString qualifiedName); + [NewObject] Attr createAttributeNS([FlyString] DOMString? namespace, DOMString qualifiedName); Range createRange(); Event createEvent(DOMString interface);