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:
Andreas Kling 2024-10-12 20:56:21 +02:00 committed by Andreas Kling
commit 175f3febb8
Notes: github-actions[bot] 2024-10-12 19:15:13 +00:00
89 changed files with 464 additions and 462 deletions

View file

@ -558,11 +558,11 @@ WebIDL::ExceptionOr<void> Document::run_the_document_write_steps(StringView inpu
{
// 1. If document is an XML document, then throw an "InvalidStateError" DOMException.
if (m_type == Type::XML)
return WebIDL::InvalidStateError::create(realm(), "write() called on XML document."_fly_string);
return WebIDL::InvalidStateError::create(realm(), "write() called on XML document."_string);
// 2. If document's throw-on-dynamic-markup-insertion counter is greater than 0, then throw an "InvalidStateError" DOMException.
if (m_throw_on_dynamic_markup_insertion_counter > 0)
return WebIDL::InvalidStateError::create(realm(), "throw-on-dynamic-markup-insertion-counter greater than zero."_fly_string);
return WebIDL::InvalidStateError::create(realm(), "throw-on-dynamic-markup-insertion-counter greater than zero."_string);
// 3. If document's active parser was aborted is true, then return.
if (m_active_parser_was_aborted)
@ -605,18 +605,18 @@ WebIDL::ExceptionOr<Document*> Document::open(Optional<String> const&, Optional<
// 1. If document is an XML document, then throw an "InvalidStateError" DOMException exception.
if (m_type == Type::XML)
return WebIDL::InvalidStateError::create(realm(), "open() called on XML document."_fly_string);
return WebIDL::InvalidStateError::create(realm(), "open() called on XML document."_string);
// 2. If document's throw-on-dynamic-markup-insertion counter is greater than 0, then throw an "InvalidStateError" DOMException.
if (m_throw_on_dynamic_markup_insertion_counter > 0)
return WebIDL::InvalidStateError::create(realm(), "throw-on-dynamic-markup-insertion-counter greater than zero."_fly_string);
return WebIDL::InvalidStateError::create(realm(), "throw-on-dynamic-markup-insertion-counter greater than zero."_string);
// FIXME: 3. Let entryDocument be the entry global object's associated Document.
auto& entry_document = *this;
// 4. If document's origin is not same origin to entryDocument's origin, then throw a "SecurityError" DOMException.
if (origin() != entry_document.origin())
return WebIDL::SecurityError::create(realm(), "Document.origin() not the same as entryDocument's."_fly_string);
return WebIDL::SecurityError::create(realm(), "Document.origin() not the same as entryDocument's."_string);
// 5. If document has an active parser whose script nesting level is greater than 0, then return document.
if (m_parser && m_parser->script_nesting_level() > 0)
@ -676,7 +676,7 @@ WebIDL::ExceptionOr<JS::GCPtr<HTML::WindowProxy>> Document::open(StringView url,
{
// 1. If this is not fully active, then throw an "InvalidAccessError" DOMException exception.
if (!is_fully_active())
return WebIDL::InvalidAccessError::create(realm(), "Cannot perform open on a document that isn't fully active."_fly_string);
return WebIDL::InvalidAccessError::create(realm(), "Cannot perform open on a document that isn't fully active."_string);
// 2. Return the result of running the window open steps with url, name, and features.
return window()->open_impl(url, name, features);
@ -687,11 +687,11 @@ WebIDL::ExceptionOr<void> Document::close()
{
// 1. If document is an XML document, then throw an "InvalidStateError" DOMException exception.
if (m_type == Type::XML)
return WebIDL::InvalidStateError::create(realm(), "close() called on XML document."_fly_string);
return WebIDL::InvalidStateError::create(realm(), "close() called on XML document."_string);
// 2. If document's throw-on-dynamic-markup-insertion counter is greater than 0, then throw an "InvalidStateError" DOMException.
if (m_throw_on_dynamic_markup_insertion_counter > 0)
return WebIDL::InvalidStateError::create(realm(), "throw-on-dynamic-markup-insertion-counter greater than zero."_fly_string);
return WebIDL::InvalidStateError::create(realm(), "throw-on-dynamic-markup-insertion-counter greater than zero."_string);
// 3. If there is no script-created parser associated with the document, then return.
if (!m_parser)
@ -861,7 +861,7 @@ HTML::HTMLElement* Document::body()
WebIDL::ExceptionOr<void> Document::set_body(HTML::HTMLElement* new_body)
{
if (!is<HTML::HTMLBodyElement>(new_body) && !is<HTML::HTMLFrameSetElement>(new_body))
return WebIDL::HierarchyRequestError::create(realm(), "Invalid document body element, must be 'body' or 'frameset'"_fly_string);
return WebIDL::HierarchyRequestError::create(realm(), "Invalid document body element, must be 'body' or 'frameset'"_string);
auto* existing_body = body();
if (existing_body) {
@ -871,7 +871,7 @@ WebIDL::ExceptionOr<void> Document::set_body(HTML::HTMLElement* new_body)
auto* document_element = this->document_element();
if (!document_element)
return WebIDL::HierarchyRequestError::create(realm(), "Missing document element"_fly_string);
return WebIDL::HierarchyRequestError::create(realm(), "Missing document element"_string);
(void)TRY(document_element->append_child(*new_body));
return {};
@ -1650,7 +1650,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> Document::create_element(String c
// 1. If localName does not match the Name production, then throw an "InvalidCharacterError" DOMException.
if (!is_valid_name(a_local_name))
return WebIDL::InvalidCharacterError::create(realm(), "Invalid character in tag name."_fly_string);
return WebIDL::InvalidCharacterError::create(realm(), "Invalid character in tag name."_string);
// 2. If this is an HTML document, then set localName to localName in ASCII lowercase.
if (document_type() == Type::HTML)
@ -1711,11 +1711,11 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<CDATASection>> Document::create_cdata_secti
{
// 1. If this is an HTML document, then throw a "NotSupportedError" DOMException.
if (is_html_document())
return WebIDL::NotSupportedError::create(realm(), "This operation is not supported for HTML documents"_fly_string);
return WebIDL::NotSupportedError::create(realm(), "This operation is not supported for HTML documents"_string);
// 2. If data contains the string "]]>", then throw an "InvalidCharacterError" DOMException.
if (data.contains("]]>"sv))
return WebIDL::InvalidCharacterError::create(realm(), "String may not contain ']]>'"_fly_string);
return WebIDL::InvalidCharacterError::create(realm(), "String may not contain ']]>'"_string);
// 3. Return a new CDATASection node with its data set to data and node document set to this.
return heap().allocate<CDATASection>(realm(), *this, data);
@ -1796,7 +1796,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> Document::create_event(StringView i
// 3. If constructor is null, then throw a "NotSupportedError" DOMException.
if (!event) {
return WebIDL::NotSupportedError::create(realm, "No constructor for interface found"_fly_string);
return WebIDL::NotSupportedError::create(realm, "No constructor for interface found"_string);
}
// FIXME: 4. If the interface indicated by constructor is not exposed on the relevant global object of this, then throw a "NotSupportedError" DOMException.
@ -1877,7 +1877,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> Document::import_node(JS::NonnullGCP
{
// 1. If node is a document or shadow root, then throw a "NotSupportedError" DOMException.
if (is<Document>(*node) || is<ShadowRoot>(*node))
return WebIDL::NotSupportedError::create(realm(), "Cannot import a document or shadow root."_fly_string);
return WebIDL::NotSupportedError::create(realm(), "Cannot import a document or shadow root."_string);
// 2. Return a clone of node, with this and the clone children flag set if deep is true.
return node->clone_node(this, deep);
@ -1951,10 +1951,10 @@ void Document::adopt_node(Node& node)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> Document::adopt_node_binding(JS::NonnullGCPtr<Node> node)
{
if (is<Document>(*node))
return WebIDL::NotSupportedError::create(realm(), "Cannot adopt a document into a document"_fly_string);
return WebIDL::NotSupportedError::create(realm(), "Cannot adopt a document into a document"_string);
if (is<ShadowRoot>(*node))
return WebIDL::HierarchyRequestError::create(realm(), "Cannot adopt a shadow root into a document"_fly_string);
return WebIDL::HierarchyRequestError::create(realm(), "Cannot adopt a shadow root into a document"_string);
if (is<DocumentFragment>(*node) && verify_cast<DocumentFragment>(*node).host())
return node;
@ -2855,7 +2855,7 @@ bool Document::is_valid_name(String const& name)
WebIDL::ExceptionOr<Document::PrefixAndTagName> Document::validate_qualified_name(JS::Realm& realm, FlyString const& qualified_name)
{
if (qualified_name.is_empty())
return WebIDL::InvalidCharacterError::create(realm, "Empty string is not a valid qualified name."_fly_string);
return WebIDL::InvalidCharacterError::create(realm, "Empty string is not a valid qualified name."_string);
auto utf8view = qualified_name.code_points();
@ -2867,19 +2867,19 @@ WebIDL::ExceptionOr<Document::PrefixAndTagName> Document::validate_qualified_nam
auto code_point = *it;
if (code_point == ':') {
if (colon_offset.has_value())
return WebIDL::InvalidCharacterError::create(realm, "More than one colon (:) in qualified name."_fly_string);
return WebIDL::InvalidCharacterError::create(realm, "More than one colon (:) in qualified name."_string);
colon_offset = utf8view.byte_offset_of(it);
at_start_of_name = true;
continue;
}
if (at_start_of_name) {
if (!is_valid_name_start_character(code_point))
return WebIDL::InvalidCharacterError::create(realm, "Invalid start of qualified name."_fly_string);
return WebIDL::InvalidCharacterError::create(realm, "Invalid start of qualified name."_string);
at_start_of_name = false;
continue;
}
if (!is_valid_name_character(code_point))
return WebIDL::InvalidCharacterError::create(realm, "Invalid character in qualified name."_fly_string);
return WebIDL::InvalidCharacterError::create(realm, "Invalid character in qualified name."_string);
}
if (!colon_offset.has_value())
@ -2889,10 +2889,10 @@ WebIDL::ExceptionOr<Document::PrefixAndTagName> Document::validate_qualified_nam
};
if (*colon_offset == 0)
return WebIDL::InvalidCharacterError::create(realm, "Qualified name can't start with colon (:)."_fly_string);
return WebIDL::InvalidCharacterError::create(realm, "Qualified name can't start with colon (:)."_string);
if (*colon_offset >= (qualified_name.bytes_as_string_view().length() - 1))
return WebIDL::InvalidCharacterError::create(realm, "Qualified name can't end with colon (:)."_fly_string);
return WebIDL::InvalidCharacterError::create(realm, "Qualified name can't end with colon (:)."_string);
return Document::PrefixAndTagName {
.prefix = MUST(FlyString::from_utf8(qualified_name.bytes_as_string_view().substring_view(0, *colon_offset))),
@ -3693,7 +3693,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> Document::create_attribute(String co
{
// 1. If localName does not match the Name production in XML, then throw an "InvalidCharacterError" DOMException.
if (!is_valid_name(local_name))
return WebIDL::InvalidCharacterError::create(realm(), "Invalid character in attribute name."_fly_string);
return WebIDL::InvalidCharacterError::create(realm(), "Invalid character in attribute name."_string);
// 2. If this is an HTML document, then set localName to localName in ASCII lowercase.
// 3. Return a new attribute whose local name is localName and node document is this.