diff options
author | Kenneth Myhra <kennethmyhra@gmail.com> | 2023-02-14 21:49:02 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-02-18 00:52:47 +0100 |
commit | 0d9076c9f57bb5eba064a803241e9d25843b58f1 (patch) | |
tree | 77a79f34a1ae1665c6fe2421379da0c9002adeee /Userland | |
parent | 552663a2ba934424ce1279cd4959d225a1f287cf (diff) | |
download | serenity-0d9076c9f57bb5eba064a803241e9d25843b58f1.zip |
LibWeb: Make factory methods of DOM::Document fallible
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/DOMImplementation.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Document.cpp | 12 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Document.h | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Node.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/DOMParser.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Loader/FrameLoader.cpp | 11 |
8 files changed, 17 insertions, 24 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/DOMImplementation.cpp b/Userland/Libraries/LibWeb/DOM/DOMImplementation.cpp index d327fd4a8a..5b7ba64eab 100644 --- a/Userland/Libraries/LibWeb/DOM/DOMImplementation.cpp +++ b/Userland/Libraries/LibWeb/DOM/DOMImplementation.cpp @@ -49,7 +49,7 @@ void DOMImplementation::visit_edges(Cell::Visitor& visitor) WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> DOMImplementation::create_document(DeprecatedString const& namespace_, DeprecatedString const& qualified_name, JS::GCPtr<DocumentType> doctype) const { // FIXME: This should specifically be an XML document. - auto xml_document = Document::create(realm()); + auto xml_document = TRY(Document::create(realm())); xml_document->set_ready_for_post_load_tasks(true); @@ -79,7 +79,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> DOMImplementation::create_docume // https://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument JS::NonnullGCPtr<Document> DOMImplementation::create_html_document(DeprecatedString const& title) const { - auto html_document = Document::create(realm()); + auto html_document = Document::create(realm()).release_value_but_fixme_should_propagate_errors(); html_document->set_content_type("text/html"); html_document->set_ready_for_post_load_tasks(true); diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index e7e5a75afe..abb4634664 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -126,7 +126,7 @@ static JS::NonnullGCPtr<HTML::BrowsingContext> obtain_a_browsing_context_to_use_ } // https://html.spec.whatwg.org/multipage/browsing-the-web.html#initialise-the-document-object -JS::NonnullGCPtr<Document> Document::create_and_initialize(Type type, DeprecatedString content_type, HTML::NavigationParams navigation_params) +WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> Document::create_and_initialize(Type type, DeprecatedString content_type, HTML::NavigationParams navigation_params) { // 1. Let browsingContext be the result of the obtaining a browsing context to use for a navigation response // given navigationParams's browsing context, navigationParams's final sandboxing flag set, @@ -230,7 +230,7 @@ JS::NonnullGCPtr<Document> Document::create_and_initialize(Type type, Deprecated // FIXME: and cross-origin opener policy is navigationParams's cross-origin opener policy, // FIXME: load timing info is loadTimingInfo, // and navigation id is navigationParams's id. - auto document = Document::create(window->realm()); + auto document = TRY(Document::create(window->realm())); document->m_type = type; document->m_content_type = move(content_type); document->set_origin(navigation_params.origin); @@ -283,14 +283,14 @@ JS::NonnullGCPtr<Document> Document::create_and_initialize(Type type, Deprecated return document; } -JS::NonnullGCPtr<Document> Document::construct_impl(JS::Realm& realm) +WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> Document::construct_impl(JS::Realm& realm) { return Document::create(realm); } -JS::NonnullGCPtr<Document> Document::create(JS::Realm& realm, AK::URL const& url) +WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> Document::create(JS::Realm& realm, AK::URL const& url) { - return realm.heap().allocate<Document>(realm, realm, url).release_allocated_value_but_fixme_should_propagate_errors(); + return MUST_OR_THROW_OOM(realm.heap().allocate<Document>(realm, realm, url)); } Document::Document(JS::Realm& realm, const AK::URL& url) @@ -2330,7 +2330,7 @@ JS::NonnullGCPtr<DOM::Document> Document::appropriate_template_contents_owner_do // 1. If doc does not yet have an associated inert template document, then: if (!m_associated_inert_template_document) { // 1. Let new doc be a new Document (whose browsing context is null). This is "a Document created by this algorithm" for the purposes of the step above. - auto new_document = DOM::Document::create(realm()); + auto new_document = DOM::Document::create(realm()).release_value_but_fixme_should_propagate_errors(); new_document->m_created_for_appropriate_template_contents = true; // 2. If doc is an HTML document, mark new doc as an HTML document also. diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index bb45b04d1d..c741e62a4f 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -82,10 +82,10 @@ public: HTML }; - static JS::NonnullGCPtr<Document> create_and_initialize(Type, DeprecatedString content_type, HTML::NavigationParams); + static WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> create_and_initialize(Type, DeprecatedString content_type, HTML::NavigationParams); - static JS::NonnullGCPtr<Document> create(JS::Realm&, AK::URL const& url = "about:blank"sv); - static JS::NonnullGCPtr<Document> construct_impl(JS::Realm&); + static WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> create(JS::Realm&, AK::URL const& url = "about:blank"sv); + static WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> construct_impl(JS::Realm&); virtual ~Document() override; // https://w3c.github.io/selection-api/#dom-document-getselection diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index 9ee0a1f330..4ca8818b88 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -730,7 +730,7 @@ JS::NonnullGCPtr<Node> Node::clone_node(Document* document, bool clone_children) else if (is<Document>(this)) { // Document auto document_ = verify_cast<Document>(this); - auto document_copy = Document::create(this->realm(), document_->url()); + auto document_copy = Document::create(this->realm(), document_->url()).release_value_but_fixme_should_propagate_errors(); // Set copy’s encoding, content type, URL, origin, type, and mode to those of node. document_copy->set_encoding(document_->encoding()); diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp index 1493d5f915..16a093186a 100644 --- a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp +++ b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp @@ -168,7 +168,7 @@ JS::NonnullGCPtr<BrowsingContext> BrowsingContext::create_a_new_browsing_context // load timing info is loadTimingInfo, // FIXME: navigation id is null, // and which is ready for post-load tasks. - auto document = DOM::Document::create(window->realm()); + auto document = DOM::Document::create(window->realm()).release_value_but_fixme_should_propagate_errors(); // Non-standard document->set_window({}, *window); diff --git a/Userland/Libraries/LibWeb/HTML/DOMParser.cpp b/Userland/Libraries/LibWeb/HTML/DOMParser.cpp index df7abd5fab..081550de37 100644 --- a/Userland/Libraries/LibWeb/HTML/DOMParser.cpp +++ b/Userland/Libraries/LibWeb/HTML/DOMParser.cpp @@ -37,7 +37,7 @@ JS::ThrowCompletionOr<void> DOMParser::initialize(JS::Realm& realm) JS::NonnullGCPtr<DOM::Document> DOMParser::parse_from_string(DeprecatedString const& string, Bindings::DOMParserSupportedType type) { // 1. Let document be a new Document, whose content type is type and url is this's relevant global object's associated Document's URL. - auto document = DOM::Document::create(realm(), verify_cast<HTML::Window>(relevant_global_object(*this)).associated_document().url()); + auto document = DOM::Document::create(realm(), verify_cast<HTML::Window>(relevant_global_object(*this)).associated_document().url()).release_value_but_fixme_should_propagate_errors(); document->set_content_type(Bindings::idl_enum_to_deprecated_string(type)); // 2. Switch on type: diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp index 8857bd4dd7..9e1c172513 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp @@ -3448,7 +3448,7 @@ DOM::Document& HTMLParser::document() Vector<JS::Handle<DOM::Node>> HTMLParser::parse_html_fragment(DOM::Element& context_element, StringView markup) { // 1. Create a new Document node, and mark it as being an HTML document. - auto temp_document = DOM::Document::create(context_element.realm()); + auto temp_document = DOM::Document::create(context_element.realm()).release_value_but_fixme_should_propagate_errors(); temp_document->set_document_type(DOM::Document::Type::HTML); // 2. If the node document of the context element is in quirks mode, then let the Document be in quirks mode. diff --git a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp index 25d585a646..2ef44a0d3a 100644 --- a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp +++ b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp @@ -313,10 +313,7 @@ void FrameLoader::load_html(StringView html, const AK::URL& url) .reserved_environment = {}, .browsing_context = browsing_context(), }; - auto document = DOM::Document::create_and_initialize( - DOM::Document::Type::HTML, - "text/html", - move(navigation_params)); + auto document = DOM::Document::create_and_initialize(DOM::Document::Type::HTML, "text/html", move(navigation_params)).release_value_but_fixme_should_propagate_errors(); browsing_context().set_active_document(document); auto parser = HTML::HTMLParser::create(document, html, "utf-8"); @@ -413,11 +410,7 @@ void FrameLoader::resource_did_load() .reserved_environment = {}, .browsing_context = browsing_context(), }; - auto document = DOM::Document::create_and_initialize( - DOM::Document::Type::HTML, - "text/html", - move(navigation_params)); - + auto document = DOM::Document::create_and_initialize(DOM::Document::Type::HTML, "text/html", move(navigation_params)).release_value_but_fixme_should_propagate_errors(); document->set_url(url); document->set_encoding(resource()->encoding()); document->set_content_type(resource()->mime_type()); |