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> DOMImplementation::create_document(DeprecatedString const& namespace_, DeprecatedString const& qualified_name, JS::GCPtr 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> DOMImplementation::create_docume // https://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument JS::NonnullGCPtr 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 obtain_a_browsing_context_to_use_ } // https://html.spec.whatwg.org/multipage/browsing-the-web.html#initialise-the-document-object -JS::NonnullGCPtr Document::create_and_initialize(Type type, DeprecatedString content_type, HTML::NavigationParams navigation_params) +WebIDL::ExceptionOr> 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::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::create_and_initialize(Type type, Deprecated return document; } -JS::NonnullGCPtr Document::construct_impl(JS::Realm& realm) +WebIDL::ExceptionOr> Document::construct_impl(JS::Realm& realm) { return Document::create(realm); } -JS::NonnullGCPtr Document::create(JS::Realm& realm, AK::URL const& url) +WebIDL::ExceptionOr> Document::create(JS::Realm& realm, AK::URL const& url) { - return realm.heap().allocate(realm, realm, url).release_allocated_value_but_fixme_should_propagate_errors(); + return MUST_OR_THROW_OOM(realm.heap().allocate(realm, realm, url)); } Document::Document(JS::Realm& realm, const AK::URL& url) @@ -2330,7 +2330,7 @@ JS::NonnullGCPtr 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 create_and_initialize(Type, DeprecatedString content_type, HTML::NavigationParams); + static WebIDL::ExceptionOr> create_and_initialize(Type, DeprecatedString content_type, HTML::NavigationParams); - static JS::NonnullGCPtr create(JS::Realm&, AK::URL const& url = "about:blank"sv); - static JS::NonnullGCPtr construct_impl(JS::Realm&); + static WebIDL::ExceptionOr> create(JS::Realm&, AK::URL const& url = "about:blank"sv); + static WebIDL::ExceptionOr> 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::clone_node(Document* document, bool clone_children) else if (is(this)) { // Document auto document_ = verify_cast(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::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 DOMParser::initialize(JS::Realm& realm) JS::NonnullGCPtr 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(relevant_global_object(*this)).associated_document().url()); + auto document = DOM::Document::create(realm(), verify_cast(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> 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());