1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-10 01:51:03 +09:00

LibWeb: Move DOMException from DOM/ to WebIDL/

This commit is contained in:
Linus Groh 2022-09-25 17:28:46 +01:00
parent ad04d7ac9b
commit bbaa05fcf9
Notes: sideshowbarker 2024-07-17 06:38:09 +09:00
49 changed files with 206 additions and 203 deletions

View file

@ -20,7 +20,6 @@
#include <LibWeb/Cookie/ParsedCookie.h>
#include <LibWeb/DOM/Comment.h>
#include <LibWeb/DOM/CustomEvent.h>
#include <LibWeb/DOM/DOMException.h>
#include <LibWeb/DOM/DOMImplementation.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/DocumentFragment.h>
@ -72,6 +71,7 @@
#include <LibWeb/UIEvents/FocusEvent.h>
#include <LibWeb/UIEvents/KeyboardEvent.h>
#include <LibWeb/UIEvents/MouseEvent.h>
#include <LibWeb/WebIDL/DOMException.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::DOM {
@ -374,11 +374,11 @@ WebIDL::ExceptionOr<void> Document::run_the_document_write_steps(String input)
{
// 1. If document is an XML document, then throw an "InvalidStateError" DOMException.
if (m_type == Type::XML)
return DOM::InvalidStateError::create(global_object(), "write() called on XML document.");
return WebIDL::InvalidStateError::create(global_object(), "write() called on XML document.");
// 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 DOM::InvalidStateError::create(global_object(), "throw-on-dynamic-markup-insertion-counter greater than zero.");
return WebIDL::InvalidStateError::create(global_object(), "throw-on-dynamic-markup-insertion-counter greater than zero.");
// 3. If document's active parser was aborted is true, then return.
if (m_active_parser_was_aborted)
@ -409,18 +409,18 @@ WebIDL::ExceptionOr<Document*> Document::open(String const&, String const&)
{
// 1. If document is an XML document, then throw an "InvalidStateError" DOMException exception.
if (m_type == Type::XML)
return DOM::InvalidStateError::create(global_object(), "open() called on XML document.");
return WebIDL::InvalidStateError::create(global_object(), "open() called on XML document.");
// 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 DOM::InvalidStateError::create(global_object(), "throw-on-dynamic-markup-insertion-counter greater than zero.");
return WebIDL::InvalidStateError::create(global_object(), "throw-on-dynamic-markup-insertion-counter greater than zero.");
// 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 DOM::SecurityError::create(global_object(), "Document.origin() not the same as entryDocument's.");
return WebIDL::SecurityError::create(global_object(), "Document.origin() not the same as entryDocument's.");
// 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)
@ -480,11 +480,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 DOM::InvalidStateError::create(global_object(), "close() called on XML document.");
return WebIDL::InvalidStateError::create(global_object(), "close() called on XML document.");
// 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 DOM::InvalidStateError::create(global_object(), "throw-on-dynamic-markup-insertion-counter greater than zero.");
return WebIDL::InvalidStateError::create(global_object(), "throw-on-dynamic-markup-insertion-counter greater than zero.");
// 3. If there is no script-created parser associated with the document, then return.
if (!m_parser)
@ -588,7 +588,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 DOM::HierarchyRequestError::create(global_object(), "Invalid document body element, must be 'body' or 'frameset'");
return WebIDL::HierarchyRequestError::create(global_object(), "Invalid document body element, must be 'body' or 'frameset'");
auto* existing_body = body();
if (existing_body) {
@ -598,7 +598,7 @@ WebIDL::ExceptionOr<void> Document::set_body(HTML::HTMLElement* new_body)
auto* document_element = this->document_element();
if (!document_element)
return DOM::HierarchyRequestError::create(global_object(), "Missing document element");
return WebIDL::HierarchyRequestError::create(global_object(), "Missing document element");
(void)TRY(document_element->append_child(*new_body));
return {};
@ -1114,7 +1114,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> Document::create_element(FlyStrin
// 1. If localName does not match the Name production, then throw an "InvalidCharacterError" DOMException.
if (!is_valid_name(local_name))
return DOM::InvalidCharacterError::create(global_object(), "Invalid character in tag name.");
return WebIDL::InvalidCharacterError::create(global_object(), "Invalid character in tag name.");
// 2. If this is an HTML document, then set localName to localName in ASCII lowercase.
if (document_type() == Type::HTML)
@ -1219,7 +1219,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> Document::create_event(String const
// 3. If constructor is null, then throw a "NotSupportedError" DOMException.
if (!event) {
return DOM::NotSupportedError::create(global_object(), "No constructor for interface found");
return WebIDL::NotSupportedError::create(global_object(), "No constructor for interface found");
}
// FIXME: 4. If the interface indicated by constructor is not exposed on the relevant global object of this, then throw a "NotSupportedError" DOMException.
@ -1289,7 +1289,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 DOM::NotSupportedError::create(global_object(), "Cannot import a document or shadow root.");
return WebIDL::NotSupportedError::create(global_object(), "Cannot import a document or shadow root.");
// 2. Return a clone of node, with this and the clone children flag set if deep is true.
return node->clone_node(this, deep);
@ -1336,10 +1336,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 DOM::NotSupportedError::create(global_object(), "Cannot adopt a document into a document");
return WebIDL::NotSupportedError::create(global_object(), "Cannot adopt a document into a document");
if (is<ShadowRoot>(*node))
return DOM::HierarchyRequestError::create(global_object(), "Cannot adopt a shadow root into a document");
return WebIDL::HierarchyRequestError::create(global_object(), "Cannot adopt a shadow root into a document");
if (is<DocumentFragment>(*node) && verify_cast<DocumentFragment>(*node).host())
return node;
@ -1801,11 +1801,11 @@ bool Document::is_valid_name(String const& name)
WebIDL::ExceptionOr<Document::PrefixAndTagName> Document::validate_qualified_name(JS::Object& global_object, String const& qualified_name)
{
if (qualified_name.is_empty())
return InvalidCharacterError::create(global_object, "Empty string is not a valid qualified name.");
return WebIDL::InvalidCharacterError::create(global_object, "Empty string is not a valid qualified name.");
Utf8View utf8view { qualified_name };
if (!utf8view.validate())
return InvalidCharacterError::create(global_object, "Invalid qualified name.");
return WebIDL::InvalidCharacterError::create(global_object, "Invalid qualified name.");
Optional<size_t> colon_offset;
@ -1815,19 +1815,19 @@ WebIDL::ExceptionOr<Document::PrefixAndTagName> Document::validate_qualified_nam
auto code_point = *it;
if (code_point == ':') {
if (colon_offset.has_value())
return InvalidCharacterError::create(global_object, "More than one colon (:) in qualified name.");
return WebIDL::InvalidCharacterError::create(global_object, "More than one colon (:) in qualified name.");
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 InvalidCharacterError::create(global_object, "Invalid start of qualified name.");
return WebIDL::InvalidCharacterError::create(global_object, "Invalid start of qualified name.");
at_start_of_name = false;
continue;
}
if (!is_valid_name_character(code_point))
return InvalidCharacterError::create(global_object, "Invalid character in qualified name.");
return WebIDL::InvalidCharacterError::create(global_object, "Invalid character in qualified name.");
}
if (!colon_offset.has_value())
@ -1837,10 +1837,10 @@ WebIDL::ExceptionOr<Document::PrefixAndTagName> Document::validate_qualified_nam
};
if (*colon_offset == 0)
return InvalidCharacterError::create(global_object, "Qualified name can't start with colon (:).");
return WebIDL::InvalidCharacterError::create(global_object, "Qualified name can't start with colon (:).");
if (*colon_offset >= (qualified_name.length() - 1))
return InvalidCharacterError::create(global_object, "Qualified name can't end with colon (:).");
return WebIDL::InvalidCharacterError::create(global_object, "Qualified name can't end with colon (:).");
return Document::PrefixAndTagName {
.prefix = qualified_name.substring_view(0, *colon_offset),