From bbaa05fcf9a2a7b9515319b102a234be930824cd Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 25 Sep 2022 17:28:46 +0100 Subject: [PATCH] LibWeb: Move DOMException from DOM/ to WebIDL/ --- .../BindingsGenerator/IDLGenerators.cpp | 3 ++ .../LibWeb/Bindings/ExceptionOrUtils.h | 2 +- .../LibWeb/Bindings/LocationObject.cpp | 6 +-- Userland/Libraries/LibWeb/CMakeLists.txt | 2 +- Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp | 6 +-- .../Libraries/LibWeb/CSS/CSSStyleSheet.cpp | 2 +- .../CSS/ResolvedCSSStyleDeclaration.cpp | 4 +- Userland/Libraries/LibWeb/Crypto/Crypto.cpp | 6 +-- .../Libraries/LibWeb/Crypto/SubtleCrypto.cpp | 8 ++-- Userland/Libraries/LibWeb/DOM/AbortSignal.cpp | 2 +- .../Libraries/LibWeb/DOM/CharacterData.cpp | 4 +- .../Libraries/LibWeb/DOM/DOMTokenList.cpp | 6 +-- Userland/Libraries/LibWeb/DOM/Document.cpp | 44 +++++++++---------- Userland/Libraries/LibWeb/DOM/Element.cpp | 22 +++++----- Userland/Libraries/LibWeb/DOM/EventTarget.cpp | 4 +- .../Libraries/LibWeb/DOM/NamedNodeMap.cpp | 4 +- Userland/Libraries/LibWeb/DOM/Node.cpp | 36 +++++++-------- .../Libraries/LibWeb/DOM/NodeIterator.cpp | 2 +- Userland/Libraries/LibWeb/DOM/ParentNode.cpp | 4 +- Userland/Libraries/LibWeb/DOM/Range.cpp | 40 ++++++++--------- Userland/Libraries/LibWeb/DOM/StaticRange.cpp | 4 +- Userland/Libraries/LibWeb/DOM/Text.cpp | 2 +- Userland/Libraries/LibWeb/DOM/TreeWalker.cpp | 4 +- .../LibWeb/DOMParsing/XMLSerializer.cpp | 28 ++++++------ .../Libraries/LibWeb/Encoding/TextDecoder.cpp | 2 +- Userland/Libraries/LibWeb/Forward.h | 2 +- .../Libraries/LibWeb/HTML/BrowsingContext.cpp | 2 +- .../LibWeb/HTML/Canvas/CanvasPath.cpp | 6 +-- .../Libraries/LibWeb/HTML/CanvasGradient.cpp | 4 +- .../LibWeb/HTML/CanvasRenderingContext2D.cpp | 6 +-- .../HTML/CrossOrigin/AbstractOperations.cpp | 8 ++-- .../Libraries/LibWeb/HTML/DOMStringMap.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLElement.cpp | 4 +- .../LibWeb/HTML/HTMLOptionsCollection.cpp | 6 +-- .../LibWeb/HTML/HTMLTableElement.cpp | 8 ++-- .../LibWeb/HTML/HTMLTableSectionElement.cpp | 4 +- Userland/Libraries/LibWeb/HTML/History.cpp | 2 +- .../LibWeb/HTML/Scripting/ClassicScript.cpp | 4 +- Userland/Libraries/LibWeb/HTML/Window.cpp | 2 +- .../Libraries/LibWeb/HTML/WindowProxy.cpp | 8 ++-- Userland/Libraries/LibWeb/HTML/Worker.cpp | 2 +- .../LibWeb/HTML/WorkerGlobalScope.cpp | 6 +-- .../LibWeb/{DOM => WebIDL}/DOMException.cpp | 4 +- .../LibWeb/{DOM => WebIDL}/DOMException.h | 22 +++++----- .../LibWeb/{DOM => WebIDL}/DOMException.idl | 0 .../Libraries/LibWeb/WebIDL/ExceptionOr.h | 16 +++---- .../Libraries/LibWeb/WebSockets/WebSocket.cpp | 14 +++--- .../Libraries/LibWeb/XHR/XMLHttpRequest.cpp | 28 ++++++------ Userland/Libraries/LibWeb/idl_files.cmake | 2 +- 49 files changed, 206 insertions(+), 203 deletions(-) rename Userland/Libraries/LibWeb/{DOM => WebIDL}/DOMException.cpp (94%) rename Userland/Libraries/LibWeb/{DOM => WebIDL}/DOMException.h (93%) rename Userland/Libraries/LibWeb/{DOM => WebIDL}/DOMException.idl (100%) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index 3cc7c80ef9..1c0a902feb 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -2087,6 +2087,7 @@ using namespace Web::Selection; using namespace Web::UIEvents; using namespace Web::XHR; using namespace Web::WebGL; +using namespace Web::WebIDL; namespace Web::Bindings { @@ -2402,6 +2403,7 @@ using namespace Web::URL; using namespace Web::WebSockets; using namespace Web::XHR; using namespace Web::WebGL; +using namespace Web::WebIDL; namespace Web::Bindings { @@ -2843,6 +2845,7 @@ using namespace Web::XHR; using namespace Web::UIEvents; using namespace Web::URL; using namespace Web::WebGL; +using namespace Web::WebIDL; namespace Web::Bindings { diff --git a/Userland/Libraries/LibWeb/Bindings/ExceptionOrUtils.h b/Userland/Libraries/LibWeb/Bindings/ExceptionOrUtils.h index 3f9b5d67ac..57862eaa23 100644 --- a/Userland/Libraries/LibWeb/Bindings/ExceptionOrUtils.h +++ b/Userland/Libraries/LibWeb/Bindings/ExceptionOrUtils.h @@ -73,7 +73,7 @@ ALWAYS_INLINE JS::Completion dom_exception_to_throw_completion(auto&& vm, auto&& VERIFY_NOT_REACHED(); } }, - [&](JS::NonnullGCPtr const& exception) { + [&](JS::NonnullGCPtr const& exception) { return throw_completion(exception); }); } diff --git a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp index c163f375c3..037b7775cc 100644 --- a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp @@ -13,10 +13,10 @@ #include #include #include -#include #include #include #include +#include namespace Web::Bindings { @@ -315,7 +315,7 @@ JS::ThrowCompletionOr LocationObject::internal_define_own_property(JS::Pro } // 2. Throw a "SecurityError" DOMException. - return throw_completion(DOM::SecurityError::create(global_object(), String::formatted("Can't define property '{}' on cross-origin object", property_key))); + return throw_completion(WebIDL::SecurityError::create(global_object(), String::formatted("Can't define property '{}' on cross-origin object", property_key))); } // 7.10.5.7 [[Get]] ( P, Receiver ), https://html.spec.whatwg.org/multipage/history.html#location-get @@ -352,7 +352,7 @@ JS::ThrowCompletionOr LocationObject::internal_delete(JS::PropertyKey cons return JS::Object::internal_delete(property_key); // 2. Throw a "SecurityError" DOMException. - return throw_completion(DOM::SecurityError::create(global_object(), String::formatted("Can't delete property '{}' on cross-origin object", property_key))); + return throw_completion(WebIDL::SecurityError::create(global_object(), String::formatted("Can't delete property '{}' on cross-origin object", property_key))); } // 7.10.5.10 [[OwnPropertyKeys]] ( ), https://html.spec.whatwg.org/multipage/history.html#location-ownpropertykeys diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 73750ce516..fed29efe8e 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -78,7 +78,6 @@ set(SOURCES DOM/Comment.cpp DOM/CustomEvent.cpp DOM/DOMEventListener.cpp - DOM/DOMException.cpp DOM/DOMImplementation.cpp DOM/DOMTokenList.cpp DOM/DOMTokenList.idl @@ -413,6 +412,7 @@ set(SOURCES WebGL/WebGLRenderingContextBase.cpp WebIDL/AbstractOperations.cpp WebIDL/CallbackType.cpp + WebIDL/DOMException.cpp WebIDL/OverloadResolution.cpp WebSockets/WebSocket.cpp XHR/EventNames.cpp diff --git a/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp b/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp index d8da0487a6..b963480450 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp @@ -55,7 +55,7 @@ WebIDL::ExceptionOr CSSRuleList::insert_a_css_rule(Variant length) - return DOM::IndexSizeError::create(global_object(), "CSS rule index out of bounds."); + return WebIDL::IndexSizeError::create(global_object(), "CSS rule index out of bounds."); // 3. Set new rule to the results of performing parse a CSS rule on argument rule. // NOTE: The insert-a-css-rule spec expects `rule` to be a string, but the CSSStyleSheet.insertRule() @@ -72,7 +72,7 @@ WebIDL::ExceptionOr CSSRuleList::insert_a_css_rule(Variant CSSRuleList::remove_a_css_rule(u32 index) // 2. If index is greater than or equal to length, then throw an IndexSizeError exception. if (index >= length) - return DOM::IndexSizeError::create(global_object(), "CSS rule index out of bounds."); + return WebIDL::IndexSizeError::create(global_object(), "CSS rule index out of bounds."); // 3. Set old rule to the indexth item in list. CSSRule& old_rule = m_rules[index]; diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp index ef8a525728..4a781c8377 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp @@ -50,7 +50,7 @@ WebIDL::ExceptionOr CSSStyleSheet::insert_rule(StringView rule, unsign // 4. If parsed rule is a syntax error, return parsed rule. if (!parsed_rule) - return DOM::SyntaxError::create(global_object(), "Unable to parse CSS rule."); + return WebIDL::SyntaxError::create(global_object(), "Unable to parse CSS rule."); // FIXME: 5. If parsed rule is an @import rule, and the constructed flag is set, throw a SyntaxError DOMException. diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp index 61b27774e0..db3bd4f4fa 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -538,14 +538,14 @@ Optional ResolvedCSSStyleDeclaration::property(PropertyID propert WebIDL::ExceptionOr ResolvedCSSStyleDeclaration::set_property(PropertyID, StringView, StringView) { // 1. If the computed flag is set, then throw a NoModificationAllowedError exception. - return DOM::NoModificationAllowedError::create(global_object(), "Cannot modify properties in result of getComputedStyle()"); + return WebIDL::NoModificationAllowedError::create(global_object(), "Cannot modify properties in result of getComputedStyle()"); } // https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-removeproperty WebIDL::ExceptionOr ResolvedCSSStyleDeclaration::remove_property(PropertyID) { // 1. If the computed flag is set, then throw a NoModificationAllowedError exception. - return DOM::NoModificationAllowedError::create(global_object(), "Cannot remove properties from result of getComputedStyle()"); + return WebIDL::NoModificationAllowedError::create(global_object(), "Cannot remove properties from result of getComputedStyle()"); } String ResolvedCSSStyleDeclaration::serialized() const diff --git a/Userland/Libraries/LibWeb/Crypto/Crypto.cpp b/Userland/Libraries/LibWeb/Crypto/Crypto.cpp index aa35018314..a5c0dc17c2 100644 --- a/Userland/Libraries/LibWeb/Crypto/Crypto.cpp +++ b/Userland/Libraries/LibWeb/Crypto/Crypto.cpp @@ -43,16 +43,16 @@ WebIDL::ExceptionOr Crypto::get_random_values(JS::Value array) const { // 1. If array is not an Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, BigInt64Array, or BigUint64Array, then throw a TypeMismatchError and terminate the algorithm. if (!array.is_object() || !(is(array.as_object()) || is(array.as_object()) || is(array.as_object()) || is(array.as_object()) || is(array.as_object()) || is(array.as_object()) || is(array.as_object()) || is(array.as_object()) || is(array.as_object()))) - return DOM::TypeMismatchError::create(global_object(), "array must be one of Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, BigInt64Array, or BigUint64Array"); + return WebIDL::TypeMismatchError::create(global_object(), "array must be one of Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, BigInt64Array, or BigUint64Array"); auto& typed_array = static_cast(array.as_object()); // 2. If the byteLength of array is greater than 65536, throw a QuotaExceededError and terminate the algorithm. if (typed_array.byte_length() > 65536) - return DOM::QuotaExceededError::create(global_object(), "array's byteLength may not be greater than 65536"); + return WebIDL::QuotaExceededError::create(global_object(), "array's byteLength may not be greater than 65536"); // IMPLEMENTATION DEFINED: If the viewed array buffer is detached, throw a InvalidStateError and terminate the algorithm. if (typed_array.viewed_array_buffer()->is_detached()) - return DOM::InvalidStateError::create(global_object(), "array is detached"); + return WebIDL::InvalidStateError::create(global_object(), "array is detached"); // FIXME: Handle SharedArrayBuffers // 3. Overwrite all elements of array with cryptographically strong random values of the appropriate type. diff --git a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp index 893f2557e6..0c67a0bc40 100644 --- a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp +++ b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp @@ -9,8 +9,8 @@ #include #include #include -#include #include +#include namespace Web::Crypto { @@ -37,7 +37,7 @@ JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handlereject(error.ptr()); return promise; @@ -58,7 +58,7 @@ JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handlereject(error.ptr()); return promise; @@ -79,7 +79,7 @@ JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handlereject(error.ptr()); return promise; } diff --git a/Userland/Libraries/LibWeb/DOM/AbortSignal.cpp b/Userland/Libraries/LibWeb/DOM/AbortSignal.cpp index 0822e81a70..80f9f7619f 100644 --- a/Userland/Libraries/LibWeb/DOM/AbortSignal.cpp +++ b/Userland/Libraries/LibWeb/DOM/AbortSignal.cpp @@ -44,7 +44,7 @@ void AbortSignal::signal_abort(JS::Value reason) if (!reason.is_undefined()) m_abort_reason = reason; else - m_abort_reason = AbortError::create(global_object(), "Aborted without reason").ptr(); + m_abort_reason = WebIDL::AbortError::create(global_object(), "Aborted without reason").ptr(); // 3. For each algorithm in signal’s abort algorithms: run algorithm. for (auto& algorithm : m_abort_algorithms) diff --git a/Userland/Libraries/LibWeb/DOM/CharacterData.cpp b/Userland/Libraries/LibWeb/DOM/CharacterData.cpp index a1344ac18b..29b8ed6d63 100644 --- a/Userland/Libraries/LibWeb/DOM/CharacterData.cpp +++ b/Userland/Libraries/LibWeb/DOM/CharacterData.cpp @@ -38,7 +38,7 @@ WebIDL::ExceptionOr CharacterData::substring_data(size_t offset, size_t // 2. If offset is greater than length, then throw an "IndexSizeError" DOMException. if (offset > length) - return DOM::IndexSizeError::create(global_object(), "Substring offset out of range."); + return WebIDL::IndexSizeError::create(global_object(), "Substring offset out of range."); // 3. If offset plus count is greater than length, return a string whose value is the code units from the offsetth code unit // to the end of node’s data, and then return. @@ -57,7 +57,7 @@ WebIDL::ExceptionOr CharacterData::replace_data(size_t offset, size_t coun // 2. If offset is greater than length, then throw an "IndexSizeError" DOMException. if (offset > length) - return DOM::IndexSizeError::create(global_object(), "Replacement offset out of range."); + return WebIDL::IndexSizeError::create(global_object(), "Replacement offset out of range."); // 3. If offset plus count is greater than length, then set count to length minus offset. if (offset + count > length) diff --git a/Userland/Libraries/LibWeb/DOM/DOMTokenList.cpp b/Userland/Libraries/LibWeb/DOM/DOMTokenList.cpp index f448000e9c..11fcdbdc0a 100644 --- a/Userland/Libraries/LibWeb/DOM/DOMTokenList.cpp +++ b/Userland/Libraries/LibWeb/DOM/DOMTokenList.cpp @@ -7,11 +7,11 @@ #include #include -#include #include #include #include #include +#include namespace { @@ -234,9 +234,9 @@ void DOMTokenList::set_value(String value) WebIDL::ExceptionOr DOMTokenList::validate_token(StringView token) const { if (token.is_empty()) - return SyntaxError::create(global_object(), "Non-empty DOM tokens are not allowed"); + return WebIDL::SyntaxError::create(global_object(), "Non-empty DOM tokens are not allowed"); if (any_of(token, is_ascii_space)) - return InvalidCharacterError::create(global_object(), "DOM tokens containing ASCII whitespace are not allowed"); + return WebIDL::InvalidCharacterError::create(global_object(), "DOM tokens containing ASCII whitespace are not allowed"); return {}; } diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 398675eef6..8d2d0b11f3 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -72,6 +71,7 @@ #include #include #include +#include #include namespace Web::DOM { @@ -374,11 +374,11 @@ WebIDL::ExceptionOr 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::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 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 Document::set_body(HTML::HTMLElement* new_body) { if (!is(new_body) && !is(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 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> 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> 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> Document::import_node(JS::NonnullGCP { // 1. If node is a document or shadow root, then throw a "NotSupportedError" DOMException. if (is(*node) || is(*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> Document::adopt_node_binding(JS::NonnullGCPtr node) { if (is(*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(*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(*node) && verify_cast(*node).host()) return node; @@ -1801,11 +1801,11 @@ bool Document::is_valid_name(String const& name) WebIDL::ExceptionOr 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 colon_offset; @@ -1815,19 +1815,19 @@ WebIDL::ExceptionOr 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::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), diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 14d2c5ef37..dd9461e574 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -38,6 +37,7 @@ #include #include #include +#include #include namespace Web::DOM { @@ -87,7 +87,7 @@ WebIDL::ExceptionOr Element::set_attribute(FlyString const& name, String c // 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 InvalidCharacterError::create(global_object(), "Attribute name must not be empty"); + return WebIDL::InvalidCharacterError::create(global_object(), "Attribute name must not be empty"); // 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. @@ -142,19 +142,19 @@ WebIDL::ExceptionOr validate_and_extract(JS::Object& global_objec // 6. If prefix is non-null and namespace is null, then throw a "NamespaceError" DOMException. if (!prefix.is_null() && namespace_.is_null()) - return NamespaceError::create(global_object, "Prefix is non-null and namespace is null."); + return WebIDL::NamespaceError::create(global_object, "Prefix is non-null and namespace is null."); // 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 NamespaceError::create(global_object, "Prefix is 'xml' and namespace is not the XML namespace."); + return WebIDL::NamespaceError::create(global_object, "Prefix is 'xml' and namespace is not the XML namespace."); // 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 NamespaceError::create(global_object, "Either qualifiedName or prefix is 'xmlns' and namespace is not the XMLNS namespace."); + return WebIDL::NamespaceError::create(global_object, "Either qualifiedName or prefix is 'xmlns' and namespace is not the XMLNS namespace."); // 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 NamespaceError::create(global_object, "Namespace is the XMLNS namespace and neither qualifiedName nor prefix is 'xmlns'."); + return WebIDL::NamespaceError::create(global_object, "Namespace is the XMLNS namespace and neither qualifiedName nor prefix is 'xmlns'."); // 10. Return namespace, prefix, and localName. return QualifiedName { local_name, prefix, namespace_ }; @@ -195,7 +195,7 @@ WebIDL::ExceptionOr Element::toggle_attribute(FlyString const& name, Optio // 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 InvalidCharacterError::create(global_object(), "Attribute name must not be empty"); + return WebIDL::InvalidCharacterError::create(global_object(), "Attribute name must not be empty"); // 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. @@ -443,7 +443,7 @@ WebIDL::ExceptionOr Element::matches(StringView selectors) const { auto maybe_selectors = parse_selector(CSS::Parser::ParsingContext(static_cast(const_cast(*this))), selectors); if (!maybe_selectors.has_value()) - return DOM::SyntaxError::create(global_object(), "Failed to parse selector"); + return WebIDL::SyntaxError::create(global_object(), "Failed to parse selector"); auto sel = maybe_selectors.value(); for (auto& s : sel) { @@ -458,7 +458,7 @@ WebIDL::ExceptionOr Element::closest(StringView selectors) { auto maybe_selectors = parse_selector(CSS::Parser::ParsingContext(static_cast(const_cast(*this))), selectors); if (!maybe_selectors.has_value()) - return DOM::SyntaxError::create(global_object(), "Failed to parse selector"); + return WebIDL::SyntaxError::create(global_object(), "Failed to parse selector"); auto matches_selectors = [](CSS::SelectorList const& selector_list, Element const* element) { for (auto& selector : selector_list) { @@ -741,7 +741,7 @@ WebIDL::ExceptionOr Element::insert_adjacent_html(String position, String // If context is null or a Document, throw a "NoModificationAllowedError" DOMException. if (!context || context->is_document()) - return NoModificationAllowedError::create(window(), "insertAdjacentHTML: context is null or a Document"sv); + return WebIDL::NoModificationAllowedError::create(window(), "insertAdjacentHTML: context is null or a Document"sv); } // - If position is an ASCII case-insensitive match for the string "afterbegin" // - If position is an ASCII case-insensitive match for the string "beforeend" @@ -752,7 +752,7 @@ WebIDL::ExceptionOr Element::insert_adjacent_html(String position, String // Otherwise else { // Throw a "SyntaxError" DOMException. - return SyntaxError::create(window(), "insertAdjacentHTML: invalid position argument"sv); + return WebIDL::SyntaxError::create(window(), "insertAdjacentHTML: invalid position argument"sv); } // 2. If context is not an Element or the following are all true: diff --git a/Userland/Libraries/LibWeb/DOM/EventTarget.cpp b/Userland/Libraries/LibWeb/DOM/EventTarget.cpp index 796015167d..df1b6855ef 100644 --- a/Userland/Libraries/LibWeb/DOM/EventTarget.cpp +++ b/Userland/Libraries/LibWeb/DOM/EventTarget.cpp @@ -227,10 +227,10 @@ WebIDL::ExceptionOr EventTarget::dispatch_event_binding(Event& event) { // 1. If event’s dispatch flag is set, or if its initialized flag is not set, then throw an "InvalidStateError" DOMException. if (event.dispatched()) - return DOM::InvalidStateError::create(global_object(), "The event is already being dispatched."); + return WebIDL::InvalidStateError::create(global_object(), "The event is already being dispatched."); if (!event.initialized()) - return DOM::InvalidStateError::create(global_object(), "Cannot dispatch an uninitialized event."); + return WebIDL::InvalidStateError::create(global_object(), "Cannot dispatch an uninitialized event."); // 2. Initialize event’s isTrusted attribute to false. event.set_is_trusted(false); diff --git a/Userland/Libraries/LibWeb/DOM/NamedNodeMap.cpp b/Userland/Libraries/LibWeb/DOM/NamedNodeMap.cpp index 07260e6475..f273a31ea5 100644 --- a/Userland/Libraries/LibWeb/DOM/NamedNodeMap.cpp +++ b/Userland/Libraries/LibWeb/DOM/NamedNodeMap.cpp @@ -93,7 +93,7 @@ WebIDL::ExceptionOr NamedNodeMap::remove_named_item(StringView qual // 2. If attr is null, then throw a "NotFoundError" DOMException. if (!attribute) - return NotFoundError::create(global_object(), String::formatted("Attribute with name '{}' not found", qualified_name)); + return WebIDL::NotFoundError::create(global_object(), String::formatted("Attribute with name '{}' not found", qualified_name)); // 3. Return attr. return nullptr; @@ -137,7 +137,7 @@ WebIDL::ExceptionOr NamedNodeMap::set_attribute(Attr& attribute) { // 1. If attr’s element is neither null nor element, throw an "InUseAttributeError" DOMException. if ((attribute.owner_element() != nullptr) && (attribute.owner_element() != &associated_element())) - return InUseAttributeError::create(global_object(), "Attribute must not already be in use"sv); + return WebIDL::InUseAttributeError::create(global_object(), "Attribute must not already be in use"sv); // 2. Let oldAttr be the result of getting an attribute given attr’s namespace, attr’s local name, and element. // FIXME: When getNamedItemNS is implemented, use that instead. diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index b2d171d2ab..1ff0fae8bb 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -315,24 +315,24 @@ WebIDL::ExceptionOr Node::ensure_pre_insertion_validity(JS::NonnullGCPtr(this) && !is(this) && !is(this)) - return DOM::HierarchyRequestError::create(global_object(), "Can only insert into a document, document fragment or element"); + return WebIDL::HierarchyRequestError::create(global_object(), "Can only insert into a document, document fragment or element"); // 2. If node is a host-including inclusive ancestor of parent, then throw a "HierarchyRequestError" DOMException. if (node->is_host_including_inclusive_ancestor_of(*this)) - return DOM::HierarchyRequestError::create(global_object(), "New node is an ancestor of this node"); + return WebIDL::HierarchyRequestError::create(global_object(), "New node is an ancestor of this node"); // 3. If child is non-null and its parent is not parent, then throw a "NotFoundError" DOMException. if (child && child->parent() != this) - return DOM::NotFoundError::create(global_object(), "This node is not the parent of the given child"); + return WebIDL::NotFoundError::create(global_object(), "This node is not the parent of the given child"); // FIXME: All the following "Invalid node type for insertion" messages could be more descriptive. // 4. If node is not a DocumentFragment, DocumentType, Element, or CharacterData node, then throw a "HierarchyRequestError" DOMException. if (!is(*node) && !is(*node) && !is(*node) && !is(*node) && !is(*node) && !is(*node)) - return DOM::HierarchyRequestError::create(global_object(), "Invalid node type for insertion"); + return WebIDL::HierarchyRequestError::create(global_object(), "Invalid node type for insertion"); // 5. If either node is a Text node and parent is a document, or node is a doctype and parent is not a document, then throw a "HierarchyRequestError" DOMException. if ((is(*node) && is(this)) || (is(*node) && !is(this))) - return DOM::HierarchyRequestError::create(global_object(), "Invalid node type for insertion"); + return WebIDL::HierarchyRequestError::create(global_object(), "Invalid node type for insertion"); // 6. If parent is a document, and any of the statements below, switched on the interface node implements, are true, then throw a "HierarchyRequestError" DOMException. if (is(this)) { @@ -343,18 +343,18 @@ WebIDL::ExceptionOr Node::ensure_pre_insertion_validity(JS::NonnullGCPtr(*node).child_element_count(); if ((node_element_child_count > 1 || node->has_child_of_type()) || (node_element_child_count == 1 && (has_child_of_type() || is(child.ptr()) || (child && child->has_following_node_of_type_in_tree_order())))) { - return DOM::HierarchyRequestError::create(global_object(), "Invalid node type for insertion"); + return WebIDL::HierarchyRequestError::create(global_object(), "Invalid node type for insertion"); } } else if (is(*node)) { // Element // If parent has an element child, child is a doctype, or child is non-null and a doctype is following child. if (has_child_of_type() || is(child.ptr()) || (child && child->has_following_node_of_type_in_tree_order())) - return DOM::HierarchyRequestError::create(global_object(), "Invalid node type for insertion"); + return WebIDL::HierarchyRequestError::create(global_object(), "Invalid node type for insertion"); } else if (is(*node)) { // DocumentType // parent has a doctype child, child is non-null and an element is preceding child, or child is null and parent has an element child. if (has_child_of_type() || (child && child->has_preceding_node_of_type_in_tree_order()) || (!child && has_child_of_type())) - return DOM::HierarchyRequestError::create(global_object(), "Invalid node type for insertion"); + return WebIDL::HierarchyRequestError::create(global_object(), "Invalid node type for insertion"); } } @@ -487,7 +487,7 @@ WebIDL::ExceptionOr> Node::pre_remove(JS::NonnullGCPtrparent() != this) - return DOM::NotFoundError::create(global_object(), "Child does not belong to this node"); + return WebIDL::NotFoundError::create(global_object(), "Child does not belong to this node"); // 2. Remove child. child->remove(); @@ -612,25 +612,25 @@ WebIDL::ExceptionOr> Node::replace_child(JS::NonnullGCPtr { // If parent is not a Document, DocumentFragment, or Element node, then throw a "HierarchyRequestError" DOMException. if (!is(this) && !is(this) && !is(this)) - return DOM::HierarchyRequestError::create(global_object(), "Can only insert into a document, document fragment or element"); + return WebIDL::HierarchyRequestError::create(global_object(), "Can only insert into a document, document fragment or element"); // 2. If node is a host-including inclusive ancestor of parent, then throw a "HierarchyRequestError" DOMException. if (node->is_host_including_inclusive_ancestor_of(*this)) - return DOM::HierarchyRequestError::create(global_object(), "New node is an ancestor of this node"); + return WebIDL::HierarchyRequestError::create(global_object(), "New node is an ancestor of this node"); // 3. If child’s parent is not parent, then throw a "NotFoundError" DOMException. if (child->parent() != this) - return DOM::NotFoundError::create(global_object(), "This node is not the parent of the given child"); + return WebIDL::NotFoundError::create(global_object(), "This node is not the parent of the given child"); // FIXME: All the following "Invalid node type for insertion" messages could be more descriptive. // 4. If node is not a DocumentFragment, DocumentType, Element, or CharacterData node, then throw a "HierarchyRequestError" DOMException. if (!is(*node) && !is(*node) && !is(*node) && !is(*node) && !is(*node) && !is(*node)) - return DOM::HierarchyRequestError::create(global_object(), "Invalid node type for insertion"); + return WebIDL::HierarchyRequestError::create(global_object(), "Invalid node type for insertion"); // 5. If either node is a Text node and parent is a document, or node is a doctype and parent is not a document, then throw a "HierarchyRequestError" DOMException. if ((is(*node) && is(this)) || (is(*node) && !is(this))) - return DOM::HierarchyRequestError::create(global_object(), "Invalid node type for insertion"); + return WebIDL::HierarchyRequestError::create(global_object(), "Invalid node type for insertion"); // If parent is a document, and any of the statements below, switched on the interface node implements, are true, then throw a "HierarchyRequestError" DOMException. if (is(this)) { @@ -641,18 +641,18 @@ WebIDL::ExceptionOr> Node::replace_child(JS::NonnullGCPtr auto node_element_child_count = verify_cast(*node).child_element_count(); if ((node_element_child_count > 1 || node->has_child_of_type()) || (node_element_child_count == 1 && (first_child_of_type() != child || child->has_following_node_of_type_in_tree_order()))) { - return DOM::HierarchyRequestError::create(global_object(), "Invalid node type for insertion"); + return WebIDL::HierarchyRequestError::create(global_object(), "Invalid node type for insertion"); } } else if (is(*node)) { // Element // parent has an element child that is not child or a doctype is following child. if (first_child_of_type() != child || child->has_following_node_of_type_in_tree_order()) - return DOM::HierarchyRequestError::create(global_object(), "Invalid node type for insertion"); + return WebIDL::HierarchyRequestError::create(global_object(), "Invalid node type for insertion"); } else if (is(*node)) { // DocumentType // parent has a doctype child that is not child, or an element is preceding child. if (first_child_of_type() != node || child->has_preceding_node_of_type_in_tree_order()) - return DOM::HierarchyRequestError::create(global_object(), "Invalid node type for insertion"); + return WebIDL::HierarchyRequestError::create(global_object(), "Invalid node type for insertion"); } } @@ -796,7 +796,7 @@ WebIDL::ExceptionOr> Node::clone_node_binding(bool deep) { // 1. If this is a shadow root, then throw a "NotSupportedError" DOMException. if (is(*this)) - return NotSupportedError::create(global_object(), "Cannot clone shadow root"); + return WebIDL::NotSupportedError::create(global_object(), "Cannot clone shadow root"); // 2. Return a clone of this, with the clone children flag set if deep is true. return clone_node(nullptr, deep); diff --git a/Userland/Libraries/LibWeb/DOM/NodeIterator.cpp b/Userland/Libraries/LibWeb/DOM/NodeIterator.cpp index 57abeefca1..db2cb941fa 100644 --- a/Userland/Libraries/LibWeb/DOM/NodeIterator.cpp +++ b/Userland/Libraries/LibWeb/DOM/NodeIterator.cpp @@ -130,7 +130,7 @@ JS::ThrowCompletionOr NodeIterator::filter(Node& node) { // 1. If traverser’s active flag is set, then throw an "InvalidStateError" DOMException. if (m_active) - return throw_completion(InvalidStateError::create(global_object(), "NodeIterator is already active")); + return throw_completion(WebIDL::InvalidStateError::create(global_object(), "NodeIterator is already active")); // 2. Let n be node’s nodeType attribute value − 1. auto n = node.node_type() - 1; diff --git a/Userland/Libraries/LibWeb/DOM/ParentNode.cpp b/Userland/Libraries/LibWeb/DOM/ParentNode.cpp index a388db88c1..24f82d4439 100644 --- a/Userland/Libraries/LibWeb/DOM/ParentNode.cpp +++ b/Userland/Libraries/LibWeb/DOM/ParentNode.cpp @@ -22,7 +22,7 @@ WebIDL::ExceptionOr> ParentNode::query_selector(StringView se { auto maybe_selectors = parse_selector(CSS::Parser::ParsingContext(*this), selector_text); if (!maybe_selectors.has_value()) - return DOM::SyntaxError::create(global_object(), "Failed to parse selector"); + return WebIDL::SyntaxError::create(global_object(), "Failed to parse selector"); auto selectors = maybe_selectors.value(); @@ -45,7 +45,7 @@ WebIDL::ExceptionOr> ParentNode::query_selector_all(S { auto maybe_selectors = parse_selector(CSS::Parser::ParsingContext(*this), selector_text); if (!maybe_selectors.has_value()) - return DOM::SyntaxError::create(global_object(), "Failed to parse selector"); + return WebIDL::SyntaxError::create(global_object(), "Failed to parse selector"); auto selectors = maybe_selectors.value(); diff --git a/Userland/Libraries/LibWeb/DOM/Range.cpp b/Userland/Libraries/LibWeb/DOM/Range.cpp index 3853c92699..7c0ae951e0 100644 --- a/Userland/Libraries/LibWeb/DOM/Range.cpp +++ b/Userland/Libraries/LibWeb/DOM/Range.cpp @@ -137,11 +137,11 @@ WebIDL::ExceptionOr Range::set_start_or_end(Node& node, u32 offset, StartO // 1. If node is a doctype, then throw an "InvalidNodeTypeError" DOMException. if (is(node)) - return InvalidNodeTypeError::create(global_object(), "Node cannot be a DocumentType."); + return WebIDL::InvalidNodeTypeError::create(global_object(), "Node cannot be a DocumentType."); // 2. If offset is greater than node’s length, then throw an "IndexSizeError" DOMException. if (offset > node.length()) - return IndexSizeError::create(global_object(), String::formatted("Node does not contain a child at offset {}", offset)); + return WebIDL::IndexSizeError::create(global_object(), String::formatted("Node does not contain a child at offset {}", offset)); // 3. Let bp be the boundary point (node, offset). @@ -196,7 +196,7 @@ WebIDL::ExceptionOr Range::set_start_before(Node& node) // 2. If parent is null, then throw an "InvalidNodeTypeError" DOMException. if (!parent) - return InvalidNodeTypeError::create(global_object(), "Given node has no parent."); + return WebIDL::InvalidNodeTypeError::create(global_object(), "Given node has no parent."); // 3. Set the start of this to boundary point (parent, node’s index). return set_start_or_end(*parent, node.index(), StartOrEnd::Start); @@ -210,7 +210,7 @@ WebIDL::ExceptionOr Range::set_start_after(Node& node) // 2. If parent is null, then throw an "InvalidNodeTypeError" DOMException. if (!parent) - return InvalidNodeTypeError::create(global_object(), "Given node has no parent."); + return WebIDL::InvalidNodeTypeError::create(global_object(), "Given node has no parent."); // 3. Set the start of this to boundary point (parent, node’s index plus 1). return set_start_or_end(*parent, node.index() + 1, StartOrEnd::Start); @@ -224,7 +224,7 @@ WebIDL::ExceptionOr Range::set_end_before(Node& node) // 2. If parent is null, then throw an "InvalidNodeTypeError" DOMException. if (!parent) - return InvalidNodeTypeError::create(global_object(), "Given node has no parent."); + return WebIDL::InvalidNodeTypeError::create(global_object(), "Given node has no parent."); // 3. Set the end of this to boundary point (parent, node’s index). return set_start_or_end(*parent, node.index(), StartOrEnd::End); @@ -238,7 +238,7 @@ WebIDL::ExceptionOr Range::set_end_after(Node& node) // 2. If parent is null, then throw an "InvalidNodeTypeError" DOMException. if (!parent) - return InvalidNodeTypeError::create(global_object(), "Given node has no parent."); + return WebIDL::InvalidNodeTypeError::create(global_object(), "Given node has no parent."); // 3. Set the end of this to boundary point (parent, node’s index plus 1). return set_start_or_end(*parent, node.index() + 1, StartOrEnd::End); @@ -254,11 +254,11 @@ WebIDL::ExceptionOr Range::compare_boundary_points(u16 how, Range const& so // - END_TO_START, // then throw a "NotSupportedError" DOMException. if (how != HowToCompareBoundaryPoints::START_TO_START && how != HowToCompareBoundaryPoints::START_TO_END && how != HowToCompareBoundaryPoints::END_TO_END && how != HowToCompareBoundaryPoints::END_TO_START) - return NotSupportedError::create(global_object(), String::formatted("Expected 'how' to be one of START_TO_START (0), START_TO_END (1), END_TO_END (2) or END_TO_START (3), got {}", how)); + return WebIDL::NotSupportedError::create(global_object(), String::formatted("Expected 'how' to be one of START_TO_START (0), START_TO_END (1), END_TO_END (2) or END_TO_START (3), got {}", how)); // 2. If this’s root is not the same as sourceRange’s root, then throw a "WrongDocumentError" DOMException. if (&root() != &source_range.root()) - return WrongDocumentError::create(global_object(), "This range is not in the same tree as the source range."); + return WebIDL::WrongDocumentError::create(global_object(), "This range is not in the same tree as the source range."); JS::GCPtr this_point_node; u32 this_point_offset = 0; @@ -339,7 +339,7 @@ WebIDL::ExceptionOr Range::select(Node& node) // 2. If parent is null, then throw an "InvalidNodeTypeError" DOMException. if (!parent) - return InvalidNodeTypeError::create(global_object(), "Given node has no parent."); + return WebIDL::InvalidNodeTypeError::create(global_object(), "Given node has no parent."); // 3. Let index be node’s index. auto index = node.index(); @@ -381,7 +381,7 @@ WebIDL::ExceptionOr Range::select_node_contents(Node const& node) { // 1. If node is a doctype, throw an "InvalidNodeTypeError" DOMException. if (is(node)) - return InvalidNodeTypeError::create(global_object(), "Node cannot be a DocumentType."); + return WebIDL::InvalidNodeTypeError::create(global_object(), "Node cannot be a DocumentType."); // 2. Let length be the length of node. auto length = node.length(); @@ -474,11 +474,11 @@ WebIDL::ExceptionOr Range::is_point_in_range(Node const& node, u32 offset) // 2. If node is a doctype, then throw an "InvalidNodeTypeError" DOMException. if (is(node)) - return InvalidNodeTypeError::create(global_object(), "Node cannot be a DocumentType."); + return WebIDL::InvalidNodeTypeError::create(global_object(), "Node cannot be a DocumentType."); // 3. If offset is greater than node’s length, then throw an "IndexSizeError" DOMException. if (offset > node.length()) - return IndexSizeError::create(global_object(), String::formatted("Node does not contain a child at offset {}", offset)); + return WebIDL::IndexSizeError::create(global_object(), String::formatted("Node does not contain a child at offset {}", offset)); // 4. If (node, offset) is before start or after end, return false. auto relative_position_to_start = position_of_boundary_point_relative_to_other_boundary_point(node, offset, m_start_container, m_start_offset); @@ -495,15 +495,15 @@ WebIDL::ExceptionOr Range::compare_point(Node const& node, u32 offset) cons { // 1. If node’s root is different from this’s root, then throw a "WrongDocumentError" DOMException. if (&node.root() != &root()) - return WrongDocumentError::create(global_object(), "Given node is not in the same document as the range."); + return WebIDL::WrongDocumentError::create(global_object(), "Given node is not in the same document as the range."); // 2. If node is a doctype, then throw an "InvalidNodeTypeError" DOMException. if (is(node)) - return InvalidNodeTypeError::create(global_object(), "Node cannot be a DocumentType."); + return WebIDL::InvalidNodeTypeError::create(global_object(), "Node cannot be a DocumentType."); // 3. If offset is greater than node’s length, then throw an "IndexSizeError" DOMException. if (offset > node.length()) - return IndexSizeError::create(global_object(), String::formatted("Node does not contain a child at offset {}", offset)); + return WebIDL::IndexSizeError::create(global_object(), String::formatted("Node does not contain a child at offset {}", offset)); // 4. If (node, offset) is before start, return −1. auto relative_position_to_start = position_of_boundary_point_relative_to_other_boundary_point(node, offset, m_start_container, m_start_offset); @@ -636,7 +636,7 @@ WebIDL::ExceptionOr> Range::extract() // 12. If any member of contained children is a doctype, then throw a "HierarchyRequestError" DOMException. for (auto const& child : contained_children) { if (is(*child)) - return DOM::HierarchyRequestError::create(global_object(), "Contained child is a DocumentType"); + return WebIDL::HierarchyRequestError::create(global_object(), "Contained child is a DocumentType"); } JS::GCPtr new_node; @@ -783,7 +783,7 @@ WebIDL::ExceptionOr Range::insert(JS::NonnullGCPtr node) if ((is(*m_start_container) || is(*m_start_container)) || (is(*m_start_container) && !m_start_container->parent_node()) || m_start_container.ptr() == node.ptr()) { - return DOM::HierarchyRequestError::create(global_object(), "Range has inappropriate start node for insertion"); + return WebIDL::HierarchyRequestError::create(global_object(), "Range has inappropriate start node for insertion"); } // 2. Let referenceNode be null. @@ -854,11 +854,11 @@ WebIDL::ExceptionOr Range::surround_contents(JS::NonnullGCPtr new_pa if (is(*end_non_text_node)) end_non_text_node = end_non_text_node->parent_node(); if (start_non_text_node != end_non_text_node) - return InvalidStateError::create(global_object(), "Non-Text node is partially contained in range."); + return WebIDL::InvalidStateError::create(global_object(), "Non-Text node is partially contained in range."); // 2. If newParent is a Document, DocumentType, or DocumentFragment node, then throw an "InvalidNodeTypeError" DOMException. if (is(*new_parent) || is(*new_parent) || is(*new_parent)) - return InvalidNodeTypeError::create(global_object(), "Invalid parent node type"); + return WebIDL::InvalidNodeTypeError::create(global_object(), "Invalid parent node type"); // 3. Let fragment be the result of extracting this. auto fragment = TRY(extract()); @@ -962,7 +962,7 @@ WebIDL::ExceptionOr> Range::clone_the_content // 12. If any member of contained children is a doctype, then throw a "HierarchyRequestError" DOMException. for (auto const& child : contained_children) { if (is(*child)) - return DOM::HierarchyRequestError::create(global_object(), "Contained child is a DocumentType"); + return WebIDL::HierarchyRequestError::create(global_object(), "Contained child is a DocumentType"); } // 13. If first partially contained child is a CharacterData node, then: diff --git a/Userland/Libraries/LibWeb/DOM/StaticRange.cpp b/Userland/Libraries/LibWeb/DOM/StaticRange.cpp index 332007fda9..68c0ada312 100644 --- a/Userland/Libraries/LibWeb/DOM/StaticRange.cpp +++ b/Userland/Libraries/LibWeb/DOM/StaticRange.cpp @@ -27,10 +27,10 @@ WebIDL::ExceptionOr StaticRange::create_with_global_object(HTML::W { // 1. If init["startContainer"] or init["endContainer"] is a DocumentType or Attr node, then throw an "InvalidNodeTypeError" DOMException. if (is(*init.start_container) || is(*init.start_container)) - return DOM::InvalidNodeTypeError::create(window, "startContainer cannot be a DocumentType or Attribute node."); + return WebIDL::InvalidNodeTypeError::create(window, "startContainer cannot be a DocumentType or Attribute node."); if (is(*init.end_container) || is(*init.end_container)) - return DOM::InvalidNodeTypeError::create(window, "endContainer cannot be a DocumentType or Attribute node."); + return WebIDL::InvalidNodeTypeError::create(window, "endContainer cannot be a DocumentType or Attribute node."); // 2. Set this’s start to (init["startContainer"], init["startOffset"]) and end to (init["endContainer"], init["endOffset"]). return window.heap().allocate(window.realm(), *init.start_container, init.start_offset, *init.end_container, init.end_offset); diff --git a/Userland/Libraries/LibWeb/DOM/Text.cpp b/Userland/Libraries/LibWeb/DOM/Text.cpp index 65bae6668e..afc7c773b1 100644 --- a/Userland/Libraries/LibWeb/DOM/Text.cpp +++ b/Userland/Libraries/LibWeb/DOM/Text.cpp @@ -50,7 +50,7 @@ WebIDL::ExceptionOr> Text::split_text(size_t offset) // 2. If offset is greater than length, then throw an "IndexSizeError" DOMException. if (offset > length) - return DOM::IndexSizeError::create(global_object(), "Split offset is greater than length"); + return WebIDL::IndexSizeError::create(global_object(), "Split offset is greater than length"); // 3. Let count be length minus offset. auto count = length - offset; diff --git a/Userland/Libraries/LibWeb/DOM/TreeWalker.cpp b/Userland/Libraries/LibWeb/DOM/TreeWalker.cpp index 309f5a55fc..e01b6bd678 100644 --- a/Userland/Libraries/LibWeb/DOM/TreeWalker.cpp +++ b/Userland/Libraries/LibWeb/DOM/TreeWalker.cpp @@ -4,12 +4,12 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include #include #include #include #include #include +#include namespace Web::DOM { @@ -231,7 +231,7 @@ JS::ThrowCompletionOr TreeWalker::filter(Node& node) { // 1. If traverser’s active flag is set, then throw an "InvalidStateError" DOMException. if (m_active) - return throw_completion(InvalidStateError::create(global_object(), "NodeIterator is already active")); + return throw_completion(WebIDL::InvalidStateError::create(global_object(), "NodeIterator is already active")); // 2. Let n be node’s nodeType attribute value − 1. auto n = node.node_type() - 1; diff --git a/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.cpp b/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.cpp index 52055c260f..7dfe2a0987 100644 --- a/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.cpp +++ b/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.cpp @@ -331,7 +331,7 @@ static WebIDL::ExceptionOr serialize_element_attributes(DOM::Element con }); if (local_name_set_iterator != local_name_set.end()) - return DOM::InvalidStateError::create(global_object, "Element contains two attributes with identical namespaces and local names"); + return WebIDL::InvalidStateError::create(global_object, "Element contains two attributes with identical namespaces and local names"); } // 2. Create a new tuple consisting of attr's namespaceURI attribute and localName attribute, and add it to the localname set. @@ -384,12 +384,12 @@ static WebIDL::ExceptionOr serialize_element_attributes(DOM::Element con // 2. If the require well-formed flag is set (its value is true), and the value of attr's value attribute matches the XMLNS namespace, // then throw an exception; the serialization of this attribute would produce invalid XML because the XMLNS namespace is reserved and cannot be applied as an element's namespace via XML parsing. if (require_well_formed == RequireWellFormed::Yes && attribute->value() == Namespace::XMLNS) - return DOM::InvalidStateError::create(global_object, "The XMLNS namespace cannot be used as an element's namespace"); + return WebIDL::InvalidStateError::create(global_object, "The XMLNS namespace cannot be used as an element's namespace"); // 3. If the require well-formed flag is set (its value is true), and the value of attr's value attribute is the empty string, // then throw an exception; namespace prefix declarations cannot be used to undeclare a namespace (use a default namespace declaration instead). if (require_well_formed == RequireWellFormed::Yes && attribute->value().is_empty()) - return DOM::InvalidStateError::create(global_object, "Attribute's value is empty"); + return WebIDL::InvalidStateError::create(global_object, "Attribute's value is empty"); // 4. [If] the attr's prefix matches the string "xmlns", then let candidate prefix be the string "xmlns". if (attribute->prefix() == "xmlns"sv) @@ -432,12 +432,12 @@ static WebIDL::ExceptionOr serialize_element_attributes(DOM::Element con // or does not match the XML Name production or equals "xmlns" and attribute namespace is null, then throw an exception; the serialization of this attr would not be a well-formed attribute. if (require_well_formed == RequireWellFormed::Yes) { if (attribute->local_name().view().contains(':')) - return DOM::InvalidStateError::create(global_object, "Attribute's local name contains a colon"); + return WebIDL::InvalidStateError::create(global_object, "Attribute's local name contains a colon"); // FIXME: Check attribute's local name against the XML Name production. if (attribute->local_name() == "xmlns"sv && attribute_namespace.is_null()) - return DOM::InvalidStateError::create(global_object, "Attribute's local name is 'xmlns' and the attribute has no namespace"); + return WebIDL::InvalidStateError::create(global_object, "Attribute's local name is 'xmlns' and the attribute has no namespace"); } // 9. Append the following strings to result, in the order listed: @@ -467,7 +467,7 @@ static WebIDL::ExceptionOr serialize_element(DOM::Element const& element // then throw an exception; the serialization of this node would not be a well-formed element. if (require_well_formed == RequireWellFormed::Yes) { if (element.local_name().view().contains(':')) - return DOM::InvalidStateError::create(global_object, "Element's local name contains a colon"); + return WebIDL::InvalidStateError::create(global_object, "Element's local name contains a colon"); // FIXME: Check element's local name against the XML Char production. } @@ -539,7 +539,7 @@ static WebIDL::ExceptionOr serialize_element(DOM::Element const& element if (prefix == "xmlns"sv) { // 1. If the require well-formed flag is set, then throw an error. An Element with prefix "xmlns" will not legally round-trip in a conforming XML parser. if (require_well_formed == RequireWellFormed::Yes) - return DOM::InvalidStateError::create(global_object, "Elements prefix is 'xmlns'"); + return WebIDL::InvalidStateError::create(global_object, "Elements prefix is 'xmlns'"); // 2. Let candidate prefix be the value of prefix. candidate_prefix = prefix; @@ -706,7 +706,7 @@ static WebIDL::ExceptionOr serialize_document(DOM::Document const& docum // If the require well-formed flag is set (its value is true), and this node has no documentElement (the documentElement attribute's value is null), // then throw an exception; the serialization of this node would not be a well-formed document. if (require_well_formed == RequireWellFormed::Yes && !document.document_element()) - return DOM::InvalidStateError::create(document.global_object(), "Document has no document element"); + return WebIDL::InvalidStateError::create(document.global_object(), "Document has no document element"); // Otherwise, run the following steps: // 1. Let serialized document be an empty string. @@ -730,10 +730,10 @@ static WebIDL::ExceptionOr serialize_comment(DOM::Comment const& comment // FIXME: Check comment's data against the XML Char production. if (comment.data().contains("--"sv)) - return DOM::InvalidStateError::create(comment.global_object(), "Comment data contains two adjacent hyphens"); + return WebIDL::InvalidStateError::create(comment.global_object(), "Comment data contains two adjacent hyphens"); if (comment.data().ends_with('-')) - return DOM::InvalidStateError::create(comment.global_object(), "Comment data ends with a hyphen"); + return WebIDL::InvalidStateError::create(comment.global_object(), "Comment data ends with a hyphen"); } // Otherwise, return the concatenation of "". @@ -788,7 +788,7 @@ static WebIDL::ExceptionOr serialize_document_type(DOM::DocumentType con // both a """ (U+0022 QUOTATION MARK) and a "'" (U+0027 APOSTROPHE), then throw an exception; the serialization of this node would not be a well-formed document type declaration. // FIXME: Check systemId against the XML Char production. if (document_type.system_id().contains('"') && document_type.system_id().contains('\'')) - return DOM::InvalidStateError::create(document_type.global_object(), "Document type system ID contains both a quotation mark and an apostrophe"); + return WebIDL::InvalidStateError::create(document_type.global_object(), "Document type system ID contains both a quotation mark and an apostrophe"); } // 3. Let markup be an empty string. @@ -850,16 +850,16 @@ static WebIDL::ExceptionOr serialize_processing_instruction(DOM::Process // 1. If the require well-formed flag is set (its value is true), and node's target contains a ":" (U+003A COLON) character // or is an ASCII case-insensitive match for the string "xml", then throw an exception; the serialization of this node's target would not be well-formed. if (processing_instruction.target().contains(':')) - return DOM::InvalidStateError::create(processing_instruction.global_object(), "Processing instruction target contains a colon"); + return WebIDL::InvalidStateError::create(processing_instruction.global_object(), "Processing instruction target contains a colon"); if (processing_instruction.target().equals_ignoring_case("xml"sv)) - return DOM::InvalidStateError::create(processing_instruction.global_object(), "Processing instruction target is equal to 'xml'"); + return WebIDL::InvalidStateError::create(processing_instruction.global_object(), "Processing instruction target is equal to 'xml'"); // 2. If the require well-formed flag is set (its value is true), and node's data contains characters that are not matched by the XML Char production or contains // the string "?>" (U+003F QUESTION MARK, U+003E GREATER-THAN SIGN), then throw an exception; the serialization of this node's data would not be well-formed. // FIXME: Check data against the XML Char production. if (processing_instruction.data().contains("?>"sv)) - return DOM::InvalidStateError::create(processing_instruction.global_object(), "Processing instruction data contains a terminator"); + return WebIDL::InvalidStateError::create(processing_instruction.global_object(), "Processing instruction data contains a terminator"); } // 3. Let markup be the concatenation of the following, in the order listed: diff --git a/Userland/Libraries/LibWeb/Encoding/TextDecoder.cpp b/Userland/Libraries/LibWeb/Encoding/TextDecoder.cpp index 99e9e896d2..5301470c46 100644 --- a/Userland/Libraries/LibWeb/Encoding/TextDecoder.cpp +++ b/Userland/Libraries/LibWeb/Encoding/TextDecoder.cpp @@ -41,7 +41,7 @@ WebIDL::ExceptionOr TextDecoder::decode(JS::Handle const& in auto data_buffer_or_error = WebIDL::get_buffer_source_copy(*input.cell()); if (data_buffer_or_error.is_error()) - return DOM::OperationError::create(global_object(), "Failed to copy bytes from ArrayBuffer"); + return WebIDL::OperationError::create(global_object(), "Failed to copy bytes from ArrayBuffer"); auto& data_buffer = data_buffer_or_error.value(); return m_decoder.to_utf8({ data_buffer.data(), data_buffer.size() }); } diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 465a9343bb..3345a23fbb 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -140,7 +140,6 @@ class DocumentFragment; class DocumentLoadEventDelayer; class DocumentType; class DOMEventListener; -class DOMException; class DOMImplementation; class DOMTokenList; class Element; @@ -394,6 +393,7 @@ class SVGSVGElement; namespace Web::WebIDL { class CallbackType; +class DOMException; template class ExceptionOr; diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp index 416ca237be..d3c3af2ab2 100644 --- a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp +++ b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp @@ -881,7 +881,7 @@ WebIDL::ExceptionOr BrowsingContext::navigate( // 1. If exceptionsEnabled is given and is true, then throw a "SecurityError" DOMException. if (exceptions_enabled) { VERIFY(source_browsing_context.active_document()); - return DOM::SecurityError::create(source_browsing_context.active_document()->global_object(), "Source browsing context not allowed to navigate"sv); + return WebIDL::SecurityError::create(source_browsing_context.active_document()->global_object(), "Source browsing context not allowed to navigate"sv); } // FIXME: 2. Otherwise, the user agent may instead offer to open resource in a new top-level browsing context diff --git a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasPath.cpp b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasPath.cpp index d2460f7fad..7964d954c2 100644 --- a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasPath.cpp +++ b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasPath.cpp @@ -39,17 +39,17 @@ void CanvasPath::bezier_curve_to(double cp1x, double cp1y, double cp2x, double c WebIDL::ExceptionOr CanvasPath::arc(float x, float y, float radius, float start_angle, float end_angle, bool counter_clockwise) { if (radius < 0) - return DOM::IndexSizeError::create(m_self.global_object(), String::formatted("The radius provided ({}) is negative.", radius)); + return WebIDL::IndexSizeError::create(m_self.global_object(), String::formatted("The radius provided ({}) is negative.", radius)); return ellipse(x, y, radius, radius, 0, start_angle, end_angle, counter_clockwise); } WebIDL::ExceptionOr CanvasPath::ellipse(float x, float y, float radius_x, float radius_y, float rotation, float start_angle, float end_angle, bool counter_clockwise) { if (radius_x < 0) - return DOM::IndexSizeError::create(m_self.global_object(), String::formatted("The major-axis radius provided ({}) is negative.", radius_x)); + return WebIDL::IndexSizeError::create(m_self.global_object(), String::formatted("The major-axis radius provided ({}) is negative.", radius_x)); if (radius_y < 0) - return DOM::IndexSizeError::create(m_self.global_object(), String::formatted("The minor-axis radius provided ({}) is negative.", radius_y)); + return WebIDL::IndexSizeError::create(m_self.global_object(), String::formatted("The minor-axis radius provided ({}) is negative.", radius_y)); if (constexpr float tau = M_TAU; (!counter_clockwise && (end_angle - start_angle) >= tau) || (counter_clockwise && (start_angle - end_angle) >= tau)) { diff --git a/Userland/Libraries/LibWeb/HTML/CanvasGradient.cpp b/Userland/Libraries/LibWeb/HTML/CanvasGradient.cpp index e0e0b398c4..49f80af456 100644 --- a/Userland/Libraries/LibWeb/HTML/CanvasGradient.cpp +++ b/Userland/Libraries/LibWeb/HTML/CanvasGradient.cpp @@ -53,14 +53,14 @@ WebIDL::ExceptionOr CanvasGradient::add_color_stop(double offset, String c { // 1. If the offset is less than 0 or greater than 1, then throw an "IndexSizeError" DOMException. if (offset < 0 || offset > 1) - return DOM::IndexSizeError::create(global_object(), "CanvasGradient color stop offset out of bounds"); + return WebIDL::IndexSizeError::create(global_object(), "CanvasGradient color stop offset out of bounds"); // 2. Let parsed color be the result of parsing color. auto parsed_color = Color::from_string(color); // 3. If parsed color is failure, throw a "SyntaxError" DOMException. if (!parsed_color.has_value()) - return DOM::SyntaxError::create(global_object(), "Could not parse color for CanvasGradient"); + return WebIDL::SyntaxError::create(global_object(), "Could not parse color for CanvasGradient"); // 4. Place a new stop on the gradient, at offset offset relative to the whole gradient, and with the color parsed color. m_color_stops.append(ColorStop { offset, parsed_color.value() }); diff --git a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp index 2b086edf05..d7381dab17 100644 --- a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp +++ b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp @@ -275,11 +275,11 @@ WebIDL::ExceptionOr> CanvasRenderingContext2D::get_image_da { // 1. If either the sw or sh arguments are zero, then throw an "IndexSizeError" DOMException. if (width == 0 || height == 0) - return DOM::IndexSizeError::create(global_object(), "Width and height must not be zero"); + return WebIDL::IndexSizeError::create(global_object(), "Width and height must not be zero"); // 2. If the CanvasRenderingContext2D's origin-clean flag is set to false, then throw a "SecurityError" DOMException. if (!m_origin_clean) - return DOM::SecurityError::create(global_object(), "CanvasRenderingContext2D is not origin-clean"); + return WebIDL::SecurityError::create(global_object(), "CanvasRenderingContext2D is not origin-clean"); // 3. Let imageData be a new ImageData object. // 4. Initialize imageData given sw, sh, settings set to settings, and defaultColorSpace set to this's color space. @@ -497,7 +497,7 @@ WebIDL::ExceptionOr check_usability_of_image(CanvasI [](JS::Handle const& canvas_element) -> WebIDL::ExceptionOr> { // If image has either a horizontal dimension or a vertical dimension equal to zero, then throw an "InvalidStateError" DOMException. if (canvas_element->width() == 0 || canvas_element->height() == 0) - return DOM::InvalidStateError::create(canvas_element->global_object(), "Canvas width or height is zero"); + return WebIDL::InvalidStateError::create(canvas_element->global_object(), "Canvas width or height is zero"); return Optional {}; })); if (usability.has_value()) diff --git a/Userland/Libraries/LibWeb/HTML/CrossOrigin/AbstractOperations.cpp b/Userland/Libraries/LibWeb/HTML/CrossOrigin/AbstractOperations.cpp index 6909effd5e..738c348b1c 100644 --- a/Userland/Libraries/LibWeb/HTML/CrossOrigin/AbstractOperations.cpp +++ b/Userland/Libraries/LibWeb/HTML/CrossOrigin/AbstractOperations.cpp @@ -15,10 +15,10 @@ #include #include #include -#include #include #include #include +#include namespace Web::HTML { @@ -78,7 +78,7 @@ JS::ThrowCompletionOr cross_origin_property_fallback(JS: return JS::PropertyDescriptor { .value = JS::js_undefined(), .writable = false, .enumerable = false, .configurable = true }; // 2. Throw a "SecurityError" DOMException. - return throw_completion(DOM::SecurityError::create(vm.current_realm()->global_object(), String::formatted("Can't access property '{}' on cross-origin object", property_key))); + return throw_completion(WebIDL::SecurityError::create(vm.current_realm()->global_object(), String::formatted("Can't access property '{}' on cross-origin object", property_key))); } // 7.2.3.3 IsPlatformObjectSameOrigin ( O ), https://html.spec.whatwg.org/multipage/browsers.html#isplatformobjectsameorigin-(-o-) @@ -196,7 +196,7 @@ JS::ThrowCompletionOr cross_origin_get(JS::VM& vm, JS::Object const& // 6. If getter is undefined, then throw a "SecurityError" DOMException. if (!getter.has_value()) - return throw_completion(DOM::SecurityError::create(vm.current_realm()->global_object(), String::formatted("Can't get property '{}' on cross-origin object", property_key))); + return throw_completion(WebIDL::SecurityError::create(vm.current_realm()->global_object(), String::formatted("Can't get property '{}' on cross-origin object", property_key))); // 7. Return ? Call(getter, Receiver). return JS::call(vm, *getter, receiver); @@ -222,7 +222,7 @@ JS::ThrowCompletionOr cross_origin_set(JS::VM& vm, JS::Object& object, JS: } // 4. Throw a "SecurityError" DOMException. - return throw_completion(DOM::SecurityError::create(vm.current_realm()->global_object(), String::formatted("Can't set property '{}' on cross-origin object", property_key))); + return throw_completion(WebIDL::SecurityError::create(vm.current_realm()->global_object(), String::formatted("Can't set property '{}' on cross-origin object", property_key))); } // 7.2.3.7 CrossOriginOwnPropertyKeys ( O ), https://html.spec.whatwg.org/multipage/browsers.html#crossoriginownpropertykeys-(-o-) diff --git a/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp b/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp index 79456fbc97..71fee91ac4 100644 --- a/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp +++ b/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp @@ -126,7 +126,7 @@ WebIDL::ExceptionOr DOMStringMap::set_value_of_new_named_property(String c if (current_character == '-' && character_index + 1 < name.length()) { auto next_character = name[character_index + 1]; if (is_ascii_lower_alpha(next_character)) - return DOM::SyntaxError::create(global_object(), "Name cannot contain a '-' followed by a lowercase character."); + return WebIDL::SyntaxError::create(global_object(), "Name cannot contain a '-' followed by a lowercase character."); } // 2. For each ASCII upper alpha in name, insert a U+002D HYPHEN-MINUS character (-) before the character and replace the character with the same character converted to ASCII lowercase. diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp index 3513098adc..a7192f08f5 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -24,6 +23,7 @@ #include #include #include +#include #include namespace Web::HTML { @@ -104,7 +104,7 @@ WebIDL::ExceptionOr HTMLElement::set_content_editable(String const& conten set_attribute(HTML::AttributeNames::contenteditable, "false"); return {}; } - return DOM::SyntaxError::create(global_object(), "Invalid contentEditable value, must be 'true', 'false', or 'inherit'"); + return WebIDL::SyntaxError::create(global_object(), "Invalid contentEditable value, must be 'true', 'false', or 'inherit'"); } void HTMLElement::set_inner_text(StringView text) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLOptionsCollection.cpp b/Userland/Libraries/LibWeb/HTML/HTMLOptionsCollection.cpp index 086560a297..22ff334903 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLOptionsCollection.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLOptionsCollection.cpp @@ -4,12 +4,12 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include #include #include #include #include #include +#include namespace Web::HTML { @@ -40,11 +40,11 @@ WebIDL::ExceptionOr HTMLOptionsCollection::add(HTMLOptionOrOptGroupElement // 1. If element is an ancestor of the select element on which the HTMLOptionsCollection is rooted, then throw a "HierarchyRequestError" DOMException. if (resolved_element->is_ancestor_of(root())) - return DOM::HierarchyRequestError::create(global_object(), "The provided element is an ancestor of the root select element."); + return WebIDL::HierarchyRequestError::create(global_object(), "The provided element is an ancestor of the root select element."); // 2. If before is an element, but that element isn't a descendant of the select element on which the HTMLOptionsCollection is rooted, then throw a "NotFoundError" DOMException. if (before_element && !before_element->is_descendant_of(root())) - return DOM::NotFoundError::create(global_object(), "The 'before' element is not a descendant of the root select element."); + return WebIDL::NotFoundError::create(global_object(), "The 'before' element is not a descendant of the root select element."); // 3. If element and before are the same element, then return. if (before_element && (resolved_element.ptr() == before_element.ptr())) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp index a200f91391..2cd7ff8138 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp @@ -103,7 +103,7 @@ WebIDL::ExceptionOr HTMLTableElement::set_t_head(HTMLTableSectionElement* VERIFY(thead); if (thead->local_name() != TagNames::thead) - return DOM::HierarchyRequestError::create(global_object(), "Element is not thead"); + return WebIDL::HierarchyRequestError::create(global_object(), "Element is not thead"); // FIXME: The spec requires deleting the current thead if thead is null // Currently the wrapper generator doesn't send us a nullable value @@ -190,7 +190,7 @@ WebIDL::ExceptionOr HTMLTableElement::set_t_foot(HTMLTableSectionElement* VERIFY(tfoot); if (tfoot->local_name() != TagNames::tfoot) - return DOM::HierarchyRequestError::create(global_object(), "Element is not tfoot"); + return WebIDL::HierarchyRequestError::create(global_object(), "Element is not tfoot"); // FIXME: The spec requires deleting the current tfoot if tfoot is null // Currently the wrapper generator doesn't send us a nullable value @@ -286,7 +286,7 @@ WebIDL::ExceptionOr> HTMLTableElement::ins auto rows_length = rows->length(); if (index < -1 || index > (long)rows_length) { - return DOM::IndexSizeError::create(global_object(), "Index is negative or greater than the number of rows"); + return WebIDL::IndexSizeError::create(global_object(), "Index is negative or greater than the number of rows"); } auto& tr = static_cast(*DOM::create_element(document(), TagNames::tr, Namespace::HTML)); if (rows_length == 0 && !has_child_of_type()) { @@ -313,7 +313,7 @@ WebIDL::ExceptionOr HTMLTableElement::delete_row(long index) // 1. If index is less than −1 or greater than or equal to the number of elements in the rows collection, then throw an "IndexSizeError" DOMException. if (index < -1 || index >= (long)rows_length) - return DOM::IndexSizeError::create(global_object(), "Index is negative or greater than or equal to the number of rows"); + return WebIDL::IndexSizeError::create(global_object(), "Index is negative or greater than or equal to the number of rows"); // 2. If index is −1, then remove the last element in the rows collection from its parent, or do nothing if the rows collection is empty. if (index == -1) { diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp index 39efff51ec..c2e2ff598d 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp @@ -43,7 +43,7 @@ WebIDL::ExceptionOr> HTMLTableSectionEleme // 1. If index is less than −1 or greater than the number of elements in the rows collection, throw an "IndexSizeError" DOMException. if (index < -1 || index > rows_collection_size) - return DOM::IndexSizeError::create(global_object(), "Index is negative or greater than the number of rows"); + return WebIDL::IndexSizeError::create(global_object(), "Index is negative or greater than the number of rows"); // 2. Let table row be the result of creating an element given this element's node document, tr, and the HTML namespace. auto& table_row = static_cast(*DOM::create_element(document(), TagNames::tr, Namespace::HTML)); @@ -67,7 +67,7 @@ WebIDL::ExceptionOr HTMLTableSectionElement::delete_row(long index) // 1. If index is less than −1 or greater than or equal to the number of elements in the rows collection, then throw an "IndexSizeError" DOMException. if (index < -1 || index >= rows_collection_size) - return DOM::IndexSizeError::create(global_object(), "Index is negative or greater than or equal to the number of rows"); + return WebIDL::IndexSizeError::create(global_object(), "Index is negative or greater than or equal to the number of rows"); // 2. If index is −1, then remove the last element in the rows collection from this element, or do nothing if the rows collection is empty. if (index == -1) { diff --git a/Userland/Libraries/LibWeb/HTML/History.cpp b/Userland/Libraries/LibWeb/HTML/History.cpp index fa579167c7..706e6e209a 100644 --- a/Userland/Libraries/LibWeb/HTML/History.cpp +++ b/Userland/Libraries/LibWeb/HTML/History.cpp @@ -50,7 +50,7 @@ WebIDL::ExceptionOr History::shared_history_push_replace_state(JS::Value, // 2. If document is not fully active, then throw a "SecurityError" DOMException. if (!m_associated_document->is_fully_active()) - return DOM::SecurityError::create(global_object(), "Cannot perform pushState or replaceState on a document that isn't fully active."); + return WebIDL::SecurityError::create(global_object(), "Cannot perform pushState or replaceState on a document that isn't fully active."); // 3. Optionally, return. (For example, the user agent might disallow calls to these methods that are invoked on a timer, // or from event listeners that are not triggered in response to a clear user action, or that are invoked in rapid succession.) diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp index 22ce90d442..59f896f58a 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp +++ b/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp @@ -8,10 +8,10 @@ #include #include #include -#include #include #include #include +#include namespace Web::HTML { @@ -124,7 +124,7 @@ JS::Completion ClassicScript::run(RethrowErrors rethrow_errors) dbgln("network error"); // 2. Throw a "NetworkError" DOMException. - return throw_completion(DOM::NetworkError::create(settings.global_object(), "Script error.")); + return throw_completion(WebIDL::NetworkError::create(settings.global_object(), "Script error.")); } // 3. Otherwise, rethrow errors is false. Perform the following steps: diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index f21ec41059..29e911bb8c 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -1075,7 +1075,7 @@ JS_DEFINE_NATIVE_FUNCTION(Window::btoa) byte_string.ensure_capacity(string.length()); for (u32 code_point : Utf8View(string)) { if (code_point > 0xff) - return throw_completion(DOM::InvalidCharacterError::create(vm.current_realm()->global_object(), "Data contains characters outside the range U+0000 and U+00FF")); + return throw_completion(WebIDL::InvalidCharacterError::create(vm.current_realm()->global_object(), "Data contains characters outside the range U+0000 and U+00FF")); byte_string.append(code_point); } diff --git a/Userland/Libraries/LibWeb/HTML/WindowProxy.cpp b/Userland/Libraries/LibWeb/HTML/WindowProxy.cpp index 9020ff230c..5f1764f3f8 100644 --- a/Userland/Libraries/LibWeb/HTML/WindowProxy.cpp +++ b/Userland/Libraries/LibWeb/HTML/WindowProxy.cpp @@ -10,12 +10,12 @@ #include #include #include -#include #include #include #include #include #include +#include namespace Web::HTML { @@ -90,7 +90,7 @@ JS::ThrowCompletionOr> WindowProxy::internal_ge return Optional {}; // 2. Throw a "SecurityError" DOMException. - return throw_completion(DOM::SecurityError::create(window(), String::formatted("Can't access property '{}' on cross-origin object", property_key))); + return throw_completion(WebIDL::SecurityError::create(window(), String::formatted("Can't access property '{}' on cross-origin object", property_key))); } // 6. Return PropertyDescriptor{ [[Value]]: value, [[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: true }. @@ -140,7 +140,7 @@ JS::ThrowCompletionOr WindowProxy::internal_define_own_property(JS::Proper } // 3. Throw a "SecurityError" DOMException. - return throw_completion(DOM::SecurityError::create(window(), String::formatted("Can't define property '{}' on cross-origin object", property_key))); + return throw_completion(WebIDL::SecurityError::create(window(), String::formatted("Can't define property '{}' on cross-origin object", property_key))); } // 7.4.7 [[Get]] ( P, Receiver ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-get @@ -213,7 +213,7 @@ JS::ThrowCompletionOr WindowProxy::internal_delete(JS::PropertyKey const& } // 3. Throw a "SecurityError" DOMException. - return throw_completion(DOM::SecurityError::create(window(), String::formatted("Can't delete property '{}' on cross-origin object", property_key))); + return throw_completion(WebIDL::SecurityError::create(window(), String::formatted("Can't delete property '{}' on cross-origin object", property_key))); } // 7.4.10 [[OwnPropertyKeys]] ( ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-ownpropertykeys diff --git a/Userland/Libraries/LibWeb/HTML/Worker.cpp b/Userland/Libraries/LibWeb/HTML/Worker.cpp index 7797b28ff5..6e64ec20bc 100644 --- a/Userland/Libraries/LibWeb/HTML/Worker.cpp +++ b/Userland/Libraries/LibWeb/HTML/Worker.cpp @@ -63,7 +63,7 @@ WebIDL::ExceptionOr> Worker::create(FlyString const& sc // 4. If this fails, throw a "SyntaxError" DOMException. if (!url.is_valid()) { dbgln_if(WEB_WORKER_DEBUG, "WebWorker: Invalid URL loaded '{}'.", script_url); - return DOM::SyntaxError::create(document.global_object(), "url is not valid"); + return WebIDL::SyntaxError::create(document.global_object(), "url is not valid"); } // 5. Let worker URL be the resulting URL record. diff --git a/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp b/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp index 93f929fca4..d45fad5491 100644 --- a/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp +++ b/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -18,6 +17,7 @@ #include #include #include +#include namespace Web::HTML { @@ -131,7 +131,7 @@ WebIDL::ExceptionOr WorkerGlobalScope::btoa(String const& data) const byte_string.ensure_capacity(data.length()); for (u32 code_point : Utf8View(data)) { if (code_point > 0xff) - return DOM::InvalidCharacterError::create(global_object(), "Data contains characters outside the range U+0000 and U+00FF"); + return WebIDL::InvalidCharacterError::create(global_object(), "Data contains characters outside the range U+0000 and U+00FF"); byte_string.append(code_point); } @@ -151,7 +151,7 @@ WebIDL::ExceptionOr WorkerGlobalScope::atob(String const& data) const // 2. If decodedData is failure, then throw an "InvalidCharacterError" DOMException. if (decoded_data.is_error()) - return DOM::InvalidCharacterError::create(global_object(), "Input string is not valid base64 data"); + return WebIDL::InvalidCharacterError::create(global_object(), "Input string is not valid base64 data"); // 3. Return decodedData. // decode_base64() returns a byte string. LibJS uses UTF-8 for strings. Use Latin1Decoder to convert bytes 128-255 to UTF-8. diff --git a/Userland/Libraries/LibWeb/DOM/DOMException.cpp b/Userland/Libraries/LibWeb/WebIDL/DOMException.cpp similarity index 94% rename from Userland/Libraries/LibWeb/DOM/DOMException.cpp rename to Userland/Libraries/LibWeb/WebIDL/DOMException.cpp index a4c9d3ae73..d263398446 100644 --- a/Userland/Libraries/LibWeb/DOM/DOMException.cpp +++ b/Userland/Libraries/LibWeb/WebIDL/DOMException.cpp @@ -4,10 +4,10 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include #include +#include -namespace Web::DOM { +namespace Web::WebIDL { JS::NonnullGCPtr DOMException::create(JS::Object& global_object, FlyString const& name, FlyString const& message) { diff --git a/Userland/Libraries/LibWeb/DOM/DOMException.h b/Userland/Libraries/LibWeb/WebIDL/DOMException.h similarity index 93% rename from Userland/Libraries/LibWeb/DOM/DOMException.h rename to Userland/Libraries/LibWeb/WebIDL/DOMException.h index 5a5612c561..17742491f1 100644 --- a/Userland/Libraries/LibWeb/DOM/DOMException.h +++ b/Userland/Libraries/LibWeb/WebIDL/DOMException.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Linus Groh + * Copyright (c) 2021-2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -10,16 +10,16 @@ #include #include -namespace Web::DOM { +namespace Web::WebIDL { -#define TRY_OR_RETURN_OOM(global_object, expression) \ - ({ \ - auto _temporary_result = (expression); \ - if (_temporary_result.is_error()) { \ - VERIFY(_temporary_result.error().code() == ENOMEM); \ - return DOM::UnknownError::create(global_object, "Out of memory."sv); \ - } \ - _temporary_result.release_value(); \ +#define TRY_OR_RETURN_OOM(global_object, expression) \ + ({ \ + auto _temporary_result = (expression); \ + if (_temporary_result.is_error()) { \ + VERIFY(_temporary_result.error().code() == ENOMEM); \ + return WebIDL::UnknownError::create(global_object, "Out of memory."sv); \ + } \ + _temporary_result.release_value(); \ }) // The following have a legacy code value but *don't* produce it as @@ -139,7 +139,7 @@ ENUMERATE_DOM_EXCEPTION_ERROR_NAMES namespace Web { -inline JS::Completion throw_completion(JS::NonnullGCPtr exception) +inline JS::Completion throw_completion(JS::NonnullGCPtr exception) { return JS::throw_completion(JS::Value(static_cast(exception.ptr()))); } diff --git a/Userland/Libraries/LibWeb/DOM/DOMException.idl b/Userland/Libraries/LibWeb/WebIDL/DOMException.idl similarity index 100% rename from Userland/Libraries/LibWeb/DOM/DOMException.idl rename to Userland/Libraries/LibWeb/WebIDL/DOMException.idl diff --git a/Userland/Libraries/LibWeb/WebIDL/ExceptionOr.h b/Userland/Libraries/LibWeb/WebIDL/ExceptionOr.h index 23944eafa3..aec297d69d 100644 --- a/Userland/Libraries/LibWeb/WebIDL/ExceptionOr.h +++ b/Userland/Libraries/LibWeb/WebIDL/ExceptionOr.h @@ -9,7 +9,7 @@ #include #include #include -#include +#include namespace Web::WebIDL { @@ -49,7 +49,7 @@ public: { } - ExceptionOr(JS::NonnullGCPtr exception) + ExceptionOr(JS::NonnullGCPtr exception) : m_exception(move(exception)) { } @@ -59,8 +59,8 @@ public: { } - ExceptionOr(Variant> exception) - : m_exception(move(exception).template downcast>()) + ExceptionOr(Variant> exception) + : m_exception(move(exception).template downcast>()) { } @@ -78,9 +78,9 @@ public: return m_result.release_value(); } - Variant> exception() const + Variant> exception() const { - return m_exception.template downcast>(); + return m_exception.template downcast>(); } bool is_exception() const @@ -90,13 +90,13 @@ public: // These are for compatibility with the TRY() macro in AK. [[nodiscard]] bool is_error() const { return is_exception(); } - Variant> release_error() { return exception(); } + Variant> release_error() { return exception(); } private: Optional m_result; // https://webidl.spec.whatwg.org/#idl-exceptions - Variant> m_exception {}; + Variant> m_exception {}; }; template<> diff --git a/Userland/Libraries/LibWeb/WebSockets/WebSocket.cpp b/Userland/Libraries/LibWeb/WebSockets/WebSocket.cpp index b429277aed..594a26bcce 100644 --- a/Userland/Libraries/LibWeb/WebSockets/WebSocket.cpp +++ b/Userland/Libraries/LibWeb/WebSockets/WebSocket.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -19,6 +18,7 @@ #include #include #include +#include #include #include @@ -51,11 +51,11 @@ WebIDL::ExceptionOr> WebSocket::create_with_global_o { AK::URL url_record(url); if (!url_record.is_valid()) - return DOM::SyntaxError::create(window, "Invalid URL"); + return WebIDL::SyntaxError::create(window, "Invalid URL"); if (!url_record.protocol().is_one_of("ws", "wss")) - return DOM::SyntaxError::create(window, "Invalid protocol"); + return WebIDL::SyntaxError::create(window, "Invalid protocol"); if (!url_record.fragment().is_empty()) - return DOM::SyntaxError::create(window, "Presence of URL fragment is invalid"); + return WebIDL::SyntaxError::create(window, "Presence of URL fragment is invalid"); // 5. If `protocols` is a string, set `protocols` to a sequence consisting of just that string // 6. If any of the values in `protocols` occur more than once or otherwise fail to match the requirements, throw SyntaxError return JS::NonnullGCPtr(*window.heap().allocate(window.realm(), window, url_record)); @@ -137,13 +137,13 @@ WebIDL::ExceptionOr WebSocket::close(Optional code, Optional { // 1. If code is present, but is neither an integer equal to 1000 nor an integer in the range 3000 to 4999, inclusive, throw an "InvalidAccessError" DOMException. if (code.has_value() && *code != 1000 && (*code < 3000 || *code > 4099)) - return DOM::InvalidAccessError::create(global_object(), "The close error code is invalid"); + return WebIDL::InvalidAccessError::create(global_object(), "The close error code is invalid"); // 2. If reason is present, then run these substeps: if (reason.has_value()) { // 1. Let reasonBytes be the result of encoding reason. // 2. If reasonBytes is longer than 123 bytes, then throw a "SyntaxError" DOMException. if (reason->bytes().size() > 123) - return DOM::SyntaxError::create(global_object(), "The close reason is longer than 123 bytes"); + return WebIDL::SyntaxError::create(global_object(), "The close reason is longer than 123 bytes"); } // 3. Run the first matching steps from the following list: auto state = ready_state(); @@ -164,7 +164,7 @@ WebIDL::ExceptionOr WebSocket::send(String const& data) { auto state = ready_state(); if (state == WebSocket::ReadyState::Connecting) - return DOM::InvalidStateError::create(global_object(), "Websocket is still CONNECTING"); + return WebIDL::InvalidStateError::create(global_object(), "Websocket is still CONNECTING"); if (state == WebSocket::ReadyState::Open) { m_websocket->send(data); // TODO : If the data cannot be sent, e.g. because it would need to be buffered but the buffer is full, the user agent must flag the WebSocket as full and then close the WebSocket connection. diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp index 39516aba6b..20240d7e46 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -33,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -84,7 +84,7 @@ WebIDL::ExceptionOr XMLHttpRequest::response_text() const { // 1. If this’s response type is not the empty string or "text", then throw an "InvalidStateError" DOMException. if (m_response_type != Bindings::XMLHttpRequestResponseType::Empty && m_response_type != Bindings::XMLHttpRequestResponseType::Text) - return DOM::InvalidStateError::create(global_object(), "XHR responseText can only be used for responseType \"\" or \"text\""); + return WebIDL::InvalidStateError::create(global_object(), "XHR responseText can only be used for responseType \"\" or \"text\""); // 2. If this’s state is not loading or done, then return the empty string. if (m_ready_state != ReadyState::Loading && m_ready_state != ReadyState::Done) @@ -276,20 +276,20 @@ WebIDL::ExceptionOr XMLHttpRequest::set_request_header(String const& name_ // 1. If this’s state is not opened, then throw an "InvalidStateError" DOMException. if (m_ready_state != ReadyState::Opened) - return DOM::InvalidStateError::create(global_object(), "XHR readyState is not OPENED"); + return WebIDL::InvalidStateError::create(global_object(), "XHR readyState is not OPENED"); // 2. If this’s send() flag is set, then throw an "InvalidStateError" DOMException. if (m_send) - return DOM::InvalidStateError::create(global_object(), "XHR send() flag is already set"); + return WebIDL::InvalidStateError::create(global_object(), "XHR send() flag is already set"); // 3. Normalize value. value = MUST(Fetch::Infrastructure::normalize_header_value(value)); // 4. If name is not a header name or value is not a header value, then throw a "SyntaxError" DOMException. if (!Fetch::Infrastructure::is_header_name(name)) - return DOM::SyntaxError::create(global_object(), "Header name contains invalid characters."); + return WebIDL::SyntaxError::create(global_object(), "Header name contains invalid characters."); if (!Fetch::Infrastructure::is_header_value(value)) - return DOM::SyntaxError::create(global_object(), "Header value contains invalid characters."); + return WebIDL::SyntaxError::create(global_object(), "Header value contains invalid characters."); // 5. If name is a forbidden header name, then return. if (Fetch::Infrastructure::is_forbidden_header_name(name)) @@ -327,15 +327,15 @@ WebIDL::ExceptionOr XMLHttpRequest::open(String const& method_string, Stri // 2. If settingsObject has a responsible document and it is not fully active, then throw an "InvalidStateError" DOMException. if (settings_object.responsible_document() && !settings_object.responsible_document()->is_active()) - return DOM::InvalidStateError::create(global_object(), "Invalid state: Responsible document is not fully active."); + return WebIDL::InvalidStateError::create(global_object(), "Invalid state: Responsible document is not fully active."); // 3. If method is not a method, then throw a "SyntaxError" DOMException. if (!Fetch::Infrastructure::is_method(method)) - return DOM::SyntaxError::create(global_object(), "An invalid or illegal string was specified."); + return WebIDL::SyntaxError::create(global_object(), "An invalid or illegal string was specified."); // 4. If method is a forbidden method, then throw a "SecurityError" DOMException. if (Fetch::Infrastructure::is_forbidden_method(method)) - return DOM::SecurityError::create(global_object(), "Forbidden method, must not be 'CONNECT', 'TRACE', or 'TRACK'"); + return WebIDL::SecurityError::create(global_object(), "Forbidden method, must not be 'CONNECT', 'TRACE', or 'TRACK'"); // 5. Normalize method. method = MUST(Fetch::Infrastructure::normalize_method(method)); @@ -345,7 +345,7 @@ WebIDL::ExceptionOr XMLHttpRequest::open(String const& method_string, Stri // 7. If parsedURL is failure, then throw a "SyntaxError" DOMException. if (!parsed_url.is_valid()) - return DOM::SyntaxError::create(global_object(), "Invalid URL"); + return WebIDL::SyntaxError::create(global_object(), "Invalid URL"); // 8. If the async argument is omitted, set async to true, and set username and password to null. // NOTE: This is handled in the overload lacking the async argument. @@ -401,10 +401,10 @@ WebIDL::ExceptionOr XMLHttpRequest::send(Optional XMLHttpRequest::override_mime_type(String const& mime) { // 1. If this’s state is loading or done, then throw an "InvalidStateError" DOMException. if (m_ready_state == ReadyState::Loading || m_ready_state == ReadyState::Done) - return DOM::InvalidStateError::create(global_object(), "Cannot override MIME type when state is Loading or Done."); + return WebIDL::InvalidStateError::create(global_object(), "Cannot override MIME type when state is Loading or Done."); // 2. Set this’s override MIME type to the result of parsing mime. m_override_mime_type = MimeSniff::MimeType::from_string(mime); @@ -570,7 +570,7 @@ WebIDL::ExceptionOr XMLHttpRequest::set_timeout(u32 timeout) // 1. If the current global object is a Window object and this’s synchronous flag is set, // then throw an "InvalidAccessError" DOMException. if (is(HTML::current_global_object()) && m_synchronous) - return DOM::InvalidAccessError::create(global_object(), "Use of XMLHttpRequest's timeout attribute is not supported in the synchronous mode in window context."); + return WebIDL::InvalidAccessError::create(global_object(), "Use of XMLHttpRequest's timeout attribute is not supported in the synchronous mode in window context."); // 2. Set this’s timeout to the given value. m_timeout = timeout; diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index 3239d265e3..815b9dd435 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -31,7 +31,6 @@ libweb_js_bindings(DOM/CustomEvent) libweb_js_bindings(DOM/Document) libweb_js_bindings(DOM/DocumentFragment) libweb_js_bindings(DOM/DocumentType) -libweb_js_bindings(DOM/DOMException) libweb_js_bindings(DOM/DOMImplementation) libweb_js_bindings(DOM/DOMTokenList) libweb_js_bindings(DOM/Element) @@ -185,6 +184,7 @@ libweb_js_bindings(URL/URL) libweb_js_bindings(URL/URLSearchParams ITERABLE) libweb_js_bindings(WebGL/WebGLContextEvent) libweb_js_bindings(WebGL/WebGLRenderingContext) +libweb_js_bindings(WebIDL/DOMException) libweb_js_bindings(WebSockets/WebSocket) libweb_js_bindings(XHR/ProgressEvent) libweb_js_bindings(XHR/XMLHttpRequest)