mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-21 18:00:16 +00:00
LibWeb: Make DOMException take error message as a String
There was no need to use FlyString for error messages, and it just caused a bunch of churn since these strings typically only existed during the lifetime of the error.
This commit is contained in:
parent
5f9a36feac
commit
175f3febb8
Notes:
github-actions[bot]
2024-10-12 19:15:13 +00:00
Author: https://github.com/awesomekling
Commit: 175f3febb8
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1743
Reviewed-by: https://github.com/ADKaster
89 changed files with 464 additions and 462 deletions
|
@ -173,7 +173,7 @@ WebIDL::ExceptionOr<void> Element::set_attribute(FlyString const& name, String c
|
|||
{
|
||||
// 1. If qualifiedName does not match the Name production in XML, then throw an "InvalidCharacterError" DOMException.
|
||||
if (!Document::is_valid_name(name.to_string()))
|
||||
return WebIDL::InvalidCharacterError::create(realm(), "Attribute name must not be empty or contain invalid characters"_fly_string);
|
||||
return WebIDL::InvalidCharacterError::create(realm(), "Attribute name must not be empty or contain invalid characters"_string);
|
||||
|
||||
// 2. If this is in the HTML namespace and its node document is an HTML document, then set qualifiedName to qualifiedName in ASCII lowercase.
|
||||
bool insert_as_lowercase = namespace_uri() == Namespace::HTML && document().document_type() == Document::Type::HTML;
|
||||
|
@ -221,19 +221,19 @@ WebIDL::ExceptionOr<QualifiedName> validate_and_extract(JS::Realm& realm, Option
|
|||
|
||||
// 6. If prefix is non-null and namespace is null, then throw a "NamespaceError" DOMException.
|
||||
if (prefix.has_value() && !namespace_.has_value())
|
||||
return WebIDL::NamespaceError::create(realm, "Prefix is non-null and namespace is null."_fly_string);
|
||||
return WebIDL::NamespaceError::create(realm, "Prefix is non-null and namespace is null."_string);
|
||||
|
||||
// 7. If prefix is "xml" and namespace is not the XML namespace, then throw a "NamespaceError" DOMException.
|
||||
if (prefix == "xml"sv && namespace_ != Namespace::XML)
|
||||
return WebIDL::NamespaceError::create(realm, "Prefix is 'xml' and namespace is not the XML namespace."_fly_string);
|
||||
return WebIDL::NamespaceError::create(realm, "Prefix is 'xml' and namespace is not the XML namespace."_string);
|
||||
|
||||
// 8. If either qualifiedName or prefix is "xmlns" and namespace is not the XMLNS namespace, then throw a "NamespaceError" DOMException.
|
||||
if ((qualified_name == "xmlns"sv || prefix == "xmlns"sv) && namespace_ != Namespace::XMLNS)
|
||||
return WebIDL::NamespaceError::create(realm, "Either qualifiedName or prefix is 'xmlns' and namespace is not the XMLNS namespace."_fly_string);
|
||||
return WebIDL::NamespaceError::create(realm, "Either qualifiedName or prefix is 'xmlns' and namespace is not the XMLNS namespace."_string);
|
||||
|
||||
// 9. If namespace is the XMLNS namespace and neither qualifiedName nor prefix is "xmlns", then throw a "NamespaceError" DOMException.
|
||||
if (namespace_ == Namespace::XMLNS && !(qualified_name == "xmlns"sv || prefix == "xmlns"sv))
|
||||
return WebIDL::NamespaceError::create(realm, "Namespace is the XMLNS namespace and neither qualifiedName nor prefix is 'xmlns'."_fly_string);
|
||||
return WebIDL::NamespaceError::create(realm, "Namespace is the XMLNS namespace and neither qualifiedName nor prefix is 'xmlns'."_string);
|
||||
|
||||
// 10. Return namespace, prefix, and localName.
|
||||
return QualifiedName { local_name, prefix, namespace_ };
|
||||
|
@ -341,7 +341,7 @@ WebIDL::ExceptionOr<bool> Element::toggle_attribute(FlyString const& name, Optio
|
|||
{
|
||||
// 1. If qualifiedName does not match the Name production in XML, then throw an "InvalidCharacterError" DOMException.
|
||||
if (!Document::is_valid_name(name.to_string()))
|
||||
return WebIDL::InvalidCharacterError::create(realm(), "Attribute name must not be empty or contain invalid characters"_fly_string);
|
||||
return WebIDL::InvalidCharacterError::create(realm(), "Attribute name must not be empty or contain invalid characters"_string);
|
||||
|
||||
// 2. If this is in the HTML namespace and its node document is an HTML document, then set qualifiedName to qualifiedName in ASCII lowercase.
|
||||
bool insert_as_lowercase = namespace_uri() == Namespace::HTML && document().document_type() == Document::Type::HTML;
|
||||
|
@ -658,11 +658,11 @@ WebIDL::ExceptionOr<void> Element::attach_a_shadow_root(Bindings::ShadowRootMode
|
|||
{
|
||||
// 1. If element’s namespace is not the HTML namespace, then throw a "NotSupportedError" DOMException.
|
||||
if (namespace_uri() != Namespace::HTML)
|
||||
return WebIDL::NotSupportedError::create(realm(), "Element's namespace is not the HTML namespace"_fly_string);
|
||||
return WebIDL::NotSupportedError::create(realm(), "Element's namespace is not the HTML namespace"_string);
|
||||
|
||||
// 2. If element’s local name is not a valid shadow host name, then throw a "NotSupportedError" DOMException.
|
||||
if (!is_valid_shadow_host_name(local_name()))
|
||||
return WebIDL::NotSupportedError::create(realm(), "Element's local name is not a valid shadow host name"_fly_string);
|
||||
return WebIDL::NotSupportedError::create(realm(), "Element's local name is not a valid shadow host name"_string);
|
||||
|
||||
// 3. If element’s local name is a valid custom element name, or element’s is value is not null, then:
|
||||
if (HTML::is_valid_custom_element_name(local_name()) || m_is_value.has_value()) {
|
||||
|
@ -671,7 +671,7 @@ WebIDL::ExceptionOr<void> Element::attach_a_shadow_root(Bindings::ShadowRootMode
|
|||
|
||||
// 2. If definition is not null and definition’s disable shadow is true, then throw a "NotSupportedError" DOMException.
|
||||
if (definition && definition->disable_shadow())
|
||||
return WebIDL::NotSupportedError::create(realm(), "Cannot attach a shadow root to a custom element that has disabled shadow roots"_fly_string);
|
||||
return WebIDL::NotSupportedError::create(realm(), "Cannot attach a shadow root to a custom element that has disabled shadow roots"_string);
|
||||
}
|
||||
|
||||
// 4. If element is a shadow host, then:
|
||||
|
@ -684,7 +684,7 @@ WebIDL::ExceptionOr<void> Element::attach_a_shadow_root(Bindings::ShadowRootMode
|
|||
// - currentShadowRoot’s mode is not mode,
|
||||
// then throw a "NotSupportedError" DOMException.
|
||||
if (!current_shadow_root->declarative() || current_shadow_root->mode() != mode) {
|
||||
return WebIDL::NotSupportedError::create(realm(), "Element already is a shadow host"_fly_string);
|
||||
return WebIDL::NotSupportedError::create(realm(), "Element already is a shadow host"_string);
|
||||
}
|
||||
|
||||
// 3. Otherwise:
|
||||
|
@ -757,7 +757,7 @@ WebIDL::ExceptionOr<bool> Element::matches(StringView selectors) const
|
|||
|
||||
// 2. If s is failure, then throw a "SyntaxError" DOMException.
|
||||
if (!maybe_selectors.has_value())
|
||||
return WebIDL::SyntaxError::create(realm(), "Failed to parse selector"_fly_string);
|
||||
return WebIDL::SyntaxError::create(realm(), "Failed to parse selector"_string);
|
||||
|
||||
// 3. If the result of match a selector against an element, using s, this, and scoping root this, returns success, then return true; otherwise, return false.
|
||||
auto sel = maybe_selectors.value();
|
||||
|
@ -776,7 +776,7 @@ WebIDL::ExceptionOr<DOM::Element const*> Element::closest(StringView selectors)
|
|||
|
||||
// 2. If s is failure, then throw a "SyntaxError" DOMException.
|
||||
if (!maybe_selectors.has_value())
|
||||
return WebIDL::SyntaxError::create(realm(), "Failed to parse selector"_fly_string);
|
||||
return WebIDL::SyntaxError::create(realm(), "Failed to parse selector"_string);
|
||||
|
||||
auto matches_selectors = [this](CSS::SelectorList const& selector_list, Element const* element) {
|
||||
// 4. For each element in elements, if match a selector against an element, using s, element, and scoping root this, returns success, return element.
|
||||
|
@ -1582,7 +1582,7 @@ WebIDL::ExceptionOr<void> Element::set_outer_html(String const& value)
|
|||
|
||||
// 4. If parent is a Document, throw a "NoModificationAllowedError" DOMException.
|
||||
if (parent->is_document())
|
||||
return WebIDL::NoModificationAllowedError::create(realm(), "Cannot set outer HTML on document"_fly_string);
|
||||
return WebIDL::NoModificationAllowedError::create(realm(), "Cannot set outer HTML on document"_string);
|
||||
|
||||
// 5. If parent is a DocumentFragment, set parent to the result of creating an element given this's node document, body, and the HTML namespace.
|
||||
if (parent->is_document_fragment())
|
||||
|
@ -1613,7 +1613,7 @@ WebIDL::ExceptionOr<void> Element::insert_adjacent_html(String const& position,
|
|||
|
||||
// 2. If context is null or a Document, throw a "NoModificationAllowedError" DOMException.
|
||||
if (!context || context->is_document())
|
||||
return WebIDL::NoModificationAllowedError::create(realm(), "insertAdjacentHTML: context is null or a Document"_fly_string);
|
||||
return WebIDL::NoModificationAllowedError::create(realm(), "insertAdjacentHTML: context is null or a Document"_string);
|
||||
}
|
||||
// - If position is an ASCII case-insensitive match for the string "afterbegin"
|
||||
// - If position is an ASCII case-insensitive match for the string "beforeend"
|
||||
|
@ -1625,7 +1625,7 @@ WebIDL::ExceptionOr<void> Element::insert_adjacent_html(String const& position,
|
|||
// Otherwise
|
||||
else {
|
||||
// Throw a "SyntaxError" DOMException.
|
||||
return WebIDL::SyntaxError::create(realm(), "insertAdjacentHTML: invalid position argument"_fly_string);
|
||||
return WebIDL::SyntaxError::create(realm(), "insertAdjacentHTML: invalid position argument"_string);
|
||||
}
|
||||
|
||||
// 3. If context is not an Element or the following are all true:
|
||||
|
@ -2132,7 +2132,7 @@ JS::ThrowCompletionOr<void> Element::upgrade_element(JS::NonnullGCPtr<HTML::Cust
|
|||
auto attempt_to_construct_custom_element = [&]() -> JS::ThrowCompletionOr<void> {
|
||||
// 1. If definition's disable shadow is true and element's shadow root is non-null, then throw a "NotSupportedError" DOMException.
|
||||
if (custom_element_definition->disable_shadow() && shadow_root())
|
||||
return JS::throw_completion(WebIDL::NotSupportedError::create(realm, "Custom element definition disables shadow DOM and the custom element has a shadow root"_fly_string));
|
||||
return JS::throw_completion(WebIDL::NotSupportedError::create(realm, "Custom element definition disables shadow DOM and the custom element has a shadow root"_string));
|
||||
|
||||
// 2. Set element's custom element state to "precustomized".
|
||||
m_custom_element_state = CustomElementState::Precustomized;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue