diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index c274b06d646..3e9b9d0b5b6 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -424,9 +424,13 @@ WebIDL::ExceptionOr> Document::create_and_initialize(Type type return document; } -WebIDL::ExceptionOr> Document::construct_impl(JS::Realm& realm) +// https://dom.spec.whatwg.org/#dom-document-document +GC::Ref Document::construct_impl(JS::Realm& realm) { - return Document::create(realm); + // The new Document() constructor steps are to set this’s origin to the origin of current global object’s associated Document. [HTML] + auto document = Document::create(realm); + document->set_origin(as(HTML::current_principal_global_object()).associated_document().origin()); + return document; } GC::Ref Document::create(JS::Realm& realm, URL::URL const& url) diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h index c704c5d80f7..b66369eb83a 100644 --- a/Libraries/LibWeb/DOM/Document.h +++ b/Libraries/LibWeb/DOM/Document.h @@ -178,7 +178,7 @@ public: [[nodiscard]] static GC::Ref create(JS::Realm&, URL::URL const& url = URL::about_blank()); [[nodiscard]] static GC::Ref create_for_fragment_parsing(JS::Realm&); - static WebIDL::ExceptionOr> construct_impl(JS::Realm&); + static GC::Ref construct_impl(JS::Realm&); virtual ~Document() override; // AD-HOC: This number increments whenever a node is added or removed from the document, or an element attribute changes. diff --git a/Tests/LibWeb/Crash/DOM/document-constructor-no-origin.html b/Tests/LibWeb/Crash/DOM/document-constructor-no-origin.html new file mode 100644 index 00000000000..8cdce459ced --- /dev/null +++ b/Tests/LibWeb/Crash/DOM/document-constructor-no-origin.html @@ -0,0 +1,4 @@ + +