mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:37:35 +00:00
LibWeb: Port DOMException interface from DeprecatedString to String
This commit is contained in:
parent
bcb6851c07
commit
41928c2902
65 changed files with 296 additions and 296 deletions
|
@ -136,7 +136,7 @@ WebIDL::ExceptionOr<void> Element::set_attribute(DeprecatedFlyString const& name
|
|||
// 1. If qualifiedName does not match the Name production in XML, then throw an "InvalidCharacterError" DOMException.
|
||||
// FIXME: Proper name validation
|
||||
if (name.is_empty())
|
||||
return WebIDL::InvalidCharacterError::create(realm(), "Attribute name must not be empty");
|
||||
return WebIDL::InvalidCharacterError::create(realm(), "Attribute name must not be empty"_fly_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.
|
||||
// FIXME: Handle the second condition, assume it is an HTML document for now.
|
||||
|
@ -193,19 +193,19 @@ 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.is_null() && namespace_.is_null())
|
||||
return WebIDL::NamespaceError::create(realm, "Prefix is non-null and namespace is null.");
|
||||
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.
|
||||
if (prefix == "xml"sv && namespace_ != Namespace::XML)
|
||||
return WebIDL::NamespaceError::create(realm, "Prefix is 'xml' and namespace is not the XML namespace.");
|
||||
return WebIDL::NamespaceError::create(realm, "Prefix is 'xml' and namespace is not the XML namespace."_fly_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.");
|
||||
return WebIDL::NamespaceError::create(realm, "Either qualifiedName or prefix is 'xmlns' and namespace is not the XMLNS namespace."_fly_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'.");
|
||||
return WebIDL::NamespaceError::create(realm, "Namespace is the XMLNS namespace and neither qualifiedName nor prefix is 'xmlns'."_fly_string);
|
||||
|
||||
// 10. Return namespace, prefix, and localName.
|
||||
return QualifiedName { local_name, prefix, namespace_ };
|
||||
|
@ -289,7 +289,7 @@ WebIDL::ExceptionOr<bool> Element::toggle_attribute(DeprecatedFlyString const& n
|
|||
// 1. If qualifiedName does not match the Name production in XML, then throw an "InvalidCharacterError" DOMException.
|
||||
// FIXME: Proper name validation
|
||||
if (name.is_empty())
|
||||
return WebIDL::InvalidCharacterError::create(realm(), "Attribute name must not be empty");
|
||||
return WebIDL::InvalidCharacterError::create(realm(), "Attribute name must not be empty"_fly_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.
|
||||
// FIXME: Handle the second condition, assume it is an HTML document for now.
|
||||
|
@ -556,7 +556,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<ShadowRoot>> Element::attach_shadow(ShadowR
|
|||
{
|
||||
// 1. If this’s namespace is not the HTML namespace, then throw a "NotSupportedError" DOMException.
|
||||
if (namespace_() != Namespace::HTML)
|
||||
return WebIDL::NotSupportedError::create(realm(), "Element's namespace is not the HTML namespace"sv);
|
||||
return WebIDL::NotSupportedError::create(realm(), "Element's namespace is not the HTML namespace"_fly_string);
|
||||
|
||||
// 2. If this’s local name is not one of the following:
|
||||
// - a valid custom element name
|
||||
|
@ -564,7 +564,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<ShadowRoot>> Element::attach_shadow(ShadowR
|
|||
if (!HTML::is_valid_custom_element_name(local_name())
|
||||
&& !local_name().is_one_of("article", "aside", "blockquote", "body", "div", "footer", "h1", "h2", "h3", "h4", "h5", "h6", "header", "main", "nav", "p", "section", "span")) {
|
||||
// then throw a "NotSupportedError" DOMException.
|
||||
return WebIDL::NotSupportedError::create(realm(), DeprecatedString::formatted("Element '{}' cannot be a shadow host", local_name()));
|
||||
return WebIDL::NotSupportedError::create(realm(), MUST(String::formatted("Element '{}' cannot be a shadow host", local_name())));
|
||||
}
|
||||
|
||||
// 3. If this’s local name is a valid custom element name, or this’s is value is not null, then:
|
||||
|
@ -574,12 +574,12 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<ShadowRoot>> Element::attach_shadow(ShadowR
|
|||
|
||||
// 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"sv);
|
||||
return WebIDL::NotSupportedError::create(realm(), "Cannot attach a shadow root to a custom element that has disabled shadow roots"_fly_string);
|
||||
}
|
||||
|
||||
// 4. If this is a shadow host, then throw an "NotSupportedError" DOMException.
|
||||
if (is_shadow_host())
|
||||
return WebIDL::NotSupportedError::create(realm(), "Element already is a shadow host");
|
||||
return WebIDL::NotSupportedError::create(realm(), "Element already is a shadow host"_fly_string);
|
||||
|
||||
// 5. Let shadow be a new shadow root whose node document is this’s node document, host is this, and mode is init["mode"].
|
||||
auto shadow = heap().allocate<ShadowRoot>(realm(), document(), *this, init.mode);
|
||||
|
@ -622,7 +622,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");
|
||||
return WebIDL::SyntaxError::create(realm(), "Failed to parse selector"_fly_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();
|
||||
|
@ -641,7 +641,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");
|
||||
return WebIDL::SyntaxError::create(realm(), "Failed to parse selector"_fly_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.
|
||||
|
@ -1308,7 +1308,7 @@ WebIDL::ExceptionOr<void> Element::insert_adjacent_html(DeprecatedString positio
|
|||
|
||||
// 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"sv);
|
||||
return WebIDL::NoModificationAllowedError::create(realm(), "insertAdjacentHTML: context is null or a Document"_fly_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"
|
||||
|
@ -1320,7 +1320,7 @@ WebIDL::ExceptionOr<void> Element::insert_adjacent_html(DeprecatedString positio
|
|||
// Otherwise
|
||||
else {
|
||||
// Throw a "SyntaxError" DOMException.
|
||||
return WebIDL::SyntaxError::create(realm(), "insertAdjacentHTML: invalid position argument"sv);
|
||||
return WebIDL::SyntaxError::create(realm(), "insertAdjacentHTML: invalid position argument"_fly_string);
|
||||
}
|
||||
|
||||
// 2. If context is not an Element or the following are all true:
|
||||
|
@ -1407,7 +1407,7 @@ WebIDL::ExceptionOr<JS::GCPtr<Node>> Element::insert_adjacent(DeprecatedString c
|
|||
|
||||
// -> Otherwise
|
||||
// Throw a "SyntaxError" DOMException.
|
||||
return WebIDL::SyntaxError::create(realm(), DeprecatedString::formatted("Unknown position '{}'. Must be one of 'beforebegin', 'afterbegin', 'beforeend' or 'afterend'"sv, where));
|
||||
return WebIDL::SyntaxError::create(realm(), MUST(String::formatted("Unknown position '{}'. Must be one of 'beforebegin', 'afterbegin', 'beforeend' or 'afterend'"sv, where)));
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-element-insertadjacentelement
|
||||
|
@ -1711,7 +1711,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"sv));
|
||||
return JS::throw_completion(WebIDL::NotSupportedError::create(realm, "Custom element definition disables shadow DOM and the custom element has a shadow root"_fly_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