LibWeb/DOM: Set Document's origin in JS constructor

We were missing this spec step, which meant that the created
document had no origin, causing a crash when accessed for same-origin
checks.
This commit is contained in:
Shannon Booth 2025-06-18 14:52:11 +12:00 committed by Jelle Raaijmakers
parent e03c558a0a
commit fc62a05c98
Notes: github-actions[bot] 2025-06-18 06:50:19 +00:00
3 changed files with 11 additions and 3 deletions

View file

@ -424,9 +424,13 @@ WebIDL::ExceptionOr<GC::Ref<Document>> Document::create_and_initialize(Type type
return document;
}
WebIDL::ExceptionOr<GC::Ref<Document>> Document::construct_impl(JS::Realm& realm)
// https://dom.spec.whatwg.org/#dom-document-document
GC::Ref<Document> Document::construct_impl(JS::Realm& realm)
{
return Document::create(realm);
// The new Document() constructor steps are to set thiss origin to the origin of current global objects associated Document. [HTML]
auto document = Document::create(realm);
document->set_origin(as<HTML::Window>(HTML::current_principal_global_object()).associated_document().origin());
return document;
}
GC::Ref<Document> Document::create(JS::Realm& realm, URL::URL const& url)