1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:27:34 +00:00

LibWeb: Move ExceptionOr from DOM/ to WebIDL/

This is a concept fully defined in the Web IDL spec and doesn't belong
in the DOM directory/namespace - not even DOMException, despite the name
:^)
This commit is contained in:
Linus Groh 2022-09-25 17:03:42 +01:00
parent c0eda77928
commit ad04d7ac9b
107 changed files with 441 additions and 440 deletions

View file

@ -31,7 +31,7 @@ void CharacterData::set_data(String data)
}
// https://dom.spec.whatwg.org/#concept-cd-substring
ExceptionOr<String> CharacterData::substring_data(size_t offset, size_t count) const
WebIDL::ExceptionOr<String> CharacterData::substring_data(size_t offset, size_t count) const
{
// 1. Let length be nodes length.
auto length = this->length();
@ -50,7 +50,7 @@ ExceptionOr<String> CharacterData::substring_data(size_t offset, size_t count) c
}
// https://dom.spec.whatwg.org/#concept-cd-replace
ExceptionOr<void> CharacterData::replace_data(size_t offset, size_t count, String const& data)
WebIDL::ExceptionOr<void> CharacterData::replace_data(size_t offset, size_t count, String const& data)
{
// 1. Let length be nodes length.
auto length = this->length();
@ -109,21 +109,21 @@ ExceptionOr<void> CharacterData::replace_data(size_t offset, size_t count, Strin
}
// https://dom.spec.whatwg.org/#dom-characterdata-appenddata
ExceptionOr<void> CharacterData::append_data(String const& data)
WebIDL::ExceptionOr<void> CharacterData::append_data(String const& data)
{
// The appendData(data) method steps are to replace data with node this, offset thiss length, count 0, and data data.
return replace_data(m_data.length(), 0, data);
}
// https://dom.spec.whatwg.org/#dom-characterdata-insertdata
ExceptionOr<void> CharacterData::insert_data(size_t offset, String const& data)
WebIDL::ExceptionOr<void> CharacterData::insert_data(size_t offset, String const& data)
{
// The insertData(offset, data) method steps are to replace data with node this, offset offset, count 0, and data data.
return replace_data(offset, 0, data);
}
// https://dom.spec.whatwg.org/#dom-characterdata-deletedata
ExceptionOr<void> CharacterData::delete_data(size_t offset, size_t count)
WebIDL::ExceptionOr<void> CharacterData::delete_data(size_t offset, size_t count)
{
// The deleteData(offset, count) method steps are to replace data with node this, offset offset, count count, and data the empty string.
return replace_data(offset, count, String::empty());

View file

@ -27,11 +27,11 @@ public:
unsigned length() const { return m_data.length(); }
ExceptionOr<String> substring_data(size_t offset, size_t count) const;
ExceptionOr<void> append_data(String const&);
ExceptionOr<void> insert_data(size_t offset, String const&);
ExceptionOr<void> delete_data(size_t offset, size_t count);
ExceptionOr<void> replace_data(size_t offset, size_t count, String const&);
WebIDL::ExceptionOr<String> substring_data(size_t offset, size_t count) const;
WebIDL::ExceptionOr<void> append_data(String const&);
WebIDL::ExceptionOr<void> insert_data(size_t offset, String const&);
WebIDL::ExceptionOr<void> delete_data(size_t offset, size_t count);
WebIDL::ExceptionOr<void> replace_data(size_t offset, size_t count, String const&);
protected:
explicit CharacterData(Document&, NodeType, String const&);

View file

@ -6,8 +6,8 @@
#pragma once
#include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/DOM/NodeOperations.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::DOM {
@ -16,7 +16,7 @@ template<typename NodeType>
class ChildNode {
public:
// https://dom.spec.whatwg.org/#dom-childnode-before
ExceptionOr<void> before(Vector<Variant<JS::Handle<Node>, String>> const& nodes)
WebIDL::ExceptionOr<void> before(Vector<Variant<JS::Handle<Node>, String>> const& nodes)
{
auto* node = static_cast<NodeType*>(this);
@ -46,7 +46,7 @@ public:
}
// https://dom.spec.whatwg.org/#dom-childnode-after
ExceptionOr<void> after(Vector<Variant<JS::Handle<Node>, String>> const& nodes)
WebIDL::ExceptionOr<void> after(Vector<Variant<JS::Handle<Node>, String>> const& nodes)
{
auto* node = static_cast<NodeType*>(this);
@ -70,7 +70,7 @@ public:
}
// https://dom.spec.whatwg.org/#dom-childnode-replacewith
ExceptionOr<void> replace_with(Vector<Variant<JS::Handle<Node>, String>> const& nodes)
WebIDL::ExceptionOr<void> replace_with(Vector<Variant<JS::Handle<Node>, String>> const& nodes)
{
auto* node = static_cast<NodeType*>(this);

View file

@ -38,7 +38,7 @@ void DOMImplementation::visit_edges(Cell::Visitor& visitor)
}
// https://dom.spec.whatwg.org/#dom-domimplementation-createdocument
ExceptionOr<JS::NonnullGCPtr<Document>> DOMImplementation::create_document(String const& namespace_, String const& qualified_name, JS::GCPtr<DocumentType> doctype) const
WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> DOMImplementation::create_document(String const& namespace_, String const& qualified_name, JS::GCPtr<DocumentType> doctype) const
{
// FIXME: This should specifically be an XML document.
auto xml_document = Document::create(Bindings::main_thread_internal_window_object());
@ -103,7 +103,7 @@ JS::NonnullGCPtr<Document> DOMImplementation::create_html_document(String const&
}
// https://dom.spec.whatwg.org/#dom-domimplementation-createdocumenttype
ExceptionOr<JS::NonnullGCPtr<DocumentType>> DOMImplementation::create_document_type(String const& qualified_name, String const& public_id, String const& system_id)
WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentType>> DOMImplementation::create_document_type(String const& qualified_name, String const& public_id, String const& system_id)
{
TRY(Document::validate_qualified_name(global_object(), qualified_name));
auto document_type = DocumentType::create(document());

View file

@ -20,9 +20,9 @@ public:
static JS::NonnullGCPtr<DOMImplementation> create(Document&);
virtual ~DOMImplementation();
ExceptionOr<JS::NonnullGCPtr<Document>> create_document(String const&, String const&, JS::GCPtr<DocumentType>) const;
WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> create_document(String const&, String const&, JS::GCPtr<DocumentType>) const;
JS::NonnullGCPtr<Document> create_html_document(String const& title) const;
ExceptionOr<JS::NonnullGCPtr<DocumentType>> create_document_type(String const& qualified_name, String const& public_id, String const& system_id);
WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentType>> create_document_type(String const& qualified_name, String const& public_id, String const& system_id);
// https://dom.spec.whatwg.org/#dom-domimplementation-hasfeature
bool has_feature() const { return true; }

View file

@ -108,7 +108,7 @@ bool DOMTokenList::contains(StringView token)
}
// https://dom.spec.whatwg.org/#dom-domtokenlist-add
ExceptionOr<void> DOMTokenList::add(Vector<String> const& tokens)
WebIDL::ExceptionOr<void> DOMTokenList::add(Vector<String> const& tokens)
{
// 1. For each token in tokens:
for (auto const& token : tokens) {
@ -126,7 +126,7 @@ ExceptionOr<void> DOMTokenList::add(Vector<String> const& tokens)
}
// https://dom.spec.whatwg.org/#dom-domtokenlist-remove
ExceptionOr<void> DOMTokenList::remove(Vector<String> const& tokens)
WebIDL::ExceptionOr<void> DOMTokenList::remove(Vector<String> const& tokens)
{
// 1. For each token in tokens:
for (auto const& token : tokens) {
@ -144,7 +144,7 @@ ExceptionOr<void> DOMTokenList::remove(Vector<String> const& tokens)
}
// https://dom.spec.whatwg.org/#dom-domtokenlist-toggle
ExceptionOr<bool> DOMTokenList::toggle(String const& token, Optional<bool> force)
WebIDL::ExceptionOr<bool> DOMTokenList::toggle(String const& token, Optional<bool> force)
{
// 1. If token is the empty string, then throw a "SyntaxError" DOMException.
// 2. If token contains any ASCII whitespace, then throw an "InvalidCharacterError" DOMException.
@ -175,7 +175,7 @@ ExceptionOr<bool> DOMTokenList::toggle(String const& token, Optional<bool> force
}
// https://dom.spec.whatwg.org/#dom-domtokenlist-replace
ExceptionOr<bool> DOMTokenList::replace(String const& token, String const& new_token)
WebIDL::ExceptionOr<bool> DOMTokenList::replace(String const& token, String const& new_token)
{
// 1. If either token or newToken is the empty string, then throw a "SyntaxError" DOMException.
// 2. If either token or newToken contains any ASCII whitespace, then throw an "InvalidCharacterError" DOMException.
@ -198,13 +198,13 @@ ExceptionOr<bool> DOMTokenList::replace(String const& token, String const& new_t
// https://dom.spec.whatwg.org/#dom-domtokenlist-supports
// https://dom.spec.whatwg.org/#concept-domtokenlist-validation
ExceptionOr<bool> DOMTokenList::supports([[maybe_unused]] StringView token)
WebIDL::ExceptionOr<bool> DOMTokenList::supports([[maybe_unused]] StringView token)
{
// FIXME: Implement this fully when any use case defines supported tokens.
// 1. If the associated attributes local name does not define supported tokens, throw a TypeError.
return DOM::SimpleException {
DOM::SimpleExceptionType::TypeError,
return WebIDL::SimpleException {
WebIDL::SimpleExceptionType::TypeError,
String::formatted("Attribute {} does not define any supported tokens", m_associated_attribute)
};
@ -231,7 +231,7 @@ void DOMTokenList::set_value(String value)
associated_element->set_attribute(m_associated_attribute, move(value));
}
ExceptionOr<void> DOMTokenList::validate_token(StringView token) const
WebIDL::ExceptionOr<void> DOMTokenList::validate_token(StringView token) const
{
if (token.is_empty())
return SyntaxError::create(global_object(), "Non-empty DOM tokens are not allowed");

View file

@ -13,8 +13,8 @@
#include <AK/StringView.h>
#include <AK/Vector.h>
#include <LibWeb/Bindings/LegacyPlatformObject.h>
#include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/Forward.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::DOM {
@ -34,18 +34,18 @@ public:
size_t length() const { return m_token_set.size(); }
String const& item(size_t index) const;
bool contains(StringView token);
ExceptionOr<void> add(Vector<String> const& tokens);
ExceptionOr<void> remove(Vector<String> const& tokens);
ExceptionOr<bool> toggle(String const& token, Optional<bool> force);
ExceptionOr<bool> replace(String const& token, String const& new_token);
ExceptionOr<bool> supports(StringView token);
WebIDL::ExceptionOr<void> add(Vector<String> const& tokens);
WebIDL::ExceptionOr<void> remove(Vector<String> const& tokens);
WebIDL::ExceptionOr<bool> toggle(String const& token, Optional<bool> force);
WebIDL::ExceptionOr<bool> replace(String const& token, String const& new_token);
WebIDL::ExceptionOr<bool> supports(StringView token);
String value() const;
void set_value(String value);
private:
DOMTokenList(Element const& associated_element, FlyString associated_attribute);
ExceptionOr<void> validate_token(StringView token) const;
WebIDL::ExceptionOr<void> validate_token(StringView token) const;
void run_update_steps();
WeakPtr<Element> m_associated_element;

View file

@ -28,7 +28,6 @@
#include <LibWeb/DOM/Element.h>
#include <LibWeb/DOM/ElementFactory.h>
#include <LibWeb/DOM/Event.h>
#include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/DOM/HTMLCollection.h>
#include <LibWeb/DOM/NodeIterator.h>
#include <LibWeb/DOM/Range.h>
@ -73,6 +72,7 @@
#include <LibWeb/UIEvents/FocusEvent.h>
#include <LibWeb/UIEvents/KeyboardEvent.h>
#include <LibWeb/UIEvents/MouseEvent.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::DOM {
@ -351,7 +351,7 @@ void Document::visit_edges(Cell::Visitor& visitor)
}
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-document-write
ExceptionOr<void> Document::write(Vector<String> const& strings)
WebIDL::ExceptionOr<void> Document::write(Vector<String> const& strings)
{
StringBuilder builder;
builder.join(""sv, strings);
@ -360,7 +360,7 @@ ExceptionOr<void> Document::write(Vector<String> const& strings)
}
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-document-writeln
ExceptionOr<void> Document::writeln(Vector<String> const& strings)
WebIDL::ExceptionOr<void> Document::writeln(Vector<String> const& strings)
{
StringBuilder builder;
builder.join(""sv, strings);
@ -370,7 +370,7 @@ ExceptionOr<void> Document::writeln(Vector<String> const& strings)
}
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#document-write-steps
ExceptionOr<void> Document::run_the_document_write_steps(String input)
WebIDL::ExceptionOr<void> Document::run_the_document_write_steps(String input)
{
// 1. If document is an XML document, then throw an "InvalidStateError" DOMException.
if (m_type == Type::XML)
@ -405,7 +405,7 @@ ExceptionOr<void> Document::run_the_document_write_steps(String input)
}
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-document-open
ExceptionOr<Document*> Document::open(String const&, String const&)
WebIDL::ExceptionOr<Document*> Document::open(String const&, String const&)
{
// 1. If document is an XML document, then throw an "InvalidStateError" DOMException exception.
if (m_type == Type::XML)
@ -476,7 +476,7 @@ ExceptionOr<Document*> Document::open(String const&, String const&)
}
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#closing-the-input-stream
ExceptionOr<void> Document::close()
WebIDL::ExceptionOr<void> Document::close()
{
// 1. If document is an XML document, then throw an "InvalidStateError" DOMException exception.
if (m_type == Type::XML)
@ -585,7 +585,7 @@ HTML::HTMLElement* Document::body()
}
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-body
ExceptionOr<void> Document::set_body(HTML::HTMLElement* new_body)
WebIDL::ExceptionOr<void> Document::set_body(HTML::HTMLElement* new_body)
{
if (!is<HTML::HTMLBodyElement>(new_body) && !is<HTML::HTMLFrameSetElement>(new_body))
return DOM::HierarchyRequestError::create(global_object(), "Invalid document body element, must be 'body' or 'frameset'");
@ -1108,7 +1108,7 @@ JS::Value Document::run_javascript(StringView source, StringView filename)
}
// https://dom.spec.whatwg.org/#dom-document-createelement
DOM::ExceptionOr<JS::NonnullGCPtr<Element>> Document::create_element(FlyString const& a_local_name)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> Document::create_element(FlyString const& a_local_name)
{
auto local_name = a_local_name;
@ -1135,7 +1135,7 @@ DOM::ExceptionOr<JS::NonnullGCPtr<Element>> Document::create_element(FlyString c
// https://dom.spec.whatwg.org/#dom-document-createelementns
// https://dom.spec.whatwg.org/#internal-createelementns-steps
// FIXME: This only implements step 4 of the algorithm and does not take in options.
DOM::ExceptionOr<JS::NonnullGCPtr<Element>> Document::create_element_ns(String const& namespace_, String const& qualified_name)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> Document::create_element_ns(String const& namespace_, String const& qualified_name)
{
// 1. Let namespace, prefix, and localName be the result of passing namespace and qualifiedName to validate and extract.
auto extracted_qualified_name = TRY(validate_and_extract(global_object(), namespace_, qualified_name));
@ -1168,7 +1168,7 @@ JS::NonnullGCPtr<Range> Document::create_range()
}
// https://dom.spec.whatwg.org/#dom-document-createevent
DOM::ExceptionOr<JS::NonnullGCPtr<Event>> Document::create_event(String const& interface)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> Document::create_event(String const& interface)
{
auto& window_object = window();
@ -1285,7 +1285,7 @@ Vector<JS::Handle<HTML::HTMLScriptElement>> Document::take_scripts_to_execute_in
}
// https://dom.spec.whatwg.org/#dom-document-importnode
ExceptionOr<JS::NonnullGCPtr<Node>> Document::import_node(JS::NonnullGCPtr<Node> node, bool deep)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> Document::import_node(JS::NonnullGCPtr<Node> node, bool deep)
{
// 1. If node is a document or shadow root, then throw a "NotSupportedError" DOMException.
if (is<Document>(*node) || is<ShadowRoot>(*node))
@ -1333,7 +1333,7 @@ void Document::adopt_node(Node& node)
}
// https://dom.spec.whatwg.org/#dom-document-adoptnode
ExceptionOr<JS::NonnullGCPtr<Node>> Document::adopt_node_binding(JS::NonnullGCPtr<Node> node)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> Document::adopt_node_binding(JS::NonnullGCPtr<Node> node)
{
if (is<Document>(*node))
return DOM::NotSupportedError::create(global_object(), "Cannot adopt a document into a document");
@ -1798,7 +1798,7 @@ bool Document::is_valid_name(String const& name)
}
// https://dom.spec.whatwg.org/#validate
ExceptionOr<Document::PrefixAndTagName> Document::validate_qualified_name(JS::Object& global_object, String const& qualified_name)
WebIDL::ExceptionOr<Document::PrefixAndTagName> Document::validate_qualified_name(JS::Object& global_object, String const& qualified_name)
{
if (qualified_name.is_empty())
return InvalidCharacterError::create(global_object, "Empty string is not a valid qualified name.");

View file

@ -21,7 +21,6 @@
#include <LibWeb/CSS/StyleComputer.h>
#include <LibWeb/CSS/StyleSheetList.h>
#include <LibWeb/Cookie/Cookie.h>
#include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/DOM/NonElementParentNode.h>
#include <LibWeb/DOM/ParentNode.h>
#include <LibWeb/HTML/CrossOrigin/CrossOriginOpenerPolicy.h>
@ -33,6 +32,7 @@
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/HTML/VisibilityState.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::DOM {
@ -156,7 +156,7 @@ public:
return const_cast<Document*>(this)->body();
}
ExceptionOr<void> set_body(HTML::HTMLElement* new_body);
WebIDL::ExceptionOr<void> set_body(HTML::HTMLElement* new_body);
String title() const;
void set_title(String const&);
@ -219,12 +219,12 @@ public:
JS::Value run_javascript(StringView source, StringView filename = "(unknown)"sv);
ExceptionOr<JS::NonnullGCPtr<Element>> create_element(FlyString const& local_name);
ExceptionOr<JS::NonnullGCPtr<Element>> create_element_ns(String const& namespace_, String const& qualified_name);
WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element(FlyString const& local_name);
WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element_ns(String const& namespace_, String const& qualified_name);
JS::NonnullGCPtr<DocumentFragment> create_document_fragment();
JS::NonnullGCPtr<Text> create_text_node(String const& data);
JS::NonnullGCPtr<Comment> create_comment(String const& data);
ExceptionOr<JS::NonnullGCPtr<Event>> create_event(String const& interface);
WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> create_event(String const& interface);
JS::NonnullGCPtr<Range> create_range();
void set_pending_parsing_blocking_script(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement*);
@ -253,9 +253,9 @@ public:
// https://dom.spec.whatwg.org/#xml-document
bool is_xml_document() const { return m_type == Type::XML; }
ExceptionOr<JS::NonnullGCPtr<Node>> import_node(JS::NonnullGCPtr<Node> node, bool deep);
WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> import_node(JS::NonnullGCPtr<Node> node, bool deep);
void adopt_node(Node&);
ExceptionOr<JS::NonnullGCPtr<Node>> adopt_node_binding(JS::NonnullGCPtr<Node>);
WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> adopt_node_binding(JS::NonnullGCPtr<Node>);
DocumentType const* doctype() const;
String const& compat_mode() const;
@ -286,11 +286,11 @@ public:
void set_window(Badge<HTML::BrowsingContext>, HTML::Window&);
ExceptionOr<void> write(Vector<String> const& strings);
ExceptionOr<void> writeln(Vector<String> const& strings);
WebIDL::ExceptionOr<void> write(Vector<String> const& strings);
WebIDL::ExceptionOr<void> writeln(Vector<String> const& strings);
ExceptionOr<Document*> open(String const& = "", String const& = "");
ExceptionOr<void> close();
WebIDL::ExceptionOr<Document*> open(String const& = "", String const& = "");
WebIDL::ExceptionOr<void> close();
HTML::Window* default_view() { return m_window.ptr(); }
@ -367,7 +367,7 @@ public:
FlyString prefix;
FlyString tag_name;
};
static ExceptionOr<PrefixAndTagName> validate_qualified_name(JS::Object& global_object, String const& qualified_name);
static WebIDL::ExceptionOr<PrefixAndTagName> validate_qualified_name(JS::Object& global_object, String const& qualified_name);
JS::NonnullGCPtr<NodeIterator> create_node_iterator(Node& root, unsigned what_to_show, JS::GCPtr<NodeFilter>);
JS::NonnullGCPtr<TreeWalker> create_tree_walker(Node& root, unsigned what_to_show, JS::GCPtr<NodeFilter>);
@ -449,7 +449,7 @@ private:
void evaluate_media_rules();
ExceptionOr<void> run_the_document_write_steps(String);
WebIDL::ExceptionOr<void> run_the_document_write_steps(String);
size_t m_next_layout_node_serial_id { 0 };

View file

@ -16,7 +16,6 @@
#include <LibWeb/DOM/DOMTokenList.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Element.h>
#include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/DOM/HTMLCollection.h>
#include <LibWeb/DOM/ShadowRoot.h>
#include <LibWeb/DOM/Text.h>
@ -39,6 +38,7 @@
#include <LibWeb/Layout/TreeBuilder.h>
#include <LibWeb/Namespace.h>
#include <LibWeb/Painting/PaintableBox.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::DOM {
@ -82,7 +82,7 @@ String Element::get_attribute(FlyString const& name) const
}
// https://dom.spec.whatwg.org/#dom-element-setattribute
ExceptionOr<void> Element::set_attribute(FlyString const& name, String const& value)
WebIDL::ExceptionOr<void> Element::set_attribute(FlyString const& name, String const& value)
{
// 1. If qualifiedName does not match the Name production in XML, then throw an "InvalidCharacterError" DOMException.
// FIXME: Proper name validation
@ -118,7 +118,7 @@ ExceptionOr<void> Element::set_attribute(FlyString const& name, String const& va
}
// https://dom.spec.whatwg.org/#validate-and-extract
ExceptionOr<QualifiedName> validate_and_extract(JS::Object& global_object, FlyString namespace_, FlyString qualified_name)
WebIDL::ExceptionOr<QualifiedName> validate_and_extract(JS::Object& global_object, FlyString namespace_, FlyString qualified_name)
{
// 1. If namespace is the empty string, then set it to null.
if (namespace_.is_empty())
@ -161,7 +161,7 @@ ExceptionOr<QualifiedName> validate_and_extract(JS::Object& global_object, FlySt
}
// https://dom.spec.whatwg.org/#dom-element-setattributens
ExceptionOr<void> Element::set_attribute_ns(FlyString const& namespace_, FlyString const& qualified_name, String const& value)
WebIDL::ExceptionOr<void> Element::set_attribute_ns(FlyString const& namespace_, FlyString const& qualified_name, String const& value)
{
// 1. Let namespace, prefix, and localName be the result of passing namespace and qualifiedName to validate and extract.
auto extracted_qualified_name = TRY(validate_and_extract(global_object(), namespace_, qualified_name));
@ -190,7 +190,7 @@ bool Element::has_attribute(FlyString const& name) const
}
// https://dom.spec.whatwg.org/#dom-element-toggleattribute
DOM::ExceptionOr<bool> Element::toggle_attribute(FlyString const& name, Optional<bool> force)
WebIDL::ExceptionOr<bool> Element::toggle_attribute(FlyString const& name, Optional<bool> force)
{
// 1. If qualifiedName does not match the Name production in XML, then throw an "InvalidCharacterError" DOMException.
// FIXME: Proper name validation
@ -439,7 +439,7 @@ DOMTokenList* Element::class_list()
}
// https://dom.spec.whatwg.org/#dom-element-matches
DOM::ExceptionOr<bool> Element::matches(StringView selectors) const
WebIDL::ExceptionOr<bool> Element::matches(StringView selectors) const
{
auto maybe_selectors = parse_selector(CSS::Parser::ParsingContext(static_cast<ParentNode&>(const_cast<Element&>(*this))), selectors);
if (!maybe_selectors.has_value())
@ -454,7 +454,7 @@ DOM::ExceptionOr<bool> Element::matches(StringView selectors) const
}
// https://dom.spec.whatwg.org/#dom-element-closest
DOM::ExceptionOr<DOM::Element const*> Element::closest(StringView selectors) const
WebIDL::ExceptionOr<DOM::Element const*> Element::closest(StringView selectors) const
{
auto maybe_selectors = parse_selector(CSS::Parser::ParsingContext(static_cast<ParentNode&>(const_cast<Element&>(*this))), selectors);
if (!maybe_selectors.has_value())
@ -479,7 +479,7 @@ DOM::ExceptionOr<DOM::Element const*> Element::closest(StringView selectors) con
return nullptr;
}
ExceptionOr<void> Element::set_inner_html(String const& markup)
WebIDL::ExceptionOr<void> Element::set_inner_html(String const& markup)
{
TRY(DOMParsing::inner_html_setter(*this, markup));
@ -729,7 +729,7 @@ void Element::serialize_pseudo_elements_as_json(JsonArraySerializer<StringBuilde
}
// https://w3c.github.io/DOM-Parsing/#dom-element-insertadjacenthtml
DOM::ExceptionOr<void> Element::insert_adjacent_html(String position, String text)
WebIDL::ExceptionOr<void> Element::insert_adjacent_html(String position, String text)
{
JS::GCPtr<Node> context;
// 1. Use the first matching item from this list:

View file

@ -12,7 +12,6 @@
#include <LibWeb/CSS/StyleComputer.h>
#include <LibWeb/DOM/Attr.h>
#include <LibWeb/DOM/ChildNode.h>
#include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/DOM/NamedNodeMap.h>
#include <LibWeb/DOM/NonDocumentTypeChildNode.h>
#include <LibWeb/DOM/ParentNode.h>
@ -22,6 +21,7 @@
#include <LibWeb/HTML/TagNames.h>
#include <LibWeb/Layout/Node.h>
#include <LibWeb/Layout/TreeBuilder.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::DOM {
@ -52,18 +52,18 @@ public:
bool has_attributes() const { return !m_attributes->is_empty(); }
String attribute(FlyString const& name) const { return get_attribute(name); }
String get_attribute(FlyString const& name) const;
ExceptionOr<void> set_attribute(FlyString const& name, String const& value);
ExceptionOr<void> set_attribute_ns(FlyString const& namespace_, FlyString const& qualified_name, String const& value);
WebIDL::ExceptionOr<void> set_attribute(FlyString const& name, String const& value);
WebIDL::ExceptionOr<void> set_attribute_ns(FlyString const& namespace_, FlyString const& qualified_name, String const& value);
void remove_attribute(FlyString const& name);
DOM::ExceptionOr<bool> toggle_attribute(FlyString const& name, Optional<bool> force);
WebIDL::ExceptionOr<bool> toggle_attribute(FlyString const& name, Optional<bool> force);
size_t attribute_list_size() const { return m_attributes->length(); }
NamedNodeMap const* attributes() const { return m_attributes.ptr(); }
Vector<String> get_attribute_names() const;
DOMTokenList* class_list();
DOM::ExceptionOr<bool> matches(StringView selectors) const;
DOM::ExceptionOr<DOM::Element const*> closest(StringView selectors) const;
WebIDL::ExceptionOr<bool> matches(StringView selectors) const;
WebIDL::ExceptionOr<DOM::Element const*> closest(StringView selectors) const;
int client_top() const;
int client_left() const;
@ -106,9 +106,9 @@ public:
CSS::CSSStyleDeclaration* style_for_bindings();
String inner_html() const;
ExceptionOr<void> set_inner_html(String const&);
WebIDL::ExceptionOr<void> set_inner_html(String const&);
ExceptionOr<void> insert_adjacent_html(String position, String text);
WebIDL::ExceptionOr<void> insert_adjacent_html(String position, String text);
bool is_focused() const;
bool is_active() const;
@ -172,6 +172,6 @@ private:
template<>
inline bool Node::fast_is<Element>() const { return is_element(); }
ExceptionOr<QualifiedName> validate_and_extract(JS::Object& global_object, FlyString namespace_, FlyString qualified_name);
WebIDL::ExceptionOr<QualifiedName> validate_and_extract(JS::Object& global_object, FlyString namespace_, FlyString qualified_name);
}

View file

@ -223,7 +223,7 @@ void EventTarget::remove_from_event_listener_list(DOMEventListener& listener)
}
// https://dom.spec.whatwg.org/#dom-eventtarget-dispatchevent
ExceptionOr<bool> EventTarget::dispatch_event_binding(Event& event)
WebIDL::ExceptionOr<bool> EventTarget::dispatch_event_binding(Event& event)
{
// 1. If events dispatch flag is set, or if its initialized flag is not set, then throw an "InvalidStateError" DOMException.
if (event.dispatched())

View file

@ -12,9 +12,9 @@
#include <LibJS/Forward.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/DOM/DOMEventListener.h>
#include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/Forward.h>
#include <LibWeb/HTML/EventHandler.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::DOM {
@ -34,7 +34,7 @@ public:
void remove_event_listener_without_options(FlyString const& type, IDLEventListener& callback);
virtual bool dispatch_event(Event&);
ExceptionOr<bool> dispatch_event_binding(Event&);
WebIDL::ExceptionOr<bool> dispatch_event_binding(Event&);
virtual EventTarget* get_parent(Event const&) { return nullptr; }

View file

@ -1,107 +0,0 @@
/*
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/NonnullRefPtr.h>
#include <AK/Optional.h>
#include <AK/RefPtr.h>
#include <LibWeb/DOM/DOMException.h>
namespace Web::DOM {
#define ENUMERATE_SIMPLE_WEBIDL_EXCEPTION_TYPES(E) \
E(EvalError) \
E(RangeError) \
E(ReferenceError) \
E(TypeError) \
E(URIError)
#define E(x) x,
enum class SimpleExceptionType {
ENUMERATE_SIMPLE_WEBIDL_EXCEPTION_TYPES(E)
};
#undef E
struct SimpleException {
SimpleExceptionType type;
String message;
};
template<typename ValueType>
class ExceptionOr {
public:
ExceptionOr() requires(IsSame<ValueType, Empty>)
: m_result(Empty {})
{
}
ExceptionOr(ValueType const& result)
: m_result(result)
{
}
ExceptionOr(ValueType&& result)
: m_result(move(result))
{
}
ExceptionOr(JS::NonnullGCPtr<DOMException> exception)
: m_exception(move(exception))
{
}
ExceptionOr(SimpleException exception)
: m_exception(move(exception))
{
}
ExceptionOr(Variant<SimpleException, JS::NonnullGCPtr<DOMException>> exception)
: m_exception(move(exception).template downcast<Empty, SimpleException, JS::NonnullGCPtr<DOMException>>())
{
}
ExceptionOr(ExceptionOr&& other) = default;
ExceptionOr(ExceptionOr const& other) = default;
~ExceptionOr() = default;
ValueType& value() requires(!IsSame<ValueType, Empty>)
{
return m_result.value();
}
ValueType release_value()
{
return m_result.release_value();
}
Variant<SimpleException, JS::NonnullGCPtr<DOMException>> exception() const
{
return m_exception.template downcast<SimpleException, JS::NonnullGCPtr<DOMException>>();
}
bool is_exception() const
{
return !m_exception.template has<Empty>();
}
// These are for compatibility with the TRY() macro in AK.
[[nodiscard]] bool is_error() const { return is_exception(); }
Variant<SimpleException, JS::NonnullGCPtr<DOMException>> release_error() { return exception(); }
private:
Optional<ValueType> m_result;
// https://webidl.spec.whatwg.org/#idl-exceptions
Variant<Empty, SimpleException, JS::NonnullGCPtr<DOMException>> m_exception {};
};
template<>
class ExceptionOr<void> : public ExceptionOr<Empty> {
public:
using ExceptionOr<Empty>::ExceptionOr;
};
}

View file

@ -41,7 +41,7 @@ void MutationObserver::visit_edges(Cell::Visitor& visitor)
}
// https://dom.spec.whatwg.org/#dom-mutationobserver-observe
ExceptionOr<void> MutationObserver::observe(Node& target, MutationObserverInit options)
WebIDL::ExceptionOr<void> MutationObserver::observe(Node& target, MutationObserverInit options)
{
// 1. If either options["attributeOldValue"] or options["attributeFilter"] exists, and options["attributes"] does not exist, then set options["attributes"] to true.
if ((options.attribute_old_value.has_value() || options.attribute_filter.has_value()) && !options.attributes.has_value())
@ -53,22 +53,22 @@ ExceptionOr<void> MutationObserver::observe(Node& target, MutationObserverInit o
// 3. If none of options["childList"], options["attributes"], and options["characterData"] is true, then throw a TypeError.
if (!options.child_list && (!options.attributes.has_value() || !options.attributes.value()) && (!options.character_data.has_value() || !options.character_data.value()))
return SimpleException { SimpleExceptionType::TypeError, "Options must have one of childList, attributes or characterData set to true." };
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Options must have one of childList, attributes or characterData set to true." };
// 4. If options["attributeOldValue"] is true and options["attributes"] is false, then throw a TypeError.
// NOTE: If attributeOldValue is present, attributes will be present because of step 1.
if (options.attribute_old_value.has_value() && options.attribute_old_value.value() && !options.attributes.value())
return SimpleException { SimpleExceptionType::TypeError, "attributes must be true if attributeOldValue is true." };
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "attributes must be true if attributeOldValue is true." };
// 5. If options["attributeFilter"] is present and options["attributes"] is false, then throw a TypeError.
// NOTE: If attributeFilter is present, attributes will be present because of step 1.
if (options.attribute_filter.has_value() && !options.attributes.value())
return SimpleException { SimpleExceptionType::TypeError, "attributes must be true if attributeFilter is present." };
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "attributes must be true if attributeFilter is present." };
// 6. If options["characterDataOldValue"] is true and options["characterData"] is false, then throw a TypeError.
// NOTE: If characterDataOldValue is present, characterData will be present because of step 2.
if (options.character_data_old_value.has_value() && options.character_data_old_value.value() && !options.character_data.value())
return SimpleException { SimpleExceptionType::TypeError, "characterData must be true if characterDataOldValue is true." };
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "characterData must be true if characterDataOldValue is true." };
// 7. For each registered of targets registered observer list, if registereds observer is this:
bool updated_existing_observer = false;

View file

@ -10,9 +10,9 @@
#include <AK/NonnullRefPtrVector.h>
#include <AK/RefCounted.h>
#include <LibJS/Heap/Handle.h>
#include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/DOM/MutationRecord.h>
#include <LibWeb/WebIDL/CallbackType.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::DOM {
@ -35,7 +35,7 @@ public:
static JS::NonnullGCPtr<MutationObserver> create_with_global_object(HTML::Window&, JS::GCPtr<WebIDL::CallbackType>);
virtual ~MutationObserver() override;
ExceptionOr<void> observe(Node& target, MutationObserverInit options = {});
WebIDL::ExceptionOr<void> observe(Node& target, MutationObserverInit options = {});
void disconnect();
Vector<JS::Handle<MutationRecord>> take_records();

View file

@ -80,13 +80,13 @@ Attr const* NamedNodeMap::get_named_item(StringView qualified_name) const
}
// https://dom.spec.whatwg.org/#dom-namednodemap-setnameditem
ExceptionOr<Attr const*> NamedNodeMap::set_named_item(Attr& attribute)
WebIDL::ExceptionOr<Attr const*> NamedNodeMap::set_named_item(Attr& attribute)
{
return set_attribute(attribute);
}
// https://dom.spec.whatwg.org/#dom-namednodemap-removenameditem
ExceptionOr<Attr const*> NamedNodeMap::remove_named_item(StringView qualified_name)
WebIDL::ExceptionOr<Attr const*> NamedNodeMap::remove_named_item(StringView qualified_name)
{
// 1. Let attr be the result of removing an attribute given qualifiedName and element.
auto const* attribute = remove_attribute(qualified_name);
@ -133,7 +133,7 @@ Attr const* NamedNodeMap::get_attribute(StringView qualified_name, size_t* item_
}
// https://dom.spec.whatwg.org/#concept-element-attributes-set
ExceptionOr<Attr const*> NamedNodeMap::set_attribute(Attr& attribute)
WebIDL::ExceptionOr<Attr const*> NamedNodeMap::set_attribute(Attr& attribute)
{
// 1. If attrs element is neither null nor element, throw an "InUseAttributeError" DOMException.
if ((attribute.owner_element() != nullptr) && (attribute.owner_element() != &associated_element()))

View file

@ -11,8 +11,8 @@
#include <AK/String.h>
#include <AK/StringView.h>
#include <LibWeb/Bindings/LegacyPlatformObject.h>
#include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/Forward.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::DOM {
@ -35,13 +35,13 @@ public:
// Methods defined by the spec for JavaScript:
Attr const* item(u32 index) const;
Attr const* get_named_item(StringView qualified_name) const;
ExceptionOr<Attr const*> set_named_item(Attr& attribute);
ExceptionOr<Attr const*> remove_named_item(StringView qualified_name);
WebIDL::ExceptionOr<Attr const*> set_named_item(Attr& attribute);
WebIDL::ExceptionOr<Attr const*> remove_named_item(StringView qualified_name);
// Methods defined by the spec for internal use:
Attr* get_attribute(StringView qualified_name, size_t* item_index = nullptr);
Attr const* get_attribute(StringView qualified_name, size_t* item_index = nullptr) const;
ExceptionOr<Attr const*> set_attribute(Attr& attribute);
WebIDL::ExceptionOr<Attr const*> set_attribute(Attr& attribute);
void replace_attribute(Attr& old_attribute, Attr& new_attribute, size_t old_attribute_index);
void append_attribute(Attr& attribute);
Attr const* remove_attribute(StringView qualified_name);

View file

@ -311,7 +311,7 @@ Element const* Node::parent_element() const
}
// https://dom.spec.whatwg.org/#concept-node-ensure-pre-insertion-validity
ExceptionOr<void> Node::ensure_pre_insertion_validity(JS::NonnullGCPtr<Node> node, JS::GCPtr<Node> child) const
WebIDL::ExceptionOr<void> Node::ensure_pre_insertion_validity(JS::NonnullGCPtr<Node> node, JS::GCPtr<Node> child) const
{
// 1. If parent is not a Document, DocumentFragment, or Element node, then throw a "HierarchyRequestError" DOMException.
if (!is<Document>(this) && !is<DocumentFragment>(this) && !is<Element>(this))
@ -456,7 +456,7 @@ void Node::insert_before(JS::NonnullGCPtr<Node> node, JS::GCPtr<Node> child, boo
}
// https://dom.spec.whatwg.org/#concept-node-pre-insert
ExceptionOr<JS::NonnullGCPtr<Node>> Node::pre_insert(JS::NonnullGCPtr<Node> node, JS::GCPtr<Node> child)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> Node::pre_insert(JS::NonnullGCPtr<Node> node, JS::GCPtr<Node> child)
{
// 1. Ensure pre-insertion validity of node into parent before child.
TRY(ensure_pre_insertion_validity(node, child));
@ -476,14 +476,14 @@ ExceptionOr<JS::NonnullGCPtr<Node>> Node::pre_insert(JS::NonnullGCPtr<Node> node
}
// https://dom.spec.whatwg.org/#dom-node-removechild
ExceptionOr<JS::NonnullGCPtr<Node>> Node::remove_child(JS::NonnullGCPtr<Node> child)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> Node::remove_child(JS::NonnullGCPtr<Node> child)
{
// The removeChild(child) method steps are to return the result of pre-removing child from this.
return pre_remove(child);
}
// https://dom.spec.whatwg.org/#concept-node-pre-remove
ExceptionOr<JS::NonnullGCPtr<Node>> Node::pre_remove(JS::NonnullGCPtr<Node> child)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> Node::pre_remove(JS::NonnullGCPtr<Node> child)
{
// 1. If childs parent is not parent, then throw a "NotFoundError" DOMException.
if (child->parent() != this)
@ -497,7 +497,7 @@ ExceptionOr<JS::NonnullGCPtr<Node>> Node::pre_remove(JS::NonnullGCPtr<Node> chil
}
// https://dom.spec.whatwg.org/#concept-node-append
ExceptionOr<JS::NonnullGCPtr<Node>> Node::append_child(JS::NonnullGCPtr<Node> node)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> Node::append_child(JS::NonnullGCPtr<Node> node)
{
// To append a node to a parent, pre-insert node into parent before null.
return pre_insert(node, nullptr);
@ -608,7 +608,7 @@ void Node::remove(bool suppress_observers)
}
// https://dom.spec.whatwg.org/#concept-node-replace
ExceptionOr<JS::NonnullGCPtr<Node>> Node::replace_child(JS::NonnullGCPtr<Node> node, JS::NonnullGCPtr<Node> child)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> Node::replace_child(JS::NonnullGCPtr<Node> node, JS::NonnullGCPtr<Node> child)
{
// If parent is not a Document, DocumentFragment, or Element node, then throw a "HierarchyRequestError" DOMException.
if (!is<Document>(this) && !is<DocumentFragment>(this) && !is<Element>(this))
@ -792,7 +792,7 @@ JS::NonnullGCPtr<Node> Node::clone_node(Document* document, bool clone_children)
}
// https://dom.spec.whatwg.org/#dom-node-clonenode
ExceptionOr<JS::NonnullGCPtr<Node>> Node::clone_node_binding(bool deep)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> Node::clone_node_binding(bool deep)
{
// 1. If this is a shadow root, then throw a "NotSupportedError" DOMException.
if (is<ShadowRoot>(*this))

View file

@ -13,7 +13,7 @@
#include <AK/TypeCasts.h>
#include <AK/Vector.h>
#include <LibWeb/DOM/EventTarget.h>
#include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::DOM {
@ -81,21 +81,21 @@ public:
virtual bool is_html_template_element() const { return false; }
virtual bool is_browsing_context_container() const { return false; }
ExceptionOr<JS::NonnullGCPtr<Node>> pre_insert(JS::NonnullGCPtr<Node>, JS::GCPtr<Node>);
ExceptionOr<JS::NonnullGCPtr<Node>> pre_remove(JS::NonnullGCPtr<Node>);
WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> pre_insert(JS::NonnullGCPtr<Node>, JS::GCPtr<Node>);
WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> pre_remove(JS::NonnullGCPtr<Node>);
ExceptionOr<JS::NonnullGCPtr<Node>> append_child(JS::NonnullGCPtr<Node>);
ExceptionOr<JS::NonnullGCPtr<Node>> remove_child(JS::NonnullGCPtr<Node>);
WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> append_child(JS::NonnullGCPtr<Node>);
WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> remove_child(JS::NonnullGCPtr<Node>);
void insert_before(JS::NonnullGCPtr<Node> node, JS::GCPtr<Node> child, bool suppress_observers = false);
void remove(bool suppress_observers = false);
void remove_all_children(bool suppress_observers = false);
u16 compare_document_position(JS::GCPtr<Node> other);
ExceptionOr<JS::NonnullGCPtr<Node>> replace_child(JS::NonnullGCPtr<Node> node, JS::NonnullGCPtr<Node> child);
WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> replace_child(JS::NonnullGCPtr<Node> node, JS::NonnullGCPtr<Node> child);
JS::NonnullGCPtr<Node> clone_node(Document* document = nullptr, bool clone_children = false);
ExceptionOr<JS::NonnullGCPtr<Node>> clone_node_binding(bool deep);
WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> clone_node_binding(bool deep);
// NOTE: This is intended for the JS bindings.
bool has_child_nodes() const { return has_children(); }
@ -177,7 +177,7 @@ public:
template<typename T>
bool fast_is() const = delete;
ExceptionOr<void> ensure_pre_insertion_validity(JS::NonnullGCPtr<Node> node, JS::GCPtr<Node> child) const;
WebIDL::ExceptionOr<void> ensure_pre_insertion_validity(JS::NonnullGCPtr<Node> node, JS::GCPtr<Node> child) const;
bool is_host_including_inclusive_ancestor_of(Node const&) const;

View file

@ -14,7 +14,7 @@
namespace Web::DOM {
// https://dom.spec.whatwg.org/#converting-nodes-into-a-node
ExceptionOr<JS::NonnullGCPtr<Node>> convert_nodes_to_single_node(Vector<Variant<JS::Handle<Node>, String>> const& nodes, DOM::Document& document)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> convert_nodes_to_single_node(Vector<Variant<JS::Handle<Node>, String>> const& nodes, DOM::Document& document)
{
// 1. Let node be null.
// 2. Replace each string in nodes with a new Text node whose data is the string and node document is document.

View file

@ -12,6 +12,6 @@
namespace Web::DOM {
ExceptionOr<JS::NonnullGCPtr<Node>> convert_nodes_to_single_node(Vector<Variant<JS::Handle<Node>, String>> const& nodes, DOM::Document& document);
WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> convert_nodes_to_single_node(Vector<Variant<JS::Handle<Node>, String>> const& nodes, DOM::Document& document);
}

View file

@ -18,7 +18,7 @@
namespace Web::DOM {
ExceptionOr<JS::GCPtr<Element>> ParentNode::query_selector(StringView selector_text)
WebIDL::ExceptionOr<JS::GCPtr<Element>> ParentNode::query_selector(StringView selector_text)
{
auto maybe_selectors = parse_selector(CSS::Parser::ParsingContext(*this), selector_text);
if (!maybe_selectors.has_value())
@ -41,7 +41,7 @@ ExceptionOr<JS::GCPtr<Element>> ParentNode::query_selector(StringView selector_t
return result;
}
ExceptionOr<JS::NonnullGCPtr<NodeList>> ParentNode::query_selector_all(StringView selector_text)
WebIDL::ExceptionOr<JS::NonnullGCPtr<NodeList>> ParentNode::query_selector_all(StringView selector_text)
{
auto maybe_selectors = parse_selector(CSS::Parser::ParsingContext(*this), selector_text);
if (!maybe_selectors.has_value())
@ -168,7 +168,7 @@ JS::NonnullGCPtr<HTMLCollection> ParentNode::get_elements_by_tag_name_ns(FlyStri
}
// https://dom.spec.whatwg.org/#dom-parentnode-prepend
ExceptionOr<void> ParentNode::prepend(Vector<Variant<JS::Handle<Node>, String>> const& nodes)
WebIDL::ExceptionOr<void> ParentNode::prepend(Vector<Variant<JS::Handle<Node>, String>> const& nodes)
{
// 1. Let node be the result of converting nodes into a node given nodes and thiss node document.
auto node = TRY(convert_nodes_to_single_node(nodes, document()));
@ -179,7 +179,7 @@ ExceptionOr<void> ParentNode::prepend(Vector<Variant<JS::Handle<Node>, String>>
return {};
}
ExceptionOr<void> ParentNode::append(Vector<Variant<JS::Handle<Node>, String>> const& nodes)
WebIDL::ExceptionOr<void> ParentNode::append(Vector<Variant<JS::Handle<Node>, String>> const& nodes)
{
// 1. Let node be the result of converting nodes into a node given nodes and thiss node document.
auto node = TRY(convert_nodes_to_single_node(nodes, document()));
@ -190,7 +190,7 @@ ExceptionOr<void> ParentNode::append(Vector<Variant<JS::Handle<Node>, String>> c
return {};
}
ExceptionOr<void> ParentNode::replace_children(Vector<Variant<JS::Handle<Node>, String>> const& nodes)
WebIDL::ExceptionOr<void> ParentNode::replace_children(Vector<Variant<JS::Handle<Node>, String>> const& nodes)
{
// 1. Let node be the result of converting nodes into a node given nodes and thiss node document.
auto node = TRY(convert_nodes_to_single_node(nodes, document()));

View file

@ -23,17 +23,17 @@ public:
JS::GCPtr<Element> last_element_child();
u32 child_element_count() const;
ExceptionOr<JS::GCPtr<Element>> query_selector(StringView);
ExceptionOr<JS::NonnullGCPtr<NodeList>> query_selector_all(StringView);
WebIDL::ExceptionOr<JS::GCPtr<Element>> query_selector(StringView);
WebIDL::ExceptionOr<JS::NonnullGCPtr<NodeList>> query_selector_all(StringView);
JS::NonnullGCPtr<HTMLCollection> children();
JS::NonnullGCPtr<HTMLCollection> get_elements_by_tag_name(FlyString const&);
JS::NonnullGCPtr<HTMLCollection> get_elements_by_tag_name_ns(FlyString const&, FlyString const&);
ExceptionOr<void> prepend(Vector<Variant<JS::Handle<Node>, String>> const& nodes);
ExceptionOr<void> append(Vector<Variant<JS::Handle<Node>, String>> const& nodes);
ExceptionOr<void> replace_children(Vector<Variant<JS::Handle<Node>, String>> const& nodes);
WebIDL::ExceptionOr<void> prepend(Vector<Variant<JS::Handle<Node>, String>> const& nodes);
WebIDL::ExceptionOr<void> append(Vector<Variant<JS::Handle<Node>, String>> const& nodes);
WebIDL::ExceptionOr<void> replace_children(Vector<Variant<JS::Handle<Node>, String>> const& nodes);
protected:
ParentNode(JS::Realm& realm, Document& document, NodeType type)

View file

@ -131,7 +131,7 @@ static RelativeBoundaryPointPosition position_of_boundary_point_relative_to_othe
return RelativeBoundaryPointPosition::Before;
}
ExceptionOr<void> Range::set_start_or_end(Node& node, u32 offset, StartOrEnd start_or_end)
WebIDL::ExceptionOr<void> Range::set_start_or_end(Node& node, u32 offset, StartOrEnd start_or_end)
{
// To set the start or end of a range to a boundary point (node, offset), run these steps:
@ -176,20 +176,20 @@ ExceptionOr<void> Range::set_start_or_end(Node& node, u32 offset, StartOrEnd sta
}
// https://dom.spec.whatwg.org/#concept-range-bp-set
ExceptionOr<void> Range::set_start(Node& node, u32 offset)
WebIDL::ExceptionOr<void> Range::set_start(Node& node, u32 offset)
{
// The setStart(node, offset) method steps are to set the start of this to boundary point (node, offset).
return set_start_or_end(node, offset, StartOrEnd::Start);
}
ExceptionOr<void> Range::set_end(Node& node, u32 offset)
WebIDL::ExceptionOr<void> Range::set_end(Node& node, u32 offset)
{
// The setEnd(node, offset) method steps are to set the end of this to boundary point (node, offset).
return set_start_or_end(node, offset, StartOrEnd::End);
}
// https://dom.spec.whatwg.org/#dom-range-setstartbefore
ExceptionOr<void> Range::set_start_before(Node& node)
WebIDL::ExceptionOr<void> Range::set_start_before(Node& node)
{
// 1. Let parent be nodes parent.
auto* parent = node.parent();
@ -203,7 +203,7 @@ ExceptionOr<void> Range::set_start_before(Node& node)
}
// https://dom.spec.whatwg.org/#dom-range-setstartafter
ExceptionOr<void> Range::set_start_after(Node& node)
WebIDL::ExceptionOr<void> Range::set_start_after(Node& node)
{
// 1. Let parent be nodes parent.
auto* parent = node.parent();
@ -217,7 +217,7 @@ ExceptionOr<void> Range::set_start_after(Node& node)
}
// https://dom.spec.whatwg.org/#dom-range-setendbefore
ExceptionOr<void> Range::set_end_before(Node& node)
WebIDL::ExceptionOr<void> Range::set_end_before(Node& node)
{
// 1. Let parent be nodes parent.
auto* parent = node.parent();
@ -231,7 +231,7 @@ ExceptionOr<void> Range::set_end_before(Node& node)
}
// https://dom.spec.whatwg.org/#dom-range-setendafter
ExceptionOr<void> Range::set_end_after(Node& node)
WebIDL::ExceptionOr<void> Range::set_end_after(Node& node)
{
// 1. Let parent be nodes parent.
auto* parent = node.parent();
@ -245,7 +245,7 @@ ExceptionOr<void> Range::set_end_after(Node& node)
}
// https://dom.spec.whatwg.org/#dom-range-compareboundarypoints
ExceptionOr<i16> Range::compare_boundary_points(u16 how, Range const& source_range) const
WebIDL::ExceptionOr<i16> Range::compare_boundary_points(u16 how, Range const& source_range) const
{
// 1. If how is not one of
// - START_TO_START,
@ -332,7 +332,7 @@ ExceptionOr<i16> Range::compare_boundary_points(u16 how, Range const& source_ran
}
// https://dom.spec.whatwg.org/#concept-range-select
ExceptionOr<void> Range::select(Node& node)
WebIDL::ExceptionOr<void> Range::select(Node& node)
{
// 1. Let parent be nodes parent.
auto* parent = node.parent();
@ -356,7 +356,7 @@ ExceptionOr<void> Range::select(Node& node)
}
// https://dom.spec.whatwg.org/#dom-range-selectnode
ExceptionOr<void> Range::select_node(Node& node)
WebIDL::ExceptionOr<void> Range::select_node(Node& node)
{
// The selectNode(node) method steps are to select node within this.
return select(node);
@ -377,7 +377,7 @@ void Range::collapse(bool to_start)
}
// https://dom.spec.whatwg.org/#dom-range-selectnodecontents
ExceptionOr<void> Range::select_node_contents(Node const& node)
WebIDL::ExceptionOr<void> Range::select_node_contents(Node const& node)
{
// 1. If node is a doctype, throw an "InvalidNodeTypeError" DOMException.
if (is<DocumentType>(node))
@ -466,7 +466,7 @@ bool Range::intersects_node(Node const& node) const
}
// https://dom.spec.whatwg.org/#dom-range-ispointinrange
ExceptionOr<bool> Range::is_point_in_range(Node const& node, u32 offset) const
WebIDL::ExceptionOr<bool> Range::is_point_in_range(Node const& node, u32 offset) const
{
// 1. If nodes root is different from thiss root, return false.
if (&node.root() != &root())
@ -491,7 +491,7 @@ ExceptionOr<bool> Range::is_point_in_range(Node const& node, u32 offset) const
}
// https://dom.spec.whatwg.org/#dom-range-comparepoint
ExceptionOr<i16> Range::compare_point(Node const& node, u32 offset) const
WebIDL::ExceptionOr<i16> Range::compare_point(Node const& node, u32 offset) const
{
// 1. If nodes root is different from thiss root, then throw a "WrongDocumentError" DOMException.
if (&node.root() != &root())
@ -549,13 +549,13 @@ String Range::to_string() const
}
// https://dom.spec.whatwg.org/#dom-range-extractcontents
ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::extract_contents()
WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::extract_contents()
{
return extract();
}
// https://dom.spec.whatwg.org/#concept-range-extract
ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::extract()
WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::extract()
{
// 1. Let fragment be a new DocumentFragment node whose node document is ranges start nodes node document.
auto* fragment = heap().allocate<DOM::DocumentFragment>(realm(), const_cast<Document&>(start_container()->document()));
@ -771,13 +771,13 @@ bool Range::partially_contains_node(Node const& node) const
}
// https://dom.spec.whatwg.org/#dom-range-insertnode
ExceptionOr<void> Range::insert_node(JS::NonnullGCPtr<Node> node)
WebIDL::ExceptionOr<void> Range::insert_node(JS::NonnullGCPtr<Node> node)
{
return insert(node);
}
// https://dom.spec.whatwg.org/#concept-range-insert
ExceptionOr<void> Range::insert(JS::NonnullGCPtr<Node> node)
WebIDL::ExceptionOr<void> Range::insert(JS::NonnullGCPtr<Node> node)
{
// 1. If ranges start node is a ProcessingInstruction or Comment node, is a Text node whose parent is null, or is node, then throw a "HierarchyRequestError" DOMException.
if ((is<ProcessingInstruction>(*m_start_container) || is<Comment>(*m_start_container))
@ -844,7 +844,7 @@ ExceptionOr<void> Range::insert(JS::NonnullGCPtr<Node> node)
}
// https://dom.spec.whatwg.org/#dom-range-surroundcontents
ExceptionOr<void> Range::surround_contents(JS::NonnullGCPtr<Node> new_parent)
WebIDL::ExceptionOr<void> Range::surround_contents(JS::NonnullGCPtr<Node> new_parent)
{
// 1. If a non-Text node is partially contained in this, then throw an "InvalidStateError" DOMException.
Node* start_non_text_node = start_container();
@ -878,13 +878,13 @@ ExceptionOr<void> Range::surround_contents(JS::NonnullGCPtr<Node> new_parent)
}
// https://dom.spec.whatwg.org/#dom-range-clonecontents
ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::clone_contents()
WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::clone_contents()
{
return clone_the_contents();
}
// https://dom.spec.whatwg.org/#concept-range-clone
ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::clone_the_contents()
WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::clone_the_contents()
{
// 1. Let fragment be a new DocumentFragment node whose node document is ranges start nodes node document.
auto* fragment = heap().allocate<DOM::DocumentFragment>(realm(), const_cast<Document&>(start_container()->document()));
@ -1040,7 +1040,7 @@ ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::clone_the_contents()
}
// https://dom.spec.whatwg.org/#dom-range-deletecontents
ExceptionOr<void> Range::delete_contents()
WebIDL::ExceptionOr<void> Range::delete_contents()
{
// 1. If this is collapsed, then return.
if (collapsed())

View file

@ -27,15 +27,15 @@ public:
// FIXME: There are a ton of methods missing here.
ExceptionOr<void> set_start(Node& node, u32 offset);
ExceptionOr<void> set_end(Node& node, u32 offset);
ExceptionOr<void> set_start_before(Node& node);
ExceptionOr<void> set_start_after(Node& node);
ExceptionOr<void> set_end_before(Node& node);
ExceptionOr<void> set_end_after(Node& node);
ExceptionOr<void> select_node(Node& node);
WebIDL::ExceptionOr<void> set_start(Node& node, u32 offset);
WebIDL::ExceptionOr<void> set_end(Node& node, u32 offset);
WebIDL::ExceptionOr<void> set_start_before(Node& node);
WebIDL::ExceptionOr<void> set_start_after(Node& node);
WebIDL::ExceptionOr<void> set_end_before(Node& node);
WebIDL::ExceptionOr<void> set_end_after(Node& node);
WebIDL::ExceptionOr<void> select_node(Node& node);
void collapse(bool to_start);
ExceptionOr<void> select_node_contents(Node const&);
WebIDL::ExceptionOr<void> select_node_contents(Node const&);
// https://dom.spec.whatwg.org/#dom-range-start_to_start
enum HowToCompareBoundaryPoints : u16 {
@ -45,7 +45,7 @@ public:
END_TO_START = 3,
};
ExceptionOr<i16> compare_boundary_points(u16 how, Range const& source_range) const;
WebIDL::ExceptionOr<i16> compare_boundary_points(u16 how, Range const& source_range) const;
JS::NonnullGCPtr<Range> inverted() const;
JS::NonnullGCPtr<Range> normalized() const;
@ -61,15 +61,15 @@ public:
}
bool intersects_node(Node const&) const;
ExceptionOr<bool> is_point_in_range(Node const&, u32 offset) const;
ExceptionOr<i16> compare_point(Node const&, u32 offset) const;
WebIDL::ExceptionOr<bool> is_point_in_range(Node const&, u32 offset) const;
WebIDL::ExceptionOr<i16> compare_point(Node const&, u32 offset) const;
ExceptionOr<void> delete_contents();
ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> extract_contents();
ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> clone_contents();
WebIDL::ExceptionOr<void> delete_contents();
WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> extract_contents();
WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> clone_contents();
ExceptionOr<void> insert_node(JS::NonnullGCPtr<Node>);
ExceptionOr<void> surround_contents(JS::NonnullGCPtr<Node> new_parent);
WebIDL::ExceptionOr<void> insert_node(JS::NonnullGCPtr<Node>);
WebIDL::ExceptionOr<void> surround_contents(JS::NonnullGCPtr<Node> new_parent);
String to_string() const;
@ -84,12 +84,12 @@ private:
End,
};
ExceptionOr<void> set_start_or_end(Node& node, u32 offset, StartOrEnd start_or_end);
ExceptionOr<void> select(Node& node);
WebIDL::ExceptionOr<void> set_start_or_end(Node& node, u32 offset, StartOrEnd start_or_end);
WebIDL::ExceptionOr<void> select(Node& node);
ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> extract();
ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> clone_the_contents();
ExceptionOr<void> insert(JS::NonnullGCPtr<Node>);
WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> extract();
WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> clone_the_contents();
WebIDL::ExceptionOr<void> insert(JS::NonnullGCPtr<Node>);
bool contains_node(Node const&) const;
bool partially_contains_node(Node const&) const;

View file

@ -37,7 +37,7 @@ String ShadowRoot::inner_html() const
}
// https://w3c.github.io/DOM-Parsing/#dom-innerhtml-innerhtml
ExceptionOr<void> ShadowRoot::set_inner_html(String const& markup)
WebIDL::ExceptionOr<void> ShadowRoot::set_inner_html(String const& markup)
{
TRY(DOMParsing::inner_html_setter(*this, markup));

View file

@ -29,7 +29,7 @@ public:
String mode() const { return m_closed ? "closed" : "open"; }
String inner_html() const;
ExceptionOr<void> set_inner_html(String const&);
WebIDL::ExceptionOr<void> set_inner_html(String const&);
private:
ShadowRoot(Document&, Element&);

View file

@ -9,8 +9,8 @@
#include <LibWeb/DOM/Attr.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/DocumentType.h>
#include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/DOM/StaticRange.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::DOM {
@ -23,7 +23,7 @@ StaticRange::StaticRange(Node& start_container, u32 start_offset, Node& end_cont
StaticRange::~StaticRange() = default;
// https://dom.spec.whatwg.org/#dom-staticrange-staticrange
ExceptionOr<StaticRange*> StaticRange::create_with_global_object(HTML::Window& window, StaticRangeInit& init)
WebIDL::ExceptionOr<StaticRange*> StaticRange::create_with_global_object(HTML::Window& window, StaticRangeInit& init)
{
// 1. If init["startContainer"] or init["endContainer"] is a DocumentType or Attr node, then throw an "InvalidNodeTypeError" DOMException.
if (is<DocumentType>(*init.start_container) || is<Attr>(*init.start_container))

View file

@ -24,7 +24,7 @@ class StaticRange final : public AbstractRange {
WEB_PLATFORM_OBJECT(StaticRange, JS::Object);
public:
static ExceptionOr<StaticRange*> create_with_global_object(HTML::Window&, StaticRangeInit& init);
static WebIDL::ExceptionOr<StaticRange*> create_with_global_object(HTML::Window&, StaticRangeInit& init);
StaticRange(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset);
virtual ~StaticRange() override;

View file

@ -43,7 +43,7 @@ void Text::set_owner_input_element(Badge<HTML::HTMLInputElement>, HTML::HTMLInpu
// https://dom.spec.whatwg.org/#dom-text-splittext
// https://dom.spec.whatwg.org/#concept-text-split
ExceptionOr<JS::NonnullGCPtr<Text>> Text::split_text(size_t offset)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Text>> Text::split_text(size_t offset)
{
// 1. Let length be nodes length.
auto length = this->length();

View file

@ -29,7 +29,7 @@ public:
void set_owner_input_element(Badge<HTML::HTMLInputElement>, HTML::HTMLInputElement&);
HTML::HTMLInputElement* owner_input_element() { return m_owner_input_element.ptr(); }
ExceptionOr<JS::NonnullGCPtr<Text>> split_text(size_t offset);
WebIDL::ExceptionOr<JS::NonnullGCPtr<Text>> split_text(size_t offset);
protected:
explicit Text(Document&, String const&);