mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:04:59 +00:00
LibWeb: Use Optional<FlyString> directly in Document & DOMImplementation
Use the [FlyString] extended attribute to allow these functions to take an Optional<FlyString> directly, allowing us to tidy up some conversions from Optional<String>.
This commit is contained in:
parent
7cf2674061
commit
636a85f04e
6 changed files with 13 additions and 28 deletions
|
@ -46,7 +46,7 @@ void DOMImplementation::visit_edges(Cell::Visitor& visitor)
|
|||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-domimplementation-createdocument
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> DOMImplementation::create_document(Optional<String> const& namespace_, String const& qualified_name, JS::GCPtr<DocumentType> doctype) const
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> DOMImplementation::create_document(Optional<FlyString> const& namespace_, String const& qualified_name, JS::GCPtr<DocumentType> doctype) const
|
||||
{
|
||||
// 1. Let document be a new XMLDocument
|
||||
auto xml_document = XMLDocument::create(realm());
|
||||
|
@ -72,15 +72,10 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> DOMImplementation::create_docume
|
|||
xml_document->set_origin(document().origin());
|
||||
|
||||
// 7. document’s content type is determined by namespace:
|
||||
// FIXME: This conversion is ugly
|
||||
Optional<FlyString> 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 {
|
||||
|
|
|
@ -21,7 +21,7 @@ public:
|
|||
[[nodiscard]] static JS::NonnullGCPtr<DOMImplementation> create(Document&);
|
||||
virtual ~DOMImplementation();
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> create_document(Optional<String> const&, String const&, JS::GCPtr<DocumentType>) const;
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> create_document(Optional<FlyString> const&, String const&, JS::GCPtr<DocumentType>) const;
|
||||
JS::NonnullGCPtr<Document> create_html_document(Optional<String> const& title) const;
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentType>> create_document_type(String const& qualified_name, String const& public_id, String const& system_id);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -1426,15 +1426,10 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> Document::create_element(String c
|
|||
|
||||
// https://dom.spec.whatwg.org/#dom-document-createelementns
|
||||
// https://dom.spec.whatwg.org/#internal-createelementns-steps
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> Document::create_element_ns(Optional<String> const& namespace_, String const& qualified_name, Variant<String, ElementCreationOptions> const& options)
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> Document::create_element_ns(Optional<FlyString> const& namespace_, String const& qualified_name, Variant<String, ElementCreationOptions> const& options)
|
||||
{
|
||||
// FIXME: This conversion is ugly
|
||||
Optional<FlyString> 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<String> is_value;
|
||||
|
@ -3082,15 +3077,10 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> Document::create_attribute(String co
|
|||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-document-createattributens
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> Document::create_attribute_ns(Optional<String> const& namespace_, String const& qualified_name)
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> Document::create_attribute_ns(Optional<FlyString> const& namespace_, String const& qualified_name)
|
||||
{
|
||||
// FIXME: This conversion is ugly
|
||||
Optional<FlyString> 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.
|
||||
|
||||
|
|
|
@ -238,14 +238,14 @@ public:
|
|||
HTML::EnvironmentSettingsObject& relevant_settings_object() const;
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element(String const& local_name, Variant<String, ElementCreationOptions> const& options);
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element_ns(Optional<String> const& namespace_, String const& qualified_name, Variant<String, ElementCreationOptions> const& options);
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element_ns(Optional<FlyString> const& namespace_, String const& qualified_name, Variant<String, ElementCreationOptions> const& options);
|
||||
JS::NonnullGCPtr<DocumentFragment> create_document_fragment();
|
||||
JS::NonnullGCPtr<Text> create_text_node(String const& data);
|
||||
JS::NonnullGCPtr<Comment> create_comment(String const& data);
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<ProcessingInstruction>> create_processing_instruction(String const& target, String const& data);
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> create_attribute(String const& local_name);
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> create_attribute_ns(Optional<String> const& namespace_, String const& qualified_name);
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> create_attribute_ns(Optional<FlyString> const& namespace_, String const& qualified_name);
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> create_event(StringView interface);
|
||||
JS::NonnullGCPtr<Range> create_range();
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue